2

Sorry if this is a duplicate, I looked at several other questions but none seemed to match or provide workable solutions.

Problem I am writing a Spring Boot (v2.0.2) app, this app exposes a RESTful API which then calls into a WSDL service. I've generated the WSDL classes with Maven/jaxb plugin and everything works from my dev machine. When deployed to the server I get an error that the WSDL service class can not load the underlying WSDL file. The problem is that when the Java classes are generated it is using the full path from my dev machine (snippet from the generated service class)

try {
        URL baseUrl;
        baseUrl = com.mytest.WSDLService.class.getResource(".");
        url = new URL(baseUrl, "/home/users/me/projects/wsdltest/wsdl/MyWSDL.wsdl");
    } catch (MalformedURLException e) { 

The WSDL file (MyWSDL.wsdl) is in the spring boot JAR file for my application, it is in a subdirectory off root called 'wsdl'

Question Is there a way that I can load this WSDL from the JAR file without having to modify the generated classes?

Ideal Solution I'm hoping to find a solution that doesn't make me modify the generated files (we intend to do this for several services), ideally I'd like a solution which can be done at build time (in the pom.xml?), if that's possible.

Solutions Tried

  • A post on here suggested using the "wsdlLocation" tag in my pom.xml and provide a explicit path to the WSDL file, e.g. <wsdlLocation>/wsdl/MyWSDL.wsdl</wsdlLocation>
  • Tried most of the solutions from this thread

Thanks in advance

Jim M.
  • 909
  • 1
  • 12
  • 29
  • I would recommend you to do a small library with everything-WSDL and import the library then into your Spring Boot application. The WSDL generation should take care about everything; the `genJaxb` task you can specify the `sourceDir`, `classesDir`, `bindings`, etc. The reason to place this in another project is because it usually doesn't change frequently, so you don't need to re-generate all that stuff every single time in your build process. – x80486 Jul 25 '18 at 13:33
  • Thanks for replying @uoɹɔıɯ, perhaps I'm missing something but I'm not sure how that solves the underlying problem of the code loading the WSDL file from the JAR file? The problem is that at run time the code tries to load the WSDL file but can't get it from the JAR, moving it into a different JAR won't solve that, will it? – Jim M. Jul 25 '18 at 14:27
  • I'm not sure why would you need the WSDL file, but as long as it's on the Java's `CLASSPATH` (preferably if that's the case), or any other known/predefined location, any artifact should be able to read it. – x80486 Jul 25 '18 at 15:39

1 Answers1

0

I think I was able to find a solution thanks to this SO Thread. Evidently the answer depends on the version of the jaxws tool being used in maven (jaxws-maven-plugin). The project (which I inherited) explicitly asked for version 1.12 (which invoked JAX-WS RI 2.1.7-b01-), using this version of the tools I was able to use the '<wsdlLocation>classpath:wsdl/MyWSDL.wsdl</wsdlLocation>' solution in the thread mentioned. Once I noticed that the pom was using an explicit version I removed that the jaxws was updated (using JAX-WS RI 2.2.10) but then the 'classpath' solution stopped working. I switched to the other option mentioned in the thread '<wsdlLocation>/wsdl/MyWSDL.wsdl</wsdlLocation>'

I did a quick test and this seemed to have solved the problem (in both my dev machine and my test site).

Thank you

Jim M.
  • 909
  • 1
  • 12
  • 29