Hi,

We are using synapse between
1)       A web service client that was created from a wsdl that doesn't have 
any authentication parameters.
2)       A web service provider that requires authentication.

One of the requirements is to introduce a header element as per the 
requirements of the service provider.

I am using custom mediation in java to do this. The java class and the 
synapse.xml are given below.
The problem is that the Header changes that I do in the custom class are not 
appearing in the Header that goes to the web service provider.
In fact, the soap envelope to the web service provider doesn't have a 
soapHeader field at all, though it appears properly when I try to log it within 
the java class.

Could you please provide any pointers to this?

public class AddHeaders extends AbstractMediator {
    public boolean mediate(MessageContext mc) {
            try {
                        NamespaceImpl secns = new NamespaceImpl
                        
("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd","oas";);

                        NamespaceImpl omns = new NamespaceImpl
                        
("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd","oas";);

                        OMFactory sfactory = new DOMSOAPFactory();
                        ElementImpl security = new ElementImpl(new 
DocumentImpl(sfactory), "Security", omns, sfactory);
                        ElementImpl usernameToken = new ElementImpl(security, 
"UsernameToken", omns, sfactory);
                        ElementImpl username = new ElementImpl(usernameToken, 
"Username", omns, sfactory);
                        username.setText("myusername");

                        ElementImpl password = new ElementImpl(usernameToken, 
"Password", omns, sfactory);
                        password.setText("mypassword");

                        mc.getEnvelope().getHeader().addChild(security);
            }catch(Exception e){
                        System.out.println("exp: " + e);
            }
            System.out.println("Logging the Header" + 
mc.getEnvelope().getHeader().toString());
                        return true;
    }
}


<definitions xmlns="http://ws.apache.org/ns/synapse";>
    <class name="samples.mediators.AddHeaders"/>
    <callout serviceURL="http://localhost:5002/baocdp/ws/workflow";
             action="execute-workflow">
        <source xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/";
                xmlns:s12="http://www.w3.org/2003/05/soap-envelope";
                            xpath="s11:Body/child::*[fn:position()=1] | 
s12:Body/child::*[fn:position()=1]"/>
        <target xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/";
                xmlns:s12="http://www.w3.org/2003/05/soap-envelope";
                xpath="s11:Body/child::*[fn:position()=1] | 
s12:Body/child::*[fn:position()=1]"/>
    </callout>
    <property name="RESPONSE" value="true"/>
</definitions>

Regards,
Sabareeswar


**************** CAUTION - Disclaimer *****************
This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely 
for the use of the addressee(s). If you are not the intended recipient, please 
notify the sender by e-mail and delete the original message. Further, you are 
not 
to copy, disclose, or distribute this e-mail or its contents to any other 
person and 
any such actions are unlawful. This e-mail may contain viruses. Infosys has 
taken 
every reasonable precaution to minimize this risk, but is not liable for any 
damage 
you may sustain as a result of any virus in this e-mail. You should carry out 
your 
own virus checks before opening the e-mail or attachment. Infosys reserves the 
right to monitor and review the content of all messages sent to or from this 
e-mail 
address. Messages sent to or from this e-mail address may be stored on the 
Infosys e-mail system.
***INFOSYS******** End of Disclaimer ********INFOSYS***

Reply via email to