Hi all!
I'm new to Axis. I would modify the body of a SOAP message *before* axis
(client-side) send it to a Web Service.
First of all, I wrote a simple Echo WS:
public class MyServerOne {
public String echo(String msg) {
System.out.println("In the WS - Server Side");
return "ECHO: % " + msg + " %";
}
}
and I deployed it with the following WSDD:
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<service name="MyServerOne" provider="java:RPC">
<parameter name="className" value="wsSamlTest.server.MyServerOne"/>
<parameter name="allowedMethods" value="echo"/>
<parameter name="scope" value="Request"/>
</service>
</deployment>
Further, I developed a simple client-side handler:
public class myClientHandler extends BasicHandler {
public void invoke(MessageContext msgContext) throws AxisFault {
try {
SOAPEnvelope env = msgContext.getRequestMessage().
getSOAPEnvelope();
SOAPBody body = env.getBody();
System.out.println("VALUE before: " +
body.
getFirstChild().
getFirstChild().
getFirstChild().
getNodeValue() );
//set the new value:
body.
getFirstChild().
getFirstChild().
getFirstChild().
setNodeValue("new value");
System.out.println("VALUE AFTER: " +
body.
getFirstChild().
getFirstChild().
getFirstChild().
getNodeValue() );
} catch (SOAPException ex) {
ex.printStackTrace();
throw new AxisFault("myClientHandler",ex);
} catch (DOMException ex) {
ex.printStackTrace();
throw new AxisFault("myClientHandler",ex);
}
}
}
I deployed the previous handler on the flow with the following WSDD:
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<transport name="http" pivot="java:org.apache.axis.transport.http.HTTPSender"/>
<globalConfiguration>
<requestFlow>
<handler type="java:wsSamlTest.client.myClientHandler" >
</handler>
</requestFlow>
</globalConfiguration >
<transport name="java" pivot="java:org.apache.axis.transport.java.JavaSender"/>
<transport name="http" pivot="java:org.apache.axis.transport.http.HTTPSender"/>
<transport name="local"
pivot="java:org.apache.axis.transport.local.LocalSender"/>
</deployment>
The output of the client-side handler is the following:
VALUE before: Original value
VALUE after: new value
But the SOAP message sent is the following:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns1:echo
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:ns1="http://server.wsSamlTest">
<msg xsi:type="soapenc:string" xmlns:soapenc=
"http://schemas.xmlsoap.org/soap/encoding/">
Original value
</msg>
</ns1:echo>
</soapenv:Body>
</soapenv:Envelope>
Where I mistake?
Thanks all in advance... and happy new year!
Antonio