Last updated: May 2008
This publication is applicable to NetBeans IDE 6.0 or 6.1.
Note: This tutorial is not applicable for XSLT SE versions newer than the one bundled with NetBeans 6.1 (build number 080408_1). To see the build number in NetBeans navigate to Services window, expand Glassfish V2 > JBI > Service Engines, right-click sun-xslt-engine and choose Properties.
In this tutorial you become acquainted with the XSLT Designer included in NetBeans IDE 6.1. The XSLT Designer is used to develop, deploy and test XSL Transformation Services.
An XSL Transformation Service acts as a web service. It receives messages from an external client, transforms the messages in accordance with an XSL stylesheet, and either sends the messages back to the originator or forwards them to another web service.
In this tutorial you create a simple XSL Transformation Service that receives a message, transforms it, and sends it back to the calling web service.
Prerequisites
This tutorial assumes that you have some basic knowledge of, or programming experience with, the NetBeans IDE.
System Requirements
This tutorial assumes that your system meets the requirements specified in the System Requirements section of the NetBeans IDE 6.1 Release Notes.
Software Needed for the Tutorial
Before you begin, download and install the following software on your computer: NetBeans IDE 6.1. Select the Download All option. The Download All option includes SOA Pack and GlassFish V2 Application Server, which are required for this tutorial.
This tutorial requires that the GlassFish V2 Application Server, which includes the JBI runtime, has been installed with NetBeans IDE 6.1. Perform the following steps to confirm that GlassFish V2 Application Server is installed with NetBeans IDE 6.1 and that the JBI runtime contains the XSLT Service Engine and Shared Util Library required for this tutorial:
Open the Services window.
Expand the Servers node.
Right-click the GlassFish V2 node and choose Start form the pop-up menu.
If the Start option is not available and there is a green “badge” next to the GlassFish V2 node, the server is already running.
After the server is started, expand the GlassFish V2 > JBI node. Then expand both the Service Engines node and the Shared Libraries node to verify that sun-xslt-engine and sun-shared-util-library are installed.
An XSL Transformation Service is created within an XSLT Module project.
To create a new XSLT Module Project:
From the IDE's main menu, choose File > New Project.
Under Categories select SOA.
Under Projects, select XSLT Module v2 Preview.
Click Next.
In the Project Name field, type HelloXSLTransformation.
Modify the project location, or accept the default.
Click Finish.
The Projects window now contains the HelloXSLTransformation project node.
Next you create two XML Schema (.xsd) files, a web service description (.wsdl) file and an XSL stylesheet (.xsl) file. To run an XSL Transformation Service, you need at least one XML Schema, one WSDL file and one XSL stylesheet. For the purpose of this tutorial, you create two XML Schemas.
You will create two XML Schemas: HelloXSLTIncoming.xsd and HelloXSLTOutgoing.xsd. You use the former as the basis for the incoming message and the latter as the basis for the outgoing message.
To create the XML Schema for the incoming message:
In the Projects window, right-click the HelloXSLTransformation > Transformation Files node and choose New > XML Schema. The New XML Schema window opens.
In the File Name field, type HelloXSLTIncoming.
Click Finish. A new node—HelloXSLTIncoming.xsd—appears under the Transformation Files node in your HelloXSLTransformation project and the new Schema opens in the XML Schema Editor.
In the first column of the Schema view, right-click Elements and choose Add Element from the pop-up menu. The Add Element dialog box opens.
In the Name field, type name.
Under Type, select the Use Existing Type radio button.
Expand the Built-in Types node and select string.
Click OK.
To view the source of the Schema you created, click the Source button on the XML Schema Editor toolbar. You should see the following code:
To create the XML Schema for the outgoing message:
In the Projects window, right-click the HelloXSLTransformation > Transformation Files node and choose New > XML Schema.
In the File Name field, type HelloXSLTOutgoing.
Click Finish. A new node—HelloXSLTOutgoing.xsd—appears under the Transformation Files node in your HelloXSLTransformation project and the new Schema opens in the XML Schema Editor.
In the first column of the Schema view, right-click Elements and choose Add Element from the pop-up menu. The Element dialog box opens.
In the Name field, type greeting.
Under Type, select the Use Existing Type radio button.
Expand the Built-in Types node and select string.
Click OK.
To view the source of the Schema you created, click the Source button on the XML Schema Editor toolbar. You should see the following code:
You should see two Schema files listed under the Transformation Files node in your HelloXSLTransformation project.
Note: The XML Schema Editor is not the subject of this tutorial. For detailed information on the XML Schema Editor, see Getting Started With XML Schema Tools.
An XSL stylesheet is an XML file that contains instructions about transforming the incoming message into the outgoing message.
To create an XSL stylesheet:
In the Projects window, right-click the HelloXSLTransformation > Transformation Files node and choose New > XSLT Service.
Under Service Type, select Request-Reply Service. Click Next.
Notice that HelloXSLTWSDL.wsdl is selected in the Web Service drop-down list. Click Next.
In the XSL File field, type HelloXSLTService. Click Finish.
The HelloXSLTService.xsl node appears under the Transformation Files node in your HelloXSLTransformation project. The HelloXSLTService.xsl file opens in the Design view of the XSL Transformation Editor. The Design view Palette opens on the right.
In the Palette, expand the String section and drag the concat function onto the Transformations pane of the XSLT Design view.
In the Palette, under the String section, select the string-literal function and drag it to the Transformations pane. Double-click the return string field to make it editable and type Hello (with a space at the end).
Drag the handle on the right side of the Hello field to the handle on the left side of the string1 row in the Concat function. An arrow snaps in place to indicate the flow.
Select the name element in the Source tree pane on the left, and drag the handle to the string2 row in the Concat function.
Drag the return string handle to the greeting element in the Destination tree pane on the right. The Design view should now resemble the following:
Click the Source button on the Design view toolbar. You should see the following code:
An XSLT project is not directly deployable. You must first add an XSLT project as a JBI module to a Composite Application project before you can deploy the Composite Application project. Deploying the project makes the service assembly available to the application server, thus allowing its service units to be run.
To create a Composite Application:
Choose File > New Project from the main menu.
Under Categories, select SOA.
Under Projects, select Composite Application. Click Next.
In the Project Name field, type HelloXSLTCAP.
Specify a project location or accept the default.
Click Finish.
The Projects window now contains the HelloXSLTCAP project node.
To add a JBI module:
Right-click the HelloXSLTCAP node and choose Add JBI Module from the pop-up menu.
Select the HelloXSLTransformation project and click Add Project Jar Files.
To verify that the JBI module has been added, expand HelloXSLTCAP > JBI Modules.
To deploy the HelloXSLTCAP Composite Application:
In the Projects window, right-click the HelloXSLTCAP node and choose Deploy from the pop-up menu. Note: If the Warning - Select Server dialog box appears, select GlassFish V2 and click OK.
In the Output window that opens in the lower part of the IDE, watch for the BUILD SUCCESSFUL message.
To verify that the project has been deployed, expand GlassFish V2 > JBI > Service Assemblies in the Runtime window. You should see the HelloXSLTCAP node.
The Output node under the test case node refers to the expected reply message that is used for comparison with the actual reply messages. Before we run the test for the first time, the Output.xml file is empty. We will populate it with the content of the reply message (provided that it is what we expect).
To run the test:
Right-click the JohnSmith node and select Run. Notice that the test fails and the following dialog box appears:
Click Yes. Notice that the failed test node appears below the Output node.
Double-click the failed test node to see the message that the XSL Transformation Service sent back: