我尝试使用基本身份验证调用REST服务,需要在JSON中处理响应。当我尝试以下操作时,我仍然得到xml:
的响应<bean id="httpAuth" class="org.apache.camel.component.http.HttpConfiguration">
<property name="authMethod" value="Basic"/>
<property name="authUsername" value="users"/>
<property name="authPassword" value="passwor"/>
</bean>
<bean id="httpBind" class="org.apache.camel.component.http.DefaultHttpBinding">
</bean>
<bean id="httpHeaderFilter" class="org.apache.camel.impl.DefaultHeaderFilterStrategy">
</bean>
<bean id="http" class="org.apache.camel.component.http.HttpComponent">
<property name="camelContext" ref="mycontext"/>
<property name="httpConfiguration" ref="httpAuth"/>
<property name="httpBinding" ref="httpBind"/>
</bean>
.
.
<camel:camelContext id="mycontext" xmlns="http://camel.apache.org/schema/spring" autoStartup="true" useMDCLogging="true" errorHandlerRef="ErrorHandler_xx">
<route id="myroute">
<from uri="http://urltorestresource?httpBindingRef=httpBind&headerFilterStrategy=httpHeaderFilter" />
<setHeader headerName="Accept">
<constant>application/json</constant>
</setHeader>
<setHeader headerName="Content-Type">
<constant>application/json</constant>
</setHeader>
<convertBodyTo type="String" charset="UTF-8" />
<to uri="file://archive?fileName=response.txt" />
</route>
</camel:camelContext>