• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

wsimport, generated code, and hardcoded URLs

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 parrot is no more. It has ceased to be. Now it's a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic