Using jaxws-maven-plugin with -clientjar option

前端 未结 2 1577
执笔经年
执笔经年 2021-01-20 12:06

I\'m using jaxws-maven-plugin to execute wsimport for a web service consumer app. I\'m using the -clientjar option on wsimport which was introduced with JAX-WS

2条回答
  •  悲&欢浪女
    2021-01-20 12:14

    The -clientjar option is really poorly documented, IMHO. Here's how I believe it works:

    When the -clientjar option is used three things are happening:

    1. You'll get a generated in the directory pointed to by the -d argument to the wsimport tool. This will contain within it both WSDL and any relevant XSD files as well. This little bundle will not be used for anything at all. If you want to make use of it it would be entirely up to you. But before you do see (2) below. I'm not sure what to use this jarfile for other than as a form of documentation.
    2. You'll get a copy of the WSDL put into a file called META-INF/wsdl/.wsdl. The generated classes will use this file in the no-arg proxy constructor. So this is what will actually be used if you request a bundled WSDL file with the -clientjar option.
    3. The generated code will change so that wsdlLocation, if you are using the default no-arg constructor on the @WebServiceClient class, will be that of the bundled WSDL (from (2)), rather than the remote WSDL. Indeed if you use -wsdllocation on your command line together with -clientjar then whatever you specify with -wsdllocation will have no effect as -clientjar will take precedence.

    So we must focus on (2) and (3) because that's the only one being actually used ... at least if you use the generated code as-is.

    It is interesting to note that the result of (2) is only a WSDL file. This file may have embedded links to XSD files but as far as I can tell such link will never be followed. The reason is that when we say a web service consumer needs the WSDL at runtime it really only needs the WSDL itself, at not the schema. The schema is "hardcoded" into the consumer and there's no way of changing it at runtime. Hence there's no reason to read schema information at runtime. (THIS IS FROM MY UNDERSTANDING)

    Second thing to note about the WSDL that's included with (2): It is really just a copy of the original WSDL so it may not have endpoint you want. Actually in most cases it won't. This means that in this situation you'll need to set the endpoint yourself :

    // Use no-arg constructor. Means it uses the WSDL bundled into the 
    // META-INF/wsdl directory rather than trying to retrieve WSDL over the
    // network.
    service = new HelloSvc_Service();
    hello = service.getHelloSvcPort();
    
    // Since we're using a bundled WSDL the web service URL cannot 
    // be derived from that (it would be wrong!). So we have to set
    // it explicitly.
    ((BindingProvider) hello).getRequestContext().put(
                    BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                    "http://myhellowebservice-address");
    

提交回复
热议问题