use of com.predic8.membrane.core.Router 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.Router 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();
}
use of com.predic8.membrane.core.Router 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);
}
use of com.predic8.membrane.core.Router in project service-proxy by membrane.
the class Http11Test method setUp.
@Before
public void setUp() throws Exception {
Rule rule = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 4000), "thomas-bayer.com", 80);
router = new HttpRouter();
router.getRuleManager().addProxyAndOpenPortIfNew(rule);
router.init();
}
use of com.predic8.membrane.core.Router in project service-proxy by membrane.
the class ViaProxyTest method setUp.
@Before
public void setUp() throws Exception {
ProxyConfiguration proxy = new ProxyConfiguration();
proxy.setHost("localhost");
proxy.setPort(3128);
proxyRouter = new HttpRouter(proxy);
proxyRouter.getRuleManager().addProxy(new ProxyRule(new ProxyRuleKey(3128)), RuleDefinitionSource.MANUAL);
proxyRouter.init();
router = new HttpRouter();
router.getRuleManager().addProxyAndOpenPortIfNew(new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 4000), "thomas-bayer.com", 80));
router.init();
}
Aggregations