CXF+SPRING+POJO

Full maven project can be downloaded from HERE.

This is a follow up article to XFIRE+EJB+POJO.
Here I show how to expose POJO using CXF project instead of XFire. Setting up WebServices with CXF is very easy and consists of two steps:

    • Setting up web.xml with CXFServlet.
    • Defining POJO endpoint.


Setting up web.xml with CXFServlet.





contextConfigLocation

classpath:/META-INF/cxf/cxf.xml
classpath:/META-INF/cxf/cxf-servlet.xml
classpath:/META-INF/cxf/cxf-extension-soap.xml

org.springframework.web.context.ContextLoaderListener

numberservice
org.apache.cxf.transport.servlet.CXFServlet

config-location
/WEB-INF/numberservice-servlet.xml

1

numberservice
/*

Most of CXF examples have one spring context file that gets loaded through a servlet listener.
The one above shows how to have multiple CXFServlets defined with their own endpoints context file.

Defining POJO endpoint.






 

Like in XFire with EJB article “numberService” bean can be replaced with EJB proxy in order to expose EJB as SOAP WebService.

After deploying to Tomcat hit http://localhost:8080/number-services-webapp/numberservice?wsdl for autogenerated WSDL.

4 comments to CXF+SPRING+POJO

  • Olivier

    Hi,

    These two articles dealing with exposing services as web services are wonderful. Deployments work like a charm !

    I’m still fighting with exposing the EJB from the previous article with CXF. I’m getting a weird NPE when deploying to weblogic.

    The only thing I did in the spring config file is replacing

    with

    Anything you’d advise to do ?

    Thanks again.

    Exception:
    java.lang.NullPointerException
    at org.apache.cxf.interceptor.AnnotationInterceptors.getAnnotationObject(AnnotationIntercept
    ors.java:50)

  • Olivier

    Missing the xml snippet. I replace numberService with NumberServiceSessionBeanProxy in the simple:serviceBean definition

  • tsolakp

    Did it work for you? I have only tested this project on Tomcat.

  • tsolakp

    “simple:server” creates adapter similar to “XFireExporter” (as explained in XFIRE+EJB+POJO article) which listens to http request at “base servler path/numberservice” address and converts SOA request to POJO method call and return value to XML according to its autogenerated WSDL.
    The “endpointName=:NumberService”, “serviceName=:NumberService”, “xmlns:e=http://service.jaxws.cxf.apache.org/endpoint
    ” and “xmlns:s=http://numberservice.tsolak.com” are used in defining WSDL namespaces.
    For more check http://cwiki.apache.org/CXF20DOC/simple-frontend.html and http://cwiki.apache.org/CXF20DOC/writing-a-service-with-spring.html.

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>