Search in sources :

Example 6 with HttpConfiguration

use of org.apache.camel.http.common.HttpConfiguration in project camel by apache.

the class HttpQueryGoogleProxyTest method testQueryGoogleProxy.

@Test
@Ignore("Run manually")
public void testQueryGoogleProxy() throws Exception {
    HttpConfiguration config = new HttpConfiguration();
    config.setProxyHost("myProxyHost");
    config.setProxyPort(8877);
    config.setProxyAuthMethod("Basic");
    config.setAuthMethodPriority("Digest,Basic");
    config.setProxyAuthUsername("myProxyUsername");
    config.setProxyAuthPassword("myProxyPassword");
    HttpComponent http = context.getComponent("http", HttpComponent.class);
    http.setHttpConfiguration(config);
    Object out = template.requestBody("http://google.com/search?q=Camel", "");
    assertNotNull(out);
    String data = context.getTypeConverter().convertTo(String.class, out);
    assertTrue("Camel should be in search result from Google", data.indexOf("Camel") > -1);
}
Also used : HttpConfiguration(org.apache.camel.http.common.HttpConfiguration) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 7 with HttpConfiguration

use of org.apache.camel.http.common.HttpConfiguration in project camel by apache.

the class HttpBasicAuthComponentConfiguredTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            HttpConfiguration config = new HttpConfiguration();
            config.setAuthMethod("Basic");
            config.setAuthUsername("donald");
            config.setAuthPassword("duck");
            HttpComponent http = context.getComponent("http", HttpComponent.class);
            http.setHttpConfiguration(config);
            from("jetty://http://localhost:{{port}}/test?handlers=myAuthHandler").process(new Processor() {

                public void process(Exchange exchange) throws Exception {
                    HttpServletRequest req = exchange.getIn().getBody(HttpServletRequest.class);
                    assertNotNull(req);
                    Principal user = req.getUserPrincipal();
                    assertNotNull(user);
                    assertEquals("donald", user.getName());
                }
            }).transform(constant("Bye World"));
            from("jetty://http://localhost:{{port}}/anotherTest?handlers=myAuthHandler").transform(constant("See you later"));
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) HttpServletRequest(javax.servlet.http.HttpServletRequest) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) HttpComponent(org.apache.camel.component.http.HttpComponent) HttpConfiguration(org.apache.camel.http.common.HttpConfiguration) Principal(java.security.Principal)

Aggregations

HttpConfiguration (org.apache.camel.http.common.HttpConfiguration)7 RouteBuilder (org.apache.camel.builder.RouteBuilder)5 Test (org.junit.Test)2 Principal (java.security.Principal)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Exchange (org.apache.camel.Exchange)1 Processor (org.apache.camel.Processor)1 HttpComponent (org.apache.camel.component.http.HttpComponent)1 HttpClient (org.apache.commons.httpclient.HttpClient)1 Ignore (org.junit.Ignore)1