title: Calling a REST service inside another REST service (Apache Camel)
body: <p>I have implemented following APIS using CXF REST Service and Apache Camel.</p>
  
  <ul>
  <li><a href="http://localhost:9090/api/compute" rel="nofollow">http://localhost:9090/api/compute</a></li>
  <li><a href="http://localhost:9091/api/listAction" rel="nofollow">http://localhost:9091/api/listAction</a></li>
  </ul>
  
  <p>Both these APIs are of <code>POST</code> type, and will accept <code>json</code> input.</p>
  
  <ul>
  <li>First API will take a single <code>json</code> object and perform some actions on that, and will return updated <code>json</code>.</li>
  <li>Second API is supposed to take a <code>json</code> array of objects of previous type and call first API for each object in array.</li>
  </ul>
  
  <p>Here you can find my camel route for second API.</p>
  
  <pre><code>&lt;route id="listActionRoute" customId="true" startupOrder="1"&gt;
      &lt;from uri="direct-vm:listAction-service"/&gt;
      &lt;log message="Mapping done ${body[0]} ${body[0].size}"/&gt;
      &lt;setBody&gt;
          &lt;simple&gt;${body[0]}&lt;/simple&gt;
      &lt;/setBody&gt;
      &lt;loop copy="true"&gt;
          &lt;simple&gt;${body.size}&lt;/simple&gt;
          &lt;setBody&gt;
              &lt;simple&gt;${body[${property.CamelLoopIndex}]}&lt;/simple&gt;
          &lt;/setBody&gt;
  
          &lt;marshal&gt;
              &lt;json library="Jackson"/&gt;
          &lt;/marshal&gt;
  
          &lt;setHeader headerName="CamelHttpMethod"&gt;
              &lt;constant&gt;POST&lt;/constant&gt;
          &lt;/setHeader&gt;
          &lt;recipientList&gt;
              &lt;simple&gt;http://localhost:9090/api/compute&lt;/simple&gt;
          &lt;/recipientList&gt;
          &lt;log message="Response is ${body}"/&gt;
      &lt;/loop&gt;
      &lt;marshal&gt;
          &lt;json library="Jackson"/&gt;
      &lt;/marshal&gt;
      &lt;setHeader headerName="CamelCxfRsUsingHttpAPI"&gt;
          &lt;constant&gt;TRUE&lt;/constant&gt;
      &lt;/setHeader&gt;
      &lt;setHeader headerName="Accept"&gt;
          &lt;constant&gt;application/json&lt;/constant&gt;
      &lt;/setHeader&gt;
  &lt;/route&gt;
  </code></pre>
  
  <p>Unfortunately, I am getting an error while calling the first API inside the camel route shared here. </p>
  
  <p>The stack trace is as follows:</p>
  
  <blockquote>
    <p>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[<a href="http://localhost:9090/api/compute]" rel="nofollow">http://localhost:9090/api/compute]</a></p>
    
    <p>Message History
    --------------------------------------------------------------------------------------------------------------------------------------- RouteId              ProcessorId          Processor<br>
    Elapsed (ms) [listActionRoute   ] [listActionRoute   ]
    [direct-vm://listAction-service<br>
    ] [       957] [demoRoute         ] [log39             ] [log<br>
    ] [        70] [demoRoute         ] [recipientList17   ]
    [recipientList[simple{direct-vm:${header.operationName}-service}]<br>
    ] [       887] [listActionRoute   ] [log35             ] [log<br>
    ] [       846] [listActionRoute   ] [setBody15         ]
    [setBody[simple{${body[0]}}]<br>
    ] [         1] [listActionRoute   ] [bean10            ]
    [bean[com.demo.service.DemoService@638f6584]<br>
    ] [        12] [listActionRoute   ] [loop8             ]
    [loop[simple{${body.size}}]<br>
    ] [        23] [listActionRoute   ] [log36             ] [log<br>
    ] [         1] [listActionRoute   ] [setBody16         ]
    [setBody[simple{${body[${property.CamelLoopIndex}]}}]<br>
    ] [         2] [listActionRoute   ] [log37             ] [log<br>
    ] [         1] [listActionRoute   ] [marshal17         ]
    [marshal[org.apache.camel.model.dataformat.JsonDataFormat@74104d19]<br>
    ] [         2] [listActionRoute   ] [setHeader26       ]
    [setHeader[CamelHttpMethod]<br>
    ] [         1] [listActionRoute   ] [recipientList16   ]
    [recipientList[simple{<a href="http://localhost:9090/api/compute" rel="nofollow">http://localhost:9090/api/compute</a>}]<br>
    ] [        15]</p>
    
    <p>Exchange
    --------------------------------------------------------------------------------------------------------------------------------------- Exchange[     Id                  ID-localhost-35741-1477139495717-17-4
      ExchangePattern     InOut   Headers<br>
    {Accept=text/html,application/xhtml+xml,application/xml;q=0.9,<em>/</em>;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,<em>/</em>;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=<a href="http://localhost:9091" rel="nofollow">http://localhost:9091</a>, 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{,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,<em>/</em>;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=<a href="http://localhost:9091/api/listAction" rel="nofollow">http://localhost:9091/api/listAction</a>,
    Accept=text/html,application/xhtml+xml,application/xml;q=0.9,<em>/</em>;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 </p>
    
    <p>, 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<br>
    byte[]    Body                {"name":"Mr XYZ Mr","salary":100.0} ]</p>
    
    <p>Stacktrace</p>
    
    <p><strong>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[<a href="http://localhost:9090/api/compute]" rel="nofollow">http://localhost:9090/api/compute]</a></strong></p>
  </blockquote>
  
  <p>Can anyone help me to understand, why am I getting this error and how to resolve this issue?</p>