Search in sources :

Example 1 with Message

use of com.predic8.membrane.core.http.Message 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);
    }
}
Also used : AbstractExchangeViewerListener(com.predic8.membrane.core.model.AbstractExchangeViewerListener)

Example 2 with Message

use of com.predic8.membrane.core.http.Message in project service-proxy by membrane.

the class HttpUtil method createSOAPValidationErrorResponse.

public static Response createSOAPValidationErrorResponse(String message) {
    Response response = new Response();
    response.setStatusCode(400);
    response.setStatusMessage("Bad request");
    response.setHeader(createHeaders(MimeType.TEXT_XML_UTF8));
    response.setBodyContent(getFaultSOAPBody(message).getBytes(Constants.UTF_8_CHARSET));
    return response;
}
Also used : Response(com.predic8.membrane.core.http.Response)

Example 3 with Message

use of com.predic8.membrane.core.http.Message in project service-proxy by membrane.

the class Exchange method block.

public void block(Message msg) throws TerminateException {
    try {
        log.debug("Message thread waits");
        msg.wait();
        log.debug("Message thread received notify");
        if (isForcedToStop())
            throw new TerminateException("Force the exchange to stop.");
    } catch (InterruptedException e1) {
        Thread.currentThread().interrupt();
    }
}
Also used : TerminateException(com.predic8.membrane.core.TerminateException)

Example 4 with Message

use of com.predic8.membrane.core.http.Message 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();
}
Also used : Message(com.predic8.membrane.core.http.Message) InputStreamReader(java.io.InputStreamReader) AbstractExchange(com.predic8.membrane.core.exchange.AbstractExchange)

Example 5 with Message

use of com.predic8.membrane.core.http.Message in project service-proxy by membrane.

the class AdminRESTInterceptor method getRequestHeader.

@Mapping("/admin/rest/exchanges/(-?\\d+)/(response|request)/header")
public Response getRequestHeader(QueryParameter params, String relativeRootPath) throws Exception {
    final AbstractExchange exc = router.getExchangeStore().getExchangeById(params.getGroupInt(1));
    if (exc == null) {
        return Response.notFound().build();
    }
    final Message msg = params.getGroup(2).equals("response") ? exc.getResponse() : exc.getRequest();
    if (msg == null) {
        return Response.noContent().build();
    }
    return json(new JSONContent() {

        public void write(JsonGenerator gen) throws Exception {
            gen.writeStartObject();
            gen.writeArrayFieldStart("headers");
            for (HeaderField hf : msg.getHeader().getAllHeaderFields()) {
                gen.writeStartObject();
                gen.writeStringField("name", hf.getHeaderName().toString());
                gen.writeStringField("value", hf.getValue());
                gen.writeEndObject();
            }
            gen.writeEndArray();
            gen.writeEndObject();
        }
    });
}
Also used : Message(com.predic8.membrane.core.http.Message) JSONContent(com.predic8.membrane.core.interceptor.rest.JSONContent) HeaderField(com.predic8.membrane.core.http.HeaderField) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) AbstractExchange(com.predic8.membrane.core.exchange.AbstractExchange) SQLException(java.sql.SQLException) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException) IOException(java.io.IOException)

Aggregations

Message (com.predic8.membrane.core.http.Message)9 Response (com.predic8.membrane.core.http.Response)7 IOException (java.io.IOException)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)5 JsonFactory (com.fasterxml.jackson.core.JsonFactory)4 AbstractExchange (com.predic8.membrane.core.exchange.AbstractExchange)4 Header (com.predic8.membrane.core.http.Header)4 Request (com.predic8.membrane.core.http.Request)4 Exchange (com.predic8.membrane.core.exchange.Exchange)2 Body (com.predic8.membrane.core.http.Body)2 HeaderField (com.predic8.membrane.core.http.HeaderField)2 ResponseBuilder (com.predic8.membrane.core.http.Response.ResponseBuilder)2 AbstractExchangeViewerListener (com.predic8.membrane.core.model.AbstractExchangeViewerListener)2 ResolverMap (com.predic8.membrane.core.resolver.ResolverMap)2 EndOfStreamException (com.predic8.membrane.core.util.EndOfStreamException)2 StringWriter (java.io.StringWriter)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)2 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)1