You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Brad Johnson <br...@mediadriver.com> on 2016/08/18 23:03:48 UTC

Invoking a REST client

Most of the switch over from using XML route builders to Java route
builders is fairly painless and straightforward and the new CDI is a
pleasure to work with.  But there are certain aspects that I'm not quite
familiar with like how to do the same thing as this in the Java DSL,

<!-- Defined the client endpoint to create the cxf-rs consumer -->
  <cxf:rsClient id="rsClient" address="http://localhost: <http://localhost/>
${CXFTestSupport.port2}/CxfRsRouterTest/rest"

serviceClass="org.apache.camel.component.cxf.jaxrs.testbean.CustomerService"
    loggingFeatureEnabled="true" skipFaultLogging="true">
    <cxf:providers>
       <ref bean="jsonProvider"/>
    </cxf:providers>
  </cxf:rsClient>

  <!-- The camel route context -->
  <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
    <route>
       <!-- Just need to ignoreDeleteMethodMessageBody -->
       <from uri="cxfrs://bean://rsServer"/>
       <to uri="log:body?level=INFO"/>
       <to uri="cxfrs://bean://rsClient?ignoreDeleteMethodMessageBody=true
"/>
    </route>
  </camelContext>


If I have an interface like this:

@Path("/api")
public interface InventoryClient {

  @GET
  @Path("/inventory_transactions/{id}")
  @Consumes(MediaType.TEXT_XML)
  InventoryTransaction getInventory(@PathParam("id") Integer id);


I can easily create a Java bean and use JAXRSClientFactory to create the
client and use it or even use a CDI Producer to create it for injection.
The only issue then is the multi-threading and how that might be handled
and then doing things like calling reset on the client after an invocation.
While I can do it it seems like I should be able to simply set up a route:

from("direct:inventory").to("cxrs://bean//inventoryClient")

in a route builder but obviously that's predicated on setting up the
client. How does that setup translate?

  <cxf:rsClient id="inventoryClient" address="https:// <http://localhost/>
remoteURI"
    serviceClass="foo.InventoryClient"


I'd rather let Camel handle the underlying issues of resource management
than do all that myself.

Re: Invoking a REST client

Posted by Brad Johnson <br...@mediadriver.com>.
Blueprint. I've done that a number of time.  I may just continue using
blueprint for that part.  I've injected producerTemplates for that sort of
thing in the past and then just route direct:foo to cxfrs what have you.

On Thu, Aug 25, 2016 at 11:56 AM, Joseph Kampf <jo...@gmail.com>
wrote:

> So what I think you are asking is how do you create a JaxRS client URI
> without using Spring to create a rsClient?
>
> Take a look at the cxfrs Component documentation.
> http://camel.apache.org/cxfrs.html  Check out the section "How to invoke
> the REST service through camel-cxfrs producer"
>
>
> Btw,  we use the Java DSL, but still use spring to construct our CXF
> beans.  We inject the bean URI into our route builders.
>
> Are you trying to use Camel without Spring or Blueprint?
>
>
>
>
>
>
> On 8/18/16, 7:03 PM, "Brad Johnson" <br...@mediadriver.com> wrote:
>
> >Most of the switch over from using XML route builders to Java route
> >builders is fairly painless and straightforward and the new CDI is a
> >pleasure to work with.  But there are certain aspects that I'm not quite
> >familiar with like how to do the same thing as this in the Java DSL,
> >
> ><!-- Defined the client endpoint to create the cxf-rs consumer -->
> >  <cxf:rsClient id="rsClient" address="http://localhost: <
> http://localhost/>
> >${CXFTestSupport.port2}/CxfRsRouterTest/rest"
> >
> >serviceClass="org.apache.camel.component.cxf.jaxrs.
> testbean.CustomerService"
> >    loggingFeatureEnabled="true" skipFaultLogging="true">
> >    <cxf:providers>
> >       <ref bean="jsonProvider"/>
> >    </cxf:providers>
> >  </cxf:rsClient>
> >
> >  <!-- The camel route context -->
> >  <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
> >    <route>
> >       <!-- Just need to ignoreDeleteMethodMessageBody -->
> >       <from uri="cxfrs://bean://rsServer"/>
> >       <to uri="log:body?level=INFO"/>
> >       <to uri="cxfrs://bean://rsClient?ignoreDeleteMethodMessageBody=
> true
> >"/>
> >    </route>
> >  </camelContext>
> >
> >
> >If I have an interface like this:
> >
> >@Path("/api")
> >public interface InventoryClient {
> >
> >  @GET
> >  @Path("/inventory_transactions/{id}")
> >  @Consumes(MediaType.TEXT_XML)
> >  InventoryTransaction getInventory(@PathParam("id") Integer id);
> >
> >
> >I can easily create a Java bean and use JAXRSClientFactory to create the
> >client and use it or even use a CDI Producer to create it for injection.
> >The only issue then is the multi-threading and how that might be handled
> >and then doing things like calling reset on the client after an
> invocation.
> >While I can do it it seems like I should be able to simply set up a route:
> >
> >from("direct:inventory").to("cxrs://bean//inventoryClient")
> >
> >in a route builder but obviously that's predicated on setting up the
> >client. How does that setup translate?
> >
> >  <cxf:rsClient id="inventoryClient" address="https:// <http://localhost/
> >
> >remoteURI"
> >    serviceClass="foo.InventoryClient"
> >
> >
> >I'd rather let Camel handle the underlying issues of resource management
> >than do all that myself.
>
>

Re: Invoking a REST client

Posted by Joseph Kampf <jo...@gmail.com>.
So what I think you are asking is how do you create a JaxRS client URI without using Spring to create a rsClient?

Take a look at the cxfrs Component documentation. http://camel.apache.org/cxfrs.html  Check out the section "How to invoke the REST service through camel-cxfrs producer"


Btw,  we use the Java DSL, but still use spring to construct our CXF beans.  We inject the bean URI into our route builders.  

Are you trying to use Camel without Spring or Blueprint? 






On 8/18/16, 7:03 PM, "Brad Johnson" <br...@mediadriver.com> wrote:

>Most of the switch over from using XML route builders to Java route
>builders is fairly painless and straightforward and the new CDI is a
>pleasure to work with.  But there are certain aspects that I'm not quite
>familiar with like how to do the same thing as this in the Java DSL,
>
><!-- Defined the client endpoint to create the cxf-rs consumer -->
>  <cxf:rsClient id="rsClient" address="http://localhost: <http://localhost/>
>${CXFTestSupport.port2}/CxfRsRouterTest/rest"
>
>serviceClass="org.apache.camel.component.cxf.jaxrs.testbean.CustomerService"
>    loggingFeatureEnabled="true" skipFaultLogging="true">
>    <cxf:providers>
>       <ref bean="jsonProvider"/>
>    </cxf:providers>
>  </cxf:rsClient>
>
>  <!-- The camel route context -->
>  <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
>    <route>
>       <!-- Just need to ignoreDeleteMethodMessageBody -->
>       <from uri="cxfrs://bean://rsServer"/>
>       <to uri="log:body?level=INFO"/>
>       <to uri="cxfrs://bean://rsClient?ignoreDeleteMethodMessageBody=true
>"/>
>    </route>
>  </camelContext>
>
>
>If I have an interface like this:
>
>@Path("/api")
>public interface InventoryClient {
>
>  @GET
>  @Path("/inventory_transactions/{id}")
>  @Consumes(MediaType.TEXT_XML)
>  InventoryTransaction getInventory(@PathParam("id") Integer id);
>
>
>I can easily create a Java bean and use JAXRSClientFactory to create the
>client and use it or even use a CDI Producer to create it for injection.
>The only issue then is the multi-threading and how that might be handled
>and then doing things like calling reset on the client after an invocation.
>While I can do it it seems like I should be able to simply set up a route:
>
>from("direct:inventory").to("cxrs://bean//inventoryClient")
>
>in a route builder but obviously that's predicated on setting up the
>client. How does that setup translate?
>
>  <cxf:rsClient id="inventoryClient" address="https:// <http://localhost/>
>remoteURI"
>    serviceClass="foo.InventoryClient"
>
>
>I'd rather let Camel handle the underlying issues of resource management
>than do all that myself.