CXF jaxws端点相对发布地址

时间:2021-08-13 13:00:34

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

在CXF web服务端点配置中使用相对的发布地址有很多困难。

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

我有一个简单的java优先的JAX-WS项目,包含以下配置文件:

applicationContent-cxf.xml:

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 . 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.

根据http://cxf.apache.org/docs/servlet-transport.html,似乎我应该能够指定HelloWorldService的发布地址,服务的URL将解析为(例如)http://localhost:8080/service/helloworldservice。但是当我尝试访问http://localhost:8080/service/helloworldservice时?我得到一个404。如果我将jaxws端点中的发布地址更改为绝对URL http://localhost:8080/services/helloworldservice,我就能够访问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!

如果可能,我想指定一个相对端点地址。我是使用CXF(和编写web服务)的新手,所以非常感谢您的帮助!

UPDATE 1:

更新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.

注意,我正在将web服务部署到Tomcat 7。我不知道日志记录的是什么,但是我的启动日志状态中有一行将服务器的发布地址设置为HelloWorldService。如果有人需要更多的信息来帮助我,请告诉我。

UPDATE 2:

更新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.

看起来,CXF检测CXFServlet是否“正在使用”,如果不是,则使用嵌入式jetty实例。http://cxf.apache.org/docs/xfire-migration-guide.html XFireMigrationGuide-HTTPandServletSetup。因此,出于某种原因,CXF使用的是嵌入式jetty实例,而不是我的servlet。但是,除了web上HelloWorldServlet之外,我不知道还需要什么配置。xml和CXF文档没有进一步帮助我。

2 个解决方案

#1


13  

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.

答案当然是很简单的。在我的cxf bean定义中,我没有导入“cxf-servlet”。这里看到的xml文件http://cxf.apache.org/docs/servlettransport.html。如果这个文件没有导入,cxf假设它应该使用嵌入式jetty实例而不是我的cxf servlet。我猜想jetty实例只适用于指定绝对发布地址的端点。

#2


0  

Shouldn't it be

它不应该

address="/HelloWorldService"

?

吗?

#1


13  

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.

答案当然是很简单的。在我的cxf bean定义中,我没有导入“cxf-servlet”。这里看到的xml文件http://cxf.apache.org/docs/servlettransport.html。如果这个文件没有导入,cxf假设它应该使用嵌入式jetty实例而不是我的cxf servlet。我猜想jetty实例只适用于指定绝对发布地址的端点。

#2


0  

Shouldn't it be

它不应该

address="/HelloWorldService"

?

吗?