CXF jaxws endpoint relative publish address

℡╲_俬逩灬. 提交于 2020-01-01 04:50:52

问题


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.


回答1:


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.




回答2:


Shouldn't it be

address="/HelloWorldService"

?



来源:https://stackoverflow.com/questions/7070748/cxf-jaxws-endpoint-relative-publish-address

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!