Remove <soapenv:Header> from payload in XML route - java

I am looking for solution how to remove <soapenv:Header> part from SOAP request using XML-based routing (Apache Camel Blueprint XML).
So this:
<soapenv:Envelope xmlns:net="..." xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
...
</soapenv:Header>
<soapenv:Body>
...
</soapenv:Body>
</soapenv:Envelope>
shall become just this:
<soapenv:Envelope xmlns:net="..." xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
...
</soapenv:Body>
</soapenv:Envelope>
I think I found java-based solution, also xslt-based solution, but I dont find them quite suitable for my project, and I still hope there is some simple way how to do it directly in XML route without creating java processing class or adding XSLT template.
I was trying <removeHeaders pattern="_something_"/> but either I cant figure out the correct "something", or this command only applies to headers above payload section...

In Blueprint you can get the body of the XML by using XPATH. Something like this:
<setProperty propertyName="MessageBody">
<xpath>//*[local-name()='Body']</xpath>
</setProperty>
Then you could reconstruct your message with the envelop tag.
<setBody>
<simple><![CDATA[<Envelope>${property.MessageBody}</Envelope>]]></simple>
</setBody>
This will only work if your Envelope tag is a constant.

The easiest way I would thing is to parse the SOAP message and then remove the header. You can do that with SAAJ.
How to remove empty header from SOAP message?
.removeHeaders() is for removing Camel exchange headers which is something completely different.

It depends on what dataformat you are using for the CXF endpoint, Is this SOAP request coming from someother service ?
Why are you not happy with XSLT ?
Regardless, You can remove if you use payload DATAFORMAT.

So I find perfect and very simple solution to my issue:
The contents of <soapenv:Header> (along with contents of <soapenv:Body>) were stored in CxfPayload object , which is part of org.apache.camel.Exchange
After I learned this, I was just one Groovy command, that can be easily included in routes.xml, away from solution:
<groovy>
exchange.getIn().getBody(org.apache.camel.impl.DefaultMessage.class).getBody(org.apache.camel.component.cxf.CxfPayload.class).getHeaders().clear();
</groovy>

Related

SOAP: How to Make Call to CountryInfoService WSDL file in Java e.g. use CapitalCity SOAP Operation

Hi so I managed to generate WSDL Java Classes using Java-WS with the "wsimport" command. The WSDL file is from:
http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?wsdl
The problem is that Im not familiar on how to use this.
How do I make a SOAP call to the CapitalCity SOAP method.
In SOAPUI, you would just pass the CountryISOCode like:
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.oorsprong.org/websamples.countryinfo">
<soapenv:Header/>
<soapenv:Body>
<web:CapitalCity>
<web:sCountryISOCode>UKR</web:sCountryISOCode>
</web:CapitalCity>
</soapenv:Body>
</soapenv:Envelope>
How to do this in Java?
This is my code that I've started.
CountryInfoService countryInfoService = new CountryInfoService();
I dont know what follows next. Again Im trying to use the "CapitalCity" SOAP Operation.
Here's a sample answer:
CountryInfoService countryInfoService = new CountryInfoService();
CountryInfoServiceSoapType countryInfoServiceSoapType = countryInfoService.getCountryInfoServiceSoap();
System.out.println(countryInfoServiceSoapType.capitalCity("RUS"));
//output is 'Moscow'
That's how to use it.

how to retrieve specific web service response from the server

Web service provider has provided us(Client) a wsdl to use their service and consume data. Our requirement is, we just need specific node value called "CHASE", see below test data. We don't want to get all records of info and corresponding nodes in the response.
Here is an example that we have tested in SOAPUI tool. Please suggest and help us how can we frame the web service request technically from the URL provided(http://host:port/ValueMappingInService/ValueMappingInImplBean)? Is it at all possible to drill down the request and get specific response from client side?
Web service Request:-
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:bas="http://sap.com/xi/BASIS">
<soapenv:Header/>
<soapenv:Body>
<bas:ValueMappingReadRequest>
<!--Optional:-->
<ReadContext>User</ReadContext>
<!--Zero or more repetitions:-->
<ValueMappingID>c44f541f-c8ac-11e8-86e5-0050569d98cc</ValueMappingID>
</bas:ValueMappingReadRequest>
</soapenv:Body>
</soapenv:Envelope>
Web service Response:-
<SOAP-ENV:Envelope xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-
ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<ns2:ValueMappingReadResponse xmlns:ns2="http://sap.com/xi/BASIS">
<ValueMapping>
<MasterLanguage>EN</MasterLanguage>
<AdministrativeData>
<ResponsibleUserAccountID>gdonna</ResponsibleUserAccountID>
<LastChangeUserAccountID>gdonna</LastChangeUserAccountID>
<LastChangeDateTime>2018-10-05T09:47:38.237-05:00</LastChangeDateTime>
<FolderPathID>/</FolderPathID>
</AdministrativeData>
<ValueMappingID>c44f541f-c8ac-11e8-86e5-0050569d98cc</ValueMappingID>
<GroupName>Mercedes</GroupName>
<Representation schemeAgencyID="LOC_BANK" schemeID="BANK">CHASE</Representation>
<Representation schemeAgencyID="LOC_SITE" schemeID="DIR">comm/as2/chase/receive/</Representation>
<Representation schemeAgencyID="LOC_COUNTRY" schemeID="CODE">US</Representation>
</ValueMapping>
<LogMessageCollection/>
</ns2:ValueMappingReadResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Try using a Groovy Script. I really like the features of the XMLSlurper, which lets me ignore the namespaces if/when they change.
Just add a new Groovy Script teststep, and put this into it. You just need to adjust the name of your Soap Request teststep, which should be placed just before this teststep.
/** The name should be modified to match the request/response you want to validate */
def holder = new com.eviware.soapui.support.GroovyUtils( context ).getXmlHolder("The Name Of Your Soap Request TestStep#Response")
def response = new XmlSlurper().parseText(holder.getXml())
for (def element : response.Body.ValueMappingReadResponse.ValueMapping.Representation)
{
log.info element
log.info element.#'schemeAgencyID'
}

Simple BPEL Error

I have developed a very simple BPEL process. It consist of receiveIinput, assign and replyoutput. When i test this process through web services explorer or SOAP UI, i always get the below error.
I put deploy.xml,.bpel and ...Artifacts.wsdl file in ode\WEB-INF\processes\hellobpel folder.
- <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
- <soapenv:Body>
- <soapenv:Fault>
<faultcode>soapenv:Server</faultcode>
<faultstring xmlns:axis2ns122="http://docs.oasis-open.org/wsbpel/2.0/process/executable">axis2ns122:selectionFailure</faultstring>
<detail />
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
Copied from the Apache ODE FAQ:
Q. My process fails with a selectionFailure; What can I do?
A. BPEL expects a single element to be selected when evaluating and expressions, and a selectionFailure fault is thrown if zero or more than one element are selected.
So I guess that the output variable is not initialized and you point to an element in the to-expression that is not (yet) existing.

WCF Client / Java Web Service - SOAP

I need to send a SOAP Message with the following format (cut down from example I was given): -
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ret="http://www.another.com/ret"
xmlns:ser="http://www.another.com/ret/retTransaction/service"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<ser:store>
<ret:retTransaction>
<ret:retailTransaction xsi:type="ret:NormalTransaction"> <ret:applicationId>POS</ret:applicationId>
</ret:retailTransaction>
</ret:retTransaction>
</ser:store>
</soapenv:Body>
</soapenv:Envelope>
The operation in question is "store". That operation has an "object" parameter in the proxy following Add Service Reference.
How do I ensure that a message with the correct format is sent? Particularly the multiple namespaces in the SOAP Envelope?
Thanks

CXF webservice client, how to handle response from a called webservice?

i have implemented a webservice client that is used inside a webapplication (using Spring) and this client gets a response in which CXF bailsout and gives me an error message.
The error message is:
Server did not recognize the value of HTTP Header SOAPAction
I have found the problem but do not know what i can do to adjust my webservice response handling.
The xml response below works without any problems.
Works and is accepted ok!
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:bar="http://www.dummyurl.com/service-v1.0/">
<soapenv:Header/>
<soapenv:Body>
<bar:StartSessionResponse>
<result>1</result>
</bar:StartSessionResponse>
</soapenv:Body>
</soapenv:Envelope>
The service actually returns:
Fails and gives me an error!
<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>
<StartSessionResponse xmlns="www.dummyurl.com/service-v1.0/">
<result xmlns="">1</result>
</StartSessionResponse>
</soap:Body>
</soap:Envelope>
The difference as far as i can see is in the placing of the
xmlns="www.dummyurl.com/service-v1.0/ element, in the success xml it is in the enveloppe, in the failed xml it is on the reponse method.
Is there a way that i can convince CXF to accept the response? Or is the service giving back an abnormal result?
The service is giving back a wrong response in the second case, assuming that the first response is proper.
In the first case "www.dummyurl.com/service-v1.0/" is the namespace of your elements - StartSessionResponse, result is not qualified with the namespace. In the second case, the StartSessionResponse has the same namespace as the first sample, but the result has a different namespace altogether, taking out xmlns="" for result will make the xml consistent.

Categories

Resources