...
Code Block |
---|
commons-logging-1.1.jar
geronimo-activation_1.1_spec-1.0-M1.jar (or Sun's Activation jar)
geronimo-annotation_1.0_spec-1.0.jar (JSR 250)
geronimo-javamail_1.4_spec-1.0-M1.jar (or Sun's JavaMail jar)
geronimo-servlet_2.5_spec-1.1-M1.jar (or Sun's Servlet jar)
jaxb-api-2.1.jar
jaxb-impl-2.1.2.jar
jaxb-xjc-2.1.2.jar
jaxws-api-2.0.jar
jsr181-api-1.0-MR1.jar
saaj-api-1.3.jar
saaj-impl-1.3.jar
stax-api-1.0.1.jar
wsdl4j-1.6.1.jar
wstx-asl-3.2.0.jar
XmlSchema-1.2.jar
|
...
Code Block |
---|
cxf-api-2.0-incubator-RC-SNAPSHOT.jar cxf-common-schemas-2.0-incubator-RC-SNAPSHOT.jar cxf-common-utilities-2.0-incubator-RC-SNAPSHOT.jar cxf-metacode-2.0-incubator-RC-SNAPSHOT.jar cxf-rt-bindings-soap-2.0-incubator-RC-SNAPSHOT.jar cxf-rt-core-2.0-incubator-RC-SNAPSHOT.jar cxf-rt-databinding-jaxb-2.0-incubator-RC-SNAPSHOT.jar cxf-rt-frontend-jaxws-2.0-incubator-RC-SNAPSHOT.jar cxf-rt-frontend-simple-2.0-incubator-RC-SNAPSHOT.jar cxf-rt-managementtransports-http-2.0-incubator-RC-SNAPSHOT.jar cxf-rttools-transportscommon-http-2.0-incubator-RC-SNAPSHOT.jar cxf-tools-common-2.0-incubator-RC-SNAPSHOT.jar |
Writing your Service
Declaring your beans
...
Writing your Service
First we'll write our service interface. It will have one operation called "sayHello" which says "Hello" to whoever submits their name.
Wiki Markup |
---|
{snippet:id=service|lang=java|url=http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/spring_http/src/main/java/demo/spring/HelloWorld.java?revision=HEAD} |
Our implementation will then look like this:
Wiki Markup |
---|
{snippet:id=service|lang=java|url=http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/spring_http/src/main/java/demo/spring/HelloWorldImpl.java?revision=HEAD} |
The @WebService annotation on the implementation class lets CXF know which interface we want to create our WSDL with. In this case its simply our HelloWorld interface.
Declaring your server beans
CXF contains support for "nice XML" within Spring 2.0. For the JAX-WS side of things, we have a <jaxws:endpoint> bean which sets up a server side endpoint.
Lets create a "beans.xml" file in our WEB-INF directory which declares an endpoint bean:
Wiki Markup |
---|
{snippet:id=beans|lang=java|url=http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/spring_http/src/webapp/WEB-INF/beans.xml?revision=HEAD} |
The bean is pretty self explanatory. The id becomes the id of the bean in the Spring context. The serviceClass property is our implementation class. Finally, the address property specifies the location which we want to host our service at. This can be either a full address with host & port or just a path.
Setting up the Servlet
We'll need to add two things to our web.xml. First, the Spring ContextLoaderLister. This starts Spring and loads our beans.xml file. We can specify where our file is via a <context-param>. The second thing is the CXF Servlet.
Wiki Markup |
---|
{snippet:id=webxml|lang=java|url=http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/spring_http/src/webapp/WEB-INF/web.xml?revision=HEAD} |
It is important to note that the address that you chose for your endpoint bean must be one your servlet listens on. For instance, if my Servlet was register for "/some-services/*" but my address was "/more-services/HelloWorld", there is no way CXF could receive a request.
Create a Client
Wiki Markup |
---|
{snippet:id=service|lang=java|url=http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/spring_http/src/main/java/demo/spring/client/client-beans.xml?revision=HEAD} |
Advanced Steps
For more information on using Spring you may want to read the Configuration and Spring sections of the User's Guide.