use of com.predic8.membrane.core.http.Body in project service-proxy by membrane.
the class HttpUtil method createResponse.
public static Response createResponse(int code, String msg, byte[] body, String contentType, String... headers) {
Response res = new Response();
res.setStatusCode(code);
res.setStatusMessage(msg);
res.setHeader(createHeaders(contentType, headers));
if (body != null)
res.setBodyContent(body);
return res;
}
use of com.predic8.membrane.core.http.Body in project service-proxy by membrane.
the class EchoInterceptor method handleRequest.
@Override
public Outcome handleRequest(Exchange exc) throws Exception {
Outcome outcome = exc.echo();
exc.getResponse().getHeader().removeFields(Header.CONTENT_LENGTH);
String body = exc.getRequest().getUri() + "\n" + new String(exc.getRequest().getBody().getContent(), Constants.UTF_8_CHARSET);
exc.getResponse().setBodyContent(body.getBytes(Constants.UTF_8_CHARSET));
return outcome;
}
use of com.predic8.membrane.core.http.Body in project service-proxy by membrane.
the class WsaEndpointRewriterInterceptorTest method testRewriterInterceptor.
@Test
public void testRewriterInterceptor() throws Exception {
exc.setRequest(MessageUtil.getPostRequest("http://localhost:9000/SoapContext/SoapPort?wsdl"));
InputStream input = WsaEndpointRewriterTest.class.getResourceAsStream("/interceptor/ws_addressing/body.xml");
exc.getRequest().setBody(new Body(input));
assertEquals(Outcome.CONTINUE, rewriter.handleRequest(exc));
assertEquals(exc.getProperty("messageId"), "urn:uuid:62a0de08-055a-4da7-aefa-730af9dbc6b6");
}
use of com.predic8.membrane.core.http.Body in project service-proxy by membrane.
the class AdminRESTInterceptor method getBeautifiedBody.
@Mapping("/admin/web/exchanges/(-?\\d+)/(response|request)/body")
public Response getBeautifiedBody(QueryParameter params, String relativeRootPath) throws Exception {
AbstractExchange exc = router.getExchangeStore().getExchangeById(params.getGroupInt(1));
if (exc == null) {
return Response.notFound().build();
}
Message msg = params.getGroup(2).equals("response") ? exc.getResponse() : exc.getRequest();
if (msg == null || msg.isBodyEmpty()) {
return Response.noContent().build();
}
return Response.ok().contentType(MimeType.TEXT_HTML_UTF8).body(TextUtil.formatXML(new InputStreamReader(msg.getBodyAsStreamDecoded(), msg.getCharset()), true)).build();
}
use of com.predic8.membrane.core.http.Body in project service-proxy by membrane.
the class AdminRESTInterceptor method getRequestBody.
@Mapping("/admin/rest/exchanges/(-?\\d+)/(response|request)/body")
public Response getRequestBody(QueryParameter params, String relativeRootPath) throws Exception {
AbstractExchange exc = router.getExchangeStore().getExchangeById(params.getGroupInt(1));
if (exc == null) {
return Response.notFound().build();
}
Message msg = params.getGroup(2).equals("response") ? exc.getResponse() : exc.getRequest();
String ct = params.getGroup(2).equals("response") ? exc.getResponseContentType() : exc.getRequestContentType();
if (msg == null || msg.isBodyEmpty()) {
return Response.noContent().build();
}
ResponseBuilder rb = Response.ok().contentType(ct).body(msg.getBodyAsStream(), false);
String contentEncoding = msg.getHeader().getContentEncoding();
if (contentEncoding != null)
rb.header(Header.CONTENT_ENCODING, contentEncoding);
return rb.build();
}
Aggregations