Calling a webservice in camel having the soap request as String - web-services

I want to call a Web Service using Apache Camel and I have the SOAP message in the form of String. Can anyone kindly let me know how to send SOAP request in form of String in Camel?

Here is a simple example. If you need to perform some modifications of SOAP request string you can just change "constant" to something like "spel"
<setBody><constant><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<MyAction>
<myparam>ABC</myparam>
</MyAction>
</soapenv:Body>
</soapenv:Envelope>]]></constant></setBody>
<setHeader headerName="SOAPAction"><constant>MySOAPAction</constant></setHeader>
<setHeader headerName="CamelHttpMethod"><constant>POST</constant></setHeader>
<setHeader headerName="Content-Type"><constant>text/xml;charset=UTF-8</constant></setHeader>
<to uri="http://myserver:1234" />

It depends of what type of endpoint you have for your outbound webservice.
If it is a CXF JAX-WS then it depends on what dataFormat property is set to: POJO or PAYLOAD.
For POJO you have take SOAP headers, SOAP Body elements, unmarshal them to JAXB Pojos, then set them to Camel Exchange Body properly pass Exchange to endpoint
For PAYLOAD - I'm not sure but maybe you can pass your string as is (or just SOAP body and SOAP headers elements) as strings. If not, check what CXF expects to get when dataFormat is PAYLOAD. (I just used it long time back).
For simple http endpoint just pass your string to it "as is" in the body with Http-method POST and Content-type header as application/xml

Related

Cannot consume Talend Soap API

I am trying to use the Tsoap component within Talend to consume the API. I have tried the Soap UI Client (separate application) and was able to get the response.
However within the Tsoap component within the Soap Message, I have pasted the sample request and I get an error eery single time. Can anyone help!
" <soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"
xmlns=\"http://clients.mindbodyonline.com/api/0_5\">
<soapenv:Header/>
<soapenv:Body>
<GetSites>
<Request>
<SourceCredentials>
<SourceName>Test235</SourceName>
<Password>3IERKOFDNFEOFMKDFOEMFD=</Password>
<SiteIDs>
<int>-99</int>
</SiteIDs>
</SourceCredentials>
<XMLDetail>Full</XMLDetail>
<PageSize>0</PageSize>
<CurrentPageIndex>0</CurrentPageIndex>
</Request>
</GetSites>
</soapenv:Body>
</soapenv:Envelope>"
What am I doing wrong?? Can anyone help please.
Can you send the error what you are getting?
Try this if you haven't done (just a guess)
--> If you are using and HTTPS web service then make sure to setup the authentication( I used Trust serve with SLL and provided the keystore file path and password)

Consume SOAP web service using REST POST method

I want to consume a simple SOAP web service using REST technology. I've heard it can be achieved using POST method. Just adding some headers to the request. Is it possible? How to do that? Thanks a lot !!!
SOAP considers different information in the headers/body than REST does, but it's all HTTP:
# Headers
Content-Type: text/xml
SOAPAction: <SOAPAction here>
# Body
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" >
<soapenv:Header>
.
</soapenv:Header>
<soapenv:Body>
.
.
.
</soapenv:Body>
</soapenv:Envelope>
You'll need to fill in the actual body with whatever the SOAP service expects (obviously) - that can be found in the WSDL if you don't have any sample requests available.
I found this blog post to be very helpful, even if you're making the call from some non-postman tool.

SOAP requests run in SOAP UI but not in WSO2ESB "Try this service" page, so the related scheduled task doesn't work

I have deployed a custom Proxy Service in WSO2 ESB and I can't obtain any response from the web service i call with it in "Try this service" page. I've tried to send the request with SOAP UI passing through the Proxy Service of WSO2ESB (I put the endpoint of the Proxy Service, and NOT of the WS, in SOAP UI) and it works correctly. The same SOAP request doesn't work in the WSO2ESB page unreasonably.
So, when i create a scheduled task with the selected proxy service it returns me an error. I don't know how to change the content of the SOAP message in order to make it correct for ESB.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://ec.europa.eu/eurostat/sri/service/2.0">
<soapenv:Header/>
<soapenv:Body>
<ns:QueryStructure>
<!--Optional:-->
<ns:Query>
<RegistryInterface xsi:schemaLocation="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/message SDMXMessage.xsd" xmlns="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/message" xmlns:common="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/common" xmlns:compact="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/compact" xmlns:cross="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/cross" xmlns:generic="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/generic" xmlns:query="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/query" xmlns:structure="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/structure" xmlns:registry="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/registry" xmlns:utility="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/utility" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Header>
<ID>JD014</ID>
<Test>true</Test>
<Truncated>false</Truncated>
<Name xml:lang="en">Trans46302</Name>
<Prepared>2001-03-11T09:30:47-05:00</Prepared>
<Sender id="BIS"/>
</Header>
<QueryStructureRequest resolveReferences="false">
<registry:DataflowRef/>
</QueryStructureRequest>
</RegistryInterface>
</ns:Query>
</ns:QueryStructure>
</soapenv:Body>
</soapenv:Envelope>
This runs on SOAP UI (through ESB) and not on the same ESB.
For changing the content of a message you can use Payload Mediator.
There's also an example on how to do this.
Hope that helps.

web service endpoint using cxf in jboss fuse

I'm using jboss fuse 6.1-final:
here is my simple route:
<route>
<from uri="cxf:bean:synchronousEndpoint"/>
<log message="Service invoked." />
<process ref="simpleProcessor"/>
</route>
and in the simpleProcessor I'm putting correct response(i.e corresponding JAXB object) to the context. But, it responds with fault:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>Marshalling Error: java.lang.Object cannot be cast to org.w3c.dom.Element</faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>
here is stack trace:
Caused by: java.lang.ClassCastException: java.lang.Object cannot be cast to org.w3c.dom.Element
is there any hints or suggestions?
Bit hard to say without seeing some more code from the simpleProcessor. However it seems like you are using the wrong dataFormat parameter.
The cxf component has a dataFormat parameter which can be any of the following:
POJO: POJOs (Plain old Java objects) are the Java parameters to the
method being invoked on the target server. Both Protocol and Logical
JAX-WS handlers are supported.
PAYLOAD: PAYLOAD is the message payload (the contents of the
soap:body) after message configuration in the CXF endpoint is
applied. Only Protocol JAX-WS handler is supported. Logical JAX-WS
handler is not supported.
MESSAGE: MESSAGE is the raw message that is received from the
transport layer. It is not suppose to touch or change Stream, some of
the CXF interceptors will be removed if you are using this kind of
DataFormat so you can't see any soap headers after the camel-cxf
consumer and JAX-WS handler is not supported.
CXF_MESSAGE: New in Camel 2.8.2, CXF_MESSAGE allows for invoking the
full capabilities of CXF interceptors by converting the message from
the transport layer into a raw SOAP message
The default is POJO which means there is no XML being passed as a message Camel is passing objects. I suspect you might be trying to manipulate the response as XML and this is causing problems.
I ran into something similiar to this a while back where I was trying to convert the POJO into XML by trying to do a XPATH query on the XML when I was receiving a POJO.

Can A Header Be Added & Body Modified In A Salesforce SOAP Response?

From doing some testing on SOAP requests to a webservice I created in Salesforce I note the response returned is of the following format.
Note my request function I called is GetMsgRQ
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://soap.sforce.com/schemas/class/MyIntegrationServices">
<soapenv:Body>
<GetMsgRQResponse>
<result>
<acctId>001J000000leVpEIAU</acctId>
<acctName>MyTest</acctName>
</result>
</lGetMsgRQResponse>
</soapenv:Body>
</soapenv:Envelope>
Relating to this I wonder is it possible to add a SOAP:Header?
Also I note the response has created an element "GetMsgRQResponse" (adding "Response" to "GetMsgRQ". Is it possible to create/specify the SOAP:Body without this occuring? Can I just set what the whole SOAP body response will be or will Salesforce always add such additional elements as the "GetMsgRQResponse" here and "result"?
Thanks in advance for any help on this. I know I can use a HTTP Request to send a full SOAP envelope but for my requirement I need to just provide a response instead of doing so.
I don't believe you can directly add any kind SOAP headers in an Apex defined WebService methods.
If you have absolutely no other option you could construct your own custom SOAP response via a REST web service (via #RestResource annotation) but that is a pretty ugly solution.