You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Muhammad Gelbana <m....@gmail.com> on 2013/03/16 02:17:10 UTC

Starting developing web services with Apache CXF

My first question here :)

So I'm assigned a web-service based task but unfortunately I don't know
almost anything about web services ! After some searching I decided to use
Apache CXF but I'm facing some trouble.

I do not need an interface so I only wrote a simple implemented class just
to get things started
----------------------------------------------------------------------------------------------------------------------------
package com.sc.ipk.ws.services;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.xml.ws.BindingType;
import javax.xml.ws.soap.SOAPBinding;

@WebService(serviceName = "calcServiceName", portName = "calcPortName")
@BindingType(SOAPBinding.SOAP12HTTP_BINDING)
public class Calculator {
    /**
     * @param firstOperand
     * @param secondOperand
     * @return The sum
     * @throws AddNumbersException
     *         if any of the numbers to be added is negative.
     */
    @WebMethod
    public int addition(@WebParam(name = "firstOperand") int int1,
@WebParam(name = "secondOperand") int int2) {
        return int1 + int2;
    }

    @PostConstruct
    @WebMethod(exclude = true)
    public void willResponse() {
        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>> Will response");
    }

    @PreDestroy
    @WebMethod(exclude = true)
    public void doneResponding() {
        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>> Responded");
    }
}
----------------------------------------------------------------------------------------------------------------------------
This is my ant java task to produce client, server and wsdl files:
----------------------------------------------------------------------------------------------------------------------------
<java classname="org.apache.cxf.tools.java2ws.JavaToWS" fork="true">
<arg value="-soap12" />
<arg value="-wsdl" />
<arg value="-server" />
<arg value="-client" />
<arg value="-verbose" />
<arg value="-o" />
<arg value="IpkWS.wsdl" />
<arg value="-databinding" />
<arg value="aegis" />
<arg value="-portname" />
<arg value="IxAccess" />
<arg value="-address" />
<arg value="http://localhost:8080/ipk-ws" />
<arg value="-servicename" />
<arg value="IpkWS" />
<arg value="-frontend" />
<arg value="jaxws" />
<!--
<arg value="-s" />
<arg value="src" />
-->
<arg value="-d" />
<arg value="webapp/WEB-INF/wsdl" />
<arg value="com.sc.ipk.ws.services.Calculator" />
<classpath>
<path refid="cxf.classpath" />
</classpath>
</java>
----------------------------------------------------------------------------------------------------------------------------
I use ant because It's much easier for, I'm *terrible* with maven.

Here is what I need to do:
- I need to publish this service so a *.net* client is able to consume it,
that's why I need to use aegis. Unfortunately the *.net* client isn't
accessible now for raid testing but I guess the generated java client code
should get me half way through

Now I'm facing the following issues:
- @WebParam isn't effective, when I use it, i get parsing errors that the
expected elements are "firstOperand" and "secondOperand", this is the error
stack:

Exception in thread "main" javax.xml.ws.soap.SOAPFaultException:
Unmarshalling Error: unexpected element (uri:"", local:"arg0"). Expected
elements are <{}secondOperand>,<{}firstOperand>
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:155)
at $Proxy38.addition(Unknown Source)
at
com.sc.ipk.ws.services.Calculator_PortTypeClient.main(Calculator_PortTypeClient.java:20)
Caused by: org.apache.cxf.binding.soap.SoapFault: Unmarshalling Error:
unexpected element (uri:"", local:"arg0"). Expected elements are
<{}secondOperand>,<{}firstOperand>
at
org.apache.cxf.binding.soap.interceptor.Soap12FaultInInterceptor.unmarshalFault(Soap12FaultInInterceptor.java:133)
at
org.apache.cxf.binding.soap.interceptor.Soap12FaultInInterceptor.handleMessage(Soap12FaultInInterceptor.java:59)
at
org.apache.cxf.binding.soap.interceptor.Soap12FaultInInterceptor.handleMessage(Soap12FaultInInterceptor.java:46)
at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
at
org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:114)
at
org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:69)
at
org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:34)
at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:800)
at
org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1592)
at
org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1490)
at
org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1309)
at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:622)
at
org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:530)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:463)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:366)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:319)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:133)
... 2 more

This is the WSDL file:

<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="
http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://services.ws.ipk.sc.com/"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:ns1="
http://schemas.xmlsoap.org/soap/http" name="calcServiceName"targetNamespace
="http://services.ws.ipk.sc.com/">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="
http://services.ws.ipk.sc.com/" elementFormDefault="unqualified"
targetNamespace="http://services.ws.ipk.sc.com/" version="1.0">
<xs:element name="addition" type="tns:addition"/>
<xs:element name="additionResponse" type="tns:additionResponse"/>
<xs:complexType name="addition">
<xs:sequence>
*<xs:element name="firstOperand" type="xs:int"/>*
*<xs:element name="secondOperand" type="xs:int"/>*
</xs:sequence>
</xs:complexType>
<xs:complexType name="additionResponse">
<xs:sequence>
<xs:element name="return" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="additionResponse">
<wsdl:part element="tns:additionResponse" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="addition">
<wsdl:part element="tns:addition" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:portType name="Calculator">
<wsdl:operation name="addition">
<wsdl:input message="tns:addition" name="addition"></wsdl:input>
<wsdl:output message="tns:additionResponse" name="additionResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="calcServiceNameSoapBinding" type="tns:Calculator">
<soap12:binding style="document" transport="
http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="addition">
<soap12:operation soapAction="" style="document"/>
<wsdl:input name="addition">
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output name="additionResponse">
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="calcServiceName">
<wsdl:port binding="tns:calcServiceNameSoapBinding" name="calcPortName">
<soap12:address location="http://localhost:8080/ipk-ws/services/calc"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

- After succeeding with that, I need to package my service as a *war* file
and deploy it into tomcat 7 and expose a servlet context parameter from
another web app on the same servlet container of course, so how can that be
done !

- Another issue is that the generated client code is generated as if the
soap binding is *1.1* while I declared explicitly in the service
implementation class that the soap binding should be *1.2*
QName serviceName = new QName("http://services.ws.ipk.sc.com/", "IpkWS");
QName portName = new QName("http://services.ws.ipk.sc.com/", "IxAccess");
Service service = Service.create(serviceName);
service.addPort(portName, *SOAPBinding.SOAP11HTTP_BINDING*, "
http://localhost:8080/ipk-ws");
com.sc.ipk.ws.services.Calculator_PortType client =
service.getPort(portName, com.sc.ipk.ws.services.Calculator_PortType.class);

I'm using Apache CXF v2.7.3 and I included these jars in my classpath:
commons-logging-1.1.1.jar
httpasyncclient-4.0-beta3.jar
httpclient-4.2.1.jar
httpcore-4.2.2.jar
httpcore-nio-4.2.2.jar
isorelax-20030108.jar
msv-core-2011.1.jar
neethi-3.0.2.jar
relaxngDatatype-20020414.jar
spring-aop-3.0.7.RELEASE.jar
spring-asm-3.0.7.RELEASE.jar
spring-beans-3.0.7.RELEASE.jar
spring-context-3.0.7.RELEASE.jar
spring-core-3.0.7.RELEASE.jar
spring-expression-3.0.7.RELEASE.jar
spring-web-3.0.7.RELEASE.jar
wsdl4j-1.6.2.jar
xmlschema-core-2.0.3.jar
xsdlib-2010.1.jar

Along with other JARS of course for other applications but these are
obviously the ones CXF needs, unless I messed something up !

Please don't hesitate to reply if I failed to clarify anything and thank
you in advance for your time.

Re: Starting developing web services with Apache CXF

Posted by Muhammad Gelbana <m....@gmail.com>.
Thank you for your very fast reply :)

When I used SoapUI to test the service while its deployed, (Instead of the
generated client\server classes), everything worked as expected. The
generated classes must have needed extra tuning from me, I think !

Thanks a lot for that great link !

-

On Sat, Mar 16, 2013 at 3:41 AM, Glen Mazza <gm...@talend.com> wrote:

> Links #2 (preferably) or #3 should take care of you here:
> http://www.jroller.com/gmazza/**entry/blog_article_index<http://www.jroller.com/gmazza/entry/blog_article_index>, link #55 for the SOAP 1.1/1.2 issue.  Link #2 serves equally well as a
> Maven tutorial.
>
> Glen
>
>
> On 03/15/2013 09:17 PM, Muhammad Gelbana wrote:
>
>> My first question here :)
>>
>> So I'm assigned a web-service based task but unfortunately I don't know
>> almost anything about web services ! After some searching I decided to use
>> Apache CXF but I'm facing some trouble.
>>
>> I do not need an interface so I only wrote a simple implemented class just
>> to get things started
>> ------------------------------**------------------------------**
>> ------------------------------**------------------------------**----
>> package com.sc.ipk.ws.services;
>>
>> import javax.annotation.**PostConstruct;
>> import javax.annotation.PreDestroy;
>> import javax.jws.WebMethod;
>> import javax.jws.WebService;
>> import javax.xml.ws.BindingType;
>> import javax.xml.ws.soap.SOAPBinding;
>>
>> @WebService(serviceName = "calcServiceName", portName = "calcPortName")
>> @BindingType(SOAPBinding.**SOAP12HTTP_BINDING)
>> public class Calculator {
>>      /**
>>       * @param firstOperand
>>       * @param secondOperand
>>       * @return The sum
>>       * @throws AddNumbersException
>>       *         if any of the numbers to be added is negative.
>>       */
>>      @WebMethod
>>      public int addition(@WebParam(name = "firstOperand") int int1,
>> @WebParam(name = "secondOperand") int int2) {
>>          return int1 + int2;
>>      }
>>
>>      @PostConstruct
>>      @WebMethod(exclude = true)
>>      public void willResponse() {
>>          System.out.println(">>>>>>>>>>**>>>>>>>>>>>>>>>>>>> Will
>> response");
>>      }
>>
>>      @PreDestroy
>>      @WebMethod(exclude = true)
>>      public void doneResponding() {
>>          System.out.println(">>>>>>>>>>**>>>>>>>>>>>>>>>>>>> Responded");
>>      }
>> }
>> ------------------------------**------------------------------**
>> ------------------------------**------------------------------**----
>> This is my ant java task to produce client, server and wsdl files:
>> ------------------------------**------------------------------**
>> ------------------------------**------------------------------**----
>> <java classname="org.apache.cxf.**tools.java2ws.JavaToWS" fork="true">
>> <arg value="-soap12" />
>> <arg value="-wsdl" />
>> <arg value="-server" />
>> <arg value="-client" />
>> <arg value="-verbose" />
>> <arg value="-o" />
>> <arg value="IpkWS.wsdl" />
>> <arg value="-databinding" />
>> <arg value="aegis" />
>> <arg value="-portname" />
>> <arg value="IxAccess" />
>> <arg value="-address" />
>> <arg value="http://localhost:8080/**ipk-ws <http://localhost:8080/ipk-ws>"
>> />
>> <arg value="-servicename" />
>> <arg value="IpkWS" />
>> <arg value="-frontend" />
>> <arg value="jaxws" />
>> <!--
>> <arg value="-s" />
>> <arg value="src" />
>> -->
>> <arg value="-d" />
>> <arg value="webapp/WEB-INF/wsdl" />
>> <arg value="com.sc.ipk.ws.services.**Calculator" />
>> <classpath>
>> <path refid="cxf.classpath" />
>> </classpath>
>> </java>
>> ------------------------------**------------------------------**
>> ------------------------------**------------------------------**----
>> I use ant because It's much easier for, I'm *terrible* with maven.
>>
>>
>> Here is what I need to do:
>> - I need to publish this service so a *.net* client is able to consume it,
>> that's why I need to use aegis. Unfortunately the *.net* client isn't
>>
>> accessible now for raid testing but I guess the generated java client code
>> should get me half way through
>>
>> Now I'm facing the following issues:
>> - @WebParam isn't effective, when I use it, i get parsing errors that the
>> expected elements are "firstOperand" and "secondOperand", this is the
>> error
>> stack:
>>
>> Exception in thread "main" javax.xml.ws.soap.**SOAPFaultException:
>> Unmarshalling Error: unexpected element (uri:"", local:"arg0"). Expected
>> elements are <{}secondOperand>,<{}**firstOperand>
>> at org.apache.cxf.jaxws.**JaxWsClientProxy.invoke(**
>> JaxWsClientProxy.java:155)
>> at $Proxy38.addition(Unknown Source)
>> at
>> com.sc.ipk.ws.services.**Calculator_PortTypeClient.**main(Calculator_**
>> PortTypeClient.java:20)
>> Caused by: org.apache.cxf.binding.soap.**SoapFault: Unmarshalling Error:
>> unexpected element (uri:"", local:"arg0"). Expected elements are
>> <{}secondOperand>,<{}**firstOperand>
>> at
>> org.apache.cxf.binding.soap.**interceptor.**Soap12FaultInInterceptor.**
>> unmarshalFault(**Soap12FaultInInterceptor.java:**133)
>> at
>> org.apache.cxf.binding.soap.**interceptor.**Soap12FaultInInterceptor.**
>> handleMessage(**Soap12FaultInInterceptor.java:**59)
>> at
>> org.apache.cxf.binding.soap.**interceptor.**Soap12FaultInInterceptor.**
>> handleMessage(**Soap12FaultInInterceptor.java:**46)
>> at
>> org.apache.cxf.phase.**PhaseInterceptorChain.**doIntercept(**
>> PhaseInterceptorChain.java:**271)
>> at
>> org.apache.cxf.interceptor.**AbstractFaultChainInitiatorObs**
>> erver.onMessage(**AbstractFaultChainInitiatorObs**erver.java:114)
>> at
>> org.apache.cxf.binding.soap.**interceptor.**CheckFaultInterceptor.**
>> handleMessage(**CheckFaultInterceptor.java:69)
>> at
>> org.apache.cxf.binding.soap.**interceptor.**CheckFaultInterceptor.**
>> handleMessage(**CheckFaultInterceptor.java:34)
>> at
>> org.apache.cxf.phase.**PhaseInterceptorChain.**doIntercept(**
>> PhaseInterceptorChain.java:**271)
>> at org.apache.cxf.endpoint.**ClientImpl.onMessage(**ClientImpl.java:800)
>> at
>> org.apache.cxf.transport.http.**HTTPConduit$**WrappedOutputStream.**
>> handleResponseInternal(**HTTPConduit.java:1592)
>> at
>> org.apache.cxf.transport.http.**HTTPConduit$**WrappedOutputStream.**
>> handleResponse(HTTPConduit.**java:1490)
>> at
>> org.apache.cxf.transport.http.**HTTPConduit$**WrappedOutputStream.close(*
>> *HTTPConduit.java:1309)
>> at org.apache.cxf.transport.**AbstractConduit.close(**
>> AbstractConduit.java:56)
>> at org.apache.cxf.transport.http.**HTTPConduit.close(HTTPConduit.**
>> java:622)
>> at
>> org.apache.cxf.interceptor.**MessageSenderInterceptor$**
>> MessageSenderEndingInterceptor**.handleMessage(**
>> MessageSenderInterceptor.java:**62)
>> at
>> org.apache.cxf.phase.**PhaseInterceptorChain.**doIntercept(**
>> PhaseInterceptorChain.java:**271)
>> at org.apache.cxf.endpoint.**ClientImpl.doInvoke(**ClientImpl.java:530)
>> at org.apache.cxf.endpoint.**ClientImpl.invoke(ClientImpl.**java:463)
>> at org.apache.cxf.endpoint.**ClientImpl.invoke(ClientImpl.**java:366)
>> at org.apache.cxf.endpoint.**ClientImpl.invoke(ClientImpl.**java:319)
>> at org.apache.cxf.frontend.**ClientProxy.invokeSync(**
>> ClientProxy.java:96)
>> at org.apache.cxf.jaxws.**JaxWsClientProxy.invoke(**
>> JaxWsClientProxy.java:133)
>> ... 2 more
>>
>> This is the WSDL file:
>>
>> <wsdl:definitions xmlns:xsd="http://www.w3.org/**2001/XMLSchema<http://www.w3.org/2001/XMLSchema>"
>> xmlns:wsdl="
>> http://schemas.xmlsoap.org/**wsdl/ <http://schemas.xmlsoap.org/wsdl/>"
>> xmlns:tns="http://services.ws.**ipk.sc.com/<http://services.ws.ipk.sc.com/>
>> "
>> xmlns:soap12="http://schemas.**xmlsoap.org/wsdl/soap12/<http://schemas.xmlsoap.org/wsdl/soap12/>"
>> xmlns:ns1="
>> http://schemas.xmlsoap.org/**soap/http<http://schemas.xmlsoap.org/soap/http>"
>> name="calcServiceName"**targetNamespace
>> ="http://services.ws.ipk.sc.**com/ <http://services.ws.ipk.sc.com/>">
>> <wsdl:types>
>> <xs:schema xmlns:xs="http://www.w3.org/**2001/XMLSchema<http://www.w3.org/2001/XMLSchema>"
>> xmlns:tns="
>> http://services.ws.ipk.sc.com/**" elementFormDefault="**unqualified"
>> targetNamespace="http://**services.ws.ipk.sc.com/<http://services.ws.ipk.sc.com/>"
>> version="1.0">
>> <xs:element name="addition" type="tns:addition"/>
>> <xs:element name="additionResponse" type="tns:additionResponse"/>
>> <xs:complexType name="addition">
>> <xs:sequence>
>> *<xs:element name="firstOperand" type="xs:int"/>*
>> *<xs:element name="secondOperand" type="xs:int"/>*
>>
>> </xs:sequence>
>> </xs:complexType>
>> <xs:complexType name="additionResponse">
>> <xs:sequence>
>> <xs:element name="return" type="xs:int"/>
>> </xs:sequence>
>> </xs:complexType>
>> </xs:schema>
>> </wsdl:types>
>> <wsdl:message name="additionResponse">
>> <wsdl:part element="tns:additionResponse" name="parameters"></wsdl:part>
>> </wsdl:message>
>> <wsdl:message name="addition">
>> <wsdl:part element="tns:addition" name="parameters"></wsdl:part>
>> </wsdl:message>
>> <wsdl:portType name="Calculator">
>> <wsdl:operation name="addition">
>> <wsdl:input message="tns:addition" name="addition"></wsdl:input>
>> <wsdl:output message="tns:additionResponse" name="additionResponse">
>> </wsdl:output>
>> </wsdl:operation>
>> </wsdl:portType>
>> <wsdl:binding name="**calcServiceNameSoapBinding" type="tns:Calculator">
>> <soap12:binding style="document" transport="
>> http://schemas.xmlsoap.org/**soap/http<http://schemas.xmlsoap.org/soap/http>
>> "/>
>> <wsdl:operation name="addition">
>> <soap12:operation soapAction="" style="document"/>
>> <wsdl:input name="addition">
>> <soap12:body use="literal"/>
>> </wsdl:input>
>> <wsdl:output name="additionResponse">
>> <soap12:body use="literal"/>
>> </wsdl:output>
>> </wsdl:operation>
>> </wsdl:binding>
>> <wsdl:service name="calcServiceName">
>> <wsdl:port binding="tns:**calcServiceNameSoapBinding"
>> name="calcPortName">
>> <soap12:address location="http://localhost:**8080/ipk-ws/services/calc<http://localhost:8080/ipk-ws/services/calc>
>> "/>
>> </wsdl:port>
>> </wsdl:service>
>> </wsdl:definitions>
>>
>> - After succeeding with that, I need to package my service as a *war* file
>>
>> and deploy it into tomcat 7 and expose a servlet context parameter from
>> another web app on the same servlet container of course, so how can that
>> be
>> done !
>>
>> - Another issue is that the generated client code is generated as if the
>> soap binding is *1.1* while I declared explicitly in the service
>> implementation class that the soap binding should be *1.2*
>>
>> QName serviceName = new QName("http://services.ws.ipk.**sc.com/<http://services.ws.ipk.sc.com/>",
>> "IpkWS");
>> QName portName = new QName("http://services.ws.ipk.**sc.com/<http://services.ws.ipk.sc.com/>",
>> "IxAccess");
>> Service service = Service.create(serviceName);
>> service.addPort(portName, *SOAPBinding.SOAP11HTTP_**BINDING*, "
>>
>> http://localhost:8080/ipk-ws")**;
>> com.sc.ipk.ws.services.**Calculator_PortType client =
>> service.getPort(portName, com.sc.ipk.ws.services.**
>> Calculator_PortType.class);
>>
>> I'm using Apache CXF v2.7.3 and I included these jars in my classpath:
>> commons-logging-1.1.1.jar
>> httpasyncclient-4.0-beta3.jar
>> httpclient-4.2.1.jar
>> httpcore-4.2.2.jar
>> httpcore-nio-4.2.2.jar
>> isorelax-20030108.jar
>> msv-core-2011.1.jar
>> neethi-3.0.2.jar
>> relaxngDatatype-20020414.jar
>> spring-aop-3.0.7.RELEASE.jar
>> spring-asm-3.0.7.RELEASE.jar
>> spring-beans-3.0.7.RELEASE.jar
>> spring-context-3.0.7.RELEASE.**jar
>> spring-core-3.0.7.RELEASE.jar
>> spring-expression-3.0.7.**RELEASE.jar
>> spring-web-3.0.7.RELEASE.jar
>> wsdl4j-1.6.2.jar
>> xmlschema-core-2.0.3.jar
>> xsdlib-2010.1.jar
>>
>> Along with other JARS of course for other applications but these are
>> obviously the ones CXF needs, unless I messed something up !
>>
>> Please don't hesitate to reply if I failed to clarify anything and thank
>> you in advance for your time.
>>
>>
>

Re: Starting developing web services with Apache CXF

Posted by Glen Mazza <gm...@talend.com>.
Links #2 (preferably) or #3 should take care of you here: 
http://www.jroller.com/gmazza/entry/blog_article_index , link #55 for 
the SOAP 1.1/1.2 issue.  Link #2 serves equally well as a Maven tutorial.

Glen

On 03/15/2013 09:17 PM, Muhammad Gelbana wrote:
> My first question here :)
>
> So I'm assigned a web-service based task but unfortunately I don't know
> almost anything about web services ! After some searching I decided to use
> Apache CXF but I'm facing some trouble.
>
> I do not need an interface so I only wrote a simple implemented class just
> to get things started
> ----------------------------------------------------------------------------------------------------------------------------
> package com.sc.ipk.ws.services;
>
> import javax.annotation.PostConstruct;
> import javax.annotation.PreDestroy;
> import javax.jws.WebMethod;
> import javax.jws.WebService;
> import javax.xml.ws.BindingType;
> import javax.xml.ws.soap.SOAPBinding;
>
> @WebService(serviceName = "calcServiceName", portName = "calcPortName")
> @BindingType(SOAPBinding.SOAP12HTTP_BINDING)
> public class Calculator {
>      /**
>       * @param firstOperand
>       * @param secondOperand
>       * @return The sum
>       * @throws AddNumbersException
>       *         if any of the numbers to be added is negative.
>       */
>      @WebMethod
>      public int addition(@WebParam(name = "firstOperand") int int1,
> @WebParam(name = "secondOperand") int int2) {
>          return int1 + int2;
>      }
>
>      @PostConstruct
>      @WebMethod(exclude = true)
>      public void willResponse() {
>          System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>> Will response");
>      }
>
>      @PreDestroy
>      @WebMethod(exclude = true)
>      public void doneResponding() {
>          System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>> Responded");
>      }
> }
> ----------------------------------------------------------------------------------------------------------------------------
> This is my ant java task to produce client, server and wsdl files:
> ----------------------------------------------------------------------------------------------------------------------------
> <java classname="org.apache.cxf.tools.java2ws.JavaToWS" fork="true">
> <arg value="-soap12" />
> <arg value="-wsdl" />
> <arg value="-server" />
> <arg value="-client" />
> <arg value="-verbose" />
> <arg value="-o" />
> <arg value="IpkWS.wsdl" />
> <arg value="-databinding" />
> <arg value="aegis" />
> <arg value="-portname" />
> <arg value="IxAccess" />
> <arg value="-address" />
> <arg value="http://localhost:8080/ipk-ws" />
> <arg value="-servicename" />
> <arg value="IpkWS" />
> <arg value="-frontend" />
> <arg value="jaxws" />
> <!--
> <arg value="-s" />
> <arg value="src" />
> -->
> <arg value="-d" />
> <arg value="webapp/WEB-INF/wsdl" />
> <arg value="com.sc.ipk.ws.services.Calculator" />
> <classpath>
> <path refid="cxf.classpath" />
> </classpath>
> </java>
> ----------------------------------------------------------------------------------------------------------------------------
> I use ant because It's much easier for, I'm *terrible* with maven.
>
> Here is what I need to do:
> - I need to publish this service so a *.net* client is able to consume it,
> that's why I need to use aegis. Unfortunately the *.net* client isn't
> accessible now for raid testing but I guess the generated java client code
> should get me half way through
>
> Now I'm facing the following issues:
> - @WebParam isn't effective, when I use it, i get parsing errors that the
> expected elements are "firstOperand" and "secondOperand", this is the error
> stack:
>
> Exception in thread "main" javax.xml.ws.soap.SOAPFaultException:
> Unmarshalling Error: unexpected element (uri:"", local:"arg0"). Expected
> elements are <{}secondOperand>,<{}firstOperand>
> at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:155)
> at $Proxy38.addition(Unknown Source)
> at
> com.sc.ipk.ws.services.Calculator_PortTypeClient.main(Calculator_PortTypeClient.java:20)
> Caused by: org.apache.cxf.binding.soap.SoapFault: Unmarshalling Error:
> unexpected element (uri:"", local:"arg0"). Expected elements are
> <{}secondOperand>,<{}firstOperand>
> at
> org.apache.cxf.binding.soap.interceptor.Soap12FaultInInterceptor.unmarshalFault(Soap12FaultInInterceptor.java:133)
> at
> org.apache.cxf.binding.soap.interceptor.Soap12FaultInInterceptor.handleMessage(Soap12FaultInInterceptor.java:59)
> at
> org.apache.cxf.binding.soap.interceptor.Soap12FaultInInterceptor.handleMessage(Soap12FaultInInterceptor.java:46)
> at
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
> at
> org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:114)
> at
> org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:69)
> at
> org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:34)
> at
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
> at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:800)
> at
> org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1592)
> at
> org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1490)
> at
> org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1309)
> at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
> at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:622)
> at
> org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
> at
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
> at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:530)
> at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:463)
> at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:366)
> at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:319)
> at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96)
> at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:133)
> ... 2 more
>
> This is the WSDL file:
>
> <wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="
> http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://services.ws.ipk.sc.com/"
> xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:ns1="
> http://schemas.xmlsoap.org/soap/http" name="calcServiceName"targetNamespace
> ="http://services.ws.ipk.sc.com/">
> <wsdl:types>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="
> http://services.ws.ipk.sc.com/" elementFormDefault="unqualified"
> targetNamespace="http://services.ws.ipk.sc.com/" version="1.0">
> <xs:element name="addition" type="tns:addition"/>
> <xs:element name="additionResponse" type="tns:additionResponse"/>
> <xs:complexType name="addition">
> <xs:sequence>
> *<xs:element name="firstOperand" type="xs:int"/>*
> *<xs:element name="secondOperand" type="xs:int"/>*
> </xs:sequence>
> </xs:complexType>
> <xs:complexType name="additionResponse">
> <xs:sequence>
> <xs:element name="return" type="xs:int"/>
> </xs:sequence>
> </xs:complexType>
> </xs:schema>
> </wsdl:types>
> <wsdl:message name="additionResponse">
> <wsdl:part element="tns:additionResponse" name="parameters"></wsdl:part>
> </wsdl:message>
> <wsdl:message name="addition">
> <wsdl:part element="tns:addition" name="parameters"></wsdl:part>
> </wsdl:message>
> <wsdl:portType name="Calculator">
> <wsdl:operation name="addition">
> <wsdl:input message="tns:addition" name="addition"></wsdl:input>
> <wsdl:output message="tns:additionResponse" name="additionResponse">
> </wsdl:output>
> </wsdl:operation>
> </wsdl:portType>
> <wsdl:binding name="calcServiceNameSoapBinding" type="tns:Calculator">
> <soap12:binding style="document" transport="
> http://schemas.xmlsoap.org/soap/http"/>
> <wsdl:operation name="addition">
> <soap12:operation soapAction="" style="document"/>
> <wsdl:input name="addition">
> <soap12:body use="literal"/>
> </wsdl:input>
> <wsdl:output name="additionResponse">
> <soap12:body use="literal"/>
> </wsdl:output>
> </wsdl:operation>
> </wsdl:binding>
> <wsdl:service name="calcServiceName">
> <wsdl:port binding="tns:calcServiceNameSoapBinding" name="calcPortName">
> <soap12:address location="http://localhost:8080/ipk-ws/services/calc"/>
> </wsdl:port>
> </wsdl:service>
> </wsdl:definitions>
>
> - After succeeding with that, I need to package my service as a *war* file
> and deploy it into tomcat 7 and expose a servlet context parameter from
> another web app on the same servlet container of course, so how can that be
> done !
>
> - Another issue is that the generated client code is generated as if the
> soap binding is *1.1* while I declared explicitly in the service
> implementation class that the soap binding should be *1.2*
> QName serviceName = new QName("http://services.ws.ipk.sc.com/", "IpkWS");
> QName portName = new QName("http://services.ws.ipk.sc.com/", "IxAccess");
> Service service = Service.create(serviceName);
> service.addPort(portName, *SOAPBinding.SOAP11HTTP_BINDING*, "
> http://localhost:8080/ipk-ws");
> com.sc.ipk.ws.services.Calculator_PortType client =
> service.getPort(portName, com.sc.ipk.ws.services.Calculator_PortType.class);
>
> I'm using Apache CXF v2.7.3 and I included these jars in my classpath:
> commons-logging-1.1.1.jar
> httpasyncclient-4.0-beta3.jar
> httpclient-4.2.1.jar
> httpcore-4.2.2.jar
> httpcore-nio-4.2.2.jar
> isorelax-20030108.jar
> msv-core-2011.1.jar
> neethi-3.0.2.jar
> relaxngDatatype-20020414.jar
> spring-aop-3.0.7.RELEASE.jar
> spring-asm-3.0.7.RELEASE.jar
> spring-beans-3.0.7.RELEASE.jar
> spring-context-3.0.7.RELEASE.jar
> spring-core-3.0.7.RELEASE.jar
> spring-expression-3.0.7.RELEASE.jar
> spring-web-3.0.7.RELEASE.jar
> wsdl4j-1.6.2.jar
> xmlschema-core-2.0.3.jar
> xsdlib-2010.1.jar
>
> Along with other JARS of course for other applications but these are
> obviously the ones CXF needs, unless I messed something up !
>
> Please don't hesitate to reply if I failed to clarify anything and thank
> you in advance for your time.
>