use of com.predic8.membrane.core.exchange.Exchange in project service-proxy by membrane.
the class SOAPStackTraceFilterTest method doit.
@Test
public void doit() throws XPathExpressionException, Exception {
Exchange exc = new Exchange(null);
exc.setRequest(getRequest());
new SOAPStackTraceFilterInterceptor().handleRequest(exc);
String body = exc.getRequest().getBody().toString();
AssertUtils.assertContainsNot("SECRET", body);
AssertUtils.assertContains("KEEP1", body);
}
use of com.predic8.membrane.core.exchange.Exchange in project service-proxy by membrane.
the class HttpKeepAliveTest method testMaxParameter.
@Test
public void testMaxParameter() throws Exception {
HttpClient client = new HttpClient();
sp1.getInterceptors().add(0, new AbstractInterceptor() {
@Override
public Outcome handleResponse(Exchange exc) throws Exception {
exc.getResponse().getHeader().add(Header.KEEP_ALIVE, "max=2");
return Outcome.CONTINUE;
}
});
assertEquals(200, issueRequest(client));
assertEquals(200, issueRequest(client));
assertEquals(1, set.size());
assertEquals(200, issueRequest(client));
assertEquals(2, set.size());
assertEquals(200, issueRequest(client));
assertEquals(2, set.size());
assertEquals(200, issueRequest(client));
assertEquals(3, set.size());
}
use of com.predic8.membrane.core.exchange.Exchange in project service-proxy by membrane.
the class HttpKeepAliveTest method setUp.
@Before
public void setUp() throws Exception {
set = new HashSet<Integer>();
service1 = new HttpRouter();
sp1 = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 2003), "thomas-bayer.com", 80);
sp1.getInterceptors().add(new AbstractInterceptor() {
@Override
public Outcome handleRequest(Exchange exc) throws Exception {
exc.getRequest().readBody();
exc.setResponse(Response.ok("OK.").build());
set.add(((HttpServerHandler) exc.getHandler()).getSrcOut().hashCode());
return Outcome.RETURN;
}
});
service1.getRuleManager().addProxyAndOpenPortIfNew(sp1);
service1.init();
}
use of com.predic8.membrane.core.exchange.Exchange in project service-proxy by membrane.
the class HttpKeepAliveTest method testTimeoutCustom.
@Test
public void testTimeoutCustom() throws Exception {
HttpClient client = createHttpClient(1000);
sp1.getInterceptors().add(0, new AbstractInterceptor() {
@Override
public Outcome handleResponse(Exchange exc) throws Exception {
exc.getResponse().getHeader().add(Header.KEEP_ALIVE, "timeout=1,max=2");
return Outcome.CONTINUE;
}
});
assertEquals(200, issueRequest(client));
assertEquals(1, set.size());
Thread.sleep(1500);
assertEquals(200, issueRequest(client));
assertEquals(2, set.size());
assertEquals(200, issueRequest(client));
assertEquals(2, set.size());
assertEquals(200, issueRequest(client));
assertEquals(3, set.size());
}
use of com.predic8.membrane.core.exchange.Exchange in project service-proxy by membrane.
the class JSONSchemaValidationTest method validate.
private void validate(String schema, String json, boolean success) throws IOException, Exception {
final StringBuffer sb = new StringBuffer();
FailureHandler fh = new FailureHandler() {
@Override
public void handleFailure(String message, Exchange exc) {
sb.append(message);
sb.append("\n");
}
};
JSONValidator jsonValidator = new JSONValidator(new ResolverMap(), schema, fh);
Request request = new Request.Builder().body(IOUtils.toByteArray(getClass().getResourceAsStream(json))).build();
Exchange exchange = new Exchange(null);
jsonValidator.validateMessage(exchange, request, "request");
if (success)
Assert.assertTrue(sb.toString(), sb.length() == 0);
else
Assert.assertTrue("No error occurred, but expected one.", sb.length() != 0);
}
Aggregations