Search in sources :

Example 76 with Exchange

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

the class XSLTInterceptorTest method testRequest.

@Test
public void testRequest() throws Exception {
    exc = new Exchange(null);
    exc.setResponse(Response.ok().body(getClass().getResourceAsStream("/customer.xml"), true).build());
    XSLTInterceptor i = new XSLTInterceptor();
    i.setXslt("classpath:/customer2person.xsl");
    i.init(new HttpRouter());
    i.handleResponse(exc);
    // printBodyContent();
    assertXPath("/person/name/first", "Rick");
    assertXPath("/person/name/last", "Cort\u00e9s Ribotta");
    assertXPath("/person/address/street", "Calle P\u00fablica \"B\" 5240 Casa 121");
    assertXPath("/person/address/city", "Omaha");
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) HttpRouter(com.predic8.membrane.core.HttpRouter) Test(org.junit.Test)

Example 77 with Exchange

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

the class SOAPFaultTest method createFaultExchange.

private Exchange createFaultExchange() {
    Exchange exc = new Exchange(null);
    exc.setResponse(HttpUtil.createSOAPValidationErrorResponse("secret"));
    return exc;
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange)

Example 78 with Exchange

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

the class SOAPFaultTest method getExchangeCP.

private Exchange getExchangeCP(String path) throws IOException {
    Exchange exc = new Exchange(null);
    exc.setResponse(Response.ok().contentType("text/xml").body(getClass().getClassLoader().getResourceAsStream(path), true).build());
    return exc;
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange)

Example 79 with Exchange

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

the class SOAPFaultTest method testSkipFault2.

@Test
public void testSkipFault2() throws Exception {
    ValidatorInterceptor i = createValidatorInterceptor(true);
    Exchange exc = getExchangeCP("wsdlValidator/soapFaultCustom.xml");
    assertEquals(Outcome.CONTINUE, i.handleResponse(exc));
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Test(org.junit.Test)

Example 80 with Exchange

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

the class ProxySSLTest method test.

@Test
public void test() throws Exception {
    // Step 1: create the backend
    Router backend = new Router();
    backend.setHotDeploy(false);
    ServiceProxy sp = new ServiceProxy(new ServiceProxyKey(backendPort), null, 0);
    if (backendUsesSSL) {
        SSLParser ssl = new SSLParser();
        ssl.setKeyStore(new KeyStore());
        ssl.getKeyStore().setLocation("classpath:/ssl-rsa.keystore");
        ssl.getKeyStore().setKeyPassword("secret");
        sp.setSslInboundParser(ssl);
    }
    sp.getInterceptors().add(new CountInterceptor());
    backend.getRuleManager().addProxy(sp, RuleManager.RuleDefinitionSource.MANUAL);
    backend.start();
    // Step 2: put a proxy in front of it
    AtomicInteger proxyCounter = new AtomicInteger();
    Router proxyRouter = new Router();
    proxyRouter.setHotDeploy(false);
    ProxyRule proxy = new ProxyRule(new ProxyRuleKey(proxyPort));
    proxy.getInterceptors().add(new AbstractInterceptor() {

        @Override
        public Outcome handleRequest(Exchange exc) throws Exception {
            proxyCounter.incrementAndGet();
            return super.handleRequest(exc);
        }
    });
    if (proxyUsesSSL) {
        SSLParser ssl = new SSLParser();
        ssl.setKeyStore(new KeyStore());
        ssl.getKeyStore().setLocation("classpath:/ssl-rsa2.keystore");
        ssl.getKeyStore().setKeyPassword("secret");
        proxy.setSslInboundParser(ssl);
    }
    proxyRouter.getRuleManager().addProxy(proxy, RuleManager.RuleDefinitionSource.MANUAL);
    proxyRouter.start();
    // Step 3: configure the client to access the backend through the proxy
    HttpClientConfiguration httpClientConfiguration = new HttpClientConfiguration();
    ProxyConfiguration proxyConfiguration = new ProxyConfiguration();
    proxyConfiguration.setHost("localhost");
    proxyConfiguration.setPort(proxyPort);
    if (proxyUsesSSL) {
        SSLParser ssl = new SSLParser();
        ssl.setTrustStore(new TrustStore());
        ssl.getTrustStore().setLocation("classpath:/ssl-rsa-pub2.keystore");
        ssl.getTrustStore().setPassword("secret");
        // workarond the fact that the certificate was not issued for 'localhost'
        ssl.setEndpointIdentificationAlgorithm("");
        proxyConfiguration.setSslParser(ssl);
    }
    httpClientConfiguration.setProxy(proxyConfiguration);
    HttpClient hc = new HttpClient(httpClientConfiguration);
    // Step 4: Test client
    Exchange exc = new Request.Builder().get("http" + (backendUsesSSL ? "s" : "") + "://localhost:" + backendPort + "/foo").buildExchange();
    if (backendUsesSSL) {
        SSLParser ssl = new SSLParser();
        ssl.setTrustStore(new TrustStore());
        ssl.getTrustStore().setLocation("classpath:/ssl-rsa-pub.keystore");
        ssl.getTrustStore().setPassword("secret");
        // workarond the fact that the certificate was not issued for 'localhost'
        ssl.setEndpointIdentificationAlgorithm("");
        exc.setProperty(Exchange.SSL_CONTEXT, new StaticSSLContext(ssl, new ResolverMap(), null));
    }
    hc.call(exc);
    Assert.assertEquals(200, exc.getResponse().getStatusCode());
    Assert.assertEquals("Did the request go through the proxy?", 1, proxyCounter.get());
    proxyRouter.shutdown();
    backend.shutdown();
}
Also used : CountInterceptor(com.predic8.membrane.core.interceptor.CountInterceptor) AbstractInterceptor(com.predic8.membrane.core.interceptor.AbstractInterceptor) StaticSSLContext(com.predic8.membrane.core.transport.ssl.StaticSSLContext) Router(com.predic8.membrane.core.Router) ResolverMap(com.predic8.membrane.core.resolver.ResolverMap) TrustStore(com.predic8.membrane.core.config.security.TrustStore) KeyStore(com.predic8.membrane.core.config.security.KeyStore) SSLParser(com.predic8.membrane.core.config.security.SSLParser) Exchange(com.predic8.membrane.core.exchange.Exchange) ProxyConfiguration(com.predic8.membrane.core.transport.http.client.ProxyConfiguration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Outcome(com.predic8.membrane.core.interceptor.Outcome) HttpClient(com.predic8.membrane.core.transport.http.HttpClient) HttpClientConfiguration(com.predic8.membrane.core.transport.http.client.HttpClientConfiguration) 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