You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Niek Palm <ni...@gmail.com> on 2011/03/12 17:35:54 UTC

JAX-WS auuthentication

We using a generic client to connect different webservices depending on a
configuration. Now we need to connect to a service that requires
authentication by username and password. Can you tell me if it is possible
to connect to this service by putting the username and password to the
headers? Below a code snippet is shown.

Service service = Service.create(SERVICE_NAME);
service.addPort(portName, soapbinding, url);
Dispatch<Source> dispatch = service.createDispatch(portName, Source.class,
Service.Mode.PAYLOAD);

// adding headers to the request
if (MapUtils.isNotEmpty(headers)) {
            final Map<String, Object> requestCtx =
dispatch.getRequestContext();
            requestCtx.putAll(headers);
}

Regars,

Niek Palm

Re: JAX-WS auuthentication

Posted by Freeman Fang <fr...@gmail.com>.
Hi,

If the service side authentication is basic auth, you can do it like
          
dispatch.getRequestContext().put(BindingProvider.USERNAME_PROPERTY,  
"username");
          
dispatch.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY,  
"password");

Freeman
On 2011-3-13, at 上午12:35, Niek Palm wrote:

> We using a generic client to connect different webservices depending  
> on a
> configuration. Now we need to connect to a service that requires
> authentication by username and password. Can you tell me if it is  
> possible
> to connect to this service by putting the username and password to the
> headers? Below a code snippet is shown.
>
> Service service = Service.create(SERVICE_NAME);
> service.addPort(portName, soapbinding, url);
> Dispatch<Source> dispatch = service.createDispatch(portName,  
> Source.class,
> Service.Mode.PAYLOAD);
>
> // adding headers to the request
> if (MapUtils.isNotEmpty(headers)) {
>            final Map<String, Object> requestCtx =
> dispatch.getRequestContext();
>            requestCtx.putAll(headers);
> }
>
> Regars,
>
> Niek Palm


-- 
Freeman Fang

------------------------

FuseSource: http://fusesource.com
blog: http://freemanfang.blogspot.com
twitter: http://twitter.com/freemanfang
Apache Servicemix:http://servicemix.apache.org
Apache Cxf: http://cxf.apache.org
Apache Karaf: http://karaf.apache.org
Apache Felix: http://felix.apache.org