how to parse xml using soap web service - java

I have a device which periodically sends xml file to a specific webservice. Also I have a web service. My web service read this xml.
My Web service definition is :
#Name("myWebService")
#SOAPBinding(style = Style.RPC)
#WebService(targetNamespace = "http://www.abc.com.tr/")
public class MyWebService {
#Resource
WebServiceContext wsContext;
#WebMethod()
public String DeviceStatus(#WebParam(name = "SP") SP SP) {..}
My class structure is SP.java, MODULES.java, MODULE.java, SENSORS.java, SENSOR.java
Before there was no problem but when the incoming xml's namespace definition has changed my webservice started to give error like : can not find child element SP
before the incoming xml was :
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:abc="http://www.abc.com.tr/">
<soap:Body>
<abc:DeviceStatus>
<SP>
<VERSION>1.2</VERSION>
<MODULES>
<MODULE><NAME>name</NAME><TYPE>1</TYPE>
<SENSORS>
<SENSOR><ID>0</ID><NAME>Input</NAME></SENSOR>
</SENSORS>
</MODULE>
</MODULES>
</SP>
</abc:DeviceStatus></soap:Body></soap:Envelope>
now the incoming xml is :
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<DeviceStatus xmlns="http://www.abc.com.tr/">
<SP>.......
I am looking forward your replies. thanks...

Related

Send Soap Request in java with Authentication

I want to send a java soap req to a web service:
url: (https://webapplicaties.agro.nl/OpvragenPandEnergieLabel/EpbdOpvragenPandEnergieLabelService.asmx?WSDL)
This is the request:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:epb="http://schemas.ep-
online.nl/EpbdOpvragenPandEnergieLabelHeader"
xmlns:epb1="http://schemas.ep-
online.nl/EpbdOpvragenPandEnergieLabelRequest">
<soapenv:Header>
<epb:PandEnergieLabelHeader>
<epb:username>username</epb:username>
<epb:password>password</epb:password>
<epb:versienr>4</epb:versienr>
</epb:PandEnergieLabelHeader>
</soapenv:Header>
<soapenv:Body>
<epb1:GetPandEnergieLabel>
<epb1:Pand_postcode>postcode</epb1:Pand_postcode>
<epb1:Pand_huisnummer>housnr</epb1:Pand_huisnummer>
<epb1:Pand_huisnummer_toev>extra</epb1:Pand_huisnummer_toev>
</epb1:GetPandEnergieLabel>
</soapenv:Body>
</soapenv:Envelope>
and the response should be like this.
Which steps should I take to have a such a response?
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<PandEnergieLabel xmlns="http://schemas.ep-online.nl/EpbdExportTypes">
<Pand_gebouwklasse>W</Pand_gebouwklasse>
<Pand_is_op_basis_van_referentie_gebouw>false</Pand_is_op_basis_van_referentie_gebouw>
<Pand_opnamedatum>29-04-2011</Pand_opnamedatum>
<Pand_berekeningstype>EP</Pand_berekeningstype>
<Pand_energieprestatieindex>1.21</Pand_energieprestatieindex>
<Pand_energieklasse>B</Pand_energieklasse>
<Pand_energielabel_is_prive>false</Pand_energielabel_is_prive>
<Pand_forfaitaire>1.21</Pand_forfaitaire>
<Meting_geldig_tot>29-04-2021</Meting_geldig_tot>
<Pand_registratiedatum>29-04-2011</Pand_registratiedatum>
<Pand_postcode>1072XC</Pand_postcode>
<Pand_huisnummer>79</Pand_huisnummer>
<Pand_huisnummer_toev>A</Pand_huisnummer_toev>
<Pand_gebouwcode />
<Pand_gebouwtype>Portiekwoning</Pand_gebouwtype>
<Pand_gebouwsubtype>Tussenvloer</Pand_gebouwsubtype>
</PandEnergieLabel>
</soap:Body>
</soap:Envelope>
How should I use Variables inside the request to ask for multiple addresses (postcode, housnr, ...)
Thanks

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?

Adding a handler for a JAX-RS Rest service

For my own hosted JAX-WS (Soap) web services, I can add handlers by defining a handler-chain file and adding them there, for instance:
#WebService(serviceName = "My_Service", portName = "My_Port_Soap12", targetNamespace = "urn:mynamespace")
#HandlerChain(file = "handler-chain.xml")
public class MyService { ... }
In my handler-chain.xml:
<?xml version="1.0" encoding="UTF-8"?>
<handler-chains xmlns="http://java.sun.com/xml/ns/javaee">
<handler-chain>
<handler>
<handler-class>MyHandler</handler-class>
</handler>
</handler-chain>
</handler-chains>
Is there any way I can do the same for a JAX-RS Rest service?
I need some custom authentication logic which I need to add to my services.

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>

jax-ws webservice client returns only empty objects

I generate a Web Service Client with the assistant of Eclipse passing the WSDL of the provider Web Service.
I generate in a JUnit test case the object to pass to the Web Service.
//After set properties of the request object
AbacusWebService wsAbacus = new AbacusWebService();
WebServiceResult wsResult = wsAbacus.irsValoration(requestObject);
With the monitor TCP-IP of Eclipse I see the the request and the response and both are correct. The response returns data:
<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>
<irsValorationResponse xmlns="http://webServices.isban.es">
<irsValorationReturn>
<error xsi:nil="true"/>
<format>dd/MM/yyyy</format>
<pricingDate>02/09/2012</pricingDate>
<results>
<results>
<bpv>-492.6493116525817</bpv>
<cer xsi:nil="true"/>
<chargeRunning xsi:nil="true"/>
<chargeUpfront xsi:nil="true"/>
<error xsi:nil="true"/>
<gamma>0.004649336915463209</gamma>
<gammaTotal xsi:nil="true"/>
<minCerReturn xsi:nil="true"/>
<name>IRS</name>
<npv>46371.877687584296</npv>
<payingNpv>0.0</payingNpv>
<pricingDelta>433.0423619134596</pricingDelta>
<receivingNpv>46371.877687584296</receivingNpv>
<swapRate>0.9412756009346844</swapRate>
</results>
</results>
</irsValorationReturn>
</irsValorationResponse>
</soapenv:Body>
But when I inspect the response object (wsResult), all of their properties are null.
Can anyone help me?
Thanks in advance.

Categories

Resources