Search in sources :

Example 21 with HttpClient

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

the class Test method main.

public static void main(String[] args) throws Exception {
    URIFactory uriFactory = new URIFactory();
    uriFactory.setAllowIllegalCharacters(true);
    Response res = new HttpClient().call(new Request.Builder().get(uriFactory, "http://localhost:2000/a.{/").buildExchange()).getResponse();
    System.out.println(res.getStatusCode());
    System.out.println(res.getStartLine());
}
Also used : Response(com.predic8.membrane.core.http.Response) HttpClient(com.predic8.membrane.core.transport.http.HttpClient) URIFactory(com.predic8.membrane.core.util.URIFactory)

Example 22 with HttpClient

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

the class SwaggerProxy method init.

@Override
public void init() throws Exception {
    super.init();
    // download swaggerUrl
    HttpClient hc = new HttpClient(router.getHttpClientConfig());
    Exchange ex = hc.call(new Request.Builder().get(swaggerUrl).buildExchange());
    if (ex.getResponse().getStatusCode() != 200) {
        log.error("Couldn't fetch Swagger URL!");
        throw new Exception("Couldn't fetch Swagger URL!");
    }
    // parse swaggerUrl
    swagger = new SwaggerParser().parse(ex.getResponse().getBodyAsStringDecoded());
    // pass swagger specification to Swagger Key
    ((SwaggerProxyKey) key).setSwagger(swagger);
    ((SwaggerProxyKey) key).setAllowUI(allowUI);
    // add interceptor to position 0.
    SwaggerRewriterInterceptor sri = new SwaggerRewriterInterceptor(swagger, swaggerUrl);
    interceptors.add(0, sri);
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) SwaggerParser(io.swagger.parser.SwaggerParser) HttpClient(com.predic8.membrane.core.transport.http.HttpClient) Request(com.predic8.membrane.core.http.Request) SwaggerRewriterInterceptor(com.predic8.membrane.core.interceptor.swagger.SwaggerRewriterInterceptor)

Aggregations

Test (org.junit.Test)15 Exchange (com.predic8.membrane.core.exchange.Exchange)13 HttpClient (com.predic8.membrane.core.transport.http.HttpClient)9 AbstractInterceptor (com.predic8.membrane.core.interceptor.AbstractInterceptor)6 Outcome (com.predic8.membrane.core.interceptor.Outcome)6 Response (com.predic8.membrane.core.http.Response)5 IOException (java.io.IOException)5 URISyntaxException (java.net.URISyntaxException)5 HttpClient (org.apache.commons.httpclient.HttpClient)5 Http11Test (com.predic8.membrane.integration.Http11Test)4 Request (com.predic8.membrane.core.http.Request)3 HttpClientConfiguration (com.predic8.membrane.core.transport.http.client.HttpClientConfiguration)2 URIFactory (com.predic8.membrane.core.util.URIFactory)2 PostMethod (org.apache.commons.httpclient.methods.PostMethod)2 HttpRouter (com.predic8.membrane.core.HttpRouter)1 Router (com.predic8.membrane.core.Router)1 KeyStore (com.predic8.membrane.core.config.security.KeyStore)1 SSLParser (com.predic8.membrane.core.config.security.SSLParser)1 TrustStore (com.predic8.membrane.core.config.security.TrustStore)1 CountInterceptor (com.predic8.membrane.core.interceptor.CountInterceptor)1