You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by sothach <ph...@gmail.com> on 2013/03/04 17:15:42 UTC

Login/session token with Camel/CXF

I need to integrate with a third party system via its WS interface.  To send
a request, I must first "login" to the server, and obtain an authentication
token to attach to all subsequent requests.  This token has a limited
shelf-life, and will time-out after a period of time, requiring me to
re-apply.
My question: is there a standard pattern in Camel for this scenario? 
My first thought is to implement this by having an enrichment stage, that
calls out to "direct:login" route, setting a header with the token, that can
then be used when marshaling the call.  
Is there a simpler way?



--
View this message in context: http://camel.465427.n5.nabble.com/Login-session-token-with-Camel-CXF-tp5728467.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Login/session token with Camel/CXF

Posted by Willem jiang <wi...@gmail.com>.
FYI, I just updated the code of InsertResponseOutHeaderProcessor.java to avoid the NPE issue


--  
Willem Jiang

Red Hat, Inc.
FuseSource is now part of Red Hat
Web: http://www.fusesource.com | http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem





On Tuesday, March 5, 2013 at 2:11 AM, kingolego wrote:

> sothach wrote
> > I need to integrate with a third party system via its WS interface. To
> > send a request, I must first "login" to the server, and obtain an
> > authentication token to attach to all subsequent requests. This token has
> > a limited shelf-life, and will time-out after a period of time, requiring
> > me to re-apply.
> > My question: is there a standard pattern in Camel for this scenario?  
> > My first thought is to implement this by having an enrichment stage, that
> > calls out to "direct:login" route, setting a header with the token, that
> > can then be used when marshaling the call.  
> > Is there a simpler way?
>  
>  
>  
> I am new to camel, but am facing the same problem and have chosen to use the
> enrichment pattern, mostly because I need to implement other, more
> "classical" enrichment scenarios. Interceptors are an alternative approach,
> but I think are not simpler, especially given the timeout and refresh
> requirements.
>  
> Two "bits" of information that may be helpful to you.  
>  
> The Enrich(er) resource is expected to implement the Producer interface.
> This may be obvious to an experienced Cameler, but I didn't see it
> documented and only discovered reading the Enricher source.
> <http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Enricher.java?view=markup>  
> The Enricher only exercises the process method of the Processor
> super-interface, however, not Service start and stop, at least in my
> configuration. I use a ProducerTemplate instance within the Producer
> implementation that is configured with the same endpoint as the regular
> messages.
>  
> This will not apply to you unless you use CXF messages in Pojo data format
> and "out-of-band" SOAP headers to send the authentication token, but the
> example code in  
> http://camel.apache.org/cxf.html#CXF-HowtogetandsetSOAPheadersinPOJOmode
> <http://camel.apache.org/cxf.html#CXF-HowtogetandsetSOAPheadersinPOJOmode>  
> is broken. If there are no existing headers, the example
> InsertResponseOutHeaderProcessor.process will throw a NullPointerException,
> mistakenly trying to use the QName from an existing header to create the new
> one.
>  
> I've been meaning to post an issue about this, but there it is....
>  
> Otherwise, the Enrich is working well for me inside a basic proxy based on
> the camel examples, with routing based on the SOAP action/operation.
>  
>  
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/Login-session-token-with-Camel-CXF-tp5728467p5728477.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).




Re: Login/session token with Camel/CXF

Posted by kingolego <jo...@sovereignsense.com>.
sothach wrote
> I need to integrate with a third party system via its WS interface.  To
> send a request, I must first "login" to the server, and obtain an
> authentication token to attach to all subsequent requests.  This token has
> a limited shelf-life, and will time-out after a period of time, requiring
> me to re-apply.
> My question: is there a standard pattern in Camel for this scenario? 
> My first thought is to implement this by having an enrichment stage, that
> calls out to "direct:login" route, setting a header with the token, that
> can then be used when marshaling the call.  
> Is there a simpler way?

I am new to camel, but am facing the same problem and have chosen to use the
enrichment pattern, mostly because I need to implement other, more
"classical" enrichment scenarios. Interceptors are an alternative approach,
but I think are not simpler, especially given the timeout and refresh
requirements.

Two "bits" of information that may be helpful to you. 

The Enrich(er) resource is expected to implement the Producer interface.
This may be obvious to an experienced Cameler, but I didn't see it
documented and only discovered reading  the Enricher source.
<http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Enricher.java?view=markup>  
The Enricher only exercises the process method of the Processor
super-interface, however, not Service start and stop, at least in my
configuration. I use a ProducerTemplate instance within the Producer
implementation that is configured with the same endpoint as the regular
messages.

This will not apply to you unless you use CXF messages in Pojo data format
and "out-of-band" SOAP headers to send the authentication token, but the
example code in 
http://camel.apache.org/cxf.html#CXF-HowtogetandsetSOAPheadersinPOJOmode
<http://camel.apache.org/cxf.html#CXF-HowtogetandsetSOAPheadersinPOJOmode>  
is broken. If there are no existing headers, the example
InsertResponseOutHeaderProcessor.process will throw a NullPointerException,
mistakenly trying to use the QName from an existing header to create the new
one.

I've been meaning to post an issue about this, but there it is....

Otherwise, the Enrich is working well for me inside a basic proxy based on
the camel examples, with routing based on the SOAP action/operation.





--
View this message in context: http://camel.465427.n5.nabble.com/Login-session-token-with-Camel-CXF-tp5728467p5728477.html
Sent from the Camel - Users mailing list archive at Nabble.com.