Adding soap header authentication to the code generated by wsdl2java

I am creating a Java web services client from wsdl. I used the Eclipses Dynamic Web Project and the new web services client to generate code using wsdl2java with Apache Axis 1.4. I need to add SOAP authentication to this code so that it works with the service. I could not find a place to do this in the generated code. After extensive research, I found this, which I used as the basis for my code.

Adding ws-security to classes created by wsdl2java

Before I received the error message "Error while processing security for message" or something like that. Now i get

"Exception: did not understand the MustUnderstand headers: { http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd } Security Message: null"

I tried many things to overcome this exception. This is the code I came to now.

javax.xml.namespace.QName headerName = new javax.xml.namespace.QName(
                "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Security");
        org.apache.axis.message.SOAPHeaderElement header = new org.apache.axis.message.SOAPHeaderElement(headerName);
        header.setActor(null);
        header.setMustUnderstand(true);

        // Add the UsernameToken element to the WS-Security header
        javax.xml.soap.SOAPElement utElem = header.addChildElement("UsernameToken");
        utElem.setAttribute("Id", "uuid-3453f017-d595-4a5b-bc16-da53e5831cd1-1");
        javax.xml.soap.SOAPElement userNameElem = utElem.addChildElement("Username");
        userNameElem.setValue("username");
        javax.xml.soap.SOAPElement passwordElem = utElem.addChildElement("Password");
        passwordElem.setAttribute("Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");
        passwordElem.setValue("password");

        header.setProcessed(true);

        // Finally, attach the header to the binding.
        setHeader(header)

This code is in my Binding_ServiceStub class (in its createCall method).

We created clients in both C # and VB with this wsdl, and there it is as simple as changing the ClientCredentials variable, which is an extension of the proxy class created. I was hoping for something like this here.

It also contains the security policy from the wsdl code.

<wsp:Policy><sp:UsernameToken sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient"><wsp:Policy><sp:WssUsernameToken10/></wsp:Policy></sp:UsernameToken></wsp:Policy>

- , ? ? setProcesses setMustUnderstand ( ).

- , Soap wsdl2java, . , , , - , , .

Update - , , SOAPUI, . - ? SOAP-, . Axis 1.4 JAX-RPC ? ( , , ...)

+3
1

. Apache CXF ,

javax.xml.ws.BindingProvider bp = (javax.xml.ws.BindingProvider) port;
    bp.getRequestContext().put("ws-security.username", username);
    bp.getRequestContext().put("ws-security.password", password);

. Axis 1.4.

+4

All Articles