You may want to take a look at Glen Mazza's website where he has a number of web service tutorials. http://www.jroller.com/gmazza/entry/blog_article_index
In particular: http://www.jroller.com/gmazza/entry/web_service_tutorial Perhaps this would be helpful? On Tue, Oct 9, 2012 at 9:56 AM, cb9 <[email protected]> wrote: > Hi, > > I am new to Apache CXF and this my first post here. > > I am trying to develop simple HelloWorld contract first webservice. I have > following wsdl which is simple. > > <?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/Hello/" > xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" > xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="Hello" > targetNamespace="http://www.example.org/Hello/"> > <wsdl:types> > <xsd:schema targetNamespace="http://www.example.org/Hello/"> > <xsd:element name="sayHello"> > <xsd:complexType> > <xsd:sequence> > <xsd:element name="in" type="xsd:string"/> > </xsd:sequence> > </xsd:complexType> > </xsd:element> > <xsd:element name="sayHelloResponse"> > <xsd:complexType> > <xsd:sequence> > <xsd:element name="out" type="xsd:string"/> > </xsd:sequence> > </xsd:complexType> > </xsd:element> > </xsd:schema> > </wsdl:types> > <wsdl:message name="sayHelloRequest"> > <wsdl:part element="tns:sayHello" name="parameters"/> > </wsdl:message> > <wsdl:message name="sayHelloResponse"> > <wsdl:part element="tns:sayHelloResponse" name="parameters"/> > </wsdl:message> > <wsdl:portType name="Hello"> > <wsdl:operation name="sayHello"> > <wsdl:input message="tns:sayHelloRequest"/> > <wsdl:output message="tns:sayHelloResponse"/> > </wsdl:operation> > </wsdl:portType> > <wsdl:binding name="HelloSOAP" type="tns:Hello"> > <soap:binding style="document" > transport="http://schemas.xmlsoap.org/soap/http"/> > <wsdl:operation name="sayHello"> > <soap:operation soapAction="http://www.example.org/Hello/sayHello"/> > <wsdl:input> > <soap:body use="literal"/> > </wsdl:input> > <wsdl:output> > <soap:body use="literal"/> > </wsdl:output> > </wsdl:operation> > </wsdl:binding> > <wsdl:service name="Hello"> > <wsdl:port binding="tns:HelloSOAP" name="HelloSOAP"> > <soap:address location="http://localhost:9002/Hello"/> > </wsdl:port> > </wsdl:service> > </wsdl:definitions> > > > I generated java classes using following command > > wsdl2java -d src -ant -impl -server -client -all Hello.wsdl > > > Then I run server using ----------------------------------- > ant HelloServer > Then I run client using ------------------------------------- > and HelloClient > > > I get error > > Invoking sayHello... > [java] Oct 9, 2012 6:40:16 PM > org.apache.cxf.phase.PhaseInterceptorChain doIntercept > [java] WARNING: Interceptor has thrown exception, unwinding now > [java] org.apache.cxf.binding.soap.SoapFault: Error reading > XMLStreamReader. > [java] at > > org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:196) > [java] at > > org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:58) > [java] at > > org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:236) > [java] at > org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:658) > [java] at > > org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:2139) > [java] at > > org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:2022) > [java] at > > org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1947) > [java] at > org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:66) > [java] at > org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:632) > [java] at > > org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62) > [java] at > > org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:236) > [java] at > org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:472) > [java] at > org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:302) > [java] at > org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:254) > [java] at > org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73) > [java] at > org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:123) > [java] at $Proxy39.sayHello(Unknown Source) > [java] at > > org.example.hello.Hello_HelloSOAP_Client.main(Hello_HelloSOAP_Client.java:69) > [java] Caused by: com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in > prolog > [java] at [row,col {unknown-source}]: [1,0] > [java] at > com.ctc.wstx.sr.StreamScanner.throwUnexpectedEOF(StreamScanner.java:686) > [java] at > com.ctc.wstx.sr.BasicStreamReader.handleEOF(BasicStreamReader.java:2134) > [java] at > > com.ctc.wstx.sr.BasicStreamReader.nextFromProlog(BasicStreamReader.java:2040) > [java] at > com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1069) > [java] at > com.ctc.wstx.sr.BasicStreamReader.nextTag(BasicStreamReader.java:1095) > [java] at > > org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:93) > [java] ... 17 more > [java] Exception in thread "main" > javax.xml.ws.soap.SOAPFaultException: > Error reading XMLStreamReader > > > > I captured traffic on wireshark. Following I get on wireshark. > > > POST /Hello HTTP/1.1 > Content-Type: text/xml; charset=UTF-8 > SOAPAction: "http://www.example.org/Hello/sayHello" > Accept: */* > User-Agent: Apache CXF 2.2.3 > Cache-Control: no-cache > Pragma: no-cache > Host: localhost:9002 > Connection: keep-alive > Content-Length: 196 > > <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> > <soap:Body> > <ns2:sayHello xmlns:ns2="http://www.example.org/Hello/"> > <in>Charles</in> > </ns2:sayHello> > </soap:Body> > </soap:Envelope> > > HTTP/1.1 302 Found > Location: http://localhost:9002/Hello/ > Content-Length: 0 > Server: Jetty(6.1.19) > > > The generated Ant file is > > > <?xml version="1.0"?> > > > <project name="cxf wsdltojava" default="build" basedir="."> > > <property environment="env"/> > <property name="home.dir" location="${basedir}"/> > <property name="build.dir" location ="${basedir}/build"/> > <property name="build.classes.dir" location ="${build.dir}/classes"/> > <property name="build.src.dir" location ="${basedir}"/> > > > <available property="tools.jar" value="$${env.JAVA_HOME}/lib/tools.jar" > file="${env.JAVA_HOME}/lib/tools.jar"/> > <path id="jdk.tools.classpath"> > <pathelement location="${tools.jar}"/> > </path> > > <condition property="is.java.version.15"> > <or> > <equals arg1="${ant.java.version}" arg2="1.5"/> > <equals arg1="${ant.java.version}" arg2="1.6"/> > </or> > </condition> > > <fail message="cxf requires Java version 1.5 or higher. You are > currently using Java version ${ant.java.version}." > unless="is.java.version.15"/> > > > <condition property="cxf.home" value="${env.CXF_HOME}"> > <isset property="env.CXF_HOME"/> > </condition> > > <fail message="Please set CXF_HOME environment variable." > unless="cxf.home"/> > > > <condition property="cxf-manifest.jar.file" > value="${cxf.home}/build/lib/cxf-manifest.jar"> > <available file="cxf-manifest.jar" type="file" > filepath="${cxf.home}/build/lib"/> > </condition> > <property name="cxf-manifest.jar.file" > value="${cxf.home}/lib/cxf-manifest.jar"/> > > <fail message="The location ${cxf.home} does not seem to contain a cxf > installation; if you are importing this common build file from a location > other than the cxf samples directory then you need to set the cxf_HOME > environment variable."> > <condition> > <not> > <isset property="cxf-manifest.jar.file" /> > </not> > </condition> > </fail> > > > <condition property="thirdparty.tools.dir" value="${cxf.home}/tools"> > <available file="tools" type="dir" filepath="${cxf.home}"/> > </condition> > > <condition property="thirdparty.tools.dir" value="${cxf.home}/lib"> > <available file="lib" type="dir" filepath="${cxf.home}"/> > </condition> > > <property name="cxf.etc.dir" location="${cxf.home}/etc"/> > > <path id="cxf.classpath"> > <pathelement location="${home.dir}" /> > <pathelement location="${build.classes.dir}"/> > <pathelement location="${cxf-manifest.jar.file}"/> > </path> > > <target name="HelloClient" description="Run > org.example.hello.Hello_HelloSOAP_Client" depends="compile"> > <property name="param" value=""/> > <cxfrun classname="org.example.hello.Hello_HelloSOAP_Client" > param1="file:Hello.wsdl" > param2="${op}" > param3="${param}"/> > </target> > > <target name="HelloServer" description="Run > org.example.hello.Hello_HelloSOAP_Server" depends="compile"> > <cxfrun classname="org.example.hello.Hello_HelloSOAP_Server" > param1="file:Hello.wsdl"/> > </target> > > > > <target name="compile"> > <mkdir dir="${build.classes.dir}"/> > <javac srcdir="${build.src.dir}" destdir="${build.classes.dir}" > debug="true"> > <classpath refid="cxf.classpath" /> > </javac> > </target> > > <target name="checkstyle"> > <checkstyle config="${checkstyle.config.file}"> > <fileset dir="${basedir}/src" includes="**/*.java"/> > <classpath> > <path refid="cxf.classpath"/> > </classpath> > </checkstyle> > </target> > > <target name="clean"> > <delete dir="${build.classes.dir}"/> > <delete file="${java.timestamp.file}"/> > <delete file="demo.log"/> > </target> > > <target name="build" depends="compile" description="build demo client > and server"/> > > <macrodef name="cxfrun"> > <attribute name="classname"/> > <attribute name="param1" default=""/> > <attribute name="param2" default=""/> > <attribute name="param3" default=""/> > <attribute name="param4" default=""/> > <attribute name="param5" default=""/> > <attribute name="jvmarg1" default="-D"/> > <attribute name="jvmarg2" default="-D"/> > <attribute name="jvmarg3" default="-D"/> > <attribute name="jvmarg4" default="-D"/> > <attribute name="jvmarg5" default="-D"/> > <sequential> > <java classname="@{classname}" fork="yes"> > <classpath> > <path refid="cxf.classpath"/> > </classpath> > <arg value="@{param1}"/> > <arg value="@{param2}"/> > <arg value="@{param3}"/> > <arg value="@{param4}"/> > <arg value="@{param5}"/> > <jvmarg value="@{jvmarg1}"/> > <jvmarg value="@{jvmarg2}"/> > <jvmarg value="@{jvmarg3}"/> > <jvmarg value="@{jvmarg4}"/> > <jvmarg value="@{jvmarg5}"/> > <assertions> > <enable package="org.apache.cxf"/> > </assertions> > <sysproperty key="java.util.logging.config.file" > value="${cxf.etc.dir}/logging.properties"/> > <sysproperty key="log4j.configuration" > value="file:///${cxf.etc.dir}/log4j.properties"/> > </java> > </sequential> > </macrodef> > </project> > > > Now I changed > > <target name="HelloClient" description="Run > org.example.hello.Hello_HelloSOAP_Client" depends="compile"> > <property name="param" value=""/> > <cxfrun classname="org.example.hello.Hello_HelloSOAP_Client" > param1="file:Hello.wsdl" > param2="${op}" > param3="${param}"/> > </target> > > > <target name="HelloClient" description="Run > org.example.hello.Hello_HelloSOAP_Client" depends="compile"> > <property name="param" value=""/> > <cxfrun classname="org.example.hello.Hello_HelloSOAP_Client" > param1="http://localhost:9002/Hello/?wsdl" > param2="${op}" > param3="${param}"/> > </target> > > > This works prefect. > > Now following traffic I get on wireshark > > GET /Hello/?wsdl HTTP/1.1 > User-Agent: Java/1.6.0_35 > Host: localhost:9002 > Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2 > Connection: keep-alive > > HTTP/1.1 200 OK > Content-Type: text/xml > Transfer-Encoding: chunked > Server: Jetty(6.1.19) > > 89D > <?xml version='1.0' encoding='UTF-8'?><wsdl:definitions name="Hello" > targetNamespace="http://www.example.org/Hello/" > xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" > xmlns:tns="http://www.example.org/Hello/" > xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" > xmlns:xsd="http://www.w3.org/2001/XMLSchema"> > <wsdl:types> > <xsd:schema targetNamespace="http://www.example.org/Hello/" > xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" > xmlns:tns="http://www.example.org/Hello/" > xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" > xmlns:xsd="http://www.w3.org/2001/XMLSchema"> > <xsd:element name="sayHello"> > <xsd:complexType> > <xsd:sequence> > <xsd:element name="in" type="xsd:string" /> > </xsd:sequence> > </xsd:complexType> > </xsd:element> > <xsd:element name="sayHelloResponse"> > <xsd:complexType> > <xsd:sequence> > <xsd:element name="out" type="xsd:string" /> > </xsd:sequence> > </xsd:complexType> > </xsd:element> > </xsd:schema> > </wsdl:types> > <wsdl:message name="sayHelloResponse"> > <wsdl:part element="tns:sayHelloResponse" name="parameters"> > </wsdl:part> > </wsdl:message> > <wsdl:message name="sayHelloRequest"> > <wsdl:part element="tns:sayHello" name="parameters"> > </wsdl:part> > </wsdl:message> > <wsdl:portType name="Hello"> > <wsdl:operation name="sayHello"> > <wsdl:input message="tns:sayHelloRequest"> > </wsdl:input> > <wsdl:output message="tns:sayHelloResponse"> > </wsdl:output> > </wsdl:operation> > </wsdl:portType> > <wsdl:binding name="HelloSOAP" type="tns:Hello"> > <soap:binding style="document" > transport="http://schemas.xmlsoap.org/soap/http" /> > <wsdl:operation name="sayHello"> > <soap:operation soapAction="http://www.example.org/Hello/sayHello" > /> > <wsdl:input> > <soap:body use="literal" /> > </wsdl:input> > <wsdl:output> > <soap:body use="literal" /> > </wsdl:output> > </wsdl:operation> > </wsdl:binding> > <wsdl:service name="Hello"> > <wsdl:port binding="tns:HelloSOAP" name="HelloSOAP"> > <soap:address location="http://localhost:9002/Hello/" /> > </wsdl:port> > </wsdl:service> > </wsdl:definitions> > 0 > > POST /Hello/ HTTP/1.1 > Content-Type: text/xml; charset=UTF-8 > SOAPAction: "http://www.example.org/Hello/sayHello" > Accept: */* > User-Agent: Apache CXF 2.2.3 > Cache-Control: no-cache > Pragma: no-cache > Host: localhost:9002 > Connection: keep-alive > Content-Length: 196 > > <soap:Envelope > xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/ > "><soap:Body><ns2:sayHello > xmlns:ns2="http://www.example.org/Hello/ > "><in>Charles</in></ns2:sayHello></soap:Body></soap:Envelope>HTTP/1.1 > 200 OK > Content-Type: text/xml; charset=utf-8 > Content-Length: 207 > Server: Jetty(6.1.19) > > <soap:Envelope > xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/ > "><soap:Body><ns2:sayHelloResponse > xmlns:ns2="http://www.example.org/Hello/ > "><out></out></ns2:sayHelloResponse></soap:Body></soap:Envelope> > > > I don't know what is problem. > > > > > -- > View this message in context: > http://cxf.547215.n5.nabble.com/Newbie-Simple-Contract-first-webservice-new-to-CXF-tp5716164.html > Sent from the cxf-user mailing list archive at Nabble.com. > * *
