You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by bob anderson <bo...@gmail.com> on 2016/01/25 22:33:11 UTC

Camel Context as Rest Consumer and HTTP Producer

I am trying to use a Rest consumer and then an HTTP Producer in the same
camel context. Both the Rest consumer works and the HTTP producer work
separately but not in the same context. The HTTP app that is called is just
another Camel servlet app that listens and returns an xml body message. I
get a 404 service not found error. I am probably not understanding some
concept about in and out bound HTTP
I have tried in two different Tomcat webservers (v6 and v7), putting the
http app on different and the same webservers.  I am running camel version
2.15.1 - I have written this in the spring dsl as follows;

<camelContext xmlns="http://camel.apache.org/schema/spring">
     <!-- not sure if this is needed as the input from the rest call seems
to be a java.lang.hasmap - which I now handle as a hashmap not as json -->
        <dataFormats>
          <xmljson id="xmljson" />
        </dataFormats>
  <!-- configure rest to use the camel-servlet component, and use json
binding mode -->
     <restConfiguration component="servlet" bindingMode="json"
contextPath="session" port="8080">
      <dataFormatProperty key="prettyPrint" value="true"/>
    </restConfiguration>
<!-- set up the listening paths that the service will accept  -->

    <rest path="/session" consumes="application/json"
produces="application/json">
    <!-- ********************************** R E S T
*************************************-->
      <post uri="/{sessionid}/start" >
         <to uri="direct:start"/>
      </post>
      <!-- ********************************** R E S T
*************************************-->
    </rest>

    <route streamCache="true">
       <from uri="direct:start"/>
       <!-- Unpack the body of the message into header fields -->
       <to uri="direct:mapStartMsg"/>
       <!-- Create XML body message for HTTP request -->
       <to uri="direct:createHTTPRequestMsg"/>
     <!-- The HTTP method for the HTTP app is POST so I've hard coded it
here even though with content in the body it shouldnt be necessary -->
      <setHeader headerName="CamelHttpMethod">
        <constant>POST</constant>
      </setHeader>
      <!--
******************************************************************************************
-->
      <!-- U R L     I S    H A R D    C O D E D     H E R
E                                           -->
     <!-- I have tried adding the port to the url, as well as using HTTP4,
as well as using -->
      <!-- a recipient list to call the URI
                                     -->
        <!--
******************************************************************************************
-->
      <to uri="
http://xx.xxx.xxx.x/myhttpapp-1/httpListener?bridgeEndpoint=true&amp;throwExceptionOnFailure=false
"/>
        <!-- Get the HTTP response code from http server -to test for
success or fail -->
         <setHeader headerName="Response">
             <simple resultType="java.lang.String">${body}</simple>
        </setHeader>
        <setHeader headerName="HttpResponseCode">
             <simple
resultType="java.lang.Integer">${header.CamelHttpResponseCode}</simple>
        </setHeader>

        <log message=" ** CALLED THE HTTP app response body = ${body}"/>

         </route>


--

Re: Camel Context as Rest Consumer and HTTP Producer

Posted by bob anderson <bo...@gmail.com>.
Hi Richard,
Thanks for the suggestion.
I tried the change by setting the CamelHttpBaseUri header BUT still get a
404 "The requested resource () is not available."
I can't see what URL camel is actually trying to call. But something
happens when you try to have an HTTP consumer (Listener) and HTTP producer.
Is this a Tomcat issue, Servlet Issue or Camel Issue do you think?
Thanks Bob

On Tue, Jan 26, 2016 at 12:31 AM, Richard Davidson <
richard.davidson.uk@gmail.com> wrote:

> Hi Bob,
>
> Could you try setting:
>
> <setHeader headerName="CamelHttpBaseUri">
>   <constant>http://xx.xxx.xxx.x/myhttpapp-1
> <
> http://xx.xxx.xxx.x/myhttpapp-1/httpListener?bridgeEndpoint=true&amp;throwExceptionOnFailure=false
> >
> </constant>
> </setHeader>
>
> before you make the outgoing HTTP call.
>
> Cheers,
> Richard
>
>
> On Mon, Jan 25, 2016 at 9:33 PM, bob anderson <bo...@gmail.com>
> wrote:
>
> > I am trying to use a Rest consumer and then an HTTP Producer in the same
> > camel context. Both the Rest consumer works and the HTTP producer work
> > separately but not in the same context. The HTTP app that is called is
> just
> > another Camel servlet app that listens and returns an xml body message. I
> > get a 404 service not found error. I am probably not understanding some
> > concept about in and out bound HTTP
> > I have tried in two different Tomcat webservers (v6 and v7), putting the
> > http app on different and the same webservers.  I am running camel
> version
> > 2.15.1 - I have written this in the spring dsl as follows;
> >
> > <camelContext xmlns="http://camel.apache.org/schema/spring">
> >      <!-- not sure if this is needed as the input from the rest call
> seems
> > to be a java.lang.hasmap - which I now handle as a hashmap not as json
> -->
> >         <dataFormats>
> >           <xmljson id="xmljson" />
> >         </dataFormats>
> >   <!-- configure rest to use the camel-servlet component, and use json
> > binding mode -->
> >      <restConfiguration component="servlet" bindingMode="json"
> > contextPath="session" port="8080">
> >       <dataFormatProperty key="prettyPrint" value="true"/>
> >     </restConfiguration>
> > <!-- set up the listening paths that the service will accept  -->
> >
> >     <rest path="/session" consumes="application/json"
> > produces="application/json">
> >     <!-- ********************************** R E S T
> > *************************************-->
> >       <post uri="/{sessionid}/start" >
> >          <to uri="direct:start"/>
> >       </post>
> >       <!-- ********************************** R E S T
> > *************************************-->
> >     </rest>
> >
> >     <route streamCache="true">
> >        <from uri="direct:start"/>
> >        <!-- Unpack the body of the message into header fields -->
> >        <to uri="direct:mapStartMsg"/>
> >        <!-- Create XML body message for HTTP request -->
> >        <to uri="direct:createHTTPRequestMsg"/>
> >      <!-- The HTTP method for the HTTP app is POST so I've hard coded it
> > here even though with content in the body it shouldnt be necessary -->
> >       <setHeader headerName="CamelHttpMethod">
> >         <constant>POST</constant>
> >       </setHeader>
> >       <!--
> >
> >
> ******************************************************************************************
> > -->
> >       <!-- U R L     I S    H A R D    C O D E D     H E R
> > E                                           -->
> >      <!-- I have tried adding the port to the url, as well as using
> HTTP4,
> > as well as using -->
> >       <!-- a recipient list to call the URI
> >                                      -->
> >         <!--
> >
> >
> ******************************************************************************************
> > -->
> >       <to uri="
> >
> >
> http://xx.xxx.xxx.x/myhttpapp-1/httpListener?bridgeEndpoint=true&amp;throwExceptionOnFailure=false
> > "/>
> >         <!-- Get the HTTP response code from http server -to test for
> > success or fail -->
> >          <setHeader headerName="Response">
> >              <simple resultType="java.lang.String">${body}</simple>
> >         </setHeader>
> >         <setHeader headerName="HttpResponseCode">
> >              <simple
> > resultType="java.lang.Integer">${header.CamelHttpResponseCode}</simple>
> >         </setHeader>
> >
> >         <log message=" ** CALLED THE HTTP app response body = ${body}"/>
> >
> >          </route>
> >
> >
> > --
> >
>



-- 
Bob Anderson
+27 (0) 82 389 0335
+234 (0)802 478 9237
[image: View my profile on LinkedIn]
<http://ng.linkedin.com/pub/bob-anderson/2/25/9b5>

Re: Camel Context as Rest Consumer and HTTP Producer

Posted by Richard Davidson <ri...@gmail.com>.
Hi Bob,

Could you try setting:

<setHeader headerName="CamelHttpBaseUri">
  <constant>http://xx.xxx.xxx.x/myhttpapp-1
<http://xx.xxx.xxx.x/myhttpapp-1/httpListener?bridgeEndpoint=true&amp;throwExceptionOnFailure=false>
</constant>
</setHeader>

before you make the outgoing HTTP call.

Cheers,
Richard


On Mon, Jan 25, 2016 at 9:33 PM, bob anderson <bo...@gmail.com>
wrote:

> I am trying to use a Rest consumer and then an HTTP Producer in the same
> camel context. Both the Rest consumer works and the HTTP producer work
> separately but not in the same context. The HTTP app that is called is just
> another Camel servlet app that listens and returns an xml body message. I
> get a 404 service not found error. I am probably not understanding some
> concept about in and out bound HTTP
> I have tried in two different Tomcat webservers (v6 and v7), putting the
> http app on different and the same webservers.  I am running camel version
> 2.15.1 - I have written this in the spring dsl as follows;
>
> <camelContext xmlns="http://camel.apache.org/schema/spring">
>      <!-- not sure if this is needed as the input from the rest call seems
> to be a java.lang.hasmap - which I now handle as a hashmap not as json -->
>         <dataFormats>
>           <xmljson id="xmljson" />
>         </dataFormats>
>   <!-- configure rest to use the camel-servlet component, and use json
> binding mode -->
>      <restConfiguration component="servlet" bindingMode="json"
> contextPath="session" port="8080">
>       <dataFormatProperty key="prettyPrint" value="true"/>
>     </restConfiguration>
> <!-- set up the listening paths that the service will accept  -->
>
>     <rest path="/session" consumes="application/json"
> produces="application/json">
>     <!-- ********************************** R E S T
> *************************************-->
>       <post uri="/{sessionid}/start" >
>          <to uri="direct:start"/>
>       </post>
>       <!-- ********************************** R E S T
> *************************************-->
>     </rest>
>
>     <route streamCache="true">
>        <from uri="direct:start"/>
>        <!-- Unpack the body of the message into header fields -->
>        <to uri="direct:mapStartMsg"/>
>        <!-- Create XML body message for HTTP request -->
>        <to uri="direct:createHTTPRequestMsg"/>
>      <!-- The HTTP method for the HTTP app is POST so I've hard coded it
> here even though with content in the body it shouldnt be necessary -->
>       <setHeader headerName="CamelHttpMethod">
>         <constant>POST</constant>
>       </setHeader>
>       <!--
>
> ******************************************************************************************
> -->
>       <!-- U R L     I S    H A R D    C O D E D     H E R
> E                                           -->
>      <!-- I have tried adding the port to the url, as well as using HTTP4,
> as well as using -->
>       <!-- a recipient list to call the URI
>                                      -->
>         <!--
>
> ******************************************************************************************
> -->
>       <to uri="
>
> http://xx.xxx.xxx.x/myhttpapp-1/httpListener?bridgeEndpoint=true&amp;throwExceptionOnFailure=false
> "/>
>         <!-- Get the HTTP response code from http server -to test for
> success or fail -->
>          <setHeader headerName="Response">
>              <simple resultType="java.lang.String">${body}</simple>
>         </setHeader>
>         <setHeader headerName="HttpResponseCode">
>              <simple
> resultType="java.lang.Integer">${header.CamelHttpResponseCode}</simple>
>         </setHeader>
>
>         <log message=" ** CALLED THE HTTP app response body = ${body}"/>
>
>          </route>
>
>
> --
>