Search in sources :

Example 41 with Exchange

use of com.predic8.membrane.core.exchange.Exchange 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 42 with Exchange

use of com.predic8.membrane.core.exchange.Exchange in project service-proxy by membrane.

the class WebSocketStompReassembler method handleFrame.

@Override
public void handleFrame(WebSocketFrame wsStompFrame, boolean frameTravelsToRight, WebSocketSender sender) throws Exception {
    if (wsStompFrame.getOpcode() != 1) {
        sender.handleFrame(wsStompFrame);
        return;
    }
    Exchange exc = convertToExchange(wsStompFrame);
    // if (frameTravelsToRight) {
    if (true) {
        for (int i = 0; i < interceptors.size(); i++) if (interceptors.get(i).handleRequest(exc) != Outcome.CONTINUE)
            return;
    } else {
        for (int i = interceptors.size(); i >= 0; i--) // return;
        break;
    }
    modifyOriginalFrameWithExchange(wsStompFrame, exc);
    sender.handleFrame(wsStompFrame);
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange)

Example 43 with Exchange

use of com.predic8.membrane.core.exchange.Exchange 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 44 with Exchange

use of com.predic8.membrane.core.exchange.Exchange in project service-proxy by membrane.

the class LimitedMemoryExchangeStoreTest method testStore.

@Test
public void testStore() throws Exception {
    store.setMaxSize(500000);
    store.snap(getExchange("0"), Flow.RESPONSE);
    Exchange exc = getExchange("1");
    store.snap(exc, Flow.RESPONSE);
    Assert.assertEquals(2, store.getAllExchangesAsList().size());
    assertStore(0, "0");
    assertStore(1, "1");
    store.setMaxSize(store.getCurrentSize() + 1);
    store.snap(getExchange("2"), Flow.RESPONSE);
    Assert.assertEquals(2, store.getAllExchangesAsList().size());
    assertStore(0, "1");
    assertStore(1, "2");
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Test(org.junit.Test)

Example 45 with Exchange

use of com.predic8.membrane.core.exchange.Exchange 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)

Aggregations

Exchange (com.predic8.membrane.core.exchange.Exchange)107 Test (org.junit.Test)39 IOException (java.io.IOException)32 Request (com.predic8.membrane.core.http.Request)25 Outcome (com.predic8.membrane.core.interceptor.Outcome)24 Response (com.predic8.membrane.core.http.Response)16 AbstractInterceptor (com.predic8.membrane.core.interceptor.AbstractInterceptor)16 ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)16 HttpRouter (com.predic8.membrane.core.HttpRouter)14 Before (org.junit.Before)13 ServiceProxyKey (com.predic8.membrane.core.rules.ServiceProxyKey)12 AbstractExchange (com.predic8.membrane.core.exchange.AbstractExchange)11 Header (com.predic8.membrane.core.http.Header)10 HttpClient (com.predic8.membrane.core.transport.http.HttpClient)10 CacheBuilder (com.google.common.cache.CacheBuilder)9 Rule (com.predic8.membrane.core.rules.Rule)6 URISyntaxException (java.net.URISyntaxException)6 UnknownHostException (java.net.UnknownHostException)6 ArrayList (java.util.ArrayList)6 Session (com.predic8.membrane.core.interceptor.authentication.session.SessionManager.Session)5