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;
}
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);
}
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;
}
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");
}
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);
}
Aggregations