Search in sources :

Example 21 with Port

use of com.predic8.wsdl.Port in project service-proxy by membrane.

the class ReverseProxyingInterceptorTest method getRewrittenDestination.

/**
 * Lets the ReverseProxyingInterceptor handle a fake Exchange and returns the rewritten "Destination" header.
 */
private String getRewrittenDestination(String requestHostHeader, String requestDestinationHeader, int port, String requestURI, String targetScheme, int targetPort) throws Exception {
    Exchange exc = createExchange(requestHostHeader, requestDestinationHeader, port, requestURI, null);
    String url = new URL(targetScheme, "target", targetPort, exc.getRequest().getUri()).toString();
    exc.getDestinations().add(url);
    Assert.assertEquals(Outcome.CONTINUE, rp.handleRequest(exc));
    return exc.getRequest().getHeader().getFirstValue(Header.DESTINATION);
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) URL(java.net.URL)

Example 22 with Port

use of com.predic8.wsdl.Port in project service-proxy by membrane.

the class ReverseProxyingInterceptorTest method createExchange.

/**
 * Creates a fake exchange which simulates a received redirect by the server.
 */
private Exchange createExchange(String requestHostHeader, String requestDestinationHeader, int port, String requestURI, String redirectionURI) {
    Exchange exc = new Exchange(new FakeHttpHandler(port));
    Request req = new Request();
    req.setUri(requestURI);
    Header header = new Header();
    if (requestHostHeader != null)
        header.setHost(requestHostHeader);
    if (requestDestinationHeader != null)
        header.add(Header.DESTINATION, requestDestinationHeader);
    req.setHeader(header);
    exc.setRequest(req);
    if (redirectionURI != null) {
        Response res = Response.redirect(redirectionURI, false).build();
        exc.setResponse(res);
        exc.getDestinations().add(requestURI);
    }
    return exc;
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Response(com.predic8.membrane.core.http.Response) Header(com.predic8.membrane.core.http.Header) FakeHttpHandler(com.predic8.membrane.core.transport.http.FakeHttpHandler) Request(com.predic8.membrane.core.http.Request)

Example 23 with Port

use of com.predic8.wsdl.Port in project service-proxy by membrane.

the class ReverseProxyingInterceptorTest method getRewrittenRedirectionLocation.

/**
 * Lets the ReverseProxyingInterceptor handle a fake Exchange and returns the rewritten "Location" header.
 */
private String getRewrittenRedirectionLocation(String requestHostHeader, int port, String requestURI, String redirectionURI) throws Exception {
    Exchange exc = createExchange(requestHostHeader, null, port, requestURI, redirectionURI);
    Assert.assertEquals(Outcome.CONTINUE, rp.handleResponse(exc));
    return exc.getResponse().getHeader().getFirstValue(Header.LOCATION);
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange)

Example 24 with Port

use of com.predic8.wsdl.Port in project service-proxy by membrane.

the class WsaEndpointRewriterTest method testRewriteEndpointAddress.

@Test
public void testRewriteEndpointAddress() throws XMLStreamException {
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    WsaEndpointRewriter rewriter = new WsaEndpointRewriter(new DecoupledEndpointRegistry());
    int port = 2000;
    rewriter.rewriteEndpoint(input, output, port, new Exchange(null));
    String rewrittenXml = output.toString();
    System.out.println(rewrittenXml);
    assertTrue(rewrittenXml.contains("<Address>http://localhost:" + port + "/decoupled_endpoint</Address>"));
}
Also used : DecoupledEndpointRegistry(com.predic8.membrane.core.interceptor.ws_addressing.DecoupledEndpointRegistry) Exchange(com.predic8.membrane.core.exchange.Exchange) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) WsaEndpointRewriter(com.predic8.membrane.core.interceptor.ws_addressing.WsaEndpointRewriter) Test(org.junit.Test)

Example 25 with Port

use of com.predic8.wsdl.Port 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)

Aggregations

ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)9 Test (org.junit.Test)7 ServiceProxyKey (com.predic8.membrane.core.rules.ServiceProxyKey)6 StringWriter (java.io.StringWriter)6 Exchange (com.predic8.membrane.core.exchange.Exchange)5 Rule (com.predic8.membrane.core.rules.Rule)5 Process2 (com.predic8.membrane.examples.Process2)5 File (java.io.File)5 ProxyRule (com.predic8.membrane.core.rules.ProxyRule)4 HttpRouter (com.predic8.membrane.core.HttpRouter)3 Request (com.predic8.membrane.core.http.Request)3 Response (com.predic8.membrane.core.http.Response)3 LoadBalancingInterceptor (com.predic8.membrane.core.interceptor.balancer.LoadBalancingInterceptor)3 Node (com.predic8.membrane.core.interceptor.balancer.Node)3 Definitions (com.predic8.wsdl.Definitions)3 Port (com.predic8.wsdl.Port)3 ArrayList (java.util.ArrayList)3 EtcdNodeInformation (com.predic8.membrane.core.cloud.etcd.EtcdNodeInformation)2 IPortChangeListener (com.predic8.membrane.core.model.IPortChangeListener)2 AbstractServiceProxy (com.predic8.membrane.core.rules.AbstractServiceProxy)2