You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by splatch <l....@pocztowy.pl> on 2008/07/08 13:20:47 UTC

JAX-WS - multiple services in separate jars

Hello CXF users and developers.

I would like create some module web application with web services. When I
use Spring's DisplatcherServlet everything works fine, but CXFServlet
doesn't see jaxws:endpoint defined in imported context.

Code snippets.
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="webapp" version="2.5" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="
        http://java.sun.com/xml/ns/javaee
        http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    >

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/security.xml <!-- spring security configuratio -->
            /WEB-INF/applicationContext.xml <!-- DAOs etc -->
<!--            classpath:/module/**-context.xml-->
        </param-value>
    </context-param>


    <servlet>
        <servlet-name>main</servlet-name>
       
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>main</servlet-name>
        <url-pattern>*.form</url-pattern>
    </servlet-mapping>

    <servlet>
        <servlet-name>CXFServlet</servlet-name>
       
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
        <init-param>
            <param-name>hide-service-list-page</param-name>
            <param-value>false</param-value>
        </init-param>
        <init-param>
            <param-name>base-address</param-name>
            <param-value>services</param-value>
        </init-param>
        <init-param>
            <param-name>config-location</param-name>
            <param-value>/WEB-INF/cxf-servlet.xml</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>CXFServlet</servlet-name>
        <url-pattern>/services/*</url-pattern>
    </servlet-mapping>

    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
       
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
</web-app>

cxf-servlet.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:cxf="http://cxf.apache.org/core"
    xmlns:simple="http://cxf.apache.org/simple"
    xmlns:jaxws="http://cxf.apache.org/jaxws"
    xsi:schemaLocation="
        http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
        http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
        http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
    ">

    <!-- import at the end also doesn't works -->
    <import resource="classpath:/module/**-context.xml" />

    <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-extension-http-binding.xml"/>
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>

    <bean id="logOutbound"
class="org.apache.cxf.interceptor.LoggingOutInterceptor"/>

    <!-- cxf:bus also doesn't works -->
    <bean id="cxf" class="org.apache.cxf.bus.CXFBusImpl">
        <property name="inInterceptors">
            <list>
                <ref bean="logOutbound" />
            </list>
        </property>
        <property name="outInterceptors">
            <list>
                <ref bean="logOutbound" />
            </list>
        </property>
        <property name="outFaultInterceptors">
            <list>
                <ref bean="logOutbound" />
            </list>
        </property>
    </bean>

</beans>

Sampel module (contribution-context.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:cxf="http://cxf.apache.org/core"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
        http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
    ">

    <bean id="contributionModule"
class="pl.bpsa.sw.modules.contribution.ContributionModule" />

    <jaxws:endpoint id="contribution" address="contribution"
        implementor="pl.bpsa.sw.modules.contribution.ContributionTypeImpl">
    </jaxws:endpoint>
</beans>

The ContributionModule implements InitializingBean and its correctly created
but CXF doesn't see endpoint.

My Maven structure:
parent
`-- webapp (web context, forms etc)
`-- modules (web services implementation)
    `-- contribution
    `-- scoring

The Webapp have dependencies to CXF:
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>2.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>2.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-bindings-http</artifactId>
            <version>2.1.1</version>
        </dependency>

Modules have the same dependencies but it's scope was set to provided.
If I copy endpoint configuration from module to applicationContext.xml in
webapp CXF will publish web service. What should I do to use dispersed
configuration with CXF?

Regards,
Luke
-- 
View this message in context: http://www.nabble.com/JAX-WS---multiple-services-in-separate-jars-tp18336903p18336903.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: JAX-WS - multiple services in separate jars

Posted by Ian Roberts <i....@dcs.shef.ac.uk>.
splatch wrote:
> Hello CXF users and developers.
> 
> I would like create some module web application with web services. When I
> use Spring's DisplatcherServlet everything works fine, but CXFServlet
> doesn't see jaxws:endpoint defined in imported context.

Rather than having the CXFServlet load its own spring context from 
cxf-servlet.xml, you can just load the whole lot into the root context. 
  Rename your existing cxf-servlet.xml to some other name (e.g. 
cxf-beans.xml) and take out the import of the /module/**-context.xml, 
then change your contextConfigLocation parameter to something like:

     <context-param>
         <param-name>contextConfigLocation</param-name>
         <param-value>
             /WEB-INF/security.xml <!-- spring security configuratio -->
             /WEB-INF/applicationContext.xml <!-- DAOs etc -->
             /WEB-INF/cxf-beans.xml <!-- common CXF definitions -->
             classpath:/module/**-context.xml
         </param-value>
     </context-param>

This should give behaviour equivalent to putting the endpoint config 
directly into applicationContext.xml.

Ian

-- 
Ian Roberts               | Department of Computer Science
i.roberts@dcs.shef.ac.uk  | University of Sheffield, UK

Re: JAX-WS - multiple services in separate jars

Posted by Daniel Kulp <dk...@apache.org>.
As Ian stated, if you are already creating a spring context, it's best  
to put the cxf stuff you want in there already and not use the cxf- 
servlet.   All the dependencies and stuff are then properly resolved  
between the beans in the context.    I would just move the contents of  
your cxf-servlet.xml into your contribution-context.xml and then  
remove the cxf-servlet.xml file.

Dan


On Jul 8, 2008, at 7:20 AM, splatch wrote:

>
> Hello CXF users and developers.
>
> I would like create some module web application with web services.  
> When I
> use Spring's DisplatcherServlet everything works fine, but CXFServlet
> doesn't see jaxws:endpoint defined in imported context.
>
> Code snippets.
> web.xml:
> <?xml version="1.0" encoding="UTF-8"?>
> <web-app id="webapp" version="2.5"
>    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>    xmlns="http://java.sun.com/xml/ns/javaee"
>    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
>    xsi:schemaLocation="
>        http://java.sun.com/xml/ns/javaee
>        http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
>>
>
>    <context-param>
>        <param-name>contextConfigLocation</param-name>
>        <param-value>
>            /WEB-INF/security.xml <!-- spring security configuratio -->
>            /WEB-INF/applicationContext.xml <!-- DAOs etc -->
> <!--            classpath:/module/**-context.xml-->
>        </param-value>
>    </context-param>
>
>
>    <servlet>
>        <servlet-name>main</servlet-name>
>
> <servlet-class>org.springframework.web.servlet.DispatcherServlet</ 
> servlet-class>
>        <load-on-startup>1</load-on-startup>
>    </servlet>
>
>    <servlet-mapping>
>        <servlet-name>main</servlet-name>
>        <url-pattern>*.form</url-pattern>
>    </servlet-mapping>
>
>    <servlet>
>        <servlet-name>CXFServlet</servlet-name>
>
> <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet- 
> class>
>        <init-param>
>            <param-name>hide-service-list-page</param-name>
>            <param-value>false</param-value>
>        </init-param>
>        <init-param>
>            <param-name>base-address</param-name>
>            <param-value>services</param-value>
>        </init-param>
>        <init-param>
>            <param-name>config-location</param-name>
>            <param-value>/WEB-INF/cxf-servlet.xml</param-value>
>        </init-param>
>        <load-on-startup>2</load-on-startup>
>    </servlet>
>    <servlet-mapping>
>        <servlet-name>CXFServlet</servlet-name>
>        <url-pattern>/services/*</url-pattern>
>    </servlet-mapping>
>
>    <filter>
>        <filter-name>springSecurityFilterChain</filter-name>
>
> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</ 
> filter-class>
>    </filter>
> </web-app>
>
> cxf-servlet.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:cxf="http://cxf.apache.org/core"
>    xmlns:simple="http://cxf.apache.org/simple"
>    xmlns:jaxws="http://cxf.apache.org/jaxws"
>    xsi:schemaLocation="
>        http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
>        http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans.xsd
>        http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
>    ">
>
>    <!-- import at the end also doesn't works -->
>    <import resource="classpath:/module/**-context.xml" />
>
>    <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-extension-http-binding.xml"/>
>    <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
>
>    <bean id="logOutbound"
> class="org.apache.cxf.interceptor.LoggingOutInterceptor"/>
>
>    <!-- cxf:bus also doesn't works -->
>    <bean id="cxf" class="org.apache.cxf.bus.CXFBusImpl">
>        <property name="inInterceptors">
>            <list>
>                <ref bean="logOutbound" />
>            </list>
>        </property>
>        <property name="outInterceptors">
>            <list>
>                <ref bean="logOutbound" />
>            </list>
>        </property>
>        <property name="outFaultInterceptors">
>            <list>
>                <ref bean="logOutbound" />
>            </list>
>        </property>
>    </bean>
>
> </beans>
>
> Sampel module (contribution-context.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:cxf="http://cxf.apache.org/core"
>    xsi:schemaLocation="
>        http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans.xsd
>        http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
>    ">
>
>    <bean id="contributionModule"
> class="pl.bpsa.sw.modules.contribution.ContributionModule" />
>
>    <jaxws:endpoint id="contribution" address="contribution"
>         
> implementor="pl.bpsa.sw.modules.contribution.ContributionTypeImpl">
>    </jaxws:endpoint>
> </beans>
>
> The ContributionModule implements InitializingBean and its correctly  
> created
> but CXF doesn't see endpoint.
>
> My Maven structure:
> parent
> `-- webapp (web context, forms etc)
> `-- modules (web services implementation)
>    `-- contribution
>    `-- scoring
>
> The Webapp have dependencies to CXF:
>        <dependency>
>            <groupId>org.apache.cxf</groupId>
>            <artifactId>cxf-rt-frontend-jaxws</artifactId>
>            <version>2.1.1</version>
>        </dependency>
>        <dependency>
>            <groupId>org.apache.cxf</groupId>
>            <artifactId>cxf-rt-transports-http</artifactId>
>            <version>2.1.1</version>
>        </dependency>
>        <dependency>
>            <groupId>org.apache.cxf</groupId>
>            <artifactId>cxf-rt-bindings-http</artifactId>
>            <version>2.1.1</version>
>        </dependency>
>
> Modules have the same dependencies but it's scope was set to provided.
> If I copy endpoint configuration from module to  
> applicationContext.xml in
> webapp CXF will publish web service. What should I do to use dispersed
> configuration with CXF?
>
> Regards,
> Luke
> -- 
> View this message in context: http://www.nabble.com/JAX-WS---multiple-services-in-separate-jars-tp18336903p18336903.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>

---
Daniel Kulp
dkulp@apache.org
http://www.dankulp.com/blog