29 August 2012

How to retrieve XML sent into SOAP Payload

Using WebLogic Server 10.3.5 , we need a way to retrieve XML payload that is not sent between CDATA:

<foo>
<bar>
foobar
</bar>
</foo>

To implement the solution, please use the following snippet code to achieve the requirement:

To achieve this, we use JAX-RPC and following webservice endpoint:
in the method nodeToString() we are getting the XML as String:

@WebMethod()

public String sayHello(javax.xml.soap.SOAPElement message) {

System.out.println("**************************ENDPOINT**************************************************");

System.out.println("sayHello:" + message.toString());

System.out.println("sayHello:" + message.getClass());



printNodeToConsole(message);

String xml_str = nodeToString(message);



System.out.println("****************************XML**********************");

System.out.println(xml_str);

System.out.println("****************************XML**********************");



return "Here is the message: '" + message + "'";

}





private String nodeToString(Node node) {

StringWriter sw = new StringWriter();

try {

System.out.println("Start string conversion...");

Transformer t = TransformerFactory.newInstance().newTransformer();

t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");

t.transform(new DOMSource(node), new StreamResult(sw));

} catch (TransformerException te) {

System.out.println("nodeToString Transformer Exception");

}

System.out.println("end string conversion...");

return sw.toString();

}


There is a workaround escaping the XML with CDATA or XML entities < >
but the solution would be to use javax.xml.soap.SOAPElement as parameter of the webservice endpoint

28 August 2012

Numbers with Thousand Separators

My solution for Numbers with Thousand Separators regexp:

^\-?[0-9]{1,3}(\,[0-9]{3})*(\.[0-9]+)?$|^[0-9]+(\.[0-9]+)?$


My Blog List

Blog Archive

Disclaimer

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.