Jai’s Weblog – Tech, Security & Fun…

Tech, Security & Fun…

  • Jaibeer Malik

    Jaibeer Malik
  • View Jaibeer Malik's profile on LinkedIn
  • Subscribe

  • Feedburner

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 29 other followers

  • Archives

  • Categories

  • Stats

    • 379,210
  • Live Traffic

Tips&Tricks: Configure Web service client to use wsdl location path as local file path

Posted by Jai on October 24, 2012

This post share how you can configure Web Service client to use wsdl file location as the local file instead of remote web service wsdl location path.

There are few ways to do the same, depending on which scenario will be fit for you.

Common approach of setting wsdl location, remote wsdl URI

If you generate web service code based on wsdl file, the below location is you local file or remote address.

public final static URL WSDL_LOCATION;
static {
        URL url = null;
        try {
            url = new URL("http://localhost:8080/trySomeWSDL.wsdl");
        } catch (MalformedURLException e) {
            java.util.logging.Logger.getLogger(WebServiceTestClient.class.getName())
                .log(java.util.logging.Level.INFO,
                     "Can not initialize the default wsdl from {0}", "http://localhost:8080/trySomeWSDL.wsdl");
        }
        WSDL_LOCATION = url;
    }

In case of remote path,

  • The chances of wsdl updates are more on server side
  • Backward compatibility will fail in case code auto generated is old and wsdl updates are applied.
  • Not a good practice to use remote wsdl if you don’t have control over both server/client updates/configurations.

In case of local path,

  • You can’t hard code the local wsdl path as it depends on environment, the absolute path may not work until you manage wsdl file copy on different environment which itself is not suggested approach.
  • Relative path is reference is preferred approach, but that also file should be in build within the client itself.

Using jax-ws-catalog approach

As explained in the post, what’s the correct path to access the local wsdl? you can use catalog approach to package local wsdl file.

Copy wsdl file and catalog xml file under META-INF

<catalog xmlns="urn\:oasis\:names\:tc\:entity\:xmlns\:xml\:catalog" prefer="system">
<system systemId="http://localhost/wsdl/trySomeWSDL.wsdl" uri="wsdl/trySomeWSDL.wsdl"/>
</catalog>

To access it in java,

public final static URL WSDL_LOCATION;
static {
        URL url = null;
        try {
            url = new URL("http://localhost/wsdl/trySomeWSDL.wsdl");
        } catch (MalformedURLException e) {
            java.util.logging.Logger.getLogger(WebServiceTestClient.class.getName())
                .log(java.util.logging.Level.INFO,
                     "Can not initialize the default wsdl from {0}", "http://localhost:8080/trySomeWSDL.wsdl");
        }
        WSDL_LOCATION = url;
    }

The problem with above approach is that for jar file you need to copy your files under META-INF but in case of war file you need to have it under WEB-INF folder. Either I make my complex maven resource copy calls or look for other options.

Locally packaged wsdl file using maven

The blog post, locally packaged wsdl gives you idea how you can use maven to package local wsdl files.

URL wsdlLocationURL = wsdlLocationURL = com.test.jai.WebServiceTestClient.class.getResource("trySomeWSDL.wsdl");

If you don’t want additional configuration for maven to copy your local wsdl file to correct path in jar file, you can create same package structure under resource folder to store the wsdl file.

src/com/test/jai/trySomeWSDL.wsdl

At least this options works well for me even if the wsdl file is packaged in a jar file which is used in web application. I don’t need to define any global parameters for the same and just use the relative path in smart way🙂

3 Responses to “Tips&Tricks: Configure Web service client to use wsdl location path as local file path”

  1. Bhaskar said

    Thanks !! for useful post..

  2. […] Tips&Tricks: Configure Web service client to use wsdl location path as local file path […]

  3. […] Tips&Tricks: Configure Web service client to use wsdl location path as local file path […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: