soap tags using JiBX
I am a web services developer. In all of my XML requests I send to a different webservice, I need to add soap envelope, soap header, soap body tags. and in the response I need to ignore those and parse just the child of soap body. Example:
Request:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://schemas.abc.com/v1.0">
<soapenv:Header/>
<soapenv:Body>
<ns:webservice-abc-Request xmlns:ns="http://schemas.abc.com/v1.0">
Response:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<ns:webservice-abc-Response xmlns:ns="http://schemas.abc.com/v1.0">
and I am using JiBX at both request and response handling.The schema obviously does not define these soap tags. So what I am currently doing is take the 开发者_JAVA百科request as string and add these soap tags at appropriate places and send the request.
In response, remove the soap tags using String operations and parse the rest of message using JiBX.
I would like to know a better approach and get rid of these String operations. I want to implement these things purely in JiBX. Is there a way?
Thanks.
Are you using flexible='true' in your JiBX binding? This will prevent JiBX from trying to parse through the SOAP envelope and you can just define a mapping for the SOAP body.
<binding>
<mapping name="Envelope" ns="http://schemas.xmlsoap.org/soap/envelope/" flexible="true" ordered="false">
<structure name="Body" ns="http://schemas.xmlsoap.org/soap/envelope/">
... your envelope binding here! ...
</structure>
</mapping>
</binding>
Secondly, are you using a web services framework such as Axis2? Axis2 can automatically remove those headers and simply return to the SOAP body to you (as an OMElement which can easily be converted into a String) and from there you can use JiBX.
http://axis.apache.org/axis2/java/core/api/org/apache/axis2/client/ServiceClient.html
精彩评论