【发布时间】:2013-09-09 17:21:42
【问题描述】:
我正在构建一个 Camel 路由,该路由将调用 Twilio's SMS API 以发送 SMS。 API 要求 BASIC authentication 但我的调用失败并出现 401 身份验证错误。我从 this worked example 复制了我的配置,并通过 curl 调用验证了我的凭据是正确的。但是,我无法弄清楚我在骆驼方面缺少什么。
我的 Camel HTTP 与不强制身份验证的 API 集成一切正常,并且 Twilio 调用的 URL 被正确提供(使用标头 *Exchange.HTTP_QUERY*)。
非常感谢任何帮助。谢谢。
这是我的 Blueprint-OSGi Camel 路线:-
<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>
这是一个例外(来自 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)
这是工作卷曲:-
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'
【问题讨论】:
标签: activemq apache-camel twilio http-authentication blueprint-osgi