• 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
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

setting the endpoint url

 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I am pretty new to web services. Currently in our application one of the requirement is to fetch data from a web service.
This web service has published a WSDL. We run a clientgen utility against this WSDL to create a set of java related artifacts for this web service.

Then in our application we use these web service generated java classes.

This was working fine. Now the problem is as we go about testing across various environments the web service provider URL will keep on changing.

The approach we follow now is manually change the endpoint url in our copy of wsdl & regenerate the entire set of java classes.
We want to avoid this task of repeateadly using clientgen to generate the same set of java artifacts just to accomodate a mere change of web service provider endpoint url.


So we want to set this endpoint url in our code where in we specify the endpoint url say in properties file.

I tried a few options which I got on the net but none seems to work successfully something like this
--------------------------------------------------------
// Invoke createProxy() to create a stub object
Stub stub = createProxy();

// Set the endpoint address the stub uses to access the service
stub._setProperty(javax.xml.rpc.Stub.ENDPOINT_ADDRESS_PROPERTY,
"http://localhost:8080/math-service/math");
-------------------------------------------------------------

Can someone tell me what would be the right way of doing this.


Regards
 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mohit, First, I would be remiss if I did not point out that this is a mispost (This should be in the Web Services forum and I have not checked for cross posting).

Having said that, you should have this in a parameter somewhere cooked into your build process. I don't see what is wrong in using clientgen producing a new client if you have a sound build process. Depending on your environment, you probably have the issue where different assets point to different URLs from environment to environment anyways. I think that the DII (using the Stub and Call class explicitly) is a bit overkill versus baking clientgen into something like an ant task.

I don't feel that there is a "right" way and a "wrong" way of doing this. it's just a matter of preference.

Just my 2 cents.
 
Mohit Sinha
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Patrick,

Sorry for selecting wrong forum for the post. No I did not cross post.

We are not against any approach. The client we are working for wants it this way so we are trying to find out how we can acheive the same.

Regards,
 
Patrick Williams
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My experience with client generating tools tells me that it usually generates the source too. You could parameterize then if that is the case. It can be tedious, but I've seen it done before.
 
Mohit Sinha
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you ellaborate a bit more on the point where you mention you can parameterize in the last post. Is this something I can take care while running the clientgen.
Currently the way I run clientgen is how we find in the example build file of weblogic something like this

------------------------------------------
<clientgen

wsdl="${basedir}\wsdl_files\ServiceInvocation.wsdl"
destDir="${clientclass-dir}"
autoDetectWrapped="false"
typeFamily="XMLBEANS_APACHE"
handlerChainFile="ClientHandlerChain.xml"
packageName="com.test.example.serviceinvocation.ws">
</clientgen>
---------------------------------------------


I spoke to the client about the trade-off you mentioned in the earlier post & the response is we as a vendor would not be having knowledge of the service endpoint url beforehand.

Thanks for your prompt help.
 
Patrick Williams
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, You will be in either one of two states. The Web Service will be deployed or it wont.

If it is, you should be running your clientgen from the http://blah.com/webservice?wsdl URL (recommended).

If it is not deployed (and from how it appears in your example, it doesn't look like it is), how is your WS client code looking? I imagine that it will have references to your file system (but I do not know as I've never taken this approach before personally, however I am speculating) to where the wsdl is.

Either way, once you have generated a valid client stub with accessible source code, parameterize your URL endpoint. I'll use your previous example.

stub._setProperty(javax.xml.rpc.Stub.ENDPOINT_ADDRESS_PROPERTY,
"http://localhost:8080/math-service/math");

to

stub._setProperty(javax.xml.rpc.Stub.ENDPOINT_ADDRESS_PROPERTY,
webSvcEndPtURL);

top of your code, declare (for example:

String webSvcEndPtURL = ###WEB_SVC_ENDPT###

Also, remove all references to http://localhost:8080/math-service/math (unless it's a namespace then convert over to a naming convention of your choosing) and have them refer to webSvcEndPtURL.

In your build process, generate a tokenization process (a pre-process) that will convert ###WEB_SVC_ENDPT### to a true URL before javac runs. Have it read the value from some properties file (and the tokenization with the ### is merely a suggestion). Modify the properties file to reflect endpoint URL from environemnt to environment.

HTH
 
Mohit Sinha
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Patrick,

Thanks a lot for your help.

Regards,
 
Mohit Sinha
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Patrick,

I did not get the part where you mention about ###WEB_SVC_ENDPT###.
Can you ellaborate a bit on
---------------------
In your build process, generate a tokenization process (a pre-process) that will convert ###WEB_SVC_ENDPT### to a true URL before javac runs.
---------------------
If you could give me a hint about this pre-process task that can convert the ###WEB_SVC_ENDPT### to a true URL. How can i run a pre-process task.

Thanks in advance
 
Patrick Williams
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mohit, Two things. First, I had a brain hiccup yesterday. I've done clientgen on WSDLs on a local file system before, your clientgen will key off of your address location in the WSDL. Having said that, you can generate your token from there.

Second, I hope you do not think I am rude, but your latest question goes deeper than I care to go. I have researched this for you though and come up with this article that, hopefully, explains this topic well.

http://www.javalobby.org/articles/ant-preprocessor/

Focus on the section title "Create Symbolic Names in a Configuration File".

All the best.
 
A teeny tiny vulgar attempt to get you to buy our stuff
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic