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

Reply via email to