I am using something like this:

   FoobarService foobarService = new FoobarService();
   FoobarPortType foobarPort = foobarService.getFoobarPort();
   context = ((BindingProvider) foobarPort).getRequestContext();
   context.put(USERNAME, "me");
   context.put(PASSWORD, "hello");
   context.put(ENDPOINT_ADDRESS, "http://localhost/ws/services/Foobar";);

FoobarService and FoobarPortType are generated by wsdl2java
and I include those classes in a JAR that is available on
both the client side and server side.

- Dan 

> -----Original Message-----
> From: xbranko [mailto:[EMAIL PROTECTED] 
> Sent: Wednesday, March 05, 2008 4:38 PM
> To: cxf-user@incubator.apache.org
> Subject: Accessing WebService that requires username/password
> 
> 
> How should a webservice that requires basic username/password for
> authentication be accessed? The CXF service class that is 
> autogenerated
> extends the javax.xml.ws.Service class. So when the client tries to
> instantiate it, it fails because it gets java.io.IOException: Server
> returned HTTP response code: 401 for URL.
> 
> Looking at the documentation, and on the web, it seems that 
> what is needed
> is to add something like this:
> 
>         //Create a dispatch instance
>         Dispatch<SOAPMessage> dispatch = 
>            createDispatch(WebService1, SOAPMessage.class,
> Service.Mode.MESSAGE);
> 
>         // Use Dispatch as BindingProvider
>         BindingProvider bp = (BindingProvider) dispatch;
> 
>         // Optionally Configure RequestContext to send SOAPAction HTTP
> Header
>         Map<String, Object> rc = bp.getRequestContext();
>         rc.put(BindingProvider.USERNAME_PROPERTY, userName);
>         rc.put(BindingProvider.PASSWORD_PROPERTY, password);
> 
> before the service hits the url. However, given that service 
> derives from
> javax.xml.ws.Service class whose constructor is protected, 
> how do I do that,
> given that constructor looks like:
> 
>     public WebServiceX() {
>         super(WSDL_LOCATION, SERVICE);
>     }
>       
> and in the super's constructor (javax.xml.ws.Service), the 
> class tries to
> connect to the url that needs the username and password, and 
> due to java,
> call to super must be the first call in the deriver class's 
> constructor.
> 
> Note that this is not an https service, but just an http 
> service that works
> well when I invoke it from the browser (once I provide 
> username and password
> in the dialog box provided by the browser).
> 
> Any help greatly appreciated!
> -- 
> View this message in context: 
> http://www.nabble.com/Accessing-WebService-that-requires-usern
> ame-password-tp15863184p15863184.html
> Sent from the cxf-user mailing list archive at Nabble.com.
> 
> 

Reply via email to