Spring Web service unmarshalling not happening correctly - spring

I have been trying to integrate the spring WS to test a SOAP webservice.Integration has hit a roadblock as I am not able receive the proper response in the unmarshelled object.
Below are the details:
Application Context is below:
<!-- Define the SOAP version used by the WSDL -->
<bean id="soapMessageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
<property name="soapVersion">
<util:constant static-field="org.springframework.ws.soap.SoapVersion.SOAP_12"/>
</property>
</bean>
<!-- The location of the generated Java files -->
<oxm:jaxb2-marshaller id="marshaller" contextPath="com.uk.fs.generatedsources"/>
<!-- Configure Spring Web Services -->
<bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
<constructor-arg ref="soapMessageFactory"/>
<property name="marshaller" ref="marshaller"/>
<property name="unmarshaller" ref="marshaller"/>
<property name="defaultUri" value="http://192.168.243.21/test/services/testservice?wsdl"/>
</bean>
Below is the method which invokes marshalSendAndReceive:
public List<FSChild> getFSChildren() {
GetFSChildren getFSChildren= new ObjectFactory().createGetFSChildren();
getFSChildren.setCountry("CA");
getFSChildren.setFsCode("5010");
getFSChildren.setLimit(6);
GetFSChildrenResponse response = (GetFSChildrenResponse) webServiceTemplate.marshalSendAndReceive(
getFSChildren);
return response.getGetFSChildrenReturn();
}
Class GetFSChildrenResponse is as below:
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "", propOrder = {
"getHSChildrenReturn"
})
#XmlRootElement(name = "getFSChildrenResponse")
public class GetFSChildrenResponse {
#XmlElement(required = true)
protected List<FSChild> getFSChildrenReturn;
public List<FSChild> getGetFSChildrenReturn() {
if (getFSChildrenReturn == null) {
getFSChildrenReturn = new ArrayList<FSChild>();
}
return this.getFSChildrenReturn;
}
}
class FSChild is as below:
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "FSChild", namespace = "http://hs.uk.com", propOrder = {
"description",
"fsCode"
})
public class FSChild {
#XmlElement(required = true, nillable = true)
protected String description;
#XmlElement(required = true, nillable = true)
protected String fsCode;
public String getDescription() {
return description;
}
public void setDescription(String value) {
this.description = value;
}
public String getFsCode() {
return hsCode;
}
public void setFsCode(String value) {
this.hsCode = value;
}
}
I feel like quite close to get it working..
Request is properly marshalled and even request is sent properly to webservice which logs the response and returns it properly.
but when try to extract the response like below:
GetFSChildrenResponse response = (GetFSChildrenResponse) webServiceTemplate.marshalSendAndReceive( getFSChildren);
now at this point when I debug,I find that response object is populated and it contains 1 getHSChildrenReturn list containing one item which was expected but code and description in fschild is set to null.
I have even turned on TRACE logs for messages.I see response xml properly returning data which is as below:
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<getHSChildrenResponse xmlns="http://service.hs.pb.com">
<getHSChildrenReturn>
<description>Silk: Silk-worm cocoons suitable for reeling.</description>
<fsCode>5001000000</hsCode>
</getFSChildrenReturn>
</getFSChildrenResponse>
</soapenv:Body>
</soapenv:Envelope>
Please find below the wsdl from which classes were generated:
<wsdl:definitions xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://service.fs.uk.com" xmlns:intf="http://service.fs.uk.com" xmlns:tns1="http://fs.uk.com" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://service.fs.uk.com">
<!--
WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)
-->
<wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://service.fs.uk.com">
<import namespace="http://fs.uk.com"/>
<element name="getCountries">
<complexType/>
</element>
<element name="getCountriesResponse">
<complexType>
<sequence>
<element maxOccurs="unbounded" name="getCountriesReturn" type="xsd:string"/>
</sequence>
</complexType>
</element>
<element name="getFSChildren">
<complexType>
<sequence>
<element name="fsCode" type="xsd:string"/>
<element name="country" type="xsd:string"/>
<element name="limit" type="xsd:int"/>
</sequence>
</complexType>
</element>
<element name="getFSChildrenResponse">
<complexType>
<sequence>
<element maxOccurs="unbounded" name="getFSChildrenReturn" type="tns1:FSChild"/>
</sequence>
</complexType>
</element>
</schema>
<schema xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://fs.uk.com">
<complexType name="FSChild">
<sequence>
<element name="description" nillable="true" type="xsd:string"/>
<element name="fsCode" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
</schema>
</wsdl:types>
<wsdl:message name="getCountriesResponse">
<wsdl:part element="impl:getCountriesResponse" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="getCountriesRequest">
<wsdl:part element="impl:getCountries" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="getFSChildrenRequest">
<wsdl:part element="impl:getFSChildren" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="getFSChildrenResponse">
<wsdl:part element="impl:getFSChildrenResponse" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:portType name="FSService">
<wsdl:operation name="getCountries">
<wsdl:input message="impl:getCountriesRequest" name="getCountriesRequest"></wsdl:input>
<wsdl:output message="impl:getCountriesResponse" name="getCountriesResponse"></wsdl:output>
</wsdl:operation>
<wsdl:operation name="getFSChildren">
<wsdl:input message="impl:getFSChildrenRequest" name="getFSChildrenRequest"></wsdl:input>
<wsdl:output message="impl:getFSChildrenResponse" name="getFSChildrenResponse"></wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="FSServiceSoapBinding" type="impl:FSService">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getCountries">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="getCountriesRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="getCountriesResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getFSChildren">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="getFSChildrenRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="getFSChildrenResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="testserviceService">
<wsdl:port binding="impl:FSServiceSoapBinding" name="testservice">
<wsdlsoap:address location="http://192.168.240.87/FSWS/testservice/FSService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

Answering my own question after getting frustrated for hours.There seems to be problem with the namespaces in wsdl.I changed following 2things in wsdl and generated the classes again resulting in proper responses.
xmlns:tns1="http://fs.uk.com" to xmlns:tns1="http://service.fs.uk.com"
targetNamespace="http://fs.uk.com" to targetNamespace="http://service.fs.uk.com"
for element FSChild.
It was little surprising for me as original wsdl without changes works perfectly with SOAPUI. If anyone can explain this,I will award him the bounty

Related

IllegalArgumentException in WSDL first maven/cxf Soap Web Service

I have a problem with a maven project using wsdl first and Camel CXF+Spring deployed on JBoss Fuse.
Calling the service the following exception occurs:
12:21:58,961 | WARN | qtp477359063-69 | PhaseInterceptorChain | 74 - org.apache.cxf.cxf-core - 3.0.4.redhat-621084 | Interceptor for {http://service.opf.meter.itd.it}OpfImpl#{http://service.opf.meter.itd.it}getOpf has thrown exception, unwinding now
java.lang.IllegalArgumentException: Part {http://service.opf.meter.itd.it}getOpfResponse should be of type it.itd.meter.opf.service.GetOpfResponse, not java.lang.String
at org.apache.cxf.jaxb.io.DataWriterImpl.checkPart(DataWriterImpl.java:292)[79:org.apache.cxf.cxf-rt-databinding-jaxb:3.0.4.redhat-621084]
at org.apache.cxf.jaxb.io.DataWriterImpl.write(DataWriterImpl.java:220)[79:org.apache.cxf.cxf-rt-databinding-jaxb:3.0.4.redhat-621084]
at org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor.writeParts(AbstractOutDatabindingInterceptor.java:122)[74:org.apache.cxf.cxf-core:3.0.4.redhat-621084]
at org.apache.cxf.wsdl.interceptors.BareOutInterceptor.handleMessage(BareOutInterceptor.java:69)[78:org.apache.cxf.cxf-rt-wsdl:3.0.4.redhat-621084]
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)[74:org.apache.cxf.cxf-core:3.0.4.redhat-621084]
at org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingChainInterceptor.java:83)[74:org.apache.cxf.cxf-core:3.0.4.redhat-621084]
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)[74:org.apache.cxf.cxf-core:3.0.4.redhat-621084]
at org.apache.cxf.phase.PhaseInterceptorChain.resume(PhaseInterceptorChain.java:277)[74:org.apache.cxf.cxf-core:3.0.4.redhat-621084]
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:78)[74:org.apache.cxf.cxf-core:3.0.4.redhat-621084]
at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:251)[96:org.apache.cxf.cxf-rt-transports-http:3.0.4.redhat-621084]
at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:234)[96:org.apache.cxf.cxf-rt-transports-http:3.0.4.redhat-621084]
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:208)[96:org.apache.cxf.cxf-rt-transports-http:3.0.4.redhat-621084]
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160)[96:org.apache.cxf.cxf-rt-transports-http:3.0.4.redhat-621084]
at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:171)[96:org.apache.cxf.cxf-rt-transports-http:3.0.4.redhat-621084]
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:293)[96:org.apache.cxf.cxf-rt-transports-http:3.0.4.redhat-621084]
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:212)[96:org.apache.cxf.cxf-rt-transports-http:3.0.4.redhat-621084]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:595)[82:org.apache.geronimo.specs.geronimo-servlet_3.0_spec:1.0.0]
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:268)[96:org.apache.cxf.cxf-rt-transports-http:3.0.4.redhat-621084]
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:684)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:503)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:69)[93:org.ops4j.pax.web.pax-web-jetty:3.2.5]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:533)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:240)[93:org.ops4j.pax.web.pax-web-jetty:3.2.5]
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:429)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:75)[93:org.ops4j.pax.web.pax-web-jetty:3.2.5]
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.server.Server.handleAsync(Server.java:410)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:519)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:982)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:1043)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:865)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:696)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:53)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at java.lang.Thread.run(Thread.java:745)[:1.7.0_101]
Here is my wsdl:
<wsdl:definitions targetNamespace="http://service.opf.meter.itd.it"
xmlns:apachesoap="http://xml.apache.org/xml-soap"
xmlns:impl="http://service.opf.meter.itd.it"
xmlns:intf="http://service.opf.meter.itd.it"
xmlns:tns1="http://bean.opf.meter.itd.it"
xmlns:tns2="http://branch.bean.opf.meter.itd.it"
xmlns:tns3="http://bus.bean.opf.meter.itd.it"
xmlns:tns4="http://constrain.bean.opf.meter.itd.it"
xmlns:tns5="http://summary.bean.opf.meter.itd.it"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
(type omitted...)
<wsdl:message name="getOpfResponse">
<wsdl:part element="impl:getOpfResponse" name="getOpfResponse">
</wsdl:part>
</wsdl:message>
<wsdl:message name="getOpfRequest">
<wsdl:part element="impl:getOpfRequest" name="getOpfRequest">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="OpfImpl">
<wsdl:operation name="getOpf">
<wsdl:input message="impl:getOpfRequest"></wsdl:input>
<wsdl:output message="impl:getOpfResponse"></wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="OpfImplSoapBinding" type="impl:OpfImpl">
<wsdlsoap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getOpf">
<wsdlsoap:operation soapAction="" style="document"/>
<wsdl:input>
<wsdlsoap:body parts="getOpfRequest" use="literal"/>
</wsdl:input>
<wsdl:output>
<wsdlsoap:body parts="getOpfResponse" use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="OpfImpl">
<wsdl:port binding="impl:OpfImplSoapBinding" name="DummyOpf">
<wsdlsoap:address location="http://192.168.80.125:8181/cxf/OptimalPowerFlow/"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
The (generated) interface:
package it.itd.meter.opf.service;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.xml.bind.annotation.XmlSeeAlso;
/**
* This class was generated by Apache CXF 2.7.0.redhat-611423
* 2017-03-16T10:52:40.701+01:00
* Generated source version: 2.7.0.redhat-611423
*
*/
#WebService(targetNamespace = "http://service.opf.meter.itd.it", name = "OpfImpl")
#XmlSeeAlso({ObjectFactory.class, it.itd.meter.opf.bean.summary.ObjectFactory.class, it.itd.meter.opf.bean.bus.ObjectFactory.class, it.itd.meter.opf.bean.constrain.ObjectFactory.class, it.itd.meter.opf.bean.ObjectFactory.class, it.itd.meter.opf.bean.branch.ObjectFactory.class})
#SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
public interface OpfImpl {
#WebMethod(action = "http://service.opf.meter.itd.it/getOpf")
#WebResult(name = "getOpfResponse", targetNamespace = "http://service.opf.meter.itd.it", partName = "getOpfResponse")
public GetOpfResponse getOpf(
#WebParam(partName = "getOpfRequest", name = "getOpfRequest", targetNamespace = "http://service.opf.meter.itd.it")
GetOpfRequest getOpfRequest
);
}
so the implementation:
#javax.jws.WebService(
serviceName = "OpfImpl",
portName = "DummyOpf",
targetNamespace = "http://service.opf.meter.itd.it",
wsdlLocation = "file:/home/meter/workdir/OptimalPowerFlow/src/main/resources/wsdl/OpfImpl.wsdl",
endpointInterface = "it.itd.meter.opf.service.OpfImpl")
public class DummyOpf implements OpfImpl {
private static final Logger LOG = Logger.getLogger(DummyOpf.class.getName());
#Override
public GetOpfResponse getOpf(GetOpfRequest getOpfRequest) {
System.out.println(getOpfRequest);
LOG.info(getOpfRequest.toString());
try{
OpfBean data = populateOpf();
GetOpfResponse getOpfResponse = new GetOpfResponse();
getOpfResponse.setGetOpfReturn(data);
return getOpfResponse;
}catch(Exception e){
e.printStackTrace();
return null;
}
}
}
Finally, the route configuration:
camel-cxf.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cxf="http://camel.apache.org/schema/cxf"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://camel.apache.org/schema/cxf
http://camel.apache.org/schema/cxf/camel-cxf.xsd">
<cxf:cxfEndpoint id="getOpfEndpoint"
address="/OptimalPowerFlow/"
serviceClass="it.itd.meter.opf.service.OpfImpl"
wsdlURL="wsdl/OpfImpl.wsdl"/>
<bean id="getDummyOpf" class=" it.itd.meter.OptimalPowerFlow.DummyOpf"/>
</beans>
camel-route.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/spring"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">
<import resource="classpath:META-INF/spring/camel-cxf.xml" />
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<!-- route starts from the cxf webservice, see camel-cxf.xml for details -->
<from uri="cxf:bean:getOpfEndpoint" />
<bean ref="getDummyOpf"/>
<to uri="seda:incomingOrders" />
<!-- and then create the OK reply for the webservice which is still waiting for a reply -->
<transform>
<constant>OK</constant>
</transform>
</route>
<!-- test route -->
<route>
<from uri="seda:incomingOrders" />
<to uri="mock:end"/>
</route>
</camelContext>
</beans>
Any suggestion?

Error cvc-elt.1.a: Cannot find the declaration of element 'soapenv:Body'

I have already tried some hints but I get this problem not solved. I validated the wsdl with xmlspy-client and it says it and the xsd are valid.
When I send a Request like this with SOAPUI I get the Exception mentioned (cvc-elt.1.a: Cannot find the declaration of element 'soapenv:Body').
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://schemas.domain.com/wsdl/fuelprice/v1" xmlns:mod="http://schemas.domain.com/wsdl/fuelprice/v1/model">
<soapenv:Header/>
<soapenv:Body>
<v1:AuthenticationHeader client="client">
<v1:token>token</v1:token>
</v1:AuthenticationHeader>
<v1:GetAreaFuelStationsRequest provider="p1" prices="true">
<v1:area>
<mod:center ellipsoid="false">
<mod:latitude>22.519172</mod:latitude>
<mod:longitude>13.406093</mod:longitude>
</mod:center>
<mod:radius>10</mod:radius>
</v1:area>
</v1:GetAreaFuelStationsRequest>
</soapenv:Body>
</soapenv:Envelope>
I have tried importing the soap schema in the wsdl. After it I got an error message:
"cvc-complex-type.2.4.a: Invalid content was found starting with element 'v1:latitude'. One of '{"http://schemas.domain.com/wsdl/fuelprice/v1/model":latitude}' is expected.".
I honestly work with rest and json and have some difficulties with this schema-configuration.
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="wsdl-viewer.xsl"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://schemas.domain.com/wsdl/fuelprice/v1" xmlns:model="http://schemas.domain.com/wsdl/fuelprice/v1/model" xmlns:exception="http://schemas.domain.com/wsdl/fuelprice/v1/exception" targetNamespace="http://schemas.domain.com/wsdl/fuelprice/v1">
<wsdl:types>
<xsi:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema" targetNamespace="http://schemas.domain.com/wsdl/fuelprice/v1" elementFormDefault="qualified">
<xsi:import namespace="http://schemas.domain.com/wsdl/fuelprice/v1/model" schemaLocation="common.xsd"/>
<xsi:import namespace="http://schemas.domain.com/wsdl/fuelprice/v1/exception" schemaLocation="exception.xsd"/>
<xsi:element name="GetAreaFuelStationsRequest">
<xsi:complexType>
<xsi:sequence>
<xsi:element name="area" type="model:Area"/>
</xsi:sequence>
<xsi:attribute name="provider" type="xsi:string" use="optional"/>
<xsi:attribute name="prices" type="xsi:boolean" use="required"/>
</xsi:complexType>
</xsi:element>
<xsi:element name="GetAreaFuelStationsResponse">
<xsi:complexType>
<xsi:sequence>
<xsi:element name="entry" type="model:SearchResult" minOccurs="0" maxOccurs="unbounded"/>
</xsi:sequence>
<xsi:attribute name="countTotal" type="xsi:int" use="optional"/>
</xsi:complexType>
</xsi:element>
</xsi:schema>
</wsdl:types>
<wsdl:message name="SearchAreaFuelStationsRequest">
<wsdl:part name="auth" element="tns:AuthenticationHeader"/>
<wsdl:part name="body" element="tns:GetAreaFuelStationsRequest"/>
</wsdl:message>
<wsdl:message name="SearchAreaFuelStationsResponse">
<wsdl:part name="body" element="tns:GetAreaFuelStationsResponse"/>
</wsdl:message>
<wsdl:portType name="FuelDataService">
<wsdl:operation name="GetAreaFuelStations">
<wsdl:input message="tns:GetAreaFuelStationsRequest"/>
<wsdl:output message="tns:GetAreaFuelStationsResponse"/>
<wsdl:fault name="ServiceError" message="tns:ServiceErrorFault"/>
<wsdl:fault name="AuthenticationError" message="tns:AuthenticationErrorFault"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="FuelDataService" type="tns:FuelDataService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="GetAreaFuelStations">
<soap:operation soapAction="urn:GetAreaFuelStations"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
<wsdl:fault name="ServiceError"/>
<wsdl:fault name="AuthenticationError"/>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="FuelDataService">
<wsdl:port name="FuelDataService" binding="tns:FuelDataService">
<soap:address location="No target address"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
The XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xsi:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema" xmlns:model="http://schemas.domain.com/wsdl/fuelprice/v1/model" targetNamespace="http://schemas.domain.com/wsdl/fuelprice/v1/model" elementFormDefault="qualified">
<xsi:complexType name="FuelStation">
<xsi:sequence>
<xsi:element name="location" type="model:GeoLocation"/>
<xsi:element name="name" type="xsi:string"/>
</xsi:sequence>
<xsi:attribute name="id" type="xsi:long" use="optional"/>
</xsi:complexType>
<xsi:complexType name="GeoLocation">
<xsi:sequence>
<xsi:element name="latitude" type="xsi:double"/>
<xsi:element name="longitude" type="xsi:double"/>
</xsi:sequence>
<xsi:attribute name="ellipsoid" type="xsi:string" use="required"/>
</xsi:complexType>
<xsi:complexType name="Area">
<xsi:sequence>
<xsi:element name="center" type="model:GeoLocation"/>
<xsi:element name="radius" type="xsi:float"/>
</xsi:sequence>
</xsi:complexType>
</xsi:schema>
For me is not obvious what I should change to get this working. Does anybody knows what is wrong with the namespace setting? I would appreciate any help.
This Question was solved with the Question validating SOAP-Request with a SOAPHandler
Extracting the body of message, adding the needed namespace in the schema and validating the body as a Document did the trick.

Apache CXF and Apache Camel: the given SOAPAction does not match an operation

I'm trying to walk through the Camel Report Incident tutorial and am stuck at the end of part 5. When I try to run the unit test it fails with the message The given SOAPAction http://reportincident.example.camel.apache.org/ReportIncident does not match an operation.
I saw a similar question where the problem was that the declared soapAction attribute on the WSDL file had a different value from the actual SOAP request. This does not seem to be my case. Any ideas about what is going wrong? Thanks in advance.
reportIncident.wsdl
<?xml version="1.0" encoding="ISO-8859-1"?>
<wsdl:definitions
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://reportincident.example.camel.apache.org"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
targetNamespace="http://reportincident.example.camel.apache.org">
<!-- Type definitions for input- and output parameters for webservice -->
<wsdl:types>
<xs:schema targetNamespace="http://reportincident.example.camel.apache.org">
<xs:element name="inputReportIncident">
<xs:complexType name="inputReportIncident">
<xs:sequence>
<xs:element type="xs:string" name="incidentId" />
<xs:element type="xs:string" name="incidentDate" />
<xs:element type="xs:string" name="givenName" />
<xs:element type="xs:string" name="familyName" />
<xs:element type="xs:string" name="summary" />
<xs:element type="xs:string" name="details" />
<xs:element type="xs:string" name="email" />
<xs:element type="xs:string" name="phone" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="outputReportIncident">
<xs:complexType name="outputReportIncident">
<xs:sequence>
<xs:element type="xs:string" name="code" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
<!-- Message definitions for input and output -->
<wsdl:message name="inputReportIncident">
<wsdl:part name="parameters" element="tns:inputReportIncident" />
</wsdl:message>
<wsdl:message name="outputReportIncident">
<wsdl:part name="parameters" element="tns:outputReportIncident" />
</wsdl:message>
<!-- Port (interface) definitions -->
<wsdl:portType name="ReportIncidentEndpoint">
<wsdl:operation name="ReportIncident">
<wsdl:input message="tns:inputReportIncident" />
<wsdl:output message="tns:outputReportIncident" />
</wsdl:operation>
</wsdl:portType>
<!-- Port bindings to transports and encoding - HTTP, document literal
encoding is used -->
<wsdl:binding name="ReportIncidentBinding" type="tns:ReportIncidentEndpoint">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="ReportIncident">
<soap:operation soapAction="http://reportincident.example.camel.apache.org/ReportIncident" style="document" />
<wsdl:input>
<soap:body parts="parameters" use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body parts="parameters" use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<!-- Service definition -->
<wsdl:service name="ReportIncidentService">
<wsdl:port name="ReportIncidentPort" binding="tns:ReportIncidentBinding">
<soap:address location="http://reportincident.example.camel.apache.org" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
route definition (inside a RouteBuilder subclass)
OutputReportIncident ok = new OutputReportIncident();
ok.setCode("0");
// endpoint to our CXF webservice
String cxfEndpoint = "cxf://http://localhost:8080/part-five/webservices/incident"
+ "?serviceClass=org.apache.camel.example.reportincident.ReportIncidentEndpoint"
+ "&wsdlURL=reportIncident.wsdl";
// first part from the webservice -> file backup
from(cxfEndpoint)
// we need to convert the CXF payload to InputReportIncident that FilenameGenerator and velocity expects
.convertBodyTo(InputReportIncident.class)
// then set the file name using the FilenameGenerator bean
.setHeader("CamelFileName", BeanLanguage.bean(FilenameGenerator.class, "generateFilename"))
// transform the message using velocity to generate the mail message
.to("velocity:mailBody.vm")
// and store the file
.to("file://target/subfolder")
// return OK as response
// usando transformaĆ§Ć£o!
.transform(constant(ok));
pom.xml (wsdl2java is used to generate Java files from WSDL)
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>2.13.0</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${project.build.directory}/generated/src/main/java</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/reportIncident.wsdl</wsdl>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
test code
package org.apache.camel.example.reportincident;
import static org.junit.Assert.*;
import org.apache.camel.CamelContext;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.junit.Test;
import org.jvnet.mock_javamail.Mailbox;
public class ReportIncidentRoutesTest {
// should be the same address as we have in our route
private static String ADDRESS = "http://localhost:8080/part-five/webservices/incident";
private CamelContext context;
#Test
public void testRendportIncident() throws Exception {
// start camel
startCamel();
// assert mailbox is empty before starting
Mailbox inbox = Mailbox.get("incident#mycompany.com");
assertEquals("Should not have mails", 0, inbox.size());
// create input parameter
InputReportIncident input = new InputReportIncident();
input.setIncidentId("123");
input.setIncidentDate("2008-08-18");
input.setGivenName("Claus");
input.setFamilyName("Ibsen");
input.setSummary("Bla");
input.setDetails("Bla bla");
input.setEmail("davsclaus#apache.org");
input.setPhone("0045 2962 7576");
// create the webservice client and send the request
ReportIncidentEndpoint client = createCXFClient();
OutputReportIncident out = client.reportIncident(input);
// assert we got a OK back
assertEquals("0", out.getCode());
// let some time pass to allow Camel to pickup the file and send it as an email
Thread.sleep(3000);
// assert mail box
assertEquals("Should have got 1 mail", 1, inbox.size());
// stop camel
context.stop();
}
private void startCamel() throws Exception {
context = new DefaultCamelContext();
context.disableJMX();
context.addRoutes(new ReportIncidentRoutes());
context.start();
}
private ReportIncidentEndpoint createCXFClient() {
// we use CXF to create a client for us as its easier than JAXWS and works
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(ReportIncidentEndpoint.class);
factory.setAddress(ADDRESS);
return (ReportIncidentEndpoint) factory.create();
}
}
I think you just need to pass the WSDL url to the JaxWsProxyFactoryBean and it can take care of the soap action for you.
Please change the ReportIncidentRoutesTest.createCXFClient() like this
private ReportIncidentEndpoint createCXFClient() {
// we use CXF to create a client for us as its easier than JAXWS and works
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(ReportIncidentEndpoint.class);
factory.setWsdlURL("reportIncident.wsdl");
factory.setAddress(ADDRESS);
return (ReportIncidentEndpoint) factory.create();
}

Oracle Service Bus (11.1.1.6.0): <xsd:include> issue

IF I use this schema:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xsd:element name="Chick">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="count" type="xsd:decimal" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
With this wsdl:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.example.org/test/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="test"
xmlns:chi="chick"
targetNamespace="http://www.example.org/test/">
<wsdl:types>
<xsd:schema targetNamespace="http://www.example.org/test/">
<xsd:include schemaLocation="testschema.xsd"></xsd:include>
<xsd:include id="ada" schemaLocation="testschema.xsd" />
<xsd:element name="doTheRightThing">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Chick" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="doTheRightThingResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="out" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<wsdl:message name="doTheRightThingRequest">
<wsdl:part element="tns:doTheRightThing" name="parameters" />
</wsdl:message>
<wsdl:message name="doTheRightThingResponse">
<wsdl:part element="tns:doTheRightThingResponse" name="parameters" />
</wsdl:message>
<wsdl:portType name="test">
<wsdl:operation name="doTheRightThing">
<wsdl:input message="tns:doTheRightThingRequest" />
<wsdl:output message="tns:doTheRightThingResponse" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="testSOAP" type="tns:test">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="doTheRightThing">
<soap:operation
soapAction="http://www.example.org/test/doTheRightThing" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="test">
<wsdl:port binding="tns:testSOAP" name="testSOAP">
<soap:address location="http://www.example.org/" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
I get this error message:
Error building the Schema Type system for the WSDL:
D:\Oracle\Middleware_11.1.1.6.0\user_projects\domains\osb_cookbook_domain\test:0: error: src-resolve.a: Could not find element 'Chick'. Do you mean to refer to the element named Chick#http://www.example.org/test/ (in testschema)?
If I change this line in wsdl:
<xsd:element ref="Chick" />
to this:
<xsd:element ref="tns:Chick" />
I could not deploy, OEPE returns this error message:
The WSDL is not semantically valid: error: src-resolve: element 'Chick#http://www.example.org/test/' not found..
Is this a bug?
Patch 14003546 solved this issue:
WSDL WITH EMBEDDED SCHEMA INCLUDE TO NO-NAMESPACE FAILS VALIDATION

Unmarshall exception for SOAP done with contract-first Spring-WS

I am trying to code my first SOAP web service.
I am getting the SOAP response Unmarshall failure
which is the response i mapped to org.springframework.oxm.UnmarshallingFailureException.
I have configured Spring to use Castor (un)marshaller.
Problem is i don't know how to find a more specific cause.
public class SentenceRequest {
public SentenceRequest() {}
private List<String> words = new ArrayList<String>();
public List<String> getWords() {
return words;
}
public void setWords(List<String> words) {
this.words = words;
}
public class SentenceResponse {
private String sentence;
public SentenceResponse() {}
public SentenceResponse(String sen) {
sentence = sen;
}
public String getSentence() {
return sentence;
}
public void setSentence(String sentence) {
this.sentence = sentence;
}
the castor mapping:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapping PUBLIC
"-//EXOLAB/Castor Object Mapping DTD Version 1.0//EN"
"http://castor.exolab.org/mapping.dtd">
<mapping xmlns="http://castor.exolab.org/">
<class name="ro.soapservice2.SentenceRequest">
<map-to xml="SentenceRequest" ns-uri="sentence" ns-prefix="s" />
<field name="words" collection="arraylist" type="java.util.List" required="true">
<bind-xml name="word" node="element"></bind-xml>
</field>
</class>
<class name="ro.soapservice2.SentenceResponse">
<map-to xml="SentenceResponse" ns-uri="sentence" ns-prefix="s" />
<field name="sentence" type="java.lang.String" required="true">
<bind-xml name="sentence" node="element" />
</field>
</class>
</mapping>
the schema (generated with Trang.jar based on two input XML files):
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="sentence" xmlns:s="sentence">
<xs:element name="SentenceRequest">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="s:word"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="word" type="xs:string"/>
<xs:element name="SentenceResponse">
<xs:complexType>
<xs:sequence>
<xs:element ref="s:sentence"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="sentence" type="xs:string"/>
</xs:schema>
and the WSDL Spring generates:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:sch="sentence" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="sentence" targetNamespace="sentence">
<wsdl:types>
<xs:schema xmlns:s="sentence" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="sentence">
<xs:element name="SentenceRequest">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="s:word"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="word" type="xs:string"/>
<xs:element name="SentenceResponse">
<xs:complexType>
<xs:sequence>
<xs:element ref="s:sentence"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="sentence" type="xs:string"/>
</xs:schema>
</wsdl:types>
<wsdl:message name="SentenceResponse">
<wsdl:part element="tns:SentenceResponse" name="SentenceResponse">
</wsdl:part>
</wsdl:message>
<wsdl:message name="SentenceRequest">
<wsdl:part element="tns:SentenceRequest" name="SentenceRequest">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="Sentence">
<wsdl:operation name="Sentence">
<wsdl:input message="tns:SentenceRequest" name="SentenceRequest">
</wsdl:input>
<wsdl:output message="tns:SentenceResponse" name="SentenceResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="SentenceSoap11" type="tns:Sentence">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="Sentence">
<soap:operation soapAction=""/>
<wsdl:input name="SentenceRequest">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="SentenceResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="SentenceService">
<wsdl:port binding="tns:SentenceSoap11" name="SentenceSoap11">
<soap:address location="http://localhost:8080/soapservice2/services"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
the SOAP request i make:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sen="sentence">
<soapenv:Header/>
<soapenv:Body>
<sen:SentenceRequest>
<!--1 or more repetitions:-->
<sen:word>asd</sen:word>
</sen:SentenceRequest>
</soapenv:Body>
</soapenv:Envelope>
Solved!
First i replaced my exception resolver from
org.springframework.ws.soap.server.endpoint.SoapFaultMappingExceptionResolver
to
org.springframework.ws.soap.server.endpoint.SimpleSoapExceptionResolver
which puts back in the SOAP response the real exception that was thrown.
Then i saw the problem was at the Castor xml mapping file:
changed from
<field name="words" collection="arraylist" type="java.util.List" required="true">
<bind-xml name="word" node="element"></bind-xml>
</field>
to
<field name="words" collection="arraylist" type="java.lang.String" required="true">
<bind-xml name="word" node="element"></bind-xml>
</field>

Resources