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);
}
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();
}
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;
}
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");
}
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);
}
Aggregations