aspose file tools*
The moose likes Web Services Certification (SCDJWS/OCEJWSD) and the fly likes setting the endpoint url Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Web Services Certification (SCDJWS/OCEJWSD)
Bookmark "setting the endpoint url " Watch "setting the endpoint url " New topic
Author

setting the endpoint url

Mohit Sinha
Ranch Hand

Joined: Nov 29, 2004
Posts: 125
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
Patrick Williams
Ranch Hand

Joined: Apr 03, 2005
Posts: 213
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.


Patrick<br /> <br />SCJP/SCWCD/SCBCD/SCDJWS/SCEA<br /> <br />Currently working on:<br />SCJP 6
Mohit Sinha
Ranch Hand

Joined: Nov 29, 2004
Posts: 125
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

Joined: Apr 03, 2005
Posts: 213
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

Joined: Nov 29, 2004
Posts: 125
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

Joined: Apr 03, 2005
Posts: 213
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

Joined: Nov 29, 2004
Posts: 125
Patrick,

Thanks a lot for your help.

Regards,
Mohit Sinha
Ranch Hand

Joined: Nov 29, 2004
Posts: 125
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

Joined: Apr 03, 2005
Posts: 213
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: setting the endpoint url