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.
Related
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
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.
I have the WSDL file of the remote web service I need to call from a proxy service in the WSO2 ESB and would like to know if I need to construct the soap:Body's elements manually through XSLT/Enrich or there is a way to generate the soapenv:Body's contains from the WSDL and maybe replace '?' for the values.
For example, if you've used soapUI before you'll know that when you import a WSDL file in a project a soapenv:Envelope gets generated automatically with all the XML elements and question marks for their values. Same goes for the TryIt tool in the WSO2 ESB.
Here is an example of an auto-generated soapenv:Envelope in soapUI after importing WSDL:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:abc="http://abc.com/">
<soapenv:Header/>
<soapenv:Body>
<abc:RegisterCandidate>
<abc:NameFirst>?</abc:NameFirst>
<abc:NameMiddle>?</abc:NameMiddle>
<abc:NameLast>?</abc:NameLast>
<abc:PhoneHome>?</abc:PhoneHome>
<abc:EmailAddress>?</abc:EmailAddress>
<abc:Address1>?</abc:Address1>
<abc:Address2>?</abc:Address2>
<abc:City>?</abc:City>
<abc:State>?</abc:State>
<abc:ZipCode>?</abc:ZipCode>
<abc:Country>?</abc:Country>
</abc:RegisterCandidate>
</soapenv:Body>
</soapenv:Envelope>
Is this possible in the Proxy Service through any of the mediators available to read a WSDL and generate soapenv:Body with its XML tags (in the code above it would be abc:RegisterCandidate with its children)? I've done it with the use of the XSL templates, but it's manual and not very elegant.
I've found a few articles/blogs online about writing proxy services in the WSO2 ESB that call remote web services and what the developers were doing in there was to insert the XML elements needed in the soapenv:Body with the use of XSL templates to have the correct/full SOAP message that is then sent (send mediator) to the remote web service server.
Thank you.
There is no way to generate the soap body from the remote service's wsdl as in your requirement. But there is an easier way than using xslt. That is to use the payload factory mediator. You can define the payload and assign values using xpath as shown in the sample.
I'd like to validate the response of a Soap Spring Webservice against XSD on server side.
The validation result should not lead to a soap fault.
For client compatiblity reason the webservice response contains
the validation error e.g. like
<SOAP-ENV:Body>
<ns:eltResponse>
<errCode>the error code</errorCode>
<errMessage>the error message</errMessage>
</ns:eltResponse>
</SOAP-ENV:Body>
I tried it with the PayloadValidatingInterceptor and a custom ValidationErrorHandler.
But this lead to soap faults. Is it possible to create a response like above mentioned, e.g. with an exception resolver?
I'm trying to create a WS based on a WSDL that defines one Request and one Response. The incoming request should be mapped to an endpoint depending on the SOAPAction defined in the SOAP message. To achieve this I'm trying to use the SoapActionEndpointMapping in my servlet.xml config file and define the mappings, as described in the Spring documentation.
<bean id="endpointMapping" class="org.springframework.ws.soap.server.endpoint.mapping.SoapActionEndpointMapping">
<property name="mappings">
<props>
<prop key="http://myCompany/MyService/MyRequest/mySoapActionOne">myFirstEndpoint</prop>
<prop key="http://myCompany/MyService/MyRequest/mySoapActionTwo">mySecondEndpoint</prop>
</props>
</property>
My endpoint extends AbstractMarshallingPayloadEndpoint and should be able to handle the requests.
The problem is that when I try to send a request (with SoapUI) i get the following error in the log:
WARN [EndpointNotFound] No endpoint mapping found for [SaajSoapMessage {http://schemas.mycompany/MyService}MyRequest]
I have used the PayloadRootQNameEndpointMapping with great success earlier but can not this to work.
Any help is appreciated.
Regards.
Do you have a handler adapter bean defined also? You'll need one in order to use a MarshallingPayloadEndpoint, so that spring knows how to perform the marshalling. The adapter is called something like MarshallingEndpointHandlerAdapter, or similar.
In your SOAP client (SOAPUI), you'll need to add the SOAPAction header to your request, to supply spring with the SOAP action to use in its mapping.
E.g. SOAPAction=http://myCompany/MyService/MyRequest/mySoapActionOne
It shouldn't make any difference what type of Endpoint you're using, because currently, you're receiving a 404 response - your request isn't finding its way to any endpoint.