Friday January 11, 2008
Web Service Vendor Framework
One of the most hidden features of NetBeans IDE 6.0 is... a framework for web service providers to integrate their web services into the IDE. To understand what that means, look at this screenshot:
I added the Daily Dilbert web service from eSynaps to the palette. (The other ones you see above are there by default.) The palette only contains these web service items if (1) you have the RESTful Web Service plugin installed and (2) an appropriate REST resource class is open in the editor.
How did I get that Dilbert web service item into the palette? Many many NetBeans API classes? Much digging through code? Pulling of hair from head? No. I looked at the WSDL file that defines the Daily Dilbert web service. Then I created an XML file with exactly this content (using the information gleaned from the three links I provided in yesterday's blog entry):
<?xml version="1.0" encoding="UTF-8"?>
<component
xmlns="http://xml.netbeans.org/websvc/rest/component/1.0"
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xsi:schemaLocation='http://xml.netbeans.org/websvc/rest/component/1.0
../../../../../../../../../../rest/src/org/netbeans/modules/websvc/rest/component/component.xsd'
name="DailyDiblert"
category="/Esynaps"
nameKey="DailyDilbert_Desc"
categoryKey="Esynaps"
bundle="com.esynaps.services.nbcomponents.Bundle">
<description key="DailyDilbert_Desc"
bundle="com.esynaps.services.nbcomponents.Bundle"/>
<icons>
<icon url="com/esynaps/services/nbcomponents/dilbert-16.png" size="16"/>
<icon url="com/esynaps/services/nbcomponents/dilbert-32.png" size="32"/>
</icons>
<service name="DailyDilbert">
<method name="DailyDilbertImagePath"
serviceName="DailyDilbert" portName="DailyDilbertSoap"
type="http://schemas.xmlsoap.org/wsdl/"
url="http://www.esynaps.com/WebServices/DailyDiblert.asmx?WSDL">
<documentation>
This operation provides a path to a Daily Dilbert image.
</documentation>
</method>
</service>
</component>
I created a new module project, put the above XML file into the module source structure, and then registered it in the layer file like this:
<folder name="RestComponents">
<folder name="Esynaps">
<file name="DailyDiblert.xml" url="DailyDiblert.xml"/>
</folder>
</folder>
And that's all. I needed to restart the IDE, and then the Dilbert item was in the palette. Now, what does that item do for me? When I drag it into a resource class, I see the following:
There are no parameters that need to be filled in for the Daily Dilbert service, hence no parameters in the dialog above. ("Wait a minute!", you should now be thinking. "When did you create that dialog?" And the answer is: I didn't. I only provided a module with the XML definition above and the layer registration. The framework provided under the hood by the IDE does the rest.)
What happens when I click OK? A new resource class, called DailyDilbertResource is created. Plus, in the class where I dropped the item, a small stub method is created, for retrieving the resource:
/**
* Returns DailyDilbertResource sub-resource.
*/
@UriTemplate("dailyDilbert/")
public DailyDilbertResource getDailyDilbert(@UriParam("customerId")
Integer id) {
try {
return new DailyDilbertResource();
} finally {
PersistenceService.getInstance().close();
}
}
Next, I discovered that I could use the "Test RESTful Web Services" functionality, to try out my Daily Dilbert integration in the IDE:
This is all pretty cool. What is missing here, of course, is a wizard. The vendor should be able to create a module project and then use an "apisupport" wizard (i.e., a wizard from "Module Development" in the New File wizard) to simply choose a WSDL file. The wizard would then extract the necessary information, create the XML file, and register it in the layer. Once we have that, vendors will be able to integrate their web services in the IDE while drinking their coffee on a Monday morning while still recovering from the weekend. In other words, without needing to think.
Jan 11 2008, 07:02:52 AM PST Permalink


