Search in sources :

Example 36 with Exchange

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

the class MessageAnalyserTest method getRequest.

private Exchange getRequest(String path) throws IOException {
    Exchange exc = new Exchange(null);
    Request req = new Request();
    req.create("POST", "http://test", "HTTP/", new Header(), getClass().getClassLoader().getResourceAsStream(path));
    exc.setRequest(req);
    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 37 with Exchange

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

the class MessageAnalyserTest method extractFromResponse.

@Test
public void extractFromResponse() throws Exception {
    Exchange exc = getResponse("messageAnalyser/getBuecherResponseSOAP11.xml");
    analyser.handleResponse(exc);
    Assert.assertEquals("Envelope", exc.getProperty(MessageAnalyser.RESPONSE_ROOT_ELEMENT_NAME));
    Assert.assertEquals(Constants.SOAP11_NS, exc.getProperty(MessageAnalyser.RESPONSE_ROOT_ELEMENT_NS));
    Assert.assertEquals(Constants.SOAP11_VERION, exc.getProperty(MessageAnalyser.RESPONSE_SOAP_VERSION));
    Assert.assertEquals("getBuecher", exc.getProperty(MessageAnalyser.RESPONSE_SOAP_OPERATION));
    Assert.assertEquals("http://predic8.de", exc.getProperty(MessageAnalyser.RESPONSE_SOAP_OPERATION_NS));
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Test(org.junit.Test)

Example 38 with Exchange

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

the class RegExReplaceInterceptorTest method testReplaceBinary.

@Test
public void testReplaceBinary() throws Exception {
    String example = "Hello";
    RegExReplaceInterceptor regexp = new RegExReplaceInterceptor();
    regexp.setRegex(Pattern.quote(example));
    regexp.setReplace("Membrane");
    Exchange exc = new Request.Builder().body(example).header("Content-Type", "text/plain").buildExchange();
    regexp.handleRequest(exc);
    assertTrue(exc.getRequest().getBodyAsStringDecoded().equals("Membrane"));
    exc = new Request.Builder().body(example).header("Content-Type", "application/octet-stream").buildExchange();
    regexp.handleRequest(exc);
    assertTrue(exc.getRequest().getBodyAsStringDecoded().equals(example));
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Request(com.predic8.membrane.core.http.Request) Test(org.junit.Test)

Example 39 with Exchange

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

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

the class WADLInterceptorTest method testDefaultSettings.

@Test
public void testDefaultSettings() throws Exception {
    Exchange exc = getExchange();
    assertEquals(interceptor.handleResponse(exc), Outcome.CONTINUE);
    assertAttribute(exc, "//wadl:resources/@base", "http://thomas-bayer.com:3011/search/V1/");
    assertAttribute(exc, "//wadl:resource/@path", "newsSearch");
    assertAttribute(exc, "//wadl:grammars/wadl:include[1]/@href", "http://thomas-bayer.com:3011/search.xsd");
    assertAttribute(exc, "//wadl:grammars/wadl:include[2]/@href", "http://thomas-bayer.com:3011/error/Error.xsd");
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) 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