You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by nw31304 <da...@gmail.com> on 2011/03/08 23:19:55 UTC

Basic HTTP Authentication headers missing using HTTP component

I am having an incredibly difficult time convincing the HTTP endpoint (Camel
version 2.6) to add basic authentication headers to a simple POST request. 
Here's a very simple route: 

         from("direct:routes"). 
        
to("http://localhost/whatever?authMethod=Basic&authUsername=me&authPassword=secret"); 

And here's how I make the request using a ProducerTemplate: 

        ProducerTemplate template = context.createProducerTemplate(); 
        HashMap headers = new HashMap(); 
        headers.put(Exchange.CONTENT_TYPE, "application/json"); 
        headers.put(Exchange.HTTP_METHOD, "POST"); 
        String payload = "{\"type\": \"data\"}"; 
        String rsp = template.requestBodyAndHeaders("direct:routes",
payload, headers, String.class); 

And here's the TCPDUMP output.  Notice that no authentication headers are
present: 

POST /whatever HTTP/1.1 
User-Agent: Jakarta Commons-HttpClient/3.1 
Host: localhost 
Content-Length: 16 
Content-Type: application/json 

{"type": "data"} 

What do I have to do to get the encoded Basic authorization headers appended
to the request?  Apologies in advance for what will surely be an utterly
obvious solution (to everyone except me).

--
View this message in context: http://camel.465427.n5.nabble.com/Basic-HTTP-Authentication-headers-missing-using-HTTP-component-tp3414749p3414749.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Basic HTTP Authentication headers missing using HTTP component

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Check unit tests in camel-jetty, such as
https://svn.apache.org/repos/asf/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBasicAuthTest.java

On Wed, Mar 9, 2011 at 7:24 AM, nw31304 <da...@gmail.com> wrote:
> Yep, thanks.  That's what I'm having to resort to (hopefully temporarily).
> Still It seems as though I ought to be able to specify the auth stuff on the
> URI, as the doc states is possible.  That would be absolutely necessary if
> for example, a route feeds the HTTP component directly (without a Java
> language producerTemplate/Processor/bean etc. having the luxury of doing the
> base64 encoding and setting of the headers).  I must be doing something
> wrong, but what escapes me.  Thanks again for the reply.
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Basic-HTTP-Authentication-headers-missing-using-HTTP-component-tp3414749p3415052.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: Basic HTTP Authentication headers missing using HTTP component

Posted by nw31304 <da...@gmail.com>.
Yep, thanks.  That's what I'm having to resort to (hopefully temporarily). 
Still It seems as though I ought to be able to specify the auth stuff on the
URI, as the doc states is possible.  That would be absolutely necessary if
for example, a route feeds the HTTP component directly (without a Java
language producerTemplate/Processor/bean etc. having the luxury of doing the
base64 encoding and setting of the headers).  I must be doing something
wrong, but what escapes me.  Thanks again for the reply.

--
View this message in context: http://camel.465427.n5.nabble.com/Basic-HTTP-Authentication-headers-missing-using-HTTP-component-tp3414749p3415052.html
Sent from the Camel - Users mailing list archive at Nabble.com.