Document doc = documentBuilder.parse(in);
Element root = doc.getDocumentElement();
NodeList nodeList = root.getElementsByTagName("soap:Envelope");
StringInputStream request;
for(int i = 0; i < nodeList.getLength(); i++){
StringBuffer envelope = new StringBuffer("<soap:Envelope");
Element element = (Element)nodeList.item(i);
NamedNodeMap attributes = element.getAttributes();
if(attributes != null){
for(int k=0; k < attributes.getLength(); k++){
envelope.append(" "+attributes.item(k).getNodeName().trim());
envelope.append("=\""+attributes.item(k).getNodeValue().trim()+"\"");
}
String content = element.getTextContent();
if(content != null && !content.equals("")){
envelope.append(">");
NodeList children = element.getChildNodes();
if(children != null){
for(int j=0; j < children.getLength(); j++){
if(children.item(j).getNodeType() == org.w3c.dom.Node.ELEMENT_NODE){
Element child = (Element)children.item(j);
envelope.append(getElementContent(child).trim());
}else if(children.item(j).getNodeType() == org.w3c.dom.Node.TEXT_NODE){
envelope.append(children.item(j).getNodeValue().trim());
}
}
}
envelope.append("</soap:Envelope>");
}else {
envelope.append("/>");
}
}
request = new StringInputStream(envelope.toString());
PortInfo portInfo = new PortInfo();
portInfo.setLocation(serviceName);
File wsdlFile = new File(RESOURCE_PATH + wsdl);
portInfo.setWsdlFile(wsdlFile.toURL().toString());
try {
Axis2Request req = new Axis2Request(504,
"text/xml; charset=utf-8",
request,
Request.POST,
new HashMap(),
new URI("/axis2/"+serviceName),
new HashMap(),
"127.0.0.1");
ByteArrayOutputStream out = new ByteArrayOutputStream();
Axis2Response res = new Axis2Response("text/xml; charset=utf-8", "127.0.0.1", null, null, 8080, out);
POJOWebServiceContainer container = new POJOWebServiceContainer(portInfo, endPointClassName, cl, null, null);
container.invoke(req, res);
System.out.println("Response "+out);
out.flush();
} catch (Throwable ex) {
ex.printStackTrace();
throw new Exception(ex.toString());
} finally {
if (request != null) {
try {
request.close();
} catch (IOException ignore) {
// ignore
}
}
}