use of com.predic8.membrane.core.transport.http.client.HttpClientConfiguration in project service-proxy by membrane.
the class LargeBodyTest method setup.
public void setup() throws Exception {
// streaming only works for maxRetries = 1
hcc = new HttpClientConfiguration();
hcc.setMaxRetries(1);
Rule rule = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 3040), "thomas-bayer.com", 80);
rule.getInterceptors().add(new AbstractInterceptor() {
@Override
public Outcome handleRequest(Exchange exc) throws Exception {
exc.setResponse(Response.ok().body("").build());
return Outcome.RETURN;
}
});
router = new HttpRouter();
((HTTPClientInterceptor) router.getTransport().getInterceptors().get(3)).setHttpClientConfig(hcc);
router.getRuleManager().addProxyAndOpenPortIfNew(rule);
router.init();
Rule rule1 = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 3041), "localhost", 3040);
router2 = new HttpRouter();
((HTTPClientInterceptor) router2.getTransport().getInterceptors().get(3)).setHttpClientConfig(hcc);
router2.getRuleManager().addProxyAndOpenPortIfNew(rule1);
router2.init();
}
use of com.predic8.membrane.core.transport.http.client.HttpClientConfiguration 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.transport.http.client.HttpClientConfiguration in project service-proxy by membrane.
the class HttpKeepAliveTest method createHttpClient.
private HttpClient createHttpClient(int defaultKeepAliveTimeout) {
HttpClientConfiguration configuration = new HttpClientConfiguration();
ConnectionConfiguration connection = new ConnectionConfiguration();
connection.setKeepAliveTimeout(defaultKeepAliveTimeout);
configuration.setConnection(connection);
HttpClient client = new HttpClient(configuration);
return client;
}
use of com.predic8.membrane.core.transport.http.client.HttpClientConfiguration in project service-proxy by membrane.
the class UnavailableSoapProxyTest method setup.
@Before
public void setup() {
r = new Router();
HttpClientConfiguration httpClientConfig = new HttpClientConfiguration();
httpClientConfig.setMaxRetries(1);
r.setHttpClientConfig(httpClientConfig);
r.setHotDeploy(false);
r.setRetryInit(true);
sp = new SOAPProxy();
sp.setPort(2000);
sp.setWsdl("http://localhost:2001/axis2/services/BLZService?wsdl");
sp3 = new ServiceProxy();
sp3.setPort(2000);
sp3.setTarget(new AbstractServiceProxy.Target("localhost", 2001));
ValidatorInterceptor v = new ValidatorInterceptor();
v.setWsdl("http://localhost:2001/axis2/services/BLZService?wsdl");
sp3.getInterceptors().add(v);
SOAPProxy sp2 = new SOAPProxy();
sp2.setPort(2001);
sp2.setWsdl("http://www.thomas-bayer.com/axis2/services/BLZService?wsdl");
r2 = new Router();
r2.setHotDeploy(false);
r2.getRules().add(sp2);
// r2 will be started during the test
}
Aggregations