use of com.predic8.membrane.core.http.Body 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.Body in project service-proxy by membrane.
the class XOPReconstitutor method getReconstitutedMessage.
/**
* @return reassembled SOAP message or null if message is not SOAP or not multipart
*/
public Message getReconstitutedMessage(Message message) throws ParseException, MalformedStreamException, IOException, EndOfStreamException, XMLStreamException, FactoryConfigurationError {
ContentType contentType = message.getHeader().getContentTypeObject();
if (contentType == null || contentType.getPrimaryType() == null)
return null;
if (!contentType.getPrimaryType().equals("multipart") || !contentType.getSubType().equals("related"))
return null;
String type = contentType.getParameter("type");
if (!"application/xop+xml".equals(type))
return null;
String start = contentType.getParameter("start");
if (start == null)
return null;
String boundary = contentType.getParameter("boundary");
if (boundary == null)
return null;
HashMap<String, Part> parts = split(message, boundary);
Part startPart = parts.get(start);
if (startPart == null)
return null;
ContentType innerContentType = new ContentType(startPart.getHeader().getContentType());
if (!innerContentType.getPrimaryType().equals("application") || !innerContentType.getSubType().equals("xop+xml"))
return null;
byte[] body = fillInXOPParts(startPart.getInputStream(), parts);
Message m = new Message() {
@Override
protected void parseStartLine(InputStream in) throws IOException, EndOfStreamException {
throw new RuntimeException("not implemented.");
}
@Override
public String getStartLine() {
throw new RuntimeException("not implemented.");
}
@Override
public <T extends Message> T createSnapshot() {
throw new RuntimeException("not implemented.");
}
};
m.setBodyContent(body);
String reconstitutedContentType = innerContentType.getParameter("type");
if (reconstitutedContentType != null)
m.getHeader().add(Header.CONTENT_TYPE, reconstitutedContentType);
return m;
}
use of com.predic8.membrane.core.http.Body in project service-proxy by membrane.
the class SOAPStackTraceFilterTest method doit.
@Test
public void doit() throws XPathExpressionException, Exception {
Exchange exc = new Exchange(null);
exc.setRequest(getRequest());
new SOAPStackTraceFilterInterceptor().handleRequest(exc);
String body = exc.getRequest().getBody().toString();
AssertUtils.assertContainsNot("SECRET", body);
AssertUtils.assertContains("KEEP1", body);
}
use of com.predic8.membrane.core.http.Body in project service-proxy by membrane.
the class SOAPStackTraceFilterTest method getRequest.
private Request getRequest() throws IOException {
Request r = new Request();
r.setBody(new Body(getClass().getResourceAsStream("/xml/soap-stack-trace.xml")));
return r;
}
use of com.predic8.membrane.core.http.Body in project service-proxy by membrane.
the class JSONSchemaValidationTest method validate.
private void validate(String schema, String json, boolean success) throws IOException, Exception {
final StringBuffer sb = new StringBuffer();
FailureHandler fh = new FailureHandler() {
@Override
public void handleFailure(String message, Exchange exc) {
sb.append(message);
sb.append("\n");
}
};
JSONValidator jsonValidator = new JSONValidator(new ResolverMap(), schema, fh);
Request request = new Request.Builder().body(IOUtils.toByteArray(getClass().getResourceAsStream(json))).build();
Exchange exchange = new Exchange(null);
jsonValidator.validateMessage(exchange, request, "request");
if (success)
Assert.assertTrue(sb.toString(), sb.length() == 0);
else
Assert.assertTrue("No error occurred, but expected one.", sb.length() != 0);
}
Aggregations