Creating Web services using Apache CXF (Part 3): Configurations

Add a comment June 11th, 2009
  • Web.xml Declarations

We have to declare Spring Context Listener, CXF Servlet, Spring Context Location and URL Mapping.

   1: <?xml version="1.0" encoding="UTF-8"?>
   2: <web-app id="services" version="2.5"
   3:     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
   4:     xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
   5:     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
   6:         http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
   7:
   8:     <!-- Adding the Spring Context Listener. It will help to init Spring Context -->
   9:     <listener>
  10:         <listener-class> org.springframework.web.context.ContextLoaderListener
  11:         </listener-class>
  12:     </listener>
  13:
  14:     <!-- Context file location of Spring -->
  15:     <context-param>
  16:         <param-name>contextConfigLocation</param-name>
  17:         <param-value>/WEB-INF/applicationContext.xml</param-value>
  18:     </context-param>
  19:
  20:     <!-- CXF Servlet -->
  21:     <servlet>
  22:         <servlet-name>CXFServlet</servlet-name>
  23:         <servlet-class> org.apache.cxf.transport.servlet.CXFServlet
  24:         </servlet-class>
  25:     </servlet>
  26:
  27:     <!-- Mapping with a URL Pattern -->
  28:     <servlet-mapping>
  29:         <servlet-name>CXFServlet</servlet-name>
  30:         <url-pattern>/*</url-pattern>
  31:     </servlet-mapping>
  32: </web-app>
  • Application Context configurations
   1: <?xml version="1.0" encoding="UTF-8"?>
   2: <beans xmlns="http://www.springframework.org/schema/beans"
   3:     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
   4:     xmlns:cxf="http://cxf.apache.org/core" xmlns:jaxws="http://cxf.apache.org/jaxws"
   5:     xsi:schemaLocation="http://www.springframework.org/schema/beans
   6:         http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
   7:         http://www.springframework.org/schema/context
   8:         http://www.springframework.org/schema/context/spring-context-2.5.xsd
   9:         http://cxf.apache.org/core
  10:         http://cxf.apache.org/schemas/core.xsd
  11:         http://cxf.apache.org/jaxws
  12:         http://cxf.apache.org/schemas/jaxws.xsd"
  13:     default-autowire="byName">
  14:
  15:     <!-- Load CXF modules from cxf.jar -->
  16:     <import resource="classpath:META-INF/cxf/cxf.xml" />
  17:     <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
  18:     <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
  19:
  20:     <!-- The service bean -->
  21:     <bean id="productServiceImpl" class="com.your.company.service.ProductServiceImpl" />
  22:
  23:     <!-- Aegis data binding -->
  24:     <bean id="aegisBean" class="org.apache.cxf.aegis.databinding.AegisDatabinding"
  25:         scope="prototype" />
  26:     <bean id="aegis-service" class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean"
  27:         scope="prototype">
  28:         <property name="dataBinding" ref="aegisBean" />
  29:         <property name="serviceConfigurations">
  30:             <list>
  31:                 <bean class="org.apache.cxf.jaxws.support.JaxWsServiceConfiguration" />
  32:                 <bean class="org.apache.cxf.aegis.databinding.AegisServiceConfiguration" />
  33:                 <bean class="org.apache.cxf.service.factory.DefaultServiceConfiguration" />
  34:             </list>
  35:         </property>
  36:     </bean>
  37:
  38:     <!-- Service endpoint -->
  39:     <jaxws:endpoint id="productService"
  40:         implementorClass="com.your.company.service.ProductServiceImpl"
  41:         implementor="#productServiceImpl" address="/productservice">
  42:         <jaxws:serviceFactory>
  43:             <ref bean="aegis-service" />
  44:         </jaxws:serviceFactory>
  45:     </jaxws:endpoint>
  46:
  47:         <!-- Enable message logging using the CXF logging feature -->
  48:     <cxf:bus>
  49:         <cxf:features>
  50:             <cxf:logging />
  51:         </cxf:features>
  52:     </cxf:bus>
  53: </beans>

Create a WAR out of this Project and deploy it in Apache Tomcat. And try to access the WSDL URL

http://localhost:8080/CXFExample/ProductService?wsdl.

Other related posts:

1. Creating Web services using Apache CXF (Part 1) : The Basics.

2. Creating Web services using Apache CXF (Part 2) : Development.

3. Creating Web services using Apache CXF (Part 3) : Configuration.

4. Creating Web services using Apache CXF (Part 4): Testing.

Book Mark it-> del.icio.us | Reddit | Slashdot | Digg | Facebook | Technorati | Google | StumbleUpon | Window Live | Tailrank | Furl | Netscape | Yahoo | BlinkList

Popularity: 19% [?]

Bookmark this on BuzzURLBookmark this on BuzzURL Post to TwitterTweets for this web page Bookmark this on FC2 Bookmark newsing it! Choix it! Add to Google Bookmark Bookmark this on Delicious Digg This

Related posts:

  1. Creating Web services using Apache CXF (Part 4): Testing To test this we can follow the same client program...
  2. Creating Web services using Apache CXF (Part 1) : The Basics. As we discussed in the previous post, CXF is the...
  3. Creating Web services using Apache CXF (Part 2): Development We need to set-up the project  environment first. Please download...
  4. Creating Web Services using CXF (Contract first Approach) Part 2 : WSDL Creation. What is WSDL and what its Structure? A WSDL document...
  5. Creating “Contract First” – Web Services using CXF (Top Down Approach) Part 1: Creating XSDs. Why people are interested in CODE-FIRST approach? Answer is simple....

Related posts brought to you by Yet Another Related Posts Plugin.

  1. No comments yet.Be the first ?
  1. |
    June 11th, 2009 at 14:18 | #1

    [...] Creating Web services using Apache CXF (Part 4) : Configuration Possibly related posts: (automatically generated)Spring Season in ITSpring Framework 2.1 is turning [...]

  2. |
    June 11th, 2009 at 16:20 | #2

    [...] Interview Guide « Creating Web services using Apache CXF (Part 3): Configurations [...]

  3. |
    June 11th, 2009 at 16:33 | #3

    [...] « Creating Web services using Apache CXF (Part 1) : The Basics. Creating Web services using Apache CXF (Part 3): Configurations [...]

  4. |
    June 11th, 2009 at 16:37 | #4

    [...] 3. Creating Web services using Apache CXF (Part 3) : Configuration. [...]

  5. |
    June 15th, 2009 at 12:18 | #5

    [...] Creating Web services using Apache CXF (Part 3) : Configuration. [...]

  6. |
    July 4th, 2009 at 11:44 | #6

    [...] Creating Web services using Apache CXF (Part 3) : Configuration. [...]

  7. |
    July 4th, 2009 at 11:44 | #7

    [...] 3. Creating Web services using Apache CXF (Part 3) : Configuration. [...]

  8. |
    July 4th, 2009 at 11:50 | #8

    [...] 3. Creating Web services using Apache CXF (Part 3) : Configuration. [...]

  9. |
    July 4th, 2009 at 11:52 | #9

    [...] 3. Creating Web services using Apache CXF (Part 3) : Configuration. [...]

  10. |
    July 4th, 2009 at 11:55 | #10

    [...] 3. Creating Web services using Apache CXF (Part 3) : Configuration. [...]

  11. |
    July 4th, 2009 at 11:57 | #11

    [...] Creating Web services using Apache CXF (Part 3) : Configuration. [...]

  12. |
    August 19th, 2009 at 08:09 | #12

    [...] 3. Creating Web services using Apache CXF (Part 3) : Configuration. 4. Creating Web services using Apache CXF (Part 4): Testing. [...]

  13. |
    August 19th, 2009 at 08:11 | #13

    [...] Creating Web services using Apache CXF (Part 3) : Configuration. 4. Creating Web services using Apache CXF (Part 4): [...]

Comments feed