0

Is it possible to make Java SOAP clients using local WSDL-files, so that the references to them are relative to the "client", at not absolute, both in stand-alone applications and Java EE, and across operating system?

I use WSIMPORT to generate artifacts, and it seems the resulting service needs access to the wsdl to initialize. How can I specify wsdl-location to be relative to the project it resides in? That means packaged in a JAR/WAR and relative to operating system (Linux/Windows) and relative to execution environment (Java EE server vs. stand alone application).

  • I have used the solution presented in [How to avoid the need to specify the WSDL location in a CXF or JAX-WS generated webservice client?](http://stackoverflow.com/questions/4455195/how-to-avoid-the-need-to-specify-the-wsdl-location-in-a-cxf-or-jax-ws-generated) with success. The `classpath:` prefix in the `wsdlLocation` property works with the CXF codegen Maven plugin, but perhaps a similar approach can be used with `wsimport` (or then you can switch to using CXF, which is a good framework BTW). – Mick Mnemonic Aug 04 '15 at 22:34
  • Thanks, it turns out the current artifacts af created with CFX, so the code looks pretty similar to the one posted in the solution. I should be able to just edit the current code to work. – Jörg Asmussen Aug 05 '15 at 22:40

1 Answers1

1

You can load the file as a resource from a location that is on your classpath. Examples here and here.

By ensuring your build process always bundles the file into your JAR at the same location, you can access the file in the same way anywhere in your code.

Community
  • 1
  • 1
user1886323
  • 1,129
  • 7
  • 15
  • Does this mean the wsdl-files should be placed in both `src/main/resource/wsdl` and `src/test/resource/wsdl` to have junit to work as well? – Jörg Asmussen Aug 05 '15 at 14:14
  • Yes. It is also common to use a different wsdl file for tests (eg pointing to a UAT or Prod parallel environment. However, you would need to check if src/main/resource is also on the classpath when you run your tests - I'm not sure what the default settings are here but normally I think only the test resources will be added in test configurations. – user1886323 Aug 05 '15 at 18:22
  • I am trying to build a generic client to be used in many of our project. If needed, the client can be initialized with a custom wsdl from outside classes/packages. If none is specified, the client should default to it's own wsdl. I have tried a Junit-test, and the placement of the wsdl-file in the `src/main/resource` is used for the tests as well. So all is well. Thanks! – Jörg Asmussen Aug 05 '15 at 22:45