You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by awillia <an...@fronde.com> on 2011/11/25 04:57:09 UTC

HTTP Basic authenticaiton on CxfEndpoint

I would like to use HTTP basic authentication when making a web service call
using CXF.

This is basically my code.

CxfEndpoint cxfEndpoint = new CxfEndpoint(app.getMessageServiceUrl(),
camelContext);
cxfEndpoint.setServiceClass(PartnerSMSService.class.getCanonicalName());
RouteDefinition def = from(RECEIVING_QUEUE_PREFIX + app.getName()); // Pull
from each application's queue

def.routeId(getRouteName(app)).transacted()
	.process(new WebServiceProcessor())
        .to(cxfEndpoint); 

The routes are dynamically created based on data, so I can not set up the
routes in the spring config. Is there any way I can set it to use HTTP basic
authentication and define the user name and password in the code that I have
posted above.

I can do this as parameters on the end point when using the HTTP end point,
but don't see anything for CXF.

thanks
Antony

I am using camel 2.8

--
View this message in context: http://camel.465427.n5.nabble.com/HTTP-Basic-authenticaiton-on-CxfEndpoint-tp5021812p5021812.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: HTTP Basic authenticaiton on CxfEndpoint

Posted by awillia <an...@fronde.com>.
Thanks, I am not able to move t0 2.9 just yet because going into production
soon.

I have basically ended up setting the basic auth headers myself and then
they get passwed through with request. Is easier for now, I will look at new
options once move to 2.9.

Thanks for you help.

--
View this message in context: http://camel.465427.n5.nabble.com/HTTP-Basic-authenticaiton-on-CxfEndpoint-tp5021812p5040052.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: HTTP Basic authenticaiton on CxfEndpoint

Posted by Willem Jiang <wi...@gmail.com>.
Hi Antony,

You already find the way to set the conduit with your custom policy :)
If you are using the latest Camel 2.9.0-SNAPSHOT , you can do the job 
by setting the property of the cxfEndpoint like this without digging 
the HttpCondit out

Map <String, Object> myProperties = new HashMap<String, Object>
myProperties.add("org.apache.cxf.configuration.security.AuthorizationPolicy", 
myAuthorizationPolicy);
cxfEndpoint.setProperties(myProperties);

On Mon Nov 28 07:47:17 2011, awillia wrote:
> Thank you for the reply. I am using the camel cxf end point, so this:
>
> import org.apache.camel.component.cxf.CxfEndpoint;
>
> I have seen some configuration setting for a conduit, but I am trying to do
> this programatically (the routes are dynamically created based on database
> configuration). So I have started looking at something like this:
>
> CxfEndpoint cxfEndpoint = new CxfEndpoint(app.getMessageServiceUrl(),
> camelContext);
> cxfEndpoint.setServiceClass(PartnerSMSService.class.getCanonicalName());
>
> CxfProducer producer = (CxfProducer)cxfEndpoint.createProducer();
> HTTPConduit conduit = (HTTPConduit)producer.getClient().getConduit();
>
> AuthorizationPolicy policy = new AuthorizationPolicy();
> policy.setAuthorizationType(HttpAuthHeader.AUTH_TYPE_BASIC);
> policy.setUserName(app.getExternalUserName());
> policy.setPassword(app.getExternalPassword());
> conduit.setAuthorization(policy);
>
> RouteDefinition def = from(RECEIVING_QUEUE_PREFIX + app.getName()); // Pull
> from each application's queue
> 	.process(new WebServiceProcessor())
> 	.to(cxfEndpoint); // Send to application's configured endpoint
>
> However I am not so sure that this will work, I think the producer that I am
> creating here is not the one that will actually be used?? I am not sure.
>
> Do you have any suggestions for how I might define the conduit
> programatically?
>
> thanks
> Antony
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/HTTP-Basic-authenticaiton-on-CxfEndpoint-tp5021812p5027441.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
         http://jnn.javaeye.com (Chinese)
Twitter: willemjiang 
Weibo: willemjiang 


Re: HTTP Basic authenticaiton on CxfEndpoint

Posted by awillia <an...@fronde.com>.
Thank you for the reply. I am using the camel cxf end point, so this:

import org.apache.camel.component.cxf.CxfEndpoint;

I have seen some configuration setting for a conduit, but I am trying to do
this programatically (the routes are dynamically created based on database
configuration). So I have started looking at something like this:

CxfEndpoint cxfEndpoint = new CxfEndpoint(app.getMessageServiceUrl(),
camelContext);
cxfEndpoint.setServiceClass(PartnerSMSService.class.getCanonicalName());

CxfProducer producer = (CxfProducer)cxfEndpoint.createProducer();
HTTPConduit conduit = (HTTPConduit)producer.getClient().getConduit();

AuthorizationPolicy policy = new AuthorizationPolicy();
policy.setAuthorizationType(HttpAuthHeader.AUTH_TYPE_BASIC);
policy.setUserName(app.getExternalUserName());
policy.setPassword(app.getExternalPassword());
conduit.setAuthorization(policy);

RouteDefinition def = from(RECEIVING_QUEUE_PREFIX + app.getName()); // Pull
from each application's queue
	.process(new WebServiceProcessor())
	.to(cxfEndpoint); // Send to application's configured endpoint

However I am not so sure that this will work, I think the producer that I am
creating here is not the one that will actually be used?? I am not sure.

Do you have any suggestions for how I might define the conduit
programatically?

thanks
Antony

--
View this message in context: http://camel.465427.n5.nabble.com/HTTP-Basic-authenticaiton-on-CxfEndpoint-tp5021812p5027441.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: HTTP Basic authenticaiton on CxfEndpoint

Posted by Willem Jiang <wi...@gmail.com>.
Are you using the same cxfEndpoint ?
If so, You can set the AuthorizationPolicy by using the conduit[1].
If not, I'm afraid you have to use other camel component to do the job.

[1]http://cxf.apache.org/docs/client-http-transport-including-ssl-support.html#ClientHTTPTransport%28includingSSLsupport%29-The%7B%7Bconduit%7D%7Delement

On Fri Nov 25 11:57:09 2011, awillia wrote:
> I would like to use HTTP basic authentication when making a web service call
> using CXF.
>
> This is basically my code.
>
> CxfEndpoint cxfEndpoint = new CxfEndpoint(app.getMessageServiceUrl(),
> camelContext);
> cxfEndpoint.setServiceClass(PartnerSMSService.class.getCanonicalName());
> RouteDefinition def = from(RECEIVING_QUEUE_PREFIX + app.getName()); // Pull
> from each application's queue
>
> def.routeId(getRouteName(app)).transacted()
> 	.process(new WebServiceProcessor())
>          .to(cxfEndpoint);
>
> The routes are dynamically created based on data, so I can not set up the
> routes in the spring config. Is there any way I can set it to use HTTP basic
> authentication and define the user name and password in the code that I have
> posted above.
>
> I can do this as parameters on the end point when using the HTTP end point,
> but don't see anything for CXF.
>
> thanks
> Antony
>
> I am using camel 2.8
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/HTTP-Basic-authenticaiton-on-CxfEndpoint-tp5021812p5021812.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
         http://jnn.javaeye.com (Chinese)
Twitter: willemjiang 
Weibo: willemjiang