The moose likes Web Services and the fly likes wsimport, generated code, and hardcoded URLs Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Web Services
Reply Bookmark "wsimport, generated code, and hardcoded URLs" Watch "wsimport, generated code, and hardcoded URLs" New topic
Author

wsimport, generated code, and hardcoded URLs

Tony Ennis
Ranch Hand

Joined: May 22, 2003
Posts: 86
My wsimport ant task is generating the following code in my MyAppService.java file:



This is correct and works fine on my machine. However, the URL isn't suitable for distribution. Unless I get smarter I'll have to distribute different versions of my client for testing, development, QA, and production. Ideally I'd just specify the appropriate URL in a properties file and distribute one zip file.

Obviously, I don't want to modify the generated source code. Is there a way to run wsimport so it doesn't hardcode the URL?
Tony Ennis
Ranch Hand

Joined: May 22, 2003
Posts: 86
Bah, a self-bonk for me. I tried googling for the words I used in the subject for this message and found I can put the following in my client code:



I am not 100% sure this will carry the day, but it looks promising. I'll report back as part of my penance for posting without searching
Tony Ennis
Ranch Hand

Joined: May 22, 2003
Posts: 86
After some agony unrelated to the task at hand, the above approach worked. I replaced the "http://new/endpointaddress" bit with something out of a properties file.

Tony Ennis
Ranch Hand

Joined: May 22, 2003
Posts: 86
Today I discovered the code above wasn't working correctly - it's true that it uses a web service on the configured endpoint but it gets the wsdl from the server used when the classes were generated! In my case, it was getting the wsdl from localhost. Fortunately for me I had my Tomcat down and my code phailed.

The problem is that "new MyAppService();" is reading the wsdl immediately. To get around this, I pushed the endpoint reference into the constructor:



I stole the QName constructor straight from the generated code. That's what it will use if no arguments are given.

The 'BindingProvider' code I referred to previously isn't needed. This suits me as I didn't like it.
Paul Lusk
Ranch Hand

Joined: Aug 29, 2009
Posts: 34
Tony, Just a quick post to says thanks for posting all the steps you went through to get your web service ready for distrobution.
I ve been having a similar problem in so far as that I have a web service that runs fine on server as localhost , but not able to connect from LAN client.
Will take me a day or two to decipher exactly what your code is doing as I am new to web service coding, but It does look to be what I might need. Thanks. PL
Tony Ennis
Ranch Hand

Joined: May 22, 2003
Posts: 86
Yer welcome.

Assuming you're using generated code, the trick is to look at the other constructors that are available to you.

MyService() has no arguments. It invokes another constructor using a default URL and QName. That URL is the one you specify in the ant task that generates the classes. I use the two-argument constructor supplying the desired URL for this argument. The default QName had nothing to do with the URL, so I lifted it as-is.

This needs to be tested more but it works and reports the right URLs...


This message was edited 1 time. Last update was at by Tony Ennis

 
 
subject: wsimport, generated code, and hardcoded URLs
 
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com