Missing input/output param namespace in SOAP
--------------------------------------------
Key: CXF-1226
URL: https://issues.apache.org/jira/browse/CXF-1226
Project: CXF
Issue Type: Bug
Affects Versions: 2.0.3, 2.0.2
Environment: Windows XP; Tomcat 5.5
Reporter: Nianhua Li
I am using the java-first approach with spring configuration on cxf 2.0.3 and
tomcat 5.5. I specified namespace for all the input and output parameters via
@WebParam and @WebResult annotation. But the namespace was somehow missing from
the SOAP message.
You can reproduce the problem by using the following test code (server side):
=================web.xml========================================
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/beans.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<display-name>CXF Servlet</display-name>
<servlet-class>
org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
---------------------------------------------------------------------------------------------------------------
=================beans.xml=======================================
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:cxf="http://cxf.apache.org/core"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<bean id="logInbound"
class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
<bean id="logOutbound"
class="org.apache.cxf.interceptor.LoggingOutInterceptor"/>
<cxf:bus>
<cxf:inInterceptors> <ref bean="logInbound"/> </cxf:inInterceptors>
<cxf:outInterceptors> <ref bean="logOutbound"/> </cxf:outInterceptors>
<cxf:inFaultInterceptors> <ref bean="logOutbound"/>
</cxf:inFaultInterceptors>
</cxf:bus>
<jaxws:endpoint id="helloWorld" implementor="demo.spring.HelloWorldImpl"
address="/HelloWorld" />
</beans>
-----------------------------------------------------------------------------------------------------------------------
=================HelloWorld.java=======================================
package demo.spring;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.xml.ws.ResponseWrapper;
import javax.xml.ws.RequestWrapper;
import javax.jws.soap.SOAPBinding;
@WebService(name="MyHelloWorldService",
targetNamespace="http://nstest.helloworld")
@SOAPBinding( parameterStyle=SOAPBinding.ParameterStyle.WRAPPED,
style=SOAPBinding.Style.DOCUMENT,
use= SOAPBinding.Use.LITERAL )
public interface HelloWorld {
@WebMethod
@WebResult(name="MyResult", targetNamespace="http://nstest.helloworld")
String sayHi(@WebParam(name="MyInput",
targetNamespace="http://nstest.helloworld") String text);
}
-----------------------------------------------------------------------------------------------------------------------
=================HelloWorldImpl.java=======================================
package demo.spring;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
@WebService(endpointInterface = "demo.spring.HelloWorld")
public class HelloWorldImpl implements HelloWorld {
public String sayHi(String text) {
return "Hello " + text;
}
}
-----------------------------------------------------------------------------------------------------------------------
Create WAR from the above code, deploy to tomcat, here is the WSDL I got from
http://localhost:8080/...::
=======main WSDL:
http://localhost:8080/spring_http/HelloWorld?wsdl=================
<?xml version="1.0" encoding="utf-8" ?>
- <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:ns1="http://nstest.helloworld"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://spring.demo/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
name="HelloWorldImplService" targetNamespace="http://spring.demo/">
<wsdl:import
location="http://localhost:8080/spring_http/HelloWorld?wsdl=MyHelloWorldService.wsdl"
namespace="http://nstest.helloworld" />
- <wsdl:binding name="HelloWorldImplServiceSoapBinding"
type="ns1:MyHelloWorldService">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
- <wsdl:operation name="sayHi">
<soap:operation soapAction="" style="document" />
- <wsdl:input name="sayHi">
<soap:body use="literal" />
</wsdl:input>
- <wsdl:output name="sayHiResponse">
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
- <wsdl:service name="HelloWorldImplService">
- <wsdl:port binding="tns:HelloWorldImplServiceSoapBinding"
name="HelloWorldImplPort">
<soap:address location="http://localhost:8080/spring_http/HelloWorld" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
-----------------------------------------------------------------------------------------------------------------------------------------------
=====imported WSDL:
http://localhost:8080/spring_http/HelloWorld?wsdl=MyHelloWorldService.wsdl====
<?xml version="1.0" encoding="utf-8" ?>
- <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:ns1="http://nstest.helloworld"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="MyHelloWorldService"
targetNamespace="http://nstest.helloworld">
- <wsdl:types>
- <xsd:schema xmlns="http://nstest.helloworld" xmlns:tns="http://spring.demo/"
attributeFormDefault="unqualified" elementFormDefault="unqualified"
targetNamespace="http://nstest.helloworld"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<import xmlns="http://www.w3.org/2001/XMLSchema"
namespace="http://spring.demo/" />
<xsd:element name="sayHi" type="sayHi" />
- <xsd:complexType name="sayHi">
- <xsd:sequence>
<xsd:element minOccurs="0" name="MyInput" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
<xsd:element name="sayHiResponse" type="sayHiResponse" />
- <xsd:complexType name="sayHiResponse">
- <xsd:sequence>
<xsd:element minOccurs="0" name="MyResult" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
</wsdl:types>
- <wsdl:message name="sayHi">
<wsdl:part element="ns1:sayHi" name="parameters" />
</wsdl:message>
- <wsdl:message name="sayHiResponse">
<wsdl:part element="ns1:sayHiResponse" name="parameters" />
</wsdl:message>
- <wsdl:portType name="MyHelloWorldService">
- <wsdl:operation name="sayHi">
<wsdl:input message="ns1:sayHi" name="sayHi" />
<wsdl:output message="ns1:sayHiResponse" name="sayHiResponse" />
</wsdl:operation>
</wsdl:portType>
</wsdl:definitions>
-------------------------------------------------------------------------------------------------------------------------------------------
Create client from WSDL by using wsdl2java. The namespaces of input/output
parameters have already been missing from the generated service interface:
================MyHelloWorldService.java (generated by
wsdl2java)======================
package helloworld.nstest;
import javax.jws.WebParam.Mode;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding.Style;
import javax.jws.soap.SOAPBinding;
import javax.jws.WebMethod;
import javax.jws.WebResult;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;
/**
* This class was generated by Apache CXF (incubator) 2.0.3-incubator
* Tue Nov 20 22:45:47 EST 2007
* Generated source version: 2.0.3-incubator
*
*/
@WebService(targetNamespace = "http://nstest.helloworld", name =
"MyHelloWorldService")
public interface MyHelloWorldService {
@ResponseWrapper(targetNamespace = "http://nstest.helloworld", className =
"helloworld.nstest.SayHiResponse", localName = "sayHiResponse")
@RequestWrapper(targetNamespace = "http://nstest.helloworld", className =
"helloworld.nstest.SayHi", localName = "sayHi")
@WebResult(targetNamespace = "", name = "MyResult")
@WebMethod
public java.lang.String sayHi(
@WebParam(targetNamespace = "", name = "MyInput")
java.lang.String myInput
);
}
===================================================================
Modify the generated client:
========MyHelloWorldService_HelloWorldImplPort_Client.java (generated by
wsdl2java)======
package helloworld.nstest;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import demo.spring.HelloWorldImplService;
import javax.jws.WebMethod;
import javax.jws.WebResult;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;
public final class MyHelloWorldService_HelloWorldImplPort_Client {
private static final QName SERVICE_NAME = new QName("http://spring.demo/",
"HelloWorldImplService");
private MyHelloWorldService_HelloWorldImplPort_Client() {
}
public static void main(String args[]) throws Exception {
HelloWorldImplService ss = new HelloWorldImplService();
MyHelloWorldService port = ss.getHelloWorldImplPort();
{
System.out.println("Invoking sayHi...");
java.lang.String _sayHi_myInput = "ABC";
java.lang.String _sayHi__return = port.sayHi(_sayHi_myInput);
System.out.println("sayHi.result=" + _sayHi__return);
}
System.exit(0);
}
}
--------------------------------------------------------------------------------------------------------
SOAP message captured on server-side:
--------------------------------------
Encoding: UTF-8
Headers: {connection=[keep-alive], cache-control=[no-cache], host=[localhost:808
0], user-agent=[Java/1.5.0_12], transfer-encoding=[chunked], pragma=[no-cache],
content-type=[text/xml; charset=UTF-8], accept=[*], soapaction=[""]}
Message:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body
><ns2:sayHi xmlns:ns2="http://nstest.helloworld"><MyInput>ABC</MyInput></ns2:say
Hi></soap:Body></soap:Envelope>
--------------------------------------
Nov 20, 2007 10:51:13 PM org.apache.cxf.interceptor.LoggingOutInterceptor$Loggin
gCallback onClose
INFO: Outbound Message:
--------------------------------------
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body
><ns1:sayHiResponse xmlns:ns1="http://nstest.helloworld"><MyResult>Hello ABC</My
Result></ns1:sayHiResponse></soap:Body></soap:Envelope>-------------------------
-------------
You can see that both "MyInput" and "MyResult" have no namespace.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.