CXF代码优先服务,WSDL生成;肥皂:地址改变?

发布于 2024-10-08 17:41:03 字数 1377 浏览 0 评论 0原文

我有一个简单的 Java 接口/实现,通过 CXF 公开。我的 Spring 配置文件中有一个 jaxws 元素,如下所示:

<jaxws:endpoint id="managementServiceJaxws"
            implementor="#managementService" address="/jaxws/ManagementService" >
</jaxws:endpoint>

它从带注释的接口生成 WSDL 并公开服务。然后,当我点击 http://myhostname/cxf/jaxws/ManagementService?wsdl 时,我得到了一个可爱的WSDL。在 wsdl:service 元素的底部,我会看到

<soap:address location="http://myhostname/cxf/jaxws/ManagementService"/>

然而,一天左右的某个时间,在没有应用程序重新启动的情况下,点击相同的 url 会产生:

<soap:address location="http://localhost/cxf/jaxws/ManagementService"/>

这会导致许多问题,但我真正想要的是修复它。现在,Web 服务有一个特定的客户端将端点设置为 localhost;因为它运行在同一台机器上。 wsdl 是否有可能重新生成并缓存,然后公开“localhost”版本?在某种程度上,我不知道从 CXF 中的 ?wsdl 请求到响应的确切机制。似乎几乎可以肯定它正在检索一些缓存的版本,因为它应该通过询问 servlet 容器(Jetty)来确定地址。

作为参考,我知道一个权宜之计的解决方案是使用客户端上的主机名并确保别名到位,以便它能够绕过环回。

编辑: 作为参考,我确认,如果我启动应用程序并首先通过 localhost 访问它,那么通过主机名查询 wsdl 将显示地址为 localhost。相反,首先在主机名上点击它会导致本地主机请求显示主机名。很明显这里有些东西被缓存了。

编辑2: 我认为问题可能是 OsgiServletController,因为有一个方法:

    private synchronized void updateDests(HttpServletRequest request) {
    if (disableAddressUpdates) {
        return;
    } //snip

但我看不出有什么方法可以确认问题是这个布尔值设置为 true 或者我如何实际更新它!

I have a simple Java interface/implementation I am exposing via CXF. I have a jaxws element in my Spring configuration file like this:

<jaxws:endpoint id="managementServiceJaxws"
            implementor="#managementService" address="/jaxws/ManagementService" >
</jaxws:endpoint>

It generates the WSDL from my annotated interface and exposes the service. Then when I hit http://myhostname/cxf/jaxws/ManagementService?wsdl I get a lovely WSDL. At the bottom in the wsdl:service element, I'll see

<soap:address location="http://myhostname/cxf/jaxws/ManagementService"/>

However, some time a day or so later, with no application restart, hitting that same url produces:

<soap:address location="http://localhost/cxf/jaxws/ManagementService"/>

This causes a number of problems, but what I really want is to fix it. Right now, there's a particular client to the webservice that sets the endpoint to localhost; because it runs on the same machine. Is it possible the wsdl is getting regenerated and cached and then exposing the 'localhost' version? In part I don't know the exact mechanism by which one goes from a ?wsdl request in CXF to the response. It seems almost certain that it's retrieving some cached version, given that it's supposed to be determining the address by asking the servletcontainer (Jetty).

For reference I know a stopgap solution is using the hostname on the client and making sure an alias in place so that it goes over the loopback.

EDIT:
For reference, I confirmed that if I bring my application up and first hit it over localhost, then querying for the wsdl via the hostname shows the address as localhost. Conversely, first hitting it over the hostname causes localhost requests to show the hostname. So obviously something is getting cached here.

EDIT2:
I think the problem might be OsgiServletController, as there is a method:

    private synchronized void updateDests(HttpServletRequest request) {
    if (disableAddressUpdates) {
        return;
    } //snip

But I see no way of confirming that the issue is that this boolean value is set to true or how I might actually update it!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

魂ガ小子 2024-10-15 17:41:03

您能否确认您正在使用的 CXF 版本 - 我在我的版本 - 2.3.1 中没有看到这种缓存行为。

服务的 URL 是根据客户端用于请求的 URL 确定的(基本上使用 httpRequest.getRequestURL),除非向上面的端点标记提供了显式的publishedEndpointUrl 属性。

编辑:奇怪,听起来你的编辑2可能是在正确的方向,至于设置“disable-address-updates”,尝试在你的web.xml文件中以这种方式初始化CXFServlet,看看它是否有帮助:

    <servlet>
    <servlet-name>CXFServlet</servlet-name>
    <servlet-class>
        org.apache.cxf.transport.servlet.CXFServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup>
    <init-param>
        <param-name>disable-address-updates</param-name>
        <param-value>false</param-value>
    </init-param>
</servlet>

Can you please confirm the version of CXF you are using - I don't see this caching behavior with the version I have - 2.3.1.

The URL for the service is determined based on the URL client is using for the request(basically using httpRequest.getRequestURL), unless an explicit publishedEndpointUrl attribute is provided to the endpoint tag above.

Edit: Strange, sounds like your EDIT 2 could be in the right direction, as for setting "disable-address-updates", try initializing the CXFServlet in this way in your web.xml file and see if it helps:

    <servlet>
    <servlet-name>CXFServlet</servlet-name>
    <servlet-class>
        org.apache.cxf.transport.servlet.CXFServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup>
    <init-param>
        <param-name>disable-address-updates</param-name>
        <param-value>false</param-value>
    </init-param>
</servlet>
雨后咖啡店 2024-10-15 17:41:03

Biju,

你的回答似乎是正确的。然而,顺序似乎是错误的。
load-on-startup 标签应该出现在最后一行,否则在 Eclipse 中会显示错误。

<servlet>
    <servlet-name>CXFServlet</servlet-name>
    <servlet-class>
        org.apache.cxf.transport.servlet.CXFServlet
    </servlet-class>
    <init-param>
        <param-name>disable-address-updates</param-name>
        <param-value>false</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

Biju,

Your answer seems correct. However, the order seems wrong.
load-on-startup tag should come in the last line or else it shows error in Eclipse.

<servlet>
    <servlet-name>CXFServlet</servlet-name>
    <servlet-class>
        org.apache.cxf.transport.servlet.CXFServlet
    </servlet-class>
    <init-param>
        <param-name>disable-address-updates</param-name>
        <param-value>false</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文