Search in sources :

Example 11 with Body

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

the class WSDLInterceptorTest method setUp.

@Before
public void setUp() throws Exception {
    exc = new Exchange(new FakeHttpHandler(3011));
    exc.setRequest(MessageUtil.getGetRequest("/axis2/services/BLZService?wsdl"));
    InputStream resourceAsStream = this.getClass().getResourceAsStream("/blz-service.wsdl");
    Response okResponse = Response.ok().contentType("text/xml; charset=utf-8").body(resourceAsStream, true).build();
    exc.setResponse(okResponse);
    exc.setOriginalHostHeader("thomas-bayer.com:80");
    interceptor = new WSDLInterceptor();
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Response(com.predic8.membrane.core.http.Response) InputStream(java.io.InputStream) FakeHttpHandler(com.predic8.membrane.core.transport.http.FakeHttpHandler) Before(org.junit.Before)

Example 12 with Body

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

the class WebSocketStompReassembler method convertToExchange.

private Exchange convertToExchange(WebSocketFrame wsStompFrame) throws IOException, EndOfStreamException {
    byte[] realPayload = new byte[(int) wsStompFrame.getPayloadLength()];
    System.arraycopy(wsStompFrame.getPayload(), 0, realPayload, 0, (int) wsStompFrame.getPayloadLength());
    if (wsStompFrame.getPayloadLength() == 0)
        throw new IOException("Empty STOMP frame.");
    ByteArrayInputStream bais = new ByteArrayInputStream(wsStompFrame.getPayload(), 0, (int) wsStompFrame.getPayloadLength() - 1);
    Request request = new Request();
    if (isHeartBeat(wsStompFrame)) {
        request.setMethod("");
        request.setBody(new Body(bais));
    } else {
        if (wsStompFrame.getPayload()[(int) wsStompFrame.getPayloadLength() - 1] != 0)
            throw new IOException("STOMP frame is not terminated by \\0.");
        request.read(bais, true);
    }
    Exchange result = new Exchange(null);
    result.setRequest(request);
    if (wsStompFrame.getOriginalExchange() != null)
        result.setProperty(Exchange.WS_ORIGINAL_EXCHANGE, wsStompFrame.getOriginalExchange());
    return result;
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) ByteArrayInputStream(java.io.ByteArrayInputStream) Request(com.predic8.membrane.core.http.Request) IOException(java.io.IOException) Body(com.predic8.membrane.core.http.Body)

Example 13 with Body

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

the class LimitedMemoryExchangeStoreTest method getExchange.

private Exchange getExchange(String id) throws IOException {
    Exchange exc = new Exchange(null);
    exc.setProperty("id", id);
    Request req = new Request();
    req.create("GET", "http://test", "HTTP/", new Header(), null);
    exc.setRequest(req);
    exc.setResponse(Response.ok().body("<xml />").build());
    return exc;
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Header(com.predic8.membrane.core.http.Header) Request(com.predic8.membrane.core.http.Request)

Example 14 with Body

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

the class LargeBodyTest method largeChunked.

@Test
public void largeChunked() throws Exception {
    setup();
    long len = Integer.MAX_VALUE + 1l;
    Exchange e = new Request.Builder().post("http://localhost:3041/foo").body(len, new ConstantInputStream(len)).header(TRANSFER_ENCODING, CHUNKED).buildExchange();
    new HttpClient(hcc).call(e);
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) HttpClient(com.predic8.membrane.core.transport.http.HttpClient) Test(org.junit.Test)

Example 15 with Body

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

the class LargeBodyTest method setup.

public void setup() throws Exception {
    // streaming only works for maxRetries = 1
    hcc = new HttpClientConfiguration();
    hcc.setMaxRetries(1);
    Rule rule = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 3040), "thomas-bayer.com", 80);
    rule.getInterceptors().add(new AbstractInterceptor() {

        @Override
        public Outcome handleRequest(Exchange exc) throws Exception {
            exc.setResponse(Response.ok().body("").build());
            return Outcome.RETURN;
        }
    });
    router = new HttpRouter();
    ((HTTPClientInterceptor) router.getTransport().getInterceptors().get(3)).setHttpClientConfig(hcc);
    router.getRuleManager().addProxyAndOpenPortIfNew(rule);
    router.init();
    Rule rule1 = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 3041), "localhost", 3040);
    router2 = new HttpRouter();
    ((HTTPClientInterceptor) router2.getTransport().getInterceptors().get(3)).setHttpClientConfig(hcc);
    router2.getRuleManager().addProxyAndOpenPortIfNew(rule1);
    router2.init();
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) HTTPClientInterceptor(com.predic8.membrane.core.interceptor.HTTPClientInterceptor) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) Outcome(com.predic8.membrane.core.interceptor.Outcome) AbstractInterceptor(com.predic8.membrane.core.interceptor.AbstractInterceptor) Rule(com.predic8.membrane.core.rules.Rule) HttpRouter(com.predic8.membrane.core.HttpRouter) HttpClientConfiguration(com.predic8.membrane.core.transport.http.client.HttpClientConfiguration) IOException(java.io.IOException)

Aggregations

Exchange (com.predic8.membrane.core.exchange.Exchange)30 IOException (java.io.IOException)17 Response (com.predic8.membrane.core.http.Response)15 Request (com.predic8.membrane.core.http.Request)12 AbstractExchange (com.predic8.membrane.core.exchange.AbstractExchange)10 Test (org.junit.Test)10 CacheBuilder (com.google.common.cache.CacheBuilder)8 MCElement (com.predic8.membrane.annot.MCElement)6 Body (com.predic8.membrane.core.http.Body)6 HttpClient (com.predic8.membrane.core.transport.http.HttpClient)6 UnknownHostException (java.net.UnknownHostException)6 Message (com.predic8.membrane.core.http.Message)5 ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)5 InputStream (java.io.InputStream)5 JsonFactory (com.fasterxml.jackson.core.JsonFactory)4 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)4 HttpRouter (com.predic8.membrane.core.HttpRouter)4 AbstractExchangeSnapshot (com.predic8.membrane.core.exchange.snapshots.AbstractExchangeSnapshot)4 DynamicAbstractExchangeSnapshot (com.predic8.membrane.core.exchange.snapshots.DynamicAbstractExchangeSnapshot)4 Header (com.predic8.membrane.core.http.Header)4