我使用CXF REST服务和Apache Camel实现了以下APIS。
这两个API均为POST
类型,并接受json
输入。
json
对象并对其执行一些操作,并将返回更新的json
。json
个对象数组,并为数组中的每个对象调用第一个API。在这里,您可以找到第二个API的骆驼路线。
<route id="listActionRoute" customId="true" startupOrder="1">
<from uri="direct-vm:listAction-service"/>
<log message="Mapping done ${body[0]} ${body[0].size}"/>
<setBody>
<simple>${body[0]}</simple>
</setBody>
<loop copy="true">
<simple>${body.size}</simple>
<setBody>
<simple>${body[${property.CamelLoopIndex}]}</simple>
</setBody>
<marshal>
<json library="Jackson"/>
</marshal>
<setHeader headerName="CamelHttpMethod">
<constant>POST</constant>
</setHeader>
<recipientList>
<simple>http://localhost:9090/api/compute</simple>
</recipientList>
<log message="Response is ${body}"/>
</loop>
<marshal>
<json library="Jackson"/>
</marshal>
<setHeader headerName="CamelCxfRsUsingHttpAPI">
<constant>TRUE</constant>
</setHeader>
<setHeader headerName="Accept">
<constant>application/json</constant>
</setHeader>
</route>
不幸的是,我在调用此处共享的camel路由中的第一个API时收到错误。
堆栈跟踪如下:
交付失败(MessageId:ID-localhost-35741-1477139495717-17-3 在ExchangeId上:ID-localhost-35741-1477139495717-17-4)。筋疲力尽 传递尝试:1捕获:java.lang.IllegalArgumentException: 无效的uri:/ api / listAction / api / listAction。如果你是 转发/桥接http端点,然后启用bridgeEndpoint 端点上的选项:端点[http://localhost:9090/api/compute]
消息历史记录 -------------------------------------------------- -------------------------------------------------- ----------------------------------- RouteId ProcessorId Processor
经过(ms)[listActionRoute] [listActionRoute] [直接-VM://的listAction服务
] [957] [demoRoute] [log39] [日志
] [70] [demoRoute] [recipientList17] [recipientList [{简单直接-VM:$ {} header.operationName} - 服务]
] [887] [listActionRoute] [log35] [日志
] [846] [listActionRoute] [setBody15] [setBody [简单{$ {体[0]}}]
] [1] [listActionRoute] [bean10] [豆[com.demo.service.DemoService@638f6584]
] [12] [listActionRoute] [loop8] [环[{简单$ {body.size}}]
] [23] [listActionRoute] [log36] [日志
] [1] [listActionRoute] [setBody16] [setBody [简单{$ {体[$ {property.CamelLoopIndex}]}}]
] [2] [listActionRoute] [log37] [日志
] [1] [listActionRoute] [marshal17] [编组[org.apache.camel.model.dataformat.JsonDataFormat@74104d19]
] [2] [listActionRoute] [setHeader26] [的setHeader [CamelHttpMethod]
] [1] [listActionRoute] [recipientList16] [recipientList [简单{http://localhost:9090/api/compute}]
] [15]交换 -------------------------------------------------- -------------------------------------------------- ----------------------------------- Exchange [Id ID-localhost-35741-1477139495717-17-4 ExchangePattern InOut接头
{接受= text / html的,应用/ XHTML + xml的,应用/ XML; Q = 0.9, / 的; Q = 0.8, accept-encoding = gzip,deflate,Accept-Language = en-US,en; q = 0.5, breadcrumbId = ID-本地主机 - 35741-1477139495717-18-1, CamelAcceptContentType = text / html的,应用/ XHTML + xml的,应用/ XML; Q = 0.9, / 的; Q = 0.8, CamelCxfMessage = {org.apache.cxf.message.MessageFIXED_PARAMETER_ORDER =假, org.apache.cxf.resource.method = public java.lang.String com.demo.endpoints.DemoResource.listAction(java.util.List中), http.base.path = http://localhost:9091,HTTP.REQUEST =(POST / api / listAction)@ 585231269 org.eclipse.jetty.server.Request@22e1eba5, org.apache.cxf.transport.Destination=org.apache.cxf.transport.http_jetty.JettyHTTPDestination@26de7b21, HTTP.CONFIG = null,jaxrs.template.parameters = {FINAL_MATCH_GROUP = [/]}, org.apache.cxf.message.Message.QUERY_STRING = NULL, org.apache.cxf.jaxrs.model.OperationResourceInfoStack = [org.apache.cxf.jaxrs.model.MethodInvocationInfo@63dce19e] org.apache.cxf.message.Message.ENCODING = ISO-8859-1, HTTP.CONTEXT=ServletContext@o.e.j.s.h.ContextHandler {,空}, 内容类型=应用/ JSON, org.apache.cxf.security.SecurityContext=org.apache.cxf.transport.http.AbstractHTTPDestination$2@7f64c12c, org.apache.cxf.continuations.ContinuationProvider=org.apache.cxf.transport.http_jetty.continuations.JettyContinuationProvider@5275a1a6, org.apache.cxf.message.Message.PROTOCOL_HEADERS = {接受= [text / html的,应用/ XHTML + xml的,应用/ XML; Q = 0.9, / 的; Q = 0.8], accept-encoding = [gzip,deflate],Accept-Language = [en-US,en; q = 0.5], connection = [keep-alive],Content-Length = [120], content-type = [application / json],Host = [localhost:9091], User-Agent = [Mozilla / 5.0(X11; Ubuntu; Linux x86_64; rv:49.0) Gecko / 20100101 Firefox / 49.0]}, org.apache.cxf.request.url = http://localhost:9091/api/listAction, 接受= text / html的,应用/ XHTML + xml的,应用/ XML; Q = 0.9, / 的; Q = 0.8, org.apache.cxf.request.uri = / API /的listAction, org.apache.cxf.message.Message.PATH_INFO = / API /的listAction, org.apache.cxf.transport.https.CertConstraints = NULL, HTTP.RESPONSE = HTTP / 1.1 200,org.apache.cxf.request.method = POST, org.apache.cxf.async.post.response.dispatch = TRUE, org.apache.cxf.message.Message.IN_INTERCEPTORS = [org.apache.cxf.transport.https.CertConstraintsInterceptor@55180f7] HTTP_CONTEXT_MATCH_STRATEGY = stem,http.service.redirection = null, path_to_match_slash = / API /的listAction, org.apache.cxf.configuration.security.AuthorizationPolicy = NULL}, CamelCxfRsOperationResourceInfoStack = [org.apache.cxf.jaxrs.model.MethodInvocationInfo@63dce19e] CamelCxfRsResponseClass = class java.lang.String, CamelCxfRsResponseGenericType = class java.lang.String, CamelHttpCharacterEncoding = ISO-8859-1,CamelHttpMethod = POST, CamelHttpPath = / api / listAction,CamelHttpUri = / api / listAction, CamelRedelivered = false,CamelRedeliveryCounter = 0, connection = keep-alive,Content-Length = 120, Content-Type = application / json,Host = localhost:9091, operationName = listAction,User-Agent = Mozilla / 5.0(X11; Ubuntu; Linux x86_64的; rv:49.0)Gecko / 20100101 Firefox / 49.0} BodyType
byte [] Body {&#34; name&#34;:&#34; Mr XYZ Mr&#34;,&#34; salary&#34;:100.0}]堆栈跟踪
java.lang.IllegalArgumentException:无效的uri:/ api / listAction / api / listAction。如果你转发/桥接http 端点,然后在端点上启用bridgeEndpoint选项: 端点[http://localhost:9090/api/compute]
任何人都可以帮助我理解,为什么我会收到此错误以及如何解决此问题?
答案 0 :(得分:1)
我认为标题混淆了。我想你可以通过在每次调用之间清除与.removeHeaders("*")
类似的标题来解决它。