cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xbranko <xbra...@netscape.net>
Subject Accessing WebService that requires username/password
Date Wed, 05 Mar 2008 23:37:56 GMT

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-username-password-tp15863184p15863184.html
Sent from the cxf-user mailing list archive at Nabble.com.


Mime
View raw message