Search in sources :

Example 31 with Response

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

the class HelpLinkExistenceTest method doit.

@Test
public void doit() throws Exception {
    Set<Class<?>> classes = getElementClasses();
    Assert.assertNotEquals(0, classes.size());
    HttpClient hc = new HttpClient();
    for (Class<?> clazz : classes) {
        if (Interceptor.class.isAssignableFrom(clazz)) {
            Interceptor i = (Interceptor) clazz.newInstance();
            String helpId = i.getHelpId();
            String url = "http://membrane-soa.org/service-proxy-doc/" + getVersion() + "/configuration/reference/" + helpId + ".htm";
            Response r = hc.call(new Request.Builder().get(url).buildExchange()).getResponse();
            try {
                Assert.assertEquals(200, r.getStatusCode());
            } catch (Throwable e) {
                throw new RuntimeException(url, e);
            }
        }
    }
}
Also used : Response(com.predic8.membrane.core.http.Response) HttpClient(com.predic8.membrane.core.transport.http.HttpClient) Interceptor(com.predic8.membrane.core.interceptor.Interceptor) Test(org.junit.Test)

Example 32 with Response

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

the class BoundConnectionTest method doExchange.

private void doExchange(Connection c, boolean includeAuthorizationHeader) throws IOException, EndOfStreamException {
    createRequest(includeAuthorizationHeader).write(c.out);
    Response r = new Response();
    r.read(c.in, true);
}
Also used : Response(com.predic8.membrane.core.http.Response)

Example 33 with Response

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

the class HttpKeepAliveTest method issueRequest.

private int issueRequest(HttpClient client) throws IOException, Exception {
    Exchange exchange = createExchange();
    Response response = client.call(exchange).getResponse();
    response.readBody();
    return response.getStatusCode();
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Response(com.predic8.membrane.core.http.Response)

Example 34 with Response

use of com.predic8.membrane.core.http.Response 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 35 with Response

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

the class IllegalCharactersInURLTest method doit.

@Test
public void doit() throws Exception {
    URIFactory uriFactory = new URIFactory(true);
    Response res = new HttpClient().call(new Request.Builder().method("GET").url(uriFactory, "http://localhost:3027/foo{}").body("").buildExchange()).getResponse();
    Assert.assertEquals(200, res.getStatusCode());
}
Also used : Response(com.predic8.membrane.core.http.Response) HttpResponse(org.apache.http.HttpResponse) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) URIFactory(com.predic8.membrane.core.util.URIFactory) Test(org.junit.Test)

Aggregations

Response (com.predic8.membrane.core.http.Response)29 Exchange (com.predic8.membrane.core.exchange.Exchange)14 IOException (java.io.IOException)14 StringWriter (java.io.StringWriter)9 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)7 Request (com.predic8.membrane.core.http.Request)7 AbstractExchange (com.predic8.membrane.core.exchange.AbstractExchange)6 Header (com.predic8.membrane.core.http.Header)6 Test (org.junit.Test)6 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)4 Message (com.predic8.membrane.core.http.Message)4 JSONContent (com.predic8.membrane.core.interceptor.rest.JSONContent)4 ProxyRule (com.predic8.membrane.core.rules.ProxyRule)4 HttpClient (com.predic8.membrane.core.transport.http.HttpClient)4 SQLException (java.sql.SQLException)4 Element (org.w3c.dom.Element)4 NodeList (org.w3c.dom.NodeList)4 JsonFactory (com.fasterxml.jackson.core.JsonFactory)3 MCElement (com.predic8.membrane.annot.MCElement)3 ResponseBuilder (com.predic8.membrane.core.http.Response.ResponseBuilder)3