Search in sources :

Example 6 with HttpRouter

use of com.predic8.membrane.core.HttpRouter 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();
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) Outcome(com.predic8.membrane.core.interceptor.Outcome) AbstractInterceptor(com.predic8.membrane.core.interceptor.AbstractInterceptor) HttpRouter(com.predic8.membrane.core.HttpRouter) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) Before(org.junit.Before)

Example 7 with HttpRouter

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

the class RewriteInterceptorTest method setUp.

@Before
public void setUp() throws Exception {
    HttpRouter router = new HttpRouter();
    di = new DispatchingInterceptor();
    di.init(router);
    sp = new ServiceProxy(new ServiceProxyKey(80, null), "www.predic8.de", 80);
    sp.init(router);
    exc = new Exchange(null);
    exc.setRequest(MessageUtil.getGetRequest("/buy/banana/3"));
    rewriter = new RewriteInterceptor();
    List<Mapping> mappings = new ArrayList<Mapping>();
    mappings.add(new Mapping("/buy/(.*)/(.*)", "/buy?item=$1&amount=$2", null));
    rewriter.setMappings(mappings);
    rewriter.init(router);
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) ArrayList(java.util.ArrayList) Mapping(com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor.Mapping) HttpRouter(com.predic8.membrane.core.HttpRouter) DispatchingInterceptor(com.predic8.membrane.core.interceptor.DispatchingInterceptor) Before(org.junit.Before)

Example 8 with HttpRouter

use of com.predic8.membrane.core.HttpRouter 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 9 with HttpRouter

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

the class OAuth2ResourceTest method testUseRefreshTokenOnTokenExpiration.

// this test also implicitly tests concurrency on oauth2resource
@Test
public void testUseRefreshTokenOnTokenExpiration() throws Exception {
    HttpRouter mockAuthServer = new HttpRouter();
    mockAuthServer.getRuleManager().addProxyAndOpenPortIfNew(getMockAuthServiceProxy());
    mockAuthServer.init();
    HttpRouter oauth2Resource = new HttpRouter();
    oauth2Resource.getRuleManager().addProxyAndOpenPortIfNew(getConfiguredOAuth2Resource());
    oauth2Resource.init();
    HttpClient httpClient = new HttpClient();
    Exchange excCallResource = new Request.Builder().get(getClientAddress()).buildExchange();
    excCallResource = httpClient.call(excCallResource);
    String cookie = excCallResource.getResponse().getHeader().getFirstValue("Set-Cookie");
    Exchange excFollowRedirectToAuth = new Request.Builder().header("Cookie", cookie).get(excCallResource.getResponse().getHeader().getFirstValue("Location")).buildExchange();
    excFollowRedirectToAuth = httpClient.call(excFollowRedirectToAuth);
    Exchange excFollowRedirectToClient = new Request.Builder().header("Cookie", cookie).get(excFollowRedirectToAuth.getResponse().getHeader().getFirstValue("Location")).buildExchange();
    excFollowRedirectToClient = httpClient.call(excFollowRedirectToClient);
    Set<String> accessTokens = new HashSet<>();
    int limit = 1000;
    List<Thread> threadList = new ArrayList<>();
    CountDownLatch cdl = new CountDownLatch(limit);
    for (int i = 0; i < limit; i++) {
        threadList.add(new Thread(() -> {
            try {
                cdl.countDown();
                cdl.await();
                Exchange excCallResource2 = new Request.Builder().get(getClientAddress()).header("Cookie", cookie).buildExchange();
                excCallResource2 = httpClient.call(excCallResource2);
                synchronized (accessTokens) {
                    accessTokens.add(excCallResource2.getResponse().getBodyAsStringDecoded());
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }));
    }
    threadList.forEach(thread -> thread.start());
    threadList.forEach(thread -> {
        try {
            thread.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    });
    assertTrue(accessTokens.size() == limit);
}
Also used : Request(com.predic8.membrane.core.http.Request) CountDownLatch(java.util.concurrent.CountDownLatch) IOException(java.io.IOException) Exchange(com.predic8.membrane.core.exchange.Exchange) HttpClient(com.predic8.membrane.core.transport.http.HttpClient) HttpRouter(com.predic8.membrane.core.HttpRouter) Test(org.junit.Test)

Example 10 with HttpRouter

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

the class RESTBLZServiceIntegrationTest method setUp.

@Before
public void setUp() throws Exception {
    Rule rule = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 3005), "thomas-bayer.com", 80);
    router = new HttpRouter();
    router.getRuleManager().addProxyAndOpenPortIfNew(rule);
    HTTP2XMLInterceptor http2xml = new HTTP2XMLInterceptor();
    router.getTransport().getInterceptors().add(http2xml);
    RewriteInterceptor urlRewriter = new RewriteInterceptor();
    List<Mapping> mappings = new ArrayList<Mapping>();
    mappings.add(new Mapping("/bank/.*", "/axis2/services/BLZService", null));
    urlRewriter.setMappings(mappings);
    router.getTransport().getInterceptors().add(urlRewriter);
    XSLTInterceptor xslt = new XSLTInterceptor();
    xslt.setXslt("classpath:/blz-httpget2soap-request.xsl");
    xslt.setFlow(Flow.Set.REQUEST);
    xslt.setXslt("classpath:/strip-soap-envelope.xsl");
    xslt.setFlow(Flow.Set.RESPONSE);
    router.getTransport().getInterceptors().add(xslt);
}
Also used : Mapping(com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor.Mapping) Rule(com.predic8.membrane.core.rules.Rule) HttpRouter(com.predic8.membrane.core.HttpRouter) XSLTInterceptor(com.predic8.membrane.core.interceptor.xslt.XSLTInterceptor)

Aggregations

HttpRouter (com.predic8.membrane.core.HttpRouter)38 ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)24 ServiceProxyKey (com.predic8.membrane.core.rules.ServiceProxyKey)23 Before (org.junit.Before)19 Exchange (com.predic8.membrane.core.exchange.Exchange)14 Rule (com.predic8.membrane.core.rules.Rule)11 AbstractInterceptor (com.predic8.membrane.core.interceptor.AbstractInterceptor)8 Outcome (com.predic8.membrane.core.interceptor.Outcome)8 IOException (java.io.IOException)7 Test (org.junit.Test)6 Mapping (com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor.Mapping)3 DummyWebServiceInterceptor (com.predic8.membrane.core.services.DummyWebServiceInterceptor)3 Request (com.predic8.membrane.core.http.Request)2 RoundRobinStrategy (com.predic8.membrane.core.interceptor.balancer.RoundRobinStrategy)2 ProxyRule (com.predic8.membrane.core.rules.ProxyRule)2 ProxyRuleKey (com.predic8.membrane.core.rules.ProxyRuleKey)2 URISyntaxException (java.net.URISyntaxException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 AbstractExchange (com.predic8.membrane.core.exchange.AbstractExchange)1 MemoryExchangeStore (com.predic8.membrane.core.exchangestore.MemoryExchangeStore)1