use of com.predic8.membrane.core.interceptor.Outcome in project service-proxy by membrane.
the class HttpKeepAliveTest method testTimeoutCustom.
@Test
public void testTimeoutCustom() throws Exception {
HttpClient client = createHttpClient(1000);
sp1.getInterceptors().add(0, new AbstractInterceptor() {
@Override
public Outcome handleResponse(Exchange exc) throws Exception {
exc.getResponse().getHeader().add(Header.KEEP_ALIVE, "timeout=1,max=2");
return Outcome.CONTINUE;
}
});
assertEquals(200, issueRequest(client));
assertEquals(1, set.size());
Thread.sleep(1500);
assertEquals(200, issueRequest(client));
assertEquals(2, set.size());
assertEquals(200, issueRequest(client));
assertEquals(2, set.size());
assertEquals(200, issueRequest(client));
assertEquals(3, set.size());
}
use of com.predic8.membrane.core.interceptor.Outcome 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.interceptor.Outcome in project service-proxy by membrane.
the class OAuth2ResourceTest method getConfiguredOAuth2Resource.
private ServiceProxy getConfiguredOAuth2Resource() {
ServiceProxy sp = new ServiceProxy(new ServiceProxyKey(clientPort), null, 99999);
OAuth2ResourceInterceptor oAuth2ResourceInterceptor = new OAuth2ResourceInterceptor();
MembraneAuthorizationService auth = new MembraneAuthorizationService();
auth.setSrc(getServerAddress());
auth.setClientId("2343243242");
auth.setClientSecret("3423233123123");
auth.setScope("openid profile");
oAuth2ResourceInterceptor.setAuthService(auth);
sp.getInterceptors().add(oAuth2ResourceInterceptor);
sp.getInterceptors().add(new AbstractInterceptor() {
@Override
public Outcome handleRequest(Exchange exc) throws Exception {
OAuth2AnswerParameters answer = OAuth2AnswerParameters.deserialize(String.valueOf(exc.getProperty(Exchange.OAUTH2)));
exc.setResponse(Response.ok(answer.getAccessToken()).build());
return Outcome.RETURN;
}
});
return sp;
}
use of com.predic8.membrane.core.interceptor.Outcome in project service-proxy by membrane.
the class ResolverTest method setup.
@BeforeClass
public static void setup() throws Exception {
ServiceProxy sp = new ServiceProxy(new ServiceProxyKey(3029), "localhost", 8080);
sp.getInterceptors().add(new AbstractInterceptor() {
@Override
public Outcome handleRequest(Exchange exc) throws Exception {
hit = true;
return Outcome.CONTINUE;
}
});
WebServerInterceptor i = new WebServerInterceptor();
if (deployment.equals(STANDALONE))
i.setDocBase("src/test/resources");
else {
i.setDocBase("/test");
router.getResolverMap().addSchemaResolver(resolverMap.getFileSchemaResolver());
}
sp.getInterceptors().add(i);
router.add(sp);
router.init();
}
use of com.predic8.membrane.core.interceptor.Outcome in project service-proxy by membrane.
the class IllegalCharactersInURLTest method init.
@Before
public void init() throws Exception {
r = new HttpRouter();
r.setHotDeploy(false);
r.add(new ServiceProxy(new ServiceProxyKey(3027), "localhost", 3028));
ServiceProxy sp2 = new ServiceProxy(new ServiceProxyKey(3028), null, 80);
sp2.getInterceptors().add(new AbstractInterceptor() {
@Override
public Outcome handleRequest(Exchange exc) throws Exception {
Assert.assertEquals("/foo{}", exc.getRequestURI());
exc.setResponse(Response.ok().build());
return Outcome.RETURN;
}
});
r.add(sp2);
r.start();
}
Aggregations