简体   繁体   中英

CXF code first service, WSDL generation; soap:address changes?

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!

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>

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM