A reader posted a comment to one of my old blogs on XFire. That rekindled my interest so I checked the XFire web site only to be informed that XFire is now Apache CXF (version 2.2.3 at this moment in time).
So how hard would it be to convert my old example to CXF. Turned out to be a piece of cake. Had to change the following:
- Updated the maven dependencies to reflect CXF libraries.
- web.xml – to point to the CXF Servlet
- Spring context (app-context.xml) – It was now a lot simpler and cleaner.
- Finally I used CXF wsdl2java utils to generate a client
Maven pom.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
1: <project> 2: <modelVersion>4.0.0</modelVersion> 3: <groupId>com.aver</groupId> 4: <artifactId>echo</artifactId> 5: <packaging>war</packaging> 6: <version>1.0-SNAPSHOT</version> 7: <name>CXF Echo Service</name> 8: <dependencies> 9: <dependency> 10: <groupId>org.springframework</groupId> 11: <artifactId>spring</artifactId> 12: <version>2.5.6</version> 13: </dependency> 14: <dependency> 15: <groupId>org.apache.cxf</groupId> 16: <artifactId>cxf-rt-frontend-jaxws</artifactId> 17: <version>2.2.3</version> 18: </dependency> 19: <dependency> 20: <groupId>org.apache.cxf</groupId> 21: <artifactId>cxf-rt-transports-http</artifactId> 22: <version>2.2.3</version> 23: </dependency> 24: <dependency> 25: <groupId>junit</groupId> 26: <artifactId>junit</artifactId> 27: <version>4.7</version> 28: <scope>test</scope> 29: </dependency> 30: <dependency> 31: <groupId>log4j</groupId> 32: <artifactId>log4j</artifactId> 33: <version>1.2.14</version> 34: </dependency> 35: </dependencies> 36: <build> 37: <plugins> 38: <plugin> 39: <groupId>org.mortbay.jetty</groupId> 40: <artifactId>maven-jetty-plugin</artifactId> 41: <configuration> 42: <contextPath>/echoservice</contextPath> 43: <connectors> 44: <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector"> 45: <port>9090</port> 46: <maxIdleTime>60000</maxIdleTime> 47: </connector> 48: </connectors> 49: </configuration> 50: </plugin> 51: <plugin> 52: <groupId>org.apache.maven.plugins</groupId> 53: <artifactId>maven-compiler-plugin</artifactId> 54: <configuration> 55: <source>1.5</source> 56: <target>1.5</target> 57: </configuration> 58: </plugin> 59: </plugins> 60: </build> 61: </project> |
The web.xml…
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
1: <web-app> 2: <context-param> 3: <param-name>contextConfigLocation</param-name> 4: <param-value> 5: /WEB-INF/app-context.xml 6: </param-value> 7: </context-param> 8: <listener> 9: <listener-class> 10: org.springframework.web.context.ContextLoaderListener 11: </listener-class> 12: </listener> 13: <servlet> 14: <servlet-name>CXFServlet</servlet-name> 15: <servlet-class> 16: org.apache.cxf.transport.servlet.CXFServlet 17: </servlet-class> 18: </servlet> 19: <servlet-mapping> 20: <servlet-name>CXFServlet</servlet-name> 21: <url-pattern>/services/*</url-pattern> 22: </servlet-mapping> 23: </web-app> |
The Spring context file – app-context.xml
1 2 3 4 5 6 7 |
1: <import resource="classpath:META-INF/cxf/cxf.xml" /> 2: <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" /> 3: <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> 4: <jaxws:endpoint id="echoService" implementor="#echo" 5: address="/EchoService" /> 6: <bean id="echo" class="com.aver.EchoServiceImpl" /> |
The wsdl2java command I executed was:
1 2 |
./wsdl2java -p com.aver.client -client localhost:9090/echoservice/services/EchoService?wsdl |
Run the project using maven: mvn clean package jetty:run
The WSDL is located at the address mentioned above in the wsld2java command.
Finally I ran the test client that wsdl2java generated…class named EchoService_EchoServicePort_Client
The output was:
1 2 3 |
Invoking echo... echo.result=echo: 'uyy ' received on 10-07-2009 10:53:59 PM |
Click here to download the maven project for this blog.