use of com.predic8.membrane.core.http.Response in project service-proxy by membrane.
the class TestServiceInterceptor method handleOperation.
private Response handleOperation(Element operation, boolean soap11) {
if (!operation.getNamespaceURI().equals("http://thomas-bayer.com/blz/"))
throw new AssertionError("Unknown operation namespace.");
if (operation.getLocalName().equals("getBank")) {
NodeList children = operation.getChildNodes();
Element param = null;
for (int i = 0; i < children.getLength(); i++) {
if (children.item(i) instanceof Text) {
String text = ((Text) children.item(i)).getNodeValue();
for (int j = 0; j < text.length(); j++) if (!Character.isWhitespace(text.charAt(j)))
throw new AssertionError("Found non-whitespace text.");
continue;
}
if (!(children.item(i) instanceof Element))
throw new AssertionError("Non-element child of <Body> found: " + children.item(i).getNodeName() + ".");
param = (Element) children.item(i);
}
if (param == null)
throw new AssertionError("No parameter child of operation element found.");
if (!param.getNamespaceURI().equals("http://thomas-bayer.com/blz/") || !param.getLocalName().equals("blz"))
throw new AssertionError("Unknown parameter element.");
children = param.getChildNodes();
if (children.getLength() != 1)
throw new AssertionError("Parameter element has children.length != 1");
if (!(children.item(0) instanceof Text))
throw new AssertionError("Parameter element has non-text child.");
Text text = (Text) children.item(0);
String blz = text.getNodeValue();
return getBank(blz, soap11);
} else {
throw new AssertionError("Unknown operation.");
}
}
use of com.predic8.membrane.core.http.Response in project service-proxy by membrane.
the class TestServiceInterceptor method handleSOAP11.
private Response handleSOAP11(Element envelope) {
Element body = null;
NodeList children = envelope.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
if (children.item(i) instanceof Text) {
String text = ((Text) children.item(i)).getNodeValue();
for (int j = 0; j < text.length(); j++) if (!Character.isWhitespace(text.charAt(j)))
throw new AssertionError("Found non-whitespace text.");
continue;
}
if (!(children.item(i) instanceof Element))
throw new AssertionError("Non-element child of <Envelope> found: " + children.item(i).getNodeName() + ".");
Element item = (Element) children.item(i);
if (!item.getNamespaceURI().equals(Constants.SOAP11_NS))
throw new AssertionError("Non-SOAP child element of <Envelope> found.");
if (item.getLocalName().equals("Body"))
body = item;
}
if (body == null)
throw new AssertionError("No SOAP <Body> found.");
children = body.getChildNodes();
Element operation = null;
for (int i = 0; i < children.getLength(); i++) {
if (children.item(i) instanceof Text) {
String text = ((Text) children.item(i)).getNodeValue();
for (int j = 0; j < text.length(); j++) if (!Character.isWhitespace(text.charAt(j)))
throw new AssertionError("Found non-whitespace text.");
continue;
}
if (!(children.item(i) instanceof Element))
throw new AssertionError("Non-element child of <Body> found: " + children.item(i).getNodeName() + ".");
operation = (Element) children.item(i);
}
if (operation == null)
throw new AssertionError("No SOAP <Body> found.");
return handleOperation(operation, true);
}
use of com.predic8.membrane.core.http.Response in project service-proxy by membrane.
the class HTTPSchemaResolver method resolve.
public InputStream resolve(String url) throws ResourceRetrievalException {
try {
Exchange exc = new Request.Builder().method(Request.METHOD_GET).url(uriFactory, url).header(Header.USER_AGENT, Constants.PRODUCT_NAME + " " + Constants.VERSION).buildExchange();
Response response = getHttpClient().call(exc).getResponse();
response.readBody();
if (response.getStatusCode() != 200) {
ResourceRetrievalException rde = new ResourceRetrievalException(url, response.getStatusCode());
throw rde;
}
return new ByteArrayInputStream(ByteUtil.getByteArrayData(response.getBodyAsStreamDecoded()));
} catch (ResourceRetrievalException e) {
throw e;
} catch (Exception e) {
ResourceRetrievalException rre = new ResourceRetrievalException(url, e);
throw rre;
}
}
use of com.predic8.membrane.core.http.Response in project service-proxy by membrane.
the class LBNotificationClient method run.
public void run(String[] args) throws Exception {
CommandLine cl = new DefaultParser().parse(getOptions(), args, false);
if (cl.hasOption('h') || args.length < 2) {
printUsage();
return;
}
parseArguments(cl);
logArguments();
Response res = notifiyClusterManager();
if (res.getStatusCode() != 204) {
throw new Exception("Got StatusCode: " + res.getStatusCode());
}
log.info("Sent " + cmd + " message to " + host + ":" + port + (skeySpec != null ? " encrypted" : ""));
}
use of com.predic8.membrane.core.http.Response in project service-proxy by membrane.
the class DynamicAbstractExchangeSnapshot method addObservers.
public static void addObservers(AbstractExchange exc, AbstractExchangeSnapshot excCopy, Consumer<AbstractExchangeSnapshot> callback) {
MessageObserver obs = new MessageObserver() {
@Override
public void bodyRequested(AbstractBody body) {
}
@Override
public void bodyComplete(AbstractBody body) {
update(callback, excCopy, exc);
}
};
exc.addExchangeViewerListener(new AbstractExchangeViewerListener() {
@Override
public void addResponse(Response response) {
response.addObserver(obs);
}
@Override
public void setExchangeFinished() {
update(callback, excCopy, exc);
}
});
Stream.of(exc.getRequest(), exc.getResponse()).forEach(msg -> {
if (msg == null)
return;
if (msg.containsObserver(obs))
return;
msg.addObserver(obs);
});
update(callback, excCopy, exc);
}
Aggregations