12

I'm new to any of open framework(I'm a solution engineer based on java) and trying to build a cxf project.

I understand that I need to have applicationContext.xml file and contents something like

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:cxf="http://cxf.apache.org/core" xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
        http://www.springframework.org/schema/context  http://www.springframework.org/schema/context/spring-context-3.1.xsd
        http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
        http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
        http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd">

<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

<http-conf:conduit name="*.http-conduit">
    <http-conf:client ReceiveTimeout=“300000“ AllowChunking="false"/>
</http-conf:conduit>

<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

<cxf:bus>
    <cxf:features>
        <cxf:logging />
    </cxf:features>
</cxf:bus>

</beans>

in it.

I now wonder where I can download
cxf/cxf.xml, cxf-extension-soap.xml, cxf-servlet.xml files.

Or that I created a Dynamic Web Project is wrong? Does some other project type automatically generates those files?

Aniket Thakur
  • 66,731
  • 38
  • 279
  • 289
Boram Lee
  • 121
  • 1
  • 1
  • 3

6 Answers6

10

I know this is an old post, but this might help others

cxf-extension-soap.xml is in cxf-rt-binding-soap jar, but you will need cxf-rt-frontend-jaxws

cxf-servlet.xml is in cxf-rt-transports-http jar

cxf.xml is in cxf-rt-core jar (which is a transitive dependency of the above ones)

Therefore, if you include cxf-rt-frontend-jaxws and cxf-rt-transports-http as dependencies (with Maven, for example) your project should work correctly.

Marius Manastireanu
  • 2,461
  • 5
  • 19
  • 29
  • 1
    For anyone (like me) still working with CXF, starting from CXF 2.4.0 you no longer need to import the cxf-extension-*.xml files ([source](http://cxf.apache.org/docs/embedding-cxf-inside-spring.html)). – RikH Aug 09 '18 at 08:21
4

Each of these files can be found in the CXF jars that you'll need to include with your project.

cxf-servlet.xml

cxf.xml

cxf-extension-soap.xml

I've always found the fastest way to getting a CXF project up and running is to use a Maven Archetype.

Bob Paulin
  • 1,088
  • 8
  • 13
4

Or that I created a Dynamic Web Project is wrong? Does some other project type automatically generates those files?

The war file you create will generally just have a manifest file under META-INF directory called MANIFEST.MF. This file has your build meta information. For me I have

Manifest-Version: 1.0
Gradle-Version: 2.0-rc-2
Created-By: 1.6.0_31 (Sun Microsystems Inc.)
Version: 10.51
Build: dev
Build-Timestamp: 10/01/2015 12:53:32
Build-User: athakur
Build-Host: ATHAKUR

This directory is automatically created when you build your project to create a jar or a war. It can have other attributes as well like the main class [Refer this Q].

Now coming to your question. Many libraries put their configuration files in the corresponding jars META-INF folder. This is just another example and the jars you are looking for are CXF jars.

enter image description here enter image description here

For gradle you can add following in your build.gradle file

compile("org.apache.cxf:cxf-rt-frontend-jaxrs:3.1.3")
compile("org.apache.cxf:cxf-rt-frontend-jaxws:3.1.3")
compile("org.apache.cxf:cxf-rt-transports-http:3.1.3")
Community
  • 1
  • 1
Aniket Thakur
  • 66,731
  • 38
  • 279
  • 289
4

This is an old post but it still comes up for people migrating old CXF to newer. And what I'm finding is that cxf-rt-bindings-soap-3.1.7.jar no longer has classpath:META-INF/cxf/cxf-extension-soap.xml

see this: REST CXF and Spring cxf-extension-jaxrs-binding File not found exception?

Community
  • 1
  • 1
Nicholas DiPiazza
  • 10,029
  • 11
  • 83
  • 152
1

the cxf-extension-http.xml and cxf-extension-soap.xml for the version 3.2.X of cxf you just need to include this line cxf-extension-jaxws.xml

0

Web.xml can be like this

CXF

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:ApplicationContext-cxf.xml</param-value>
</context-param>

<listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener
    </listener-class>
</listener>

<servlet>
    <servlet-name>CXFServlet</servlet-name>
    <display-name>CXF Servlet</display-name>
    <servlet-class>
        org.apache.cxf.transport.servlet.CXFServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>CXFServlet</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

Following is a working ApplicationContext.xml

 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:cxf="http://cxf.apache.org/core" xmlns:task="http://www.springframework.org/schema/task"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
     http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.1.xsd">


    <import resource="classpath:META-INF/cxf/cxf.xml"/>
<import resource="classpath:META-INF/cxf/cxf-extension-xml.xml"/>
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />

    <task:annotation-driven />

    <context:component-scan base-package="com.smoothexample">
        <context:include-filter type="annotation"
            expression="org.springframework.stereotype.Service" />
        <context:include-filter type="annotation"
            expression="org.springframework.stereotype.Component" />
        <context:include-filter type="annotation"
            expression="org.springframework.stereotype.Repository" />
    </context:component-scan>

    <context:annotation-config />
    <context:component-scan base-package="com.smoothexample" />


    <bean
        class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor" />


<bean id="addressSoapService" class="com.smoothexample.cxf.soap.ws.impl.AddressSoapServiceImpl" />

    <jaxws:endpoint id="addressEndpointId"
        implementorClass="com.smoothexample.cxf.soap.ws.impl.AddressSoapServiceImpl"
        implementor="#addressSoapService" address="/addressSoapService">

    </jaxws:endpoint>

</beans>

All the maven dependencies are defined as follows, which includes jars for cxf/cxf.xml, cxf-extension-soap.xml, cxf-servlet.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.lal.pro</groupId>
    <artifactId>apache-cxf-soap-ws</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>apache-cxf-soap-ws Maven Webapp</name>
    <url>http://maven.apache.org</url>

    <properties>
        <cxf.version>2.5.0</cxf.version>

        <org.springframework.version>4.1.1.RELEASE</org.springframework.version>

        <ch.qos.logback.version>1.1.3</ch.qos.logback.version>
        <org.sl4j.version>1.7.12</org.sl4j.version>
        <spring.ws.version>2.2.4.RELEASE</spring.ws.version>
    </properties>
    <dependencies>

        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>${cxf.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>${cxf.version}</version>
        </dependency>


        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.1</version>
        </dependency>

    </dependencies>
    <build>
        <finalName>apache-cxf-soap-ws</finalName>
    </build>
</project>

Please find more details at http://www.smoothexample.com/webservices/apache_cxf_soap_web_services.html

user902997
  • 77
  • 7