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