cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xbranko <>
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 class. So when the client tries to
instantiate it, it fails because it gets 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,

        // Use Dispatch as BindingProvider
        BindingProvider bp = (BindingProvider) dispatch;

        // Optionally Configure RequestContext to send SOAPAction HTTP
        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 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 (, 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:
Sent from the cxf-user mailing list archive at

View raw message