Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CXF jaxws endpoint relative publish address

I am having a lot of difficulty trying to use a relative publish address in my CXF web service endpoint configuration.

I have a simple Java-first JAX-WS project with the following configuration files:

applicationContent-cxf.xml:

<beans xmlns=...>
    ...
    <jaxws:endpoint
        id="helloWorldService"
        implementorClass="org.helloworld.ws.HelloWorldServiceImpl"
        implementor="#helloWorldServiceImpl" <!-- spring managed -->
        endpointName="sayHello"
        address="HelloWorldService"/>
</beans>

web.xml:

<web-app>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            WEB-INF/applicationContext.xml
            WEB-INF/applicationContext-cxf.xml
        </param-value>
    </context-param>

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

    <servlet>
        <servlet-name>HelloWorldServlet</servlet-name>
        <display-name>Hello World Servlet</display-name>
        <servlet-class>
            org.apache.cxf.transport.servlet.CXFServlet
        </servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>HelloWorldServlet</servlet-name>
        <url-pattern>/services/*</url-pattern>
    </servlet-mapping>
</web-app>

According to http://cxf.apache.org/docs/servlet-transport.html, it seems i should be able to specify the publish address of HelloWorldService and the URL of the service will resolve to (e.g.) http://localhost:8080/services/HelloWorldService. But when I try to go to http://localhost:8080/services/HelloWorldService?wsdl I get a 404. If i change the publish address in my jaxws endpoint to the absolute URL http://localhost:8080/services/HelloWorldService I am able to access the wsdl.

I want to specify a relative endpoint address if possible. I am new to using CXF (and writing web services), so any help is much appreciated!

UPDATE 1:

Note that I am deploying my web service to Tomcat 7. I don't know what is logging it, but one of the lines in my start up log states Setting the server's publish address to be HelloWorldService. If anyone needs more info to help me please let me know.

UPDATE 2:

It appears that CXF detects whether a CXFServlet is "being used" and uses an embedded jetty instance if it is not. http://cxf.apache.org/docs/xfire-migration-guide.html#XFireMigrationGuide-HTTPandServletSetup. So, for some reason CXF is using the embedded jetty instance instead of my servlet. However, I don't know what further configuration I need besides the HelloWorldServlet in my web.xml, and the CXF documentation doesn't help me further.

like image 966
Jpnh Avatar asked Aug 15 '11 20:08

Jpnh


1 Answers

The answer was, of course, simple (banging-head-on-desk simple, that is). In my cxf bean definitions, i was not importing the "cxf-servlet.xml" file as seen here http://cxf.apache.org/docs/servlet-transport.html. If this file is not imported, cxf assumes it should use the embedded jetty instance instead of my CXF servlet. My guess is the jetty instance only works with endpoints specifying an absolute publish address.

like image 63
Jpnh Avatar answered Oct 03 '22 07:10

Jpnh