Sadly, I was able to get this portion of your code below to work for
Metro but not CXF:

        rc.put(BindingProvider.USERNAME_PROPERTY, userName);
        rc.put(BindingProvider.PASSWORD_PROPERTY, password);

I have been meaning to look at this to find out the reason why.  But in
the meantime, CXF has an alternate method of supplying this information,
documented here[1].

Glen

[1] http://tinyurl.com/ytc77j

Am Mittwoch, den 05.03.2008, 15:37 -0800 schrieb xbranko:
> 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!

Reply via email to