I have implemented following APIS using CXF REST Service and Apache Camel.
Both these APIs are of POST
type, and will accept json
input.
- First API will take a single
json
object and perform some actions on that, and will return updatedjson
. - Second API is supposed to take a
json
array of objects of previous type and call first API for each object in array.
Here you can find my camel route for second 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>
Unfortunately, I am getting an error while calling the first API inside the camel route shared here.
The stack trace is as follows:
Failed delivery for (MessageId: ID-localhost-35741-1477139495717-17-3 on ExchangeId: ID-localhost-35741-1477139495717-17-4). Exhausted after delivery attempt: 1 caught: java.lang.IllegalArgumentException: Invalid uri: /api/listAction/api/listAction. If you are forwarding/bridging http endpoints, then enable the bridgeEndpoint option on the endpoint: Endpoint[http://localhost:9090/api/compute]
Message History --------------------------------------------------------------------------------------------------------------------------------------- RouteId ProcessorId Processor
Elapsed (ms) [listActionRoute ] [listActionRoute ] [direct-vm://listAction-service
] [ 957] [demoRoute ] [log39 ] [log
] [ 70] [demoRoute ] [recipientList17 ] [recipientList[simple{direct-vm:${header.operationName}-service}]
] [ 887] [listActionRoute ] [log35 ] [log
] [ 846] [listActionRoute ] [setBody15 ] [setBody[simple{${body[0]}}]
] [ 1] [listActionRoute ] [bean10 ] [bean[com.demo.service.DemoService@638f6584]
] [ 12] [listActionRoute ] [loop8 ] [loop[simple{${body.size}}]
] [ 23] [listActionRoute ] [log36 ] [log
] [ 1] [listActionRoute ] [setBody16 ] [setBody[simple{${body[${property.CamelLoopIndex}]}}]
] [ 2] [listActionRoute ] [log37 ] [log
] [ 1] [listActionRoute ] [marshal17 ] [marshal[org.apache.camel.model.dataformat.JsonDataFormat@74104d19]
] [ 2] [listActionRoute ] [setHeader26 ] [setHeader[CamelHttpMethod]
] [ 1] [listActionRoute ] [recipientList16 ] [recipientList[simple{http://localhost:9090/api/compute}]
] [ 15]Exchange --------------------------------------------------------------------------------------------------------------------------------------- Exchange[ Id ID-localhost-35741-1477139495717-17-4 ExchangePattern InOut Headers
{Accept=text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8, accept-encoding=gzip, deflate, Accept-Language=en-US,en;q=0.5, breadcrumbId=ID-localhost-35741-1477139495717-18-1, CamelAcceptContentType=text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8, CamelCxfMessage={org.apache.cxf.message.MessageFIXED_PARAMETER_ORDER=false, 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, [email protected]{,null}, Content-Type=application/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={Accept=[text/html,application/xhtml+xml,application/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, Accept=text/html,application/xhtml+xml,application/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 {"name":"Mr XYZ Mr","salary":100.0} ]Stacktrace
java.lang.IllegalArgumentException: Invalid uri: /api/listAction/api/listAction. If you are forwarding/bridging http endpoints, then enable the bridgeEndpoint option on the endpoint: Endpoint[http://localhost:9090/api/compute]
Can anyone help me to understand, why am I getting this error and how to resolve this issue?