Spring WS is not generating wsdl operations for all the public methods in the Endpoint class - spring

I have a Spring endpoint class with two public methods. But when Spring is auto-generating the wsdl it doesn't include the second public method. Could you pleas let me know what is wrong and what needs to be done. I am using Spring 4.3 and below are the classes.
Configuration class
#EnableWs
#Configuration
public class SoapServiceConfig extends WsConfigurerAdapter {
#Bean
public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
servlet.setTransformWsdlLocations(true);
return new ServletRegistrationBean(servlet, "/ws/*");
}
#Bean(name = "policies")
public DefaultWsdl11Definition policyserviceWsdl11Definition(#Autowired #Qualifier("swissSchema") XsdSchema swissSchema) {
DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
wsdl11Definition.setPortTypeName("PoliciesPort");
wsdl11Definition.setLocationUri("/ws");
wsdl11Definition.setTargetNamespace("http://www.testcomp.com/iaworkflow/soapservice");
wsdl11Definition.setSchema(swissSchema);
return wsdl11Definition;
}
#Bean(name = "bankservice")
public DefaultWsdl11Definition bankServiceWsdlDefinition(#Autowired #Qualifier("bankSchema")XsdSchema bankSchema) {
DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
wsdl11Definition.setPortTypeName("BankAPIPort");
wsdl11Definition.setLocationUri("/ws/bankapi");
wsdl11Definition.setTargetNamespace("http://www.testcomp.com/consumer/bankservice/soapservice");
wsdl11Definition.setSchema(bankSchema);
return wsdl11Definition;
}
#Bean
#Qualifier("bankSchema")
public XsdSchema bankSchema() {
return new SimpleXsdSchema(new ClassPathResource("bankservice.xsd"));
}
#Bean
#Qualifier("swissSchema")
public XsdSchema swissSchema() {
return new SimpleXsdSchema(new ClassPathResource("policylookup.xsd"));
}
}
Endpoint
#Endpoint
public class BankingServiceEndpoint {
private static final String NAMESPACE_URI = "http://www.testcomp.com/consumer/bankservice/soapservice";
#PayloadRoot(namespace = NAMESPACE_URI, localPart = "BankInfoSearchRequest")
#ResponsePayload
public BankInfoSearchResponse getBankInfo(#RequestPayload BankInfoSearchRequest request) {
BankInfoSearchResponse response = createDummyResponse(request.getPolicyNumber(),request.getLimit());
return response;
}
#PayloadRoot(namespace = NAMESPACE_URI, localPart = "BankVerificationRequest")
#ResponsePayload
public BankVerificationResponse verifyBankInformation(#RequestPayload BankVerificationRequest request) {
return BankVerificationResponse.builder().build();
}
}
Generated WSDL
<?xml version="1.0" encoding="UTF-8" standalone="no"?><wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:sch="http://www.testcomp.com/consumer/bankservice/soapservice" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.testcomp.com/consumer/bankservice/soapservice" targetNamespace="http://www.testcomp.com/consumer/bankservice/soapservice">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://www.testcomp.com/consumer/bankservice/soapservice" version="1.0">
<xs:element name="BankInfoSearchRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="policyNumber" type="xs:string"/>
<xs:element name="limit" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="BankInfoSearchResponse">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="1" name="policyNumber" nillable="false" type="xs:string"/>
<xs:element name="bankdatas" type="tns:BankDatas"/>
<xs:element maxOccurs="1" name="error" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="BankDatas">
<xs:sequence>
<xs:element maxOccurs="unbounded" name="bankinfo" type="tns:BankInfo"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="BankInfo">
<xs:sequence>
<xs:element name="AccountNumber" type="xs:string"/>
<xs:element name="RoutingNumber" type="xs:string"/>
<xs:element name="BankName" type="xs:string"/>
<xs:element name="VerificationDescription" type="xs:string"/>
<xs:element name="VerificationCode" type="xs:string"/>
<xs:element name="Verified" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="BankVerificationRequest">
<xs:sequence>
<xs:element maxOccurs="1" name="PolicyOwnerInformation" type="tns:PolicyOwnerInformation"/>
<xs:element maxOccurs="1" name="BankInfo" type="tns:BankInfo"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="PolicyOwnerInformation">
<xs:sequence>
<xs:element name="FirstName" type="xs:string"/>
<xs:element name="MiddleName" type="xs:string"/>
<xs:element name="LastName" type="xs:string"/>
<xs:element name="SSN" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="BankVerificationResponse">
<xs:sequence>
<xs:element maxOccurs="1" name="PolicyOwnerInformation" type="tns:PolicyOwnerInformation"/>
<xs:element maxOccurs="1" name="Bankinfo" type="tns:BankInfo"/>
<xs:element name="BankVerificationTransactionId" type="xs:string"/>
<xs:element name="ItemReferenceId" type="xs:string"/>
<xs:element name="SubmittedBy" type="xs:string"/>
<xs:element name="VerificationResponse" type="xs:string"/>
<xs:element name="VerificationStatus" type="xs:string"/>
<xs:element name="BankVerificationTransactionType" type="xs:string"/>
<xs:element name="Created" type="xs:string"/>
<xs:element name="Success" type="xs:string"/>
<xs:element name="Error" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="BankInfoSearchResponse">
<wsdl:part element="tns:BankInfoSearchResponse" name="BankInfoSearchResponse">
</wsdl:part>
</wsdl:message>
<wsdl:message name="BankInfoSearchRequest">
<wsdl:part element="tns:BankInfoSearchRequest" name="BankInfoSearchRequest">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="BankAPIPort">
<wsdl:operation name="BankInfoSearch">
<wsdl:input message="tns:BankInfoSearchRequest" name="BankInfoSearchRequest">
</wsdl:input>
<wsdl:output message="tns:BankInfoSearchResponse" name="BankInfoSearchResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="BankAPIPortSoap11" type="tns:BankAPIPort">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="BankInfoSearch">
<soap:operation soapAction=""/>
<wsdl:input name="BankInfoSearchRequest">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="BankInfoSearchResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="BankAPIPortService">
<wsdl:port binding="tns:BankAPIPortSoap11" name="BankAPIPortSoap11">
<soap:address location="http://localhost:9080/workflowintg/ws/bankapi"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

I figured out the issue. There was a problem in the XSD. I declared the root element as xs:complexType instead of xs:element.

Related

SOAP mode wsdl : How to post and receive data in the format provided by wsdl

I am learning the soap webservices for which a wsdl file has been provided. I work in PHP (laravel 9 and I did not use a soap package because I want to better understand the native) I want to be able to post and receive data in the format recommended by the wsdl. Except that when I make a test on the code that I implemented and I make a
var_dump($client->__getLastRequest()) and var_dump( $client->__soapCall('ombRequest', $params))
For the request I don't see my inputs and the output always returns me null
I present below the wsdl code for a function so as not to be very long.
I would like to send the inputs of type AccountToWalletTransfer and have the output of type AccountToWalletTransferResponse as specified by the wsdl file
partner.wsdl
<wsdl:definitions name="IB2WService" targetNamespace="http://localhost/om-integration/public/wsld/bankapi/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://localhost/om-integration/public/wsld/bankapi/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<xs:schema targetNamespace="http://localhost/om-integration/public/wsld/bankapi/" version="1.0" xmlns:tns="http://localhost/om-integration/public/wsld/bankapi/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="HeaderRequest">
<xs:sequence>
<xs:element name="operatorCode" type="xs:string" />
<xs:element name="requestId" type="xs:string" />
<xs:element name="requestToken" type="xs:string" />
<xs:element name="requestType" type="xs:string" />
<xs:element name="affiliateCode" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="HeaderResponse">
<xs:sequence>
<xs:element name="operatorCode" type="xs:string" />
<xs:element name="requestId" type="xs:string" />
<xs:element name="affiliateCode" type="xs:string" />
<xs:element name="responseCode" type="xs:string" />
<xs:element name="responseMessage" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:schema>
<xs:schema elementFormDefault="unqualified" targetNamespace="http://localhost/om-integration/public/wsld/bankapi/" version="1.0" xmlns:ns1="http://localhost/om-integration/public/wsld/bankapi/" xmlns:tns="http://localhost/om-integration/public/wsld/bankapi/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="AccountToWalletTransfer" type="tns:AccountToWalletTransfer" />
<xs:element name="AccountToWalletTransferResponse" type="tns:AccountToWalletTransferResponse" />
<xs:complexType name="AccountToWalletTransfer">
<xs:sequence>
<xs:element minOccurs="0" name="MobileTransferRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="mmHeaderInfo" type="ns1:HeaderRequest" />
<xs:element name="externalRefNo" type="xs:string" />
<xs:element name="mobileNo" type="xs:string" />
<xs:element name="mobileName" type="xs:string" />
<xs:element name="mobileAlias" type="xs:string" />
<xs:element name="accountNo" type="xs:string" />
<xs:element name="accountAlias" type="xs:string" />
<xs:element name="accountName" type="xs:string" />
<xs:element name="transferDescription" type="xs:string" />
<xs:element name="ccy" type="xs:string" />
<xs:element name="amount" type="xs:double" />
<xs:element name="charge" type="xs:double" />
<xs:element name="tranDate" type="xs:date" />
<xs:element name="udf1" type="xs:string" />
<xs:element name="udf2" type="xs:string" />
<xs:element name="udf3" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="AccountToWalletTransferResponse">
<xs:sequence>
<xs:element minOccurs="0" name="return">
<xs:complexType>
<xs:sequence>
<xs:element name="mmHeaderInfo" type="ns1:HeaderResponse" />
<xs:element name="externalRefNo" type="xs:string" />
<xs:element name="CBAReferenceNo" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="AccountToWalletTransfer">
<wsdl:part element="tns:AccountToWalletTransfer" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="AccountToWalletTransferResponse">
<wsdl:part element="tns:AccountToWalletTransferResponse" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:portType name="B2WServices">
<wsdl:operation name="AccountToWalletTransfer">
<wsdl:input message="tns:AccountToWalletTransfer" name="AccountToWalletTransfer"></wsdl:input>
<wsdl:output message="tns:AccountToWalletTransferResponse" name="AccountToWalletTransferResponse"></wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="IB2WServiceSoapBinding" type="tns:B2WServices">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="AccountToWalletTransfer">
<soap:operation soapAction="http://localhost/om-integration/public/AccountToWalletTransfer" style="document" />
<wsdl:input name="AccountToWalletTransfer">
<soap:body use="literal" />
</wsdl:input>
<wsdl:output name="AccountToWalletTransferResponse">
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="IB2WService">
<wsdl:port binding="tns:IB2WServiceSoapBinding" name="B2WServicesPort">
<soap:address location="EXPOSED_URL" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
My inputs_____________
$client->__setLocation('http://localhost/om-integration/public/server');
$params = [
'AccountToWalletTransfer ' =>[
'operatorCode' => 'MODSSEZZZDD',
'requestId' => 'AZASSRFF',
'requestToken' => 'ea9ce3f18ecc96bbfdbd72800dc0f0b04ada7e09672dcb289346d4fd47',
'requestType' => 'A2W',
'affiliateCode' => 'EML',
'externalRefNo' => '',
'mobileNo' => '',
'mobileName' => '',
'mobileAlias' => '',
'accountNo' => '',
'accountAlias' => 'BICBICBI0000000001300',
'accountName' => '',
'transferDescription' => '',
'ccy' => 'EURO',
'amount' => '1000',
'charge' => '0',
'tranDate' => '2022-09-22',
'udf1' => '',
'udf2' => '',
'udf3' => '',
]
];
$response = $client->__soapCall('AccountToWalletTransfer', $params);
Server___________
if($request){
$server = new SoapServer(asset('wsdl/bankapi/partner.wsdl'), ['uri'=>'http://localhost/om-integration/public/server']);
$server->setClass('App\Soap\Services');
$server->handle();
}
else
return false;
Response______________
$response = new AccountToWalletTransferResponse('RETEDDFZSDD',
$params['requestId'],
$params['affiliateCode'],
'200',
'Success',
$params['requestId'],
'FKGI22541'
);
return $response;

src-resolve: Cannot resolve the name 'PkReportsTo' to a(n) 'identity constraint' component. [XSD]

I was trying to create FK and PK in the XML schema, but it is showing an error in the featured code above. Is shows the message: src-resolve: Cannot resolve the name 'PkReportsTo' to a(n) 'identity constraint' component. [XSD]
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.ricardoterra.com.br"
elementFormDefault="qualified">
<xs:element name="employees">
<xs:complexType>
<xs:sequence>
<xs:element name="employee" maxOccurs="unbounded">
<xs:complexType>
<xs:all>
<xs:element name="firstName" type="xs:string"></xs:element>
<xs:element name="lastName" type="xs:string"></xs:element>
<xs:element name="extension">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="([x][1-9])\w+"></xs:pattern>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="email">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="([a-z])\w+(#)([a-z])\w+(.[a-z]+)*"></xs:pattern>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="officeCode" type="xs:string"></xs:element>
<xs:element name="jobTitle" type="xs:string"></xs:element>
<xs:element name="reportsTo" type="xs:integer" minOccurs="0">
</xs:element>
</xs:all>
<xs:attribute name="number" type="xs:integer"></xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:unique name="number">
<xs:selector xpath="employee"></xs:selector>
<xs:field xpath="#number"></xs:field>
</xs:unique>
<xs:key name="PkEmploye">
<xs:selector xpath="employee"/>
<xs:field xpath="#number"></xs:field>
</xs:key>
<xs:key name="PkReportsTo">
<xs:selector xpath="employee/reportsTo"></xs:selector>
<xs:field xpath="."></xs:field>
</xs:key>
<xs:keyref name="FKtoReportsToEmployee" refer="PkReportsTo">
<xs:selector xpath="employee"></xs:selector>
<xs:field xpath="#number"></xs:field>
</xs:keyref>
</xs:element>
</xs:schema>
I am with a error at the part of my code:
<xs:keyref name="FKtoReportsToEmployee" refer="PkReportsTo">
<xs:selector xpath="employee"></xs:selector>
<xs:field xpath="#number"></xs:field>
</xs:keyref>
I don't know why.
I think you want the target namespace of the schema to be http://www.ricardoterra.com.br so use
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.ricardoterra.com.br"
targetNamespace="http://www.ricardoterra.com.br"
elementFormDefault="qualified">
and that error is likely to go away.

Fully Qualified Xpath returns null

<Trial1Response xmlns="http://schemas.microsoft.com/Sql/2008/05/Procedures/dbo">
<Trial1Result>
<DataSet xmlns="http://schemas.datacontract.org/2004/07/System.Data">
<xs:schema id="NewDataSet" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element msdata:IsDataSet="true" name="NewDataSet">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="NewTable">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="cust_id" type="xs:int">
</xs:element>
<xs:element minOccurs="0" name="fname" type="xs:string">
</xs:element>
<xs:element minOccurs="0" name="lname" type="xs:string">
</xs:element>
<xs:element minOccurs="0" name="addr" type="xs:string">
</xs:element>
<xs:element minOccurs="0" name="city" type="xs:string">
</xs:element>
<xs:element minOccurs="0" name="order_id" type="xs:int">
</xs:element>
<xs:element minOccurs="0" name="amount" type="xs:int">
</xs:element>
<xs:element minOccurs="0" name="particulars" type="xs:string">
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<NewDataSet xmlns="">
<NewTable><cust_id>1</cust_id><fname>Akshay</fname><lname>Jain</lname><addr>Borivali</addr><city>Mumbai</city><order_id>221</order_id><amount>41</amount><particulars>Item B</particulars>
</NewTable>
<NewTable><id>223</id><Akshay1id>682</Akshay1id><amount>345</amount><particulars>Item A</particulars>
</NewTable>
</NewDataSet>
</diffgr:diffgram>
</DataSet>
</Trial1Result>
<ReturnValue>0</ReturnValue>
</Trial1Response>
I want to extract the data between the tags NewDataSet. For this, I am using the following Xpath:
/*[local-name="Trial1Response" and namespace-uri()="http://schemas.microsoft.com/Sql/2008/05/Procedures/dbo"]/*[local-name="Trial1Result" and namespace-uri()="http://schemas.microsoft.com/Sql/2008/05/Procedures/dbo"]/*[local-name="DataSet" and namespace-uri()="http://schemas.datacontract.org/2004/07/System.Data"]/*[local-name="diffgr:diffgram" and namespace-uri()="urn:schemas-microsoft-com:xml-diffgram-v1"]/*[local-name="NewDataSet" and namespace-uri()=""]
I get null as my result. What am I doing wrong?
I am expected to use the fully qualified Xpath because Logic apps do not work without it
Edit: I have edited the XML after comments
Correct your xml.
And change local-name to local-name()
like this
/*[local-name()="Trial1Response" and namespace-uri()="http://schemas.microsoft.com/Sql/2008/05/Procedures/dbo"]/*[local-name()="Trial1Result" and namespace-uri()="http://schemas.microsoft.com/Sql/2008/05/Procedures/dbo"]/*[local-name()="DataSet" and namespace-uri()="http://schemas.datacontract.org/2004/07/System.Data"]/*[local-name()="diffgram" and namespace-uri()="urn:schemas-microsoft-com:xml-diffgram-v1"]/*[local-name()="NewDataSet" and namespace-uri()=""]
note: no need of using namespace-uri() if you have single/unique elements in the xml.

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>

Apache CXF 2.2.7 Spring 3 Web Service Unmarshalling Error: unexpected element

I have developed a simple web service application using Apache CXF 2.2.7 and Spring 3, deployed onto Tomcat as a WAR file, but I'm getting the following error message:
12-Apr-2010 15:56:12 org.apache.cxf.phase.PhaseInterceptorChain doDefaultLogging
WARNING: Interceptor for {http://services.aristabi.com/}ReportingServiceImplService#{http://services.aristabi.com/}getNewBusinessVolumeByCreateDate_v2 has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Unmarshalling Error: unexpected element (uri:"http://services.aristabi.com/", local:"searchCriteria"). Expected elements are <{}searchCriteria>
at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:764)
at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:623)
at org.apache.cxf.jaxb.io.DataReaderImpl.read(DataReaderImpl.java:128)
at org.apache.cxf.interceptor.DocLiteralInInterceptor.handleMessage(DocLiteralInInterceptor.java:106)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:243)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:109)
at org.apache.cxf.transport.servlet.ServletDestination.invoke(ServletDestination.java:98)
at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:406)
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:178)
at org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFServlet.java:142)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:179)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:103)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:159)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Thread.java:619)
Caused by: javax.xml.bind.UnmarshalException
- with linked exception:
[javax.xml.bind.UnmarshalException: unexpected element (uri:"http://services.aristabi.com/", local:"searchCriteria"). Expected elements are <{}searchCriteria>]
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(UnmarshallerImpl.java:425)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:362)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:339)
at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:749)
... 25 more
Caused by: javax.xml.bind.UnmarshalException: unexpected element (uri:"http://services.aristabi.com/", local:"searchCriteria"). Expected elements are <{}searchCriteria>
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:642)
at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:254)
at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:249)
at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportUnexpectedChildElement(Loader.java:116)
at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.childElement(Loader.java:101)
at com.sun.xml.bind.v2.runtime.unmarshaller.StructureLoader.childElement(StructureLoader.java:245)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:478)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:459)
at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.handleStartElement(StAXStreamConnector.java:242)
at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:176)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:360)
... 27 more
Caused by: javax.xml.bind.UnmarshalException: unexpected element (uri:"http://services.aristabi.com/", local:"searchCriteria"). Expected elements are <{}searchCriteria>
... 38 more
This is probably a simple issue, but I can't seem to be able to resolve it. Can anyone point me in the right direction to solve this issue?
Thanks,
Zahanghir
Btw, this is what my wsdl looks like
<?xml version='1.0' encoding='UTF-8'?><wsdl:definitions name="ReportingServiceImplService" targetNamespace="http://services.aristabi.com/" xmlns:ns1="http://cxf.apache.org/bindings/xformat" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://services.aristabi.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://services.aristabi.com/" xmlns:tns="http://services.aristabi.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="getNewBusinessVolumeByCreateDate" type="tns:getNewBusinessVolumeByCreateDate" />
<xs:element name="getNewBusinessVolumeByCreateDateResponse" type="tns:getNewBusinessVolumeByCreateDateResponse" />
<xs:element name="getNewBusinessVolumeByCreateDate_v2" type="tns:getNewBusinessVolumeByCreateDate_v2" />
<xs:element name="getNewBusinessVolumeByCreateDate_v2Response" type="tns:getNewBusinessVolumeByCreateDate_v2Response" />
<xs:element name="newBusinessLead" type="tns:newBusinessLead" />
<xs:element name="quotes" type="tns:quotes" />
<xs:element name="searchCriteria" type="tns:searchCriteria" />
<xs:complexType name="getNewBusinessVolumeByCreateDate">
<xs:sequence>
<xs:element minOccurs="0" name="agent" type="xs:string" />
<xs:element minOccurs="0" name="broker" type="xs:string" />
<xs:element minOccurs="0" name="businessUnit" type="xs:string" />
<xs:element minOccurs="0" name="fromMonth" type="xs:string" />
<xs:element minOccurs="0" name="fromYear" type="xs:string" />
<xs:element minOccurs="0" name="region" type="xs:string" />
<xs:element minOccurs="0" name="toMonth" type="xs:string" />
<xs:element minOccurs="0" name="toYear" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="getNewBusinessVolumeByCreateDateResponse">
<xs:sequence>
<xs:element minOccurs="0" name="return" type="tns:newBusinessLead" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="newBusinessLead">
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="convertedQuotes" nillable="true" type="tns:quotes" />
<xs:element maxOccurs="unbounded" minOccurs="0" name="declinedQuotes" nillable="true" type="tns:quotes" />
<xs:element maxOccurs="unbounded" minOccurs="0" name="ntuQuotes" nillable="true" type="tns:quotes" />
<xs:element maxOccurs="unbounded" minOccurs="0" name="pendingQuotes" nillable="true" type="tns:quotes" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="quotes">
<xs:sequence>
<xs:element minOccurs="0" name="month" type="xs:string" />
<xs:element name="premium" type="xs:int" />
<xs:element minOccurs="0" name="quoteStatus" type="xs:string" />
<xs:element name="volume" type="xs:int" />
<xs:element minOccurs="0" name="year" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="arrayList">
<xs:complexContent>
<xs:extension base="tns:abstractList">
<xs:sequence />
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType abstract="true" name="abstractList">
<xs:complexContent>
<xs:extension base="tns:abstractCollection">
<xs:sequence />
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType abstract="true" name="abstractCollection">
<xs:sequence />
</xs:complexType>
<xs:complexType name="getNewBusinessVolumeByCreateDate_v2">
<xs:sequence>
<xs:element minOccurs="0" name="searchCriteria" type="tns:searchCriteria" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="searchCriteria">
<xs:sequence>
<xs:element minOccurs="0" name="agent" type="xs:string" />
<xs:element minOccurs="0" name="broker" type="xs:string" />
<xs:element minOccurs="0" name="businessUnit" type="xs:string" />
<xs:element minOccurs="0" name="fromMonth" type="xs:string" />
<xs:element minOccurs="0" name="fromYear" type="xs:string" />
<xs:element minOccurs="0" name="region" type="xs:string" />
<xs:element minOccurs="0" name="toMonth" type="xs:string" />
<xs:element minOccurs="0" name="toYear" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="getNewBusinessVolumeByCreateDate_v2Response">
<xs:sequence>
<xs:element minOccurs="0" name="return" type="tns:newBusinessLead" />
</xs:sequence>
</xs:complexType>
<xs:element name="InvalidUserCredentialsException" type="tns:InvalidUserCredentialsException" />
<xs:complexType name="InvalidUserCredentialsException">
<xs:sequence />
</xs:complexType>
<xs:element name="tokenString" nillable="true" type="xs:string" />
</xs:schema>
</wsdl:types>
<wsdl:message name="InvalidUserCredentialsException">
<wsdl:part element="tns:InvalidUserCredentialsException" name="InvalidUserCredentialsException">
</wsdl:part>
</wsdl:message>
<wsdl:message name="getNewBusinessVolumeByCreateDateResponse">
<wsdl:part element="tns:getNewBusinessVolumeByCreateDateResponse" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="getNewBusinessVolumeByCreateDate">
<wsdl:part element="tns:getNewBusinessVolumeByCreateDate" name="parameters">
</wsdl:part>
<wsdl:part element="tns:tokenString" name="tokenString">
</wsdl:part>
</wsdl:message>
<wsdl:message name="getNewBusinessVolumeByCreateDate_v2Response">
<wsdl:part element="tns:getNewBusinessVolumeByCreateDate_v2Response" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="getNewBusinessVolumeByCreateDate_v2">
<wsdl:part element="tns:getNewBusinessVolumeByCreateDate_v2" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="IReportingService">
<wsdl:operation name="getNewBusinessVolumeByCreateDate">
<wsdl:input message="tns:getNewBusinessVolumeByCreateDate" name="getNewBusinessVolumeByCreateDate">
</wsdl:input>
<wsdl:output message="tns:getNewBusinessVolumeByCreateDateResponse" name="getNewBusinessVolumeByCreateDateResponse">
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getNewBusinessVolumeByCreateDate_v2">
<wsdl:input message="tns:getNewBusinessVolumeByCreateDate_v2" name="getNewBusinessVolumeByCreateDate_v2">
</wsdl:input>
<wsdl:output message="tns:getNewBusinessVolumeByCreateDate_v2Response" name="getNewBusinessVolumeByCreateDate_v2Response">
</wsdl:output>
<wsdl:fault message="tns:InvalidUserCredentialsException" name="InvalidUserCredentialsException">
</wsdl:fault>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ReportingServiceImplServiceSoapBinding" type="tns:IReportingService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="getNewBusinessVolumeByCreateDate">
<soap:operation soapAction="" style="document" />
<wsdl:input name="getNewBusinessVolumeByCreateDate">
<soap:header message="tns:getNewBusinessVolumeByCreateDate" part="tokenString" use="literal">
</soap:header>
<soap:body parts="parameters" use="literal" />
</wsdl:input>
<wsdl:output name="getNewBusinessVolumeByCreateDateResponse">
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getNewBusinessVolumeByCreateDate_v2">
<soap:operation soapAction="" style="document" />
<wsdl:input name="getNewBusinessVolumeByCreateDate_v2">
<soap:body use="literal" />
</wsdl:input>
<wsdl:output name="getNewBusinessVolumeByCreateDate_v2Response">
<soap:body use="literal" />
</wsdl:output>
<wsdl:fault name="InvalidUserCredentialsException">
<soap:fault name="InvalidUserCredentialsException" use="literal" />
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="ReportingServiceImplService">
<wsdl:port binding="tns:ReportingServiceImplServiceSoapBinding" name="ReportingServiceImplPort">
<soap:address location="http://localhost:8889/AristaInsuranceServices/reportingService" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
I don't have a XSD. Can you please point out what is wrong with the WSDL?
I know this question is a year old with no accepted answer but I had exactly the same error today.
Like the original question poster, I have a Java-First service with a method that returns an object. The problem for me was that I added an extra property to the bean that gets returned by the service method.
Once I republished/redeployed the service, the client side jaxb generated class for the return object was no longer the same as the server side WSDL complex-type (i.e. the client side classes lacked the new property) and so I had the "unexpected element" exception with the name of the missing property.
Once I regenated all the jaxb objects using WsdlToJava the client side code worked as normal.
I also came across a suggested workaround for this situation where you might not want to regenerate your client code every time a property changes on the server side. The solution is basically to ignore the unexpected element exception on the client side because it is for new elements that your existing code doesn't use. Link here to the solution:
http://whileonefork.blogspot.com/2010/11/cxf-backwards-compatibility-adding.html
The incoming message is invalid. Basically, it doesn't match the schema. (or at least what JAXB is expecting) Basically, someplace in the message, you have an element like:
<ns1:searchCriteria> ..... </ns1:searchCriteria>
or possibly with no namespace prefix, but with a default namespace set someplace. However, JAXB is expecting the element to be unqualified. something like:
<searchCriteria> ..... </searchCriteria>
Definitely check the sending side to see what they are sending as well as check the schema to see what the schema says it should look like. (elementFormDefault=unqualified is the default if not specified)
I had a similar problem, but the reason was the whitespace in the element name in the xsd schema.
elemname__. I just corrected it to elemname and now it works. The Error was thrown because xml had elemname not elemname__.

Resources