I'm constructing a Camel route that will make calls to Twilio's SMS API to send SMSs. The API demands BASIC authentication but my calls are failing with a 401 authentication error. I've copied my config from this worked example and validated that my credentials are sound by curl-ing the call. However, I can't work out what I'm missing on the Camel side.
My Camel HTTP integration with APIs that don't enforce authentication all work fine and the URL for the Twilio call is being fed correctly (using the header *Exchange.HTTP_QUERY*).
Any help much appreciated. Thanks.
Here's my Blueprint-OSGi Camel route:-
<camelContext id="jellyfish-messaging-sms" errorHandlerRef="deadLetterQueue"
trace="false" xmlns="http://camel.apache.org/schema/blueprint">
<route id="sms.twilio">
<from uri="activemq:sms.twilio" />
<setHeader headerName="Content-Type">
<constant>application/x-www-form-urlencoded</constant>
</setHeader>
<setHeader headerName="CamelHttpMethod">
<constant>POST</constant>
</setHeader>
<to uri="https://api.twilio.com/2010-04-01/Accounts/{{sms.accountSid}}/SMS/Messages" />
</route>
</camelContext>
<!-- BEANS -->
<bean id="httpAuth" class="org.apache.camel.component.http.HttpConfiguration">
<property name="authMethod" value="Basic"/>
<property name="authUsername" value="${sms.accountSid}"/>
<property name="authPassword" value="${sms.authToken}"/>
</bean>
<bean id="http" class="org.apache.camel.component.http.HttpComponent">
<property name="camelContext" ref="jellyfish-messaging-sms"/>
<property name="httpConfiguration" ref="httpAuth"/>
</bean>
Here's the exception (from karaf.log):-
2013-09-09 17:37:27,627 | INFO | umer[sms.twilio] | HttpMethodDirector | 366 - org.apache.servicemix.bundles.commons-httpclient - 3.1.0.7 | No credentials available for BASIC 'Twilio API'@api.twilio.com:443
2013-09-09 17:37:27,632 | ERROR | umer[sms.twilio] | jellyfish-messaging | 266 - org.apache.camel.camel-core - 2.10.2 | Dead letter interceptor invoked
2013-09-09 17:37:27,635 | ERROR | umer[sms.twilio] | sms | 266 - org.apache.camel.camel-core - 2.10.2 | Exchange[ExchangePattern:InOnly, BodyType:String, Body:Nothing to see here, CaughtExceptionType:org.apache.camel.component.http.HttpOperationFailedException, CaughtExceptionMessage:HTTP operation failed invoking https://api.twilio.com/2010-04-01/Accounts/...snip.../SMS/Messages?From=%2B44...snip...&To=%2B44...snip...&Body=fred with statusCode: 401, StackTrace:org.apache.camel.component.http.HttpOperationFailedException: HTTP operation failed invoking https://api.twilio.com/2010-04-01/Accounts/...snip.../SMS/Messages?From=%2B44...snip...&To=%2B44...snip...&Body=fred with statusCode: 401 at org.apache.camel.component.http.HttpProducer.populateHttpOperationFailedException(HttpProducer.java:229) at org.apache.camel.component.http.HttpProducer.process(HttpProducer.java:157)
And here's the working curl:-
curl -X POST https://api.twilio.com/2010-04-01/Accounts/...snip.../SMS/Messages -u ...snip...:...snip... -d "From=+44...snip..." -d "To=+44...snip..." -d 'Body=Hello'