Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Soap Axis Handler

Hello,

I tried to add custom handler in soap axis sender adapter to map soap fault response to another structure.

Pls see below code:

public class MapSoapResponse extends BasicHandler {

protected static Log log = LogFactory.getLog(MapSoapResponse.class.getName());

private static final String NSURI = "http://sap.com/xi/XI/System/Axis/sample";

private static final String LCNAME = "SimpleAuthentication";

/* (non-Javadoc)

  • @see org.apache.axis.Handler#invoke(org.apache.axis.MessageContext)

*/

public void invoke(MessageContext msgContext) throws AxisFault {

try {

Message msg = msgContext.getCurrentMessage();

SOAPEnvelope soap = msg.getSOAPEnvelope();

if (soap.getBody().hasFault())

{soap.clearBody();

soap.addBodyElement(createSimpleAuthenticationHeader());}

else

soap.addBodyElement(createSimpleAuthenticationHeader());

}

catch (Exception e) {

Message msg = msgContext.getCurrentMessage();

SOAPEnvelope soap = msg.getSOAPEnvelope();

soap.clearBody();

try {

soap.addBodyElement(createSimpleAuthenticationHeader());

} catch (Exception e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

throw AxisFault.makeFault(e);

}

}

private SOAPBodyElement createSimpleAuthenticationHeader() throws Exception {

Document doc = XMLUtils.newDocument();

Element root = doc.createElementNS(NSURI, LCNAME);

Element nameNode = doc.createElementNS("", "name");

Text nameText = doc.createTextNode("");

nameNode.appendChild(nameText);

Element passwordNode = doc.createElementNS("", "password");

Text passwordText = doc.createTextNode("");

passwordNode.appendChild(passwordText);

root.appendChild(nameNode);

root.appendChild(passwordNode);

SOAPBodyElement body = new SOAPBodyElement(root);

return body;

}

}

The handler code gets executed if I have a timeout of 40sec in soap receiver adapter and I get following response:

<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>

<Export>A</Export>

<ns1:SimpleAuthentication xmlns:ns1="http://sap.com/xi/XI/System/Axis/sample">

<name/>

<password/>

</ns1:SimpleAuthentication>

</soapenv:Body>

</soapenv:Envelope>

SimpleAuthentication is added by custom handler.

But if I have a timeout of 4 sec in soap receiver adapter and I get following response:

<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>

<soapenv:Fault>

<faultcode>soapenv:Server.generalException</faultcode>

<faultstring>senderChannel 'bb92aea1ad2c38868e8aec4dff6c69cb': Catching exception calling messaging system; nested exception is:

com.sap.aii.af.ra.ms.api.DeliveryException: XIAdapterFramework:GENERAL:com.sap.aii.af.ra.ms.api.DeliveryException: Read timed out</faultstring>

<detail>

<ns1:hostname xmlns:ns1="http://xml.apache.org/axis/">sapxis01</ns1:hostname>

</detail>

</soapenv:Fault>

</soapenv:Body>

</soapenv:Envelope>

Here, custom handler is not clearing out the body and adding SimpleAuthentication element in the body.

I was expecting following output in this case:

<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:SimpleAuthentication xmlns:ns1="http://sap.com/xi/XI/System/Axis/sample">

<name/>

<password/>

</ns1:SimpleAuthentication>

</soapenv:Body>

</soapenv:Envelope>

Any Ideas?

Please help.

Am I missing something or is there any alternative?

Thanks in advance,

Beena.

Not what you were looking for? View more on this topic or Ask a question