Search in sources :

Example 21 with Request

use of com.predic8.membrane.core.http.xml.Request in project service-proxy by membrane.

the class ACLTest method test.

@Test
public void test() throws IOException, InterruptedException {
    File baseDir = getExampleDir("acl");
    Process2 sl = new Process2.Builder().in(baseDir).script("service-proxy").waitForMembrane().start();
    try {
        getAndAssert200("http://localhost:2000/");
        String result = getAndAssert(404, "http://localhost:2000/contacts/");
        // this request succeeds through membrane, but fails on the backend with 404
        AssertUtils.assertContains("Tomcat", result);
        getAndAssert(403, "http://localhost:2000/open-source/");
    } finally {
        sl.killScript();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) File(java.io.File) Test(org.junit.Test)

Example 22 with Request

use of com.predic8.membrane.core.http.xml.Request in project service-proxy by membrane.

the class HttpServletHandler method createRequest.

private Request createRequest() throws IOException {
    Request srcReq = new Request();
    String pathQuery = request.getRequestURI();
    if (request.getQueryString() != null)
        pathQuery += "?" + request.getQueryString();
    if (getTransport().isRemoveContextRoot()) {
        String contextPath = request.getContextPath();
        if (contextPath.length() > 0 && pathQuery.startsWith(contextPath))
            pathQuery = pathQuery.substring(contextPath.length());
    }
    srcReq.create(request.getMethod(), pathQuery, request.getProtocol(), createHeader(), request.getInputStream());
    return srcReq;
}
Also used : Request(com.predic8.membrane.core.http.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest)

Example 23 with Request

use of com.predic8.membrane.core.http.xml.Request in project service-proxy by membrane.

the class LoadBalancingInterceptorTest method doTestGetDestinationURL.

private void doTestGetDestinationURL(String requestUri, String expectedUri) throws URISyntaxException {
    Exchange exc = new Exchange(null);
    exc.setRequest(new Request());
    exc.getRequest().setUri(URLUtil.getPathQuery(new URIFactory(), requestUri));
    exc.setOriginalRequestUri(requestUri);
    assertEquals(expectedUri, new Node("thomas-bayer.com", 80).getDestinationURL(exc));
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Node(com.predic8.membrane.core.interceptor.balancer.Node) Request(com.predic8.membrane.core.http.Request) URIFactory(com.predic8.membrane.core.util.URIFactory)

Example 24 with Request

use of com.predic8.membrane.core.http.xml.Request in project service-proxy by membrane.

the class MyInterceptor method handleRequest.

@Override
public Outcome handleRequest(Exchange exc) throws Exception {
    System.out.println("MyInterceptor invoked.");
    System.out.println("Request headers:");
    for (HeaderField headerField : exc.getRequest().getHeader().getAllHeaderFields()) System.out.print(headerField.getHeaderName() + ": " + headerField.getValue());
    return Outcome.CONTINUE;
}
Also used : HeaderField(com.predic8.membrane.core.http.HeaderField)

Example 25 with Request

use of com.predic8.membrane.core.http.xml.Request 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)

Aggregations

Request (com.predic8.membrane.core.http.Request)39 Exchange (com.predic8.membrane.core.exchange.Exchange)20 Test (org.junit.Test)12 IOException (java.io.IOException)11 Header (com.predic8.membrane.core.http.Header)8 Response (com.predic8.membrane.core.http.Response)8 AbstractExchange (com.predic8.membrane.core.exchange.AbstractExchange)5 Message (com.predic8.membrane.core.http.Message)5 Outcome (com.predic8.membrane.core.interceptor.Outcome)5 Body (com.predic8.membrane.core.http.Body)3 Request (com.predic8.membrane.core.http.xml.Request)3 EndOfStreamException (com.predic8.membrane.core.util.EndOfStreamException)3 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)2 CacheBuilder (com.google.common.cache.CacheBuilder)2 HeaderField (com.predic8.membrane.core.http.HeaderField)2 ResponseBuilder (com.predic8.membrane.core.http.Response.ResponseBuilder)2 ResolverMap (com.predic8.membrane.core.resolver.ResolverMap)2 HttpClient (com.predic8.membrane.core.transport.http.HttpClient)2 StringReader (java.io.StringReader)2 SocketException (java.net.SocketException)2