use of com.predic8.membrane.core.exchange.Exchange in project service-proxy by membrane.
the class WSDLInterceptor method createExchange.
private Exchange createExchange(String uri) throws MalformedURLException {
URL url = new URL(uri);
Request req = MessageUtil.getGetRequest(getCompletePath(url));
req.getHeader().setHost(url.getHost());
Exchange exc = new Exchange(null);
exc.setRequest(req);
exc.getDestinations().add(uri);
return exc;
}
use of com.predic8.membrane.core.exchange.Exchange in project service-proxy by membrane.
the class WSDLInterceptor method rewrite.
@Override
protected void rewrite(Exchange exc) throws Exception, IOException {
log.debug("Changing endpoint address in WSDL");
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Relocator relocator = new Relocator(new OutputStreamWriter(stream, exc.getResponse().getCharset()), getLocationProtocol(), getLocationHost(exc), getLocationPort(exc), pathRewriter);
if (rewriteEndpoint) {
relocator.getRelocatingAttributes().put(new QName(WSDL_SOAP11_NS, "address"), "location");
relocator.getRelocatingAttributes().put(new QName(WSDL_SOAP12_NS, "address"), "location");
relocator.getRelocatingAttributes().put(new QName(WSDL_HTTP_NS, "address"), "location");
}
relocator.getRelocatingAttributes().put(new QName(XSD_NS, "import"), "schemaLocation");
relocator.getRelocatingAttributes().put(new QName(XSD_NS, "include"), "schemaLocation");
relocator.relocate(new InputStreamReader(exc.getResponse().getBodyAsStreamDecoded(), exc.getResponse().getCharset()));
if (relocator.isWsdlFound()) {
registerWSDL(exc);
}
exc.getResponse().setBodyContent(stream.toByteArray());
}
use of com.predic8.membrane.core.exchange.Exchange in project service-proxy by membrane.
the class LimitedMemoryExchangeStore method oldSnap.
private void oldSnap(AbstractExchange exc, Flow flow) {
// TODO: [fix me] support multi-snap
// TODO: [fix me] snap message headers and request *here*, not in observer/response
exc.addExchangeViewerListener(new AbstractExchangeViewerListener() {
@Override
public void setExchangeFinished() {
inflight.remove(exc);
}
});
if (flow == Flow.REQUEST) {
exc.getRequest().addObserver(new MessageObserver() {
@Override
public void bodyRequested(AbstractBody body) {
}
@Override
public void bodyComplete(AbstractBody body) {
Response r = exc.getResponse();
if (r != null) {
AbstractBody b = r.getBody();
if (b != null && b.isRead())
// request-bodyComplete might occur after response-bodyComplete
return;
}
// System.out.println("Exchange put inflight " + exc.hashCode() + " " + exc.getRequest().getStartLine());
inflight.put(exc, exc.getRequest());
modify();
}
});
return;
}
try {
Message m = exc.getResponse();
if (m != null)
m.addObserver(new MessageObserver() {
public void bodyRequested(AbstractBody body) {
}
public void bodyComplete(AbstractBody body) {
snapInternal(exc, flow);
inflight.remove(exc);
modify();
// System.out.println("Exchange remove inflight " + exc.hashCode());
}
});
else {
inflight.remove(exc);
modify();
// System.out.println("Exchange remove inflight " + exc.hashCode() + " (2)");
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of com.predic8.membrane.core.exchange.Exchange in project service-proxy by membrane.
the class LimitedMemoryExchangeStore method getAllExchangesAsList.
public synchronized List<AbstractExchange> getAllExchangesAsList() {
List<AbstractExchange> ret = new LinkedList<AbstractExchange>();
for (Map.Entry<AbstractExchange, Request> entry : inflight.entrySet()) {
AbstractExchange ex = entry.getKey();
Request req = entry.getValue();
Exchange newEx = new Exchange(null);
newEx.setId(ex.getId());
newEx.setRequest(req);
newEx.setRule(ex.getRule());
newEx.setRemoteAddr(ex.getRemoteAddr());
newEx.setTime(ex.getTime());
newEx.setTimeReqSent(ex.getTimeReqSent() != 0 ? ex.getTimeReqSent() : ex.getTimeReqReceived());
newEx.setTimeResReceived(System.currentTimeMillis());
ret.add(newEx);
}
ret.addAll(exchanges);
return ret;
}
use of com.predic8.membrane.core.exchange.Exchange in project service-proxy by membrane.
the class IndexInterceptor method getServiceInfo.
private ServiceInfo getServiceInfo(Exchange exc, AbstractServiceProxy sp) {
if (sp.getInterceptors().size() == 1 && sp.getInterceptors().get(0) instanceof IndexInterceptor)
return null;
ServiceProxyKey k = (ServiceProxyKey) sp.getKey();
ServiceInfo ri = new ServiceInfo();
ri.method = k.getMethod();
// NOTE: when running as servlet, we have no idea what the protocol was
ri.ssl = sp.getSslInboundContext() != null;
String protocol = ri.ssl ? "https" : "http";
String host = k.isHostWildcard() ? new HostColonPort(ri.ssl, exc.getRequest().getHeader().getHost()).host : fullfillRegexp(ServiceProxyKey.createHostPattern(k.getHost()));
if (host == null || host.length() == 0)
host = exc.getHandler().getLocalAddress().getHostAddress().toString();
int port = k.getPort();
if (port == -1 || !exc.getHandler().isMatchLocalPort())
port = exc.getHandler().getLocalPort();
String path;
if (!k.isUsePathPattern()) {
path = "/";
} else if (k.isPathRegExp()) {
path = fullfillRegexp(k.getPath());
} else {
path = "/" + StringUtils.removeStart(k.getPath(), "/");
}
if (!"".equals(exc.getHandler().getContextPath(exc))) {
path = StringUtils.removeEnd(exc.getHandler().getContextPath(exc), "/") + "/" + StringUtils.removeStart(path, "/");
}
ri.name = sp.getName();
if (path != null)
ri.url = protocol + "://" + host + ":" + port + path;
ri.host = k.isHostWildcard() ? "" : StringEscapeUtils.escapeHtml(k.getHost());
ri.port = k.getPort() == -1 ? "" : "" + k.getPort();
ri.path = k.isUsePathPattern() ? "<tt>" + StringEscapeUtils.escapeHtml(k.getPath()) + "</tt>" + (k.isPathRegExp() ? " (regex)" : "") : "";
return ri;
}
Aggregations