Refreshing Web Services in Java Studio Creator 2

In a previous developer's life, like almost two years ago, I worked on the web service consumption feature in Java Studio Creator.  I struggled with defining the scenario for "refreshing" a web service.  A developer has recently brought the subject up again so I though I would blog on the topic.  So in this blog, I'll cover how to "refresh" a WSDL in Java Studio Creator.

Required Background Information

Before I dive into the how-to, I need to cover some background information about scopes in Java Studio Creator.  There are basically two scopes in Java Studio Creator that matter for this discussion, IDE scope and Project scope.

IDE Scope

When you do an "Add web service..." using the following dialog, you are adding to the IDE scope.

Add web service

All web services in the IDE scope are available to all projects.  The "Web Services" node in the "Servers" window shows the IDE-scoped web services.

server window


Project Scope

When you use a web service in a web page, the web service is copied to the Project scope.  


There are two techniques for adding a web service to the web page and thus the Project scope, via the context menu and drag-n-drop.

With the visual designer showing the target page...

Context Menu: Entire Web Service
  1. Select a web service  from the "Web Services" node.
  2. Right-click on the web service and select "Add to page".
context menu
Web Service Added to Project Scope

This will add a web service client property to the page as shown in the Outline window and the web service client Jar files to the project as shown in the Projects window.

Context Menu: Web Service Method
  1. Select a web service method from the "Web Services" node.
  2. Right-click on the web service method and select "Add to page".
add method
Web Service Method Added to Project Scope

This will add a web service client property and a web service data provider to the page as shown in the Outline window and the web service client Jar files to the project as shown in the Projects window.  The web service data provider wraps the web service client.


Drag-n-Drop: Entire Web Service
  1. Select a web service  from the "Web Services" node.
  2. Drag the web service  and drop it on the visual designer background.  A component is not a valid drop target for an entire web service.
You'll get the same results as adding a web service from the context menu above.
Drag-n-Drop: Web Service Method
  1. Select a web service method  from the "Web Services" node.
  2. Drag the web service method and drop it either on the visual designer background or on a component.
You'll get the same results as adding a web service method from the context menu above.

On to Refreshing

The most common use case of refreshing a web service I've seen involves a developer who is trying to get a web service interface correct so they keep changing the WSDL.  When they change the WSDL, they'd like to "refresh" the view of what Creator sees as that web service.  So now that we've looked at the scope issue above, you should know that we need to refresh the web service in both the IDE and the Project scope.

Refreshing the Web Service in the IDE Scope

Unlike the EJB consumption in Java Studio Creator, the web service consumption doesn't have a "refresh" option.  I have some good excuses but I won't go into those here. :)  In order to refresh the web service in the IDE scope, if you want to use the same name, you need to delete the web service and re-add it.  If you are OK with keeping multiple versions of the web service around, you don't have to delete the old one.  Simply add the new one.  The new name will have a number postfixed that will be incremented each time you add the same named web service.

Refreshing the Web Service in the Project Scope

This is a little more involved.  As I discussed above, a web service client property and also a web service data provider property are added to the web page. Web service client Jar files are also added to the project libraries.  If you really want to refresh the web service, the safest way is to delete the web service artifacts and re-add the web service to the project.

For example, if I drag-n-drop the "WorldTime->web service in the "samples"  folder  to a web page, I'll have these web service client artifacts added.

  • Added to the Page (viewed in the Outline window) -  "worldTimeTzStampNow1" data provider and "worldTimeClient1" web service client.
  • Added to the Project window "Libraries" node - "worldtime.jar" and "worldtimeDesignTime.jar".  If a non-sample web service was added, the jar name will be prefixed with the web service name. like "TravelWS-".
So to refresh this web service in this project, I would delete the "worldTimeTzStampNow1" data provider and "worldTimeClient1" web service client from the Outline window and I would remove the "worldtime.jar" and "worldtimeDesignTime.jar" from the "Libraries" node.  Then I would again drag-n-drop the "WorldTime->web service in the "samples"  folder  to a web page.

Also note that if you've written code around the web service client, re-adding the web service increments the number in the name.  To change this, click on the "..." next to the name in the property for the web service client and change it back to the name you used in the code.  Here's an example of some code that uses "worldTimeClient1".

          try {
                this.staticText1.setText(this.worldTimeClient1.tzStampNow("MST"));
            } catch (Exception ex) {
                log("Error Description", ex);
            }

Here's a snapshot of what you would change.

name change


Now isn't that refreshing! :)

Cheers!
-David
Comments:

Sounds great david, but a quick note: From my personal experience, you can get by a lot easier by just removing the older jars from the current project. This allows you to maintain all your references, and is actually an easier process than what you describe. Also note that I assume it is a bug in creator that causes it to use the older jars before the new ones (even though as you say they have a higer number [I assume this is some sort of time hash??]). It seems like it uses the first class def it finds, no matter if a more recent one follows it (maybe not a bug persay,but an annoying design decision, especially when debugging it for the first time). What I do to refresh my webservice? 1) Delete the web service in the ide as you mention. 2) Re-add the wsdl. (This keeps everything named the same and is easy for me to maintain my huge codebase of convaluted methods and objects). 3) Right click on the Libraries option in the "project" navigation menu and select properties. Remove the older jars (identifiable by the lower number) from both the "libraries" and "build/packaging" tree nodes (There should be 2 for each web service in the library node and 1 more in the packaging node). At this point, your older files have been removed, leaving only your new files. Your import statements don't care about file names, just classes, which are clearly the same, so all is now updated. No need to update properties or refactor any code that calls your web service. David, thanks for your blog as one of the few places to look for good creator-portlet info. Without you and Tor, I'm not sure how I would have even gotten as far as I have. Now, if you want to talk a little bit about facesportlet and how to deal with sending ipc events(processAction(), how to get to it, I wouldn't mind at all. Hopefully these notes will help someone else exploring web services as a way to share data within creator.

Posted by J Jones on August 24, 2006 at 03:10 PM MDT #

J Jones,
Thanks for sharing that great tip! This will work if nothing in the interface changes. I'm thinking you missed a step between 2 and 3 where you re-add the web service to the page. This would produce the new Jar files in the project allowing you to delete the old Jar files.

The procedure I outlined was geared more for WSDL refinement processes where the actual interface changes. That is, the method signatures change somehow. In this case, the IDE scope Jar files will have the new signatures and any source code using those signatures would have to be changed once the new WSDL was re-added to the page (Project scope). Creator creates a web service client adapter that encapsulates the weird web service client dealings in JAX-RPC. Also, if a web service method is added, a data provider, specific to the method signature, gets created. So in these cases, value-bindings and backing bean source are likely to be affected.

Please let me know if I misinterpreted your solution.

Thanks again for sharing your tip!
-David

Posted by David Botterill on August 25, 2006 at 10:59 AM MDT #

It wasn't exactly what I was looking for BUT . . . it "shined the light." thx.

Posted by James Bowers on December 08, 2006 at 11:40 PM MST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

David Botterill

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today