Search in sources :

Example 36 with ServiceProxy

use of com.predic8.membrane.core.rules.ServiceProxy in project service-proxy by membrane.

the class RewriteInterceptorIntegrationTest method setUp.

@Before
public void setUp() throws Exception {
    interceptor = new RewriteInterceptor();
    interceptor.getMappings().add(new Mapping("/blz-service\\?wsdl", "/axis2/services/BLZService?wsdl", null));
    Rule rule = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 3006), "thomas-bayer.com", 80);
    rule.getInterceptors().add(interceptor);
    router = new HttpRouter();
    router.getRuleManager().addProxyAndOpenPortIfNew(rule);
}
Also used : Mapping(com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor.Mapping) Rule(com.predic8.membrane.core.rules.Rule) HttpRouter(com.predic8.membrane.core.HttpRouter)

Example 37 with ServiceProxy

use of com.predic8.membrane.core.rules.ServiceProxy in project service-proxy by membrane.

the class REST2SOAPInterceptorIntegrationTest method setUp.

@Before
public void setUp() throws Exception {
    Rule rule = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 3004), "www.thomas-bayer.com", 80);
    router = new HttpRouter();
    router.getRuleManager().addProxyAndOpenPortIfNew(rule);
    REST2SOAPInterceptor rest2SoapInt = new REST2SOAPInterceptor();
    rest2SoapInt.setMappings(getMappings());
    rule.getInterceptors().add(rest2SoapInt);
    router.init();
}
Also used : Rule(com.predic8.membrane.core.rules.Rule) HttpRouter(com.predic8.membrane.core.HttpRouter)

Example 38 with ServiceProxy

use of com.predic8.membrane.core.rules.ServiceProxy in project service-proxy by membrane.

the class OAuth2ResourceTest method getMockAuthServiceProxy.

private ServiceProxy getMockAuthServiceProxy() throws IOException {
    ServiceProxy sp = new ServiceProxy(new ServiceProxyKey(serverPort), null, 99999);
    WellknownFile wkf = new WellknownFile();
    wkf.setIssuer(getServerAddress());
    wkf.setAuthorizationEndpoint(getServerAddress() + "/auth");
    wkf.setTokenEndpoint(getServerAddress() + "/token");
    wkf.setUserinfoEndpoint(getServerAddress() + "/userinfo");
    wkf.setRevocationEndpoint(getServerAddress() + "/revoke");
    wkf.setJwksUri(getServerAddress() + "/certs");
    wkf.setSupportedResponseTypes("code token");
    wkf.setSupportedSubjectType("public");
    wkf.setSupportedIdTokenSigningAlgValues("RS256");
    wkf.setSupportedScopes("openid email profile");
    wkf.setSupportedTokenEndpointAuthMethods("client_secret_post");
    wkf.setSupportedClaims("sub email username");
    wkf.init(new HttpRouter());
    sp.getInterceptors().add(new AbstractInterceptor() {

        SecureRandom rand = new SecureRandom();

        @Override
        public synchronized Outcome handleRequest(Exchange exc) throws Exception {
            if (exc.getRequestURI().endsWith("/.well-known/openid-configuration")) {
                exc.setResponse(Response.ok(wkf.getWellknown()).build());
            } else if (exc.getRequestURI().startsWith("/auth?")) {
                Map<String, String> params = URLParamUtil.getParams(new URIFactory(), exc);
                exc.setResponse(Response.redirect(getClientAddress() + "/oauth2callback?code=1234&state=" + params.get("state"), false).build());
            } else if (exc.getRequestURI().startsWith("/token")) {
                ObjectMapper om = new ObjectMapper();
                Map<String, String> res = new HashMap<>();
                res.put("access_token", new BigInteger(130, rand).toString(32));
                res.put("token_type", "bearer");
                res.put("expires_in", "1");
                res.put("refresh_token", new BigInteger(130, rand).toString(32));
                exc.setResponse(Response.ok(om.writeValueAsString(res)).contentType("application/json").build());
            } else if (exc.getRequestURI().startsWith("/userinfo")) {
                ObjectMapper om = new ObjectMapper();
                Map<String, String> res = new HashMap<>();
                res.put("username", "dummy");
                exc.setResponse(Response.ok(om.writeValueAsString(res)).contentType("application/json").build());
            }
            if (exc.getResponse() == null)
                exc.setResponse(Response.notFound().build());
            return Outcome.RETURN;
        }
    });
    return sp;
}
Also used : AbstractInterceptor(com.predic8.membrane.core.interceptor.AbstractInterceptor) SecureRandom(java.security.SecureRandom) IOException(java.io.IOException) Exchange(com.predic8.membrane.core.exchange.Exchange) ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) Outcome(com.predic8.membrane.core.interceptor.Outcome) URIFactory(com.predic8.membrane.core.util.URIFactory) BigInteger(java.math.BigInteger) HttpRouter(com.predic8.membrane.core.HttpRouter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 39 with ServiceProxy

use of com.predic8.membrane.core.rules.ServiceProxy in project service-proxy by membrane.

the class MyApplication method main.

public static void main(String[] args) throws Exception {
    System.out.println("Starting up");
    // create a new service proxy that listens on port 8080 and has a target to localhost:2001
    ServiceProxy sp = createServiceProxy();
    // create an enclosing WebSocket interceptor to add our own Logging interceptor to it
    WebSocketInterceptor ws = new WebSocketInterceptor();
    ws.getInterceptors().add(new MyWebSocketLogInterceptor());
    // attach the WebSocket interceptor to the service proxy
    sp.getInterceptors().add(ws);
    // add the service proxy to a new router instance and start it
    HttpRouter router = new HttpRouter();
    router.add(sp);
    router.init();
    System.out.println("Starting finished - Waiting for WebSocket communication");
}
Also used : ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) WebSocketInterceptor(com.predic8.membrane.core.interceptor.tunnel.WebSocketInterceptor) MyWebSocketLogInterceptor(com.predic8.membrane.core.interceptor.websocket.custom.MyWebSocketLogInterceptor) HttpRouter(com.predic8.membrane.core.HttpRouter)

Example 40 with ServiceProxy

use of com.predic8.membrane.core.rules.ServiceProxy in project service-proxy by membrane.

the class MyApplication method createServiceProxy.

private static ServiceProxy createServiceProxy() {
    String hostname = "*";
    String method = "*";
    String path = ".*";
    int listenPort = 8080;
    ServiceProxyKey key = new ServiceProxyKey(hostname, method, path, listenPort);
    String targetHost = "localhost";
    int targetPort = 2001;
    return new ServiceProxy(key, targetHost, targetPort);
}
Also used : ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy)

Aggregations

ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)47 ServiceProxyKey (com.predic8.membrane.core.rules.ServiceProxyKey)34 HttpRouter (com.predic8.membrane.core.HttpRouter)25 Before (org.junit.Before)19 Rule (com.predic8.membrane.core.rules.Rule)17 Exchange (com.predic8.membrane.core.exchange.Exchange)16 Outcome (com.predic8.membrane.core.interceptor.Outcome)14 AbstractInterceptor (com.predic8.membrane.core.interceptor.AbstractInterceptor)12 IOException (java.io.IOException)9 Test (org.junit.Test)9 LoadBalancingInterceptor (com.predic8.membrane.core.interceptor.balancer.LoadBalancingInterceptor)5 ArrayList (java.util.ArrayList)4 Router (com.predic8.membrane.core.Router)3 Mapping (com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor.Mapping)3 AbstractServiceProxy (com.predic8.membrane.core.rules.AbstractServiceProxy)3 ProxyRule (com.predic8.membrane.core.rules.ProxyRule)3 HttpClientConfiguration (com.predic8.membrane.core.transport.http.client.HttpClientConfiguration)3 URISyntaxException (java.net.URISyntaxException)3 Interceptor (com.predic8.membrane.core.interceptor.Interceptor)2 MockInterceptor (com.predic8.membrane.core.interceptor.MockInterceptor)2