0
votes

I need to consume a soap service having ws-security username token. Below is my code and error.

<?xml version="1.0" encoding="UTF-8"?>
<api context="/Service" name="ServiceA-Service" xmlns="http://ws.apache.org/ns/synapse">
    <resource methods="POST">
        <inSequence>
            <header name="To" scope="default" value="https://Service/Service.svc"/>
            <property name="Username" scope="axis2" type="STRING" value="MYUSER"/>
            <property name="Password" scope="axis2" type="STRING" value="MYPASSWORD"/>
            <send>
                <endpoint>
                    <wsdl port="CustomBinding_Service" service="Service" uri="workingSFD.xml">
                        <enableSec policy="conf:myresources/NewResource.xml"/>
                    </wsdl>
                </endpoint>
            </send>
        </inSequence>
        <outSequence>
            <respond/>
        </outSequence>
        <faultSequence/>
    </resource>
</api>

But while sending the below request from Postman:

<soapenv:Envelope>
   <soapenv:Header/>
   <soapenv:Body>
      <arg1>asdsa</arg1>
   </soapenv:Body>
</soapenv:Envelope>

It showed me the below error:

 Missing wsse:Security header in request {org.apache.axis2.engine.AxisEngine}

I am using the default policy of WSO2 Username token.

1
Does the service expect the header? How is the message being handled? Is there a SOAP message handler including the header?Michael C Good
The sender will only send the request without headers wso2 esb should add headers and send to wsdl. The same approach i am doing it in MULE but i am new to WSO2 so that's why i need help sir.Chris Ryan

1 Answers

0
votes

You have to set the username and password as client options, not as axis2 properties. You can refer this for detailed explanation - http://xacmlinfo.org/2014/03/25/how-to-esb-invoking-username-token-secured-backend-service/

Following is a simplified version of the class mediator to set the username and password.

public class UTTokenBuilder extends AbstractMediator{
    @Override
    public boolean mediate(MessageContext messageContext) {
        try {
            org.apache.axis2.context.MessageContext context = ((Axis2MessageContext) messageContext)
                    .getAxis2MessageContext();
            context.getOptions().setUserName("admin");
            context.getOptions().setPassword("admin");
            return true;
        } catch (SynapseException e) {
            throw e;
        } catch (Exception e) {
            throw new SynapseException("Error while building UT Token");
        }
    }
}