JAX-WS Loading WSDL from jar

前端 未结 13 848
予麋鹿
予麋鹿 2020-11-28 04:40

I\'m writing a fat client that makes use of a SOAP service for some features (bug reporting etc.)

I\'ve got JAX-WS working fine, but by default (in netbeans at least

相关标签:
13条回答
  • 2020-11-28 05:21

    What you describe is a bug in JAX-WS: JAX_WS-888 - Wrong code for resolving the URL for a custom wsdlLocation.

    It was fixed for V2.2, so just setting wsdlLocation, as you write, should work now.

    0 讨论(0)
  • 2020-11-28 05:23

    My solution was to modify the generated Service. You have to change wsdlLocation in the header annotation and the instantion block looks like this:

        static {
        URL url = null;
        url = com.ups.wsdl.xoltws.ship.v1.ShipService.class.getResource("Ship.wsdl");
        SHIPSERVICE_WSDL_LOCATION = url;
        }
    

    I place the wsdl file in the bin directory next to the ShipService class

    0 讨论(0)
  • 2020-11-28 05:25

    Although you can get it to work with some manipulations, I would recommend not doing it and keeping it the way you have right now.

    Web Service endpoint providers should provide a WSDL as part of their contract. The code you generate should be pulling from the WSDL from the server itself.

    At deployment on WebSphere you can change the endpoints to other endpoints from the deployment UI. Other application servers you may need to find out the vendor specific binding XML to do it it.

    It only happens on initialization so the impact to your overall application should be negligible.

    0 讨论(0)
  • 2020-11-28 05:29

    Atleast for the recent JAX-WS you don't need to do any schema catalogs or programmatic wsdl location setting IF you put the WSDL in the JAR and then set wsimport wsdlLocation to the relative resource path of the WSDL in the JAR. That is JAX-WS uses Java's builtin Class.getResource to load the WSDL.

    If your using Maven its something like:

      <plugin>
        <groupId>org.jvnet.jax-ws-commons</groupId>
        <artifactId>jaxws-maven-plugin</artifactId>
        <version>2.3</version>
        <executions>
          <execution>
            <goals>
              <goal>wsimport</goal>
            </goals>
            <!-- Following configuration will invoke wsimport once for each wsdl. -->
            <configuration>
                <!--- VERY IMPORTANT THAT THE PATH START WITH '/' -->
        <wsdlLocation>/com/adamgent/ws/blah.wsdl</wsdlLocation>
        <wsdlDirectory>${basedir}/src/main/resources/com/adamgent/ws</wsdlDirectory>
        <wsdlFiles><wsdlFile>blah.wsdl</wsdlFile></wsdlFiles>
           </configuration>
          </execution>
        </executions>
      </plugin>
    

    For the example above you would thus put the WSDL using Maven project layout here src/main/resources/com/adamgent/ws.

    Make sure the WSDL gets in the JAR for Maven like:

    <build>
          <resources>
            <resource>
              <directory>src/main/resources</directory>
            </resource>
          </resources> ....
    

    Now your wsimport generated code and WSDL are in a self contained JAR. To use the service you do not have to set the WSDL location and is as easy as:

    BlahService myService = new BlayService_Service().getBlahServicePort();
    

    It should be trivial to map this over to ANT's wsimport.

    0 讨论(0)
  • 2020-11-28 05:32

    An other answer is to use the

    new Service(wsdllocation, servicename );
    

    to get the Service Object.

    This is how I solved the problem.

    0 讨论(0)
  • 2020-11-28 05:38

    Maybe a bit late, but I found a quite simple solution which worked to solve this problem, but this involved a change in the generated code of the Service class:

    If the following line in the Service class

    baseUrl = net.example.ApplicationService.class.getResource(".");
    

    is changed to

    baseUrl = net.example.ApplicationService.class.getResource("");
    

    it works fine even with a WSDL that is packed within a JAR. Not sure about the exact supposed behaviour of getResource() in either of this cases, but I didn't experience any problems with this approach so far, on multiple OS and Java versions.

    0 讨论(0)
提交回复
热议问题