I need to analyse the xml string below - java

The service at this address http://www.cs12333.com:8001/Service/PersonSearchService returns the following XML:
<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body><ns2:findPersonListResponse xmlns:ns2="http://service.person.search/">
<return>
<result>true</result>
<resultList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:grxxBean">
<aab001>cooperation</aab001>
<aac001>34305742</aac001>
<aac002>430423198906237024</aac002>
<aac003>licong</aac003>
<aac004>2</aac004>
<aac031>2</aac031>`
<pwd>1</pwd>
</resultList>
</return>
</ns2:findPersonListResponse>
</S:Body>
</S:Envelope>
I'm reading the values like this:
dom = DocumentHelper.parseText(result);
Element root=dom.getRootElement();
The root's value is "org.dom4j.tree.DefaultElement#db23f1 [Element: <S:Envelope schemas.xmlsoap.org/soap/envelope/attributes: []/>]".
How do I get the value of tag <aac003>?

Try this expath to get <aac003> value
/*:Envelope/*:Body/*:findPersonListResponse/*:return/*:resultList/*:aac003

Related

Transformer removes the namespace incorrectly from xml

I have the following xml file which has namespace on NFe and enviNFe tags:
<?xml version="1.0" encoding="UTF-8"?>
<nfeDadosMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NFeAutorizacao4">
<enviNFe xmlns="http://www.portalfiscal.inf.br/nfe" versao="4.00">
<idLote>203364605034338</idLote>
<indSinc>0</indSinc>
<NFe xmlns="http://www.portalfiscal.inf.br/nfe">
...
...
But while send the request, exactly on WebServiceTemplate.sendSourceAndReceiveToResult, there is a Transformer that removes the namespace of the NFe tag, as follows:
<?xml version="1.0" encoding="UTF-8"?>
<nfeDadosMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NFeAutorizacao4">
<enviNFe xmlns="http://www.portalfiscal.inf.br/nfe" versao="4.00">
<idLote>203364605034338</idLote>
<indSinc>0</indSinc>
<NFe>
...
...
The Webservice doesn't accept the request n this case.
What should I do to avoid this behavior?

SOAP - null body

Have a SOAP response that I can't parse into NodeList.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<soap-env:Envelope xmlns:soap-
env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap-env:Body>
<s0:response xmlns:s0="urn:company.processing.messages">
<newOutput>
<messageType>OKAY</messageType>
<messageCode>00000000</messageCode>
<messageText>SUCCESSFUL</messageText>
</newOutput>
</s0:response>
</soap-env:Body>
</soap-env:Envelope>
Returns NullPointerException:
SOAPMessage soapMessage = ((SaajSoapMessage) messageContext.getResponse()).getSaajMessage();
NodeList nodeList = soapMessage.getSOAPBody().getChildNodes().item(0).getFirstChild().getChildNodes();
My guess something is wrong with the the format of this message but can't figure out what exactly is wrong.
The issues was with XML formatting. Resolved.

Problems with returning String[] from Java Web Service to Swing client

I am just trying to return a String[] from a #webMethod to the ws swing client. The problem is that it is not returning anything. When I test the web service it shows
Method returned
net.java.dev.jaxb.array.StringArray : "net.java.dev.jaxb.array.StringArray#2f741802"
SOAP Request
<?xml version="1.0" encoding="UTF-8"?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<S:Body>
<ns2:getEmployeeNames xmlns:ns2="http://employee.bank.com/"/>
</S:Body>
</S:Envelope>
SOAP Response
<?xml version="1.0" encoding="UTF-8"?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<S:Body>
<ns2:getEmployeeNamesResponse xmlns:ns2="http://employee.bank.com/">
<return>
<item>73869</item>
</return>
</ns2:getEmployeeNamesResponse>
</S:Body>
</S:Envelope>
the web service method is
public String[] getEmployeeNames()
{
String[] nameList = ........;
return nameList;
}

How to remove an element prefix in a soap message

I have to send an xml content into soap message.
The web service rejects the request because there is an extra prefix in the root element of the body.
The generated soap message is :
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns3:rootElement xmlns:ns2="http://webserviceprovider/result" xmlns:ns3="http://webserviceprovider/request">
--- other data
</ns3:rootElement>
</S:Body>
What is expected by the web service is a soap message without prefix (ns3):
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<rootElement xmlns:ns2="http://webserviceprovider/result" xmlns:ns3="http://webserviceprovider/request">
--- other data
</rootElement>
</S:Body>
Thanks.

How to parse soap response from web service to get value of node using java

I am getting soap response from web service. I need to parse to get the value inside the node. Please provide some code to parse the soap response.
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<ns3:Response xmlns:ns3="http://www.example.org/Response" userid="100">
<name date="23-10-2013">Sample</name>
<name date="02-09-2013">Hello</name>
</ns3:Response>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Categories

Resources