Search in sources :

Example 21 with Client

use of com.predic8.membrane.core.interceptor.oauth2.Client in project service-proxy by membrane.

the class SSLClient method test.

@Test
public void test() throws IOException, InterruptedException, NoSuchAlgorithmException, KeyManagementException {
    File baseDir = getExampleDir("ssl-client");
    AssertUtils.replaceInFile(new File(baseDir, "proxies.xml"), "8080", "3023");
    Process2 sl = new Process2.Builder().in(baseDir).script("service-proxy").waitForMembrane().start();
    try {
        AssertUtils.assertContains("<title>Google", getAndAssert200("http://localhost:3023/"));
    } finally {
        sl.killScript();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) File(java.io.File) Test(org.junit.Test)

Example 22 with Client

use of com.predic8.membrane.core.interceptor.oauth2.Client in project service-proxy by membrane.

the class LBNotificationClient method notifiyClusterManager.

private Response notifiyClusterManager() throws Exception {
    HttpClient client = new HttpClient();
    Exchange exc = new Exchange(null);
    Request r = MessageUtil.getPostRequest(getRequestURL());
    r.setBodyContent(new byte[0]);
    exc.setRequest(r);
    exc.getDestinations().add(getRequestURL());
    Response res = client.call(exc).getResponse();
    return res;
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Response(com.predic8.membrane.core.http.Response) HttpClient(com.predic8.membrane.core.transport.http.HttpClient) Request(com.predic8.membrane.core.http.Request)

Example 23 with Client

use of com.predic8.membrane.core.interceptor.oauth2.Client in project service-proxy by membrane.

the class HttpKeepAliveTest method testMaxParameter.

@Test
public void testMaxParameter() throws Exception {
    HttpClient client = new HttpClient();
    sp1.getInterceptors().add(0, new AbstractInterceptor() {

        @Override
        public Outcome handleResponse(Exchange exc) throws Exception {
            exc.getResponse().getHeader().add(Header.KEEP_ALIVE, "max=2");
            return Outcome.CONTINUE;
        }
    });
    assertEquals(200, issueRequest(client));
    assertEquals(200, issueRequest(client));
    assertEquals(1, set.size());
    assertEquals(200, issueRequest(client));
    assertEquals(2, set.size());
    assertEquals(200, issueRequest(client));
    assertEquals(2, set.size());
    assertEquals(200, issueRequest(client));
    assertEquals(3, set.size());
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Outcome(com.predic8.membrane.core.interceptor.Outcome) AbstractInterceptor(com.predic8.membrane.core.interceptor.AbstractInterceptor) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) Test(org.junit.Test)

Example 24 with Client

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

Example 25 with Client

use of com.predic8.membrane.core.interceptor.oauth2.Client 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();
}
Also used : CountInterceptor(com.predic8.membrane.core.interceptor.CountInterceptor) AbstractInterceptor(com.predic8.membrane.core.interceptor.AbstractInterceptor) StaticSSLContext(com.predic8.membrane.core.transport.ssl.StaticSSLContext) Router(com.predic8.membrane.core.Router) ResolverMap(com.predic8.membrane.core.resolver.ResolverMap) TrustStore(com.predic8.membrane.core.config.security.TrustStore) KeyStore(com.predic8.membrane.core.config.security.KeyStore) SSLParser(com.predic8.membrane.core.config.security.SSLParser) Exchange(com.predic8.membrane.core.exchange.Exchange) ProxyConfiguration(com.predic8.membrane.core.transport.http.client.ProxyConfiguration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Outcome(com.predic8.membrane.core.interceptor.Outcome) HttpClient(com.predic8.membrane.core.transport.http.HttpClient) HttpClientConfiguration(com.predic8.membrane.core.transport.http.client.HttpClientConfiguration) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)27 Client (org.orcid.jaxb.model.client_v2.Client)18 Exchange (com.predic8.membrane.core.exchange.Exchange)12 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)10 IOException (java.io.IOException)8 AbstractInterceptor (com.predic8.membrane.core.interceptor.AbstractInterceptor)6 Outcome (com.predic8.membrane.core.interceptor.Outcome)6 HashSet (java.util.HashSet)6 BaseTest (org.orcid.core.BaseTest)6 ClientRedirectUri (org.orcid.jaxb.model.client_v2.ClientRedirectUri)6 URISyntaxException (java.net.URISyntaxException)5 HttpClient (org.apache.commons.httpclient.HttpClient)5 ScopePathType (org.orcid.jaxb.model.message.ScopePathType)5 Request (com.predic8.membrane.core.http.Request)4 Response (com.predic8.membrane.core.http.Response)4 Process2 (com.predic8.membrane.examples.Process2)4 Http11Test (com.predic8.membrane.integration.Http11Test)4 SessionManager (com.predic8.membrane.core.interceptor.authentication.session.SessionManager)3 Client (com.predic8.membrane.core.interceptor.oauth2.Client)3 HttpClient (com.predic8.membrane.core.transport.http.HttpClient)3