use of com.predic8.membrane.core.http.Body in project service-proxy by membrane.
the class XMLContentFilterTest method getMessage.
private Message getMessage() {
Message m = new Request();
m.setBody(new Body(DOC.getBytes()));
return m;
}
use of com.predic8.membrane.core.http.Body in project service-proxy by membrane.
the class XSLTInterceptorTest method testXSLTParameter.
@Test
public void testXSLTParameter() throws Exception {
exc = new Exchange(null);
exc.setResponse(Response.ok().body(getClass().getResourceAsStream("/customer.xml"), true).build());
exc.setProperty("XSLT_COMPANY", "predic8");
XSLTInterceptor i = new XSLTInterceptor();
i.setXslt("classpath:/customer2personAddCompany.xsl");
i.init(new HttpRouter());
i.handleResponse(exc);
// printBodyContent();
assertXPath("/person/name/first", "Rick");
assertXPath("/person/name/last", "Cort\u00e9s Ribotta");
assertXPath("/person/address/street", "Calle P\u00fablica \"B\" 5240 Casa 121");
assertXPath("/person/address/city", "Omaha");
assertXPath("/person/company", "predic8");
}
use of com.predic8.membrane.core.http.Body in project service-proxy by membrane.
the class IllegalCharactersInURLTest method doit.
@Test
public void doit() throws Exception {
URIFactory uriFactory = new URIFactory(true);
Response res = new HttpClient().call(new Request.Builder().method("GET").url(uriFactory, "http://localhost:3027/foo{}").body("").buildExchange()).getResponse();
Assert.assertEquals(200, res.getStatusCode());
}
use of com.predic8.membrane.core.http.Body in project service-proxy by membrane.
the class SwaggerRewriterInterceptor method handleResponse.
@Override
public Outcome handleResponse(Exchange exc) throws Exception {
// replacement in swagger.json
if (exc.getRequest().getUri().endsWith(swaggerJson) && exc.getResponseContentType().equalsIgnoreCase(MediaType.APPLICATION_JSON_VALUE)) {
Swagger swagBody = new SwaggerParser().parse(exc.getResponse().getBodyAsStringDecoded());
swagBody.setHost(exc2originalHostPort(exc));
exc.getResponse().setBodyContent(Json.pretty(swagBody).getBytes(exc.getResponse().getCharset()));
}
// replacement in json and javascript (specifically UI)
if (rewriteUI && (exc.getRequest().getUri().matches("/.*.js(on)?") || exc.getResponse().getHeader().getContentType() != null && exc.getResponse().getHeader().getContentType().equals(MediaType.TEXT_HTML_VALUE))) {
String from = "(http(s)?://)" + Pattern.quote(((ServiceProxy) exc.getRule()).getTarget().getHost()) + "(/.*\\.js(on)?)";
String to = "$1" + exc2originalHostPort(exc) + "$3";
byte[] body = exc.getResponse().getBodyAsStringDecoded().replaceAll(from, to).getBytes(exc.getResponse().getCharset());
exc.getResponse().setBodyContent(body);
}
return super.handleResponse(exc);
}
use of com.predic8.membrane.core.http.Body in project service-proxy by membrane.
the class TestServiceInterceptor method handleSOAP12.
private Response handleSOAP12(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.SOAP12_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, false);
}
Aggregations