8

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.

Jpnh
  • 806
  • 1
  • 11
  • 22

2 Answers2

16

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.

Jpnh
  • 806
  • 1
  • 11
  • 22
0

Shouldn't it be

address="/HelloWorldService"

?

beny23
  • 34,390
  • 5
  • 82
  • 85
  • Thanks for pointing that out. I did try /HelloWorldService, but it still seems to not work. – Jpnh Aug 16 '11 at 13:06
  • Please add serviceName="service'sName" in your endpoint and try – Ganesh Aug 17 '11 at 07:43
  • Thanks. I didn't mention that I have the service name configured in the JaxWS annotation on my web service implementation. – Jpnh Aug 17 '11 at 18:42
  • `serviceName=HelloWorldService` didnt work for me, besides it requires a namespac ein curly brackets before `HelloWorldService` – vikingsteve May 30 '18 at 07:20