Hi,
I'm trying to add spring web service module to my project. I've added the the necessary beans and the required schema definition files. But I'm facing some issues with the name space declarations.
I'm using annotation based endpoints in my spring configurations(XPathParamAnnotationMethodEndpointA dapter).
In my schema definition I've declared the "targetNamespace" as "http://apj.com/ws/invoice-ops/".
If I use @XmlRootElement(namespace="http://apj.com/ws/invoice-ops/", name="invoiceCountRequest") in my marshlling class, during the web service client request I'm getting an error saying
But if I change the XmlRootElement as "@XmlRootElement(namespace="http://apj.com/ws/invoice-ops", name="invoiceCountRequest")" (namespace without the last slash) then the request works fine but the schema validation fails.2010-09-24 10:05:04,718 [main] TRACE org.springframework.ws.client.MessageTracing.sent - Sent request [<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soapenv:mustUnderstand="1"><wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-1"><wsse:Username>Bert</wsse:Username><wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">DmT+jElaKcgQ6I2X+3TYcc0qckM=</wsse:Password><wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">5kuvcV3D7Wsq62xdRDvBSg==</wsse:Nonce><wsu:Created>2010-09-24T04:35:04.640Z</wsu:Created></wsse:UsernameToken></wsse:Security></soapenv:Header><soapenv:Body><ns2:invoiceCountRequ est xmlns:ns2="http://apj.com/ws/invoice-ops/" xmlns:ns3="http://apj.com/ws/invoice-ops"><accountId>5</accountId><key>5555</key><fromDate>2010-09-24T10:05:04.453+05:30</fromDate><toDate>2010-09-24T10:05:04.453+05:30</toDate><codes>cld</codes></ns2:invoiceCountRequest></soapenv:Body></soapenv:Envelope>]
2010-09-24 10:05:05,656 [main] TRACE org.springframework.ws.client.MessageTracing.recei ved - Received response [<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><soapenv:Fault><faultcode>soapenv: Server</faultcode><faultstring xml:lang="en">argument type mismatch</faultstring></soapenv:Fault></soapenv:Body></soapenv:Envelope>] for request [<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soapenv:mustUnderstand="1"><wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-1"><wsse:Username>Bert</wsse:Username><wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">DmT+jElaKcgQ6I2X+3TYcc0qckM=</wsse:Password><wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">5kuvcV3D7Wsq62xdRDvBSg==</wsse:Nonce><wsu:Created>2010-09-24T04:35:04.640Z</wsu:Created></wsse:UsernameToken></wsse:Security></soapenv:Header><soapenv:Body><ns2:invoiceCountRequ est xmlns:ns2="http://apj.com/ws/invoice-ops/" xmlns:ns3="http://apj.com/ws/invoice-ops"><accountId>5</accountId><key>5555</key><fromDate>2010-09-24T10:05:04.453+05:30</fromDate><toDate>2010-09-24T10:05:04.453+05:30</toDate><codes>cld</codes></ns2:invoiceCountRequest></soapenv:Body></soapenv:Envelope>]
org.springframework.ws.soap.client.SoapFaultClient Exception: argument type mismatch
at org.springframework.ws.soap.client.core.SoapFaultM essageResolver.resolveFault(SoapFaultMessageResolv er.java:37)
at org.springframework.ws.client.core.WebServiceTempl ate.handleFault(WebServiceTemplate.java:738)
at org.springframework.ws.client.core.WebServiceTempl ate.doSendAndReceive(WebServiceTemplate.java:564)
at org.springframework.ws.client.core.WebServiceTempl ate.sendAndReceive(WebServiceTemplate.java:502)
at org.springframework.ws.client.core.WebServiceTempl ate.marshalSendAndReceive(WebServiceTemplate.java: 351)
at org.springframework.ws.client.core.WebServiceTempl ate.marshalSendAndReceive(WebServiceTemplate.java: 345)
at org.springframework.ws.client.core.WebServiceTempl ate.marshalSendAndReceive(WebServiceTemplate.java: 337)
at InvoiceCountRequestTest.request(InvoiceCountReques tTest.java:37)
at InvoiceCountRequestTest.main(InvoiceCountRequestTe st.java:53)
Can you help me to resolve this issue. I'll be happy to provide any more information required by you.
I'm attaching my schema, and the endpoint below.
In my schema definition is as follows
Then I created my model objects using the xjc.bat utility from jaxb.Code:<?xml version="1.0" encoding="UTF-8"?> <schema targetNamespace="http://apj.com/ws/invoice-ops/" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://apj.com/ws/invoice-ops/"> <element name="invoiceCountRequest" type="tns:invoiceCountRequest"></element> <complexType name="invoiceCountRequest"> <sequence> <element name="accountId"> <simpleType> <restriction base="int"> <minInclusive value="1"></minInclusive> </restriction> </simpleType> </element> <element name="key"> <simpleType> <restriction base="string"> <minLength value="1"></minLength> </restriction> </simpleType> </element> <element name="fromDate" type="dateTime"></element> <element name="toDate" type="dateTime"></element> <element name="codes" type="string" minOccurs="1" maxOccurs="unbounded"> </element> </sequence> </complexType> <complexType name="invoiceCountResponse"> <sequence> <element name="countMap" type="tns:MyMap"></element> </sequence> </complexType> <element name="invoiceCountResponse" type="tns:invoiceCountResponse"></element> <complexType name="MyMap"> <sequence> <element name="Entry" type="tns:MapEntry" minOccurs="1" maxOccurs="unbounded"></element> </sequence> </complexType> <complexType name="MapEntry"> <attribute name="key" type="string"></attribute> <attribute name="value" type="string"></attribute> </complexType> </schema>
My endpoint class is as follows
I'm using the following class to test the web serviceCode:import java.util.HashMap; import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Component; import org.springframework.ws.server.endpoint.annotation.Endpoint; import org.springframework.ws.server.endpoint.annotation.PayloadRoot; @Endpoint @Component("InvoiceCountRequestEndPoint") public class InvoiceCountRequestEndPoint { private static Log log = LogFactory .getLog(InvoiceCountRequestEndPoint.class); @PayloadRoot(localPart = "invoiceCountRequest", namespace = "http://apj.com/ws/invoice-ops/") public InvoiceCountResponse memberDetails(InvoiceCountRequest request) throws EncryptionException { InvoiceCountResponse response = new InvoiceCountResponse(); Map<String, String> m=new HashMap<String, String>(); m.put("00", "0000000"); response.setCountMap(m); return response; } }
Thank You,Code:import java.io.IOException; import java.util.Date; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.ws.client.core.WebServiceTemplate; import org.springframework.ws.soap.client.SoapFaultClientException; public class InvoiceCountRequestTest { private WebServiceTemplate webServiceTemplate; public void setWebServiceTemplate(WebServiceTemplate webServiceTemplate) { this.webServiceTemplate = webServiceTemplate; } public void request() throws IOException { try { InvoiceCountRequest request = new InvoiceCountRequest(); request.setAccountId(5); request.setFromDate(new Date()); request.setKey("5555"); request.setToDate(new Date()); request.getCodes().add("cld"); InvoiceCountResponse response = (InvoiceCountResponse) webServiceTemplate .marshalSendAndReceive(request); System.out.println("result: " + response); } catch (SoapFaultClientException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) throws IOException { ApplicationContext applicationContext = new ClassPathXmlApplicationContext( "applicationContext.xml", InvoiceCountRequestTest.class); InvoiceCountRequestTest echoClient = (InvoiceCountRequestTest) applicationContext .getBean("client"); echoClient.request(); } }
Arun P Johny


Reply With Quote

