The list below comprises the subjects covered in this topic:
In this tutorial you become acquainted with the XSLT Service Designer, which is part of the OpenESB software package. 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 a client, transforms them, 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.
This tutorial assumes that you have some basic knowledge of, or programming experience with, the NetBeans IDE, and some experience with XSLT.
This tutorial assumes that your system meets the following minimum requirements:
To run this tutorial, download and install the following software:
Latest GlassFish ESB build
Because the OpenESB project is currently in active development, there may be minor inconsistencies between later builds and this tutorial. If you have any corrections or updates, please send them to us through the OpenESB Documentation Feedback Form
Perform the following steps to confirm that GlassFish V2 Application Server is installed and that the JBI runtime contains the XSLT Service Engine and Transform Shared 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, that means the server is already running.
After the server is started, expand the GlassFish V2 > JBI node. Then expand the Shared Libraries node to verify that sun-wsdl-ext-library is installed.
An XSL Transformation Service is created within an XSLT Module project.
From the IDE's main menu, choose File > New Project.
Under Categories select SOA.
Under Projects, select XSLT Module.
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.
Expand the HelloXSLTransformation > Transformation Files node. Note that the transformmap.xml file was created, which is a custom configuration file used to define transformation processes.
In the next steps 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.
In this step you are going to create two XML Schema filea: HelloXSLTIncoming.xsd as a basis for the incoming message, and HelloXSLTOutgoing.xsd as a basis 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 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, and 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:
<?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://xml.netbeans.org/schema/HelloXSLTIncoming" xmlns:tns="http://xml.netbeans.org/schema/HelloXSLTIncoming" elementFormDefault="qualified"> <xsd:element name="name" type="xsd:string"></xsd:element> </xsd:schema> |
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, select string and 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:
<?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://xml.netbeans.org/schema/HelloXSLTOutgoing" xmlns:tns="http://xml.netbeans.org/schema/HelloXSLTOutgoing" elementFormDefault="qualified"> <xsd:element name="greeting" type="xsd:string"></xsd:element> </xsd:schema> |
Click the Save All button on the toolbar.
You should see two Schema files listed under the Transformation Files node in your HelloXSLTransformation project.
In this step you create a web service description file that defines the web interface of our XSLT Service.
In the Projects window, right-click the HelloXSLTransformation > Transformation Files node and choose New > WSDL Document.
In the File Name field, type HelloXSLTWSDL.
Select Concrete WSDL Document as the WSDL type.
Select SOAP from the Binding drop-down list, and Document Literal from the Type drop-down list, then click Next.
The Abstract Configuration window will open. Under Input, in the Element Or Type column, click the ellipsis (...) button. The Select Element Or Type dialog box opens.
Scroll up and select By File > HelloXSLTransformation > src/HelloXSLTIncoming.xsd > Elements > name and click OK.
Under Output, in the Element Or Type column, click the ellipsis (...) button. The Select Element Or Type dialog box opens.
Select By File > HelloXSLTransformation > src/HelloXSLTOutgoing.xsd > Elements > greeting and click OK.
Click Next.
On the Concrete Configuration page review the values and click Finish. You should see the HelloXSLTWSDL.wsdl file listed under the Transformation Files node in your HelloXSLTransformation project.
Creating and editing WSDL files is not covered in this tutorial. For detailed information on the WSDL Editor in the NetBeans IDE, see Developer Guide to the WSDL Editor.
In this step, you will create a simple request-reply XSLT service, which is a web service that receives input messages, transforms them in accordance with an XSL stylesheet, and sends them back.
In the Projects window, right-click the HelloXSLTransformation > Transformation Files node and choose New > XSLT Service.
In the Service Type window, ensure that the Request-Reply Service radio button is selected and click Next.
In the next step, enter HelloXSLTServiceas the service name and click Choose to select Operation for the service.
In the TransformMap Service Parameters window, expand the upper node with the target namespace until you see the operation, select HelloXSLTWSDLOperation and click Next.
Click Finish. The HelloXSLTService.xslfile opens in the XSLT Editor, where you can only view and edit the source code.
Now you need to populate the XSL stylesheet with the transformation rules. The XSL stylesheet defines how to transform the input XML document. In this version of the XSLT Designer, you can only edit the source code in the Source view.
Open the HelloXSLTService.xslfile and type in the following code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.
xmlns:ns1="http://xml.netbeans.org/schema/HelloXSLTIncoming
xmlns:ns="http://xml.netbeans.org/schema/HelloXSLTOutgoing"
<xsl:template match="/">
<xsl:element name="ns:greeting">
<xsl:value-of select="concat('Hello ', /ns1:name)"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Press the Validate File () button on the toolbar to ensure that the code
has no errors.
Right-click the HelloXSLTransformationnode and choose Clean and Build from the drop-down menu to build the project. You should see the BUILD SUCCESSFULmessage after building the project completes.
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 as a JBI service unit. After deployment, you will be able to perform a test run of your XSLT service.
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.
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.
In the Projects window, right-click the HelloXSLTCAP node and choose Deploy Project from the pop-up menu. This operation might take a while because the GlassFish V2 Application Server starts.
Note: If the Warning - Select Server dialog box appears, select Sun Java System Application Server 9 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 Sun Java System Application Server 9 > JBI > Service Assemblies in the Runtime window. You should see the HelloXSLTCAP node.
Testing an XSL Transformation Service means sending a message that the Service is expecting and receiving, in this case, a reply message.
Before we can perform the testing, we must create a test case.
In the Projects window, expand the HelloXSLTCAP node and right-click the Test node.
From the pop-up menu, select New Test Case.
In the Test Case Name field, type JohnSmith. Click Next.
Under Select the WSDL Document, expand HelloXSLTransformation - XSLT Process Files and select HelloXSLTWSDL.wsdl. Click Next.
Under Select the Operation to Test, expand HelloXSLTWSDLBinding and select HelloXSLTWSDLOperation. Click Finish.
The JohnSmith node appears under HelloXSLTCAP > Test and the input message file—Input.xml —opens in the editor.
In the Input.xml, modify the
<hel:name>?string?</hel:name> |
line to
<hel:name>John Smith</hel:name> |
The Input.xml file should be:
<soapenv:Envelope xsi:schemaLocation= "http://schemas.xmlsoap.org/soap/envelope/ http://schemas.xmlsoap.org/ soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv= "http://schemas.xmlsoap.org/soap/envelope/" xmlns:hel="http://xml.netbeans.org/schema/HelloXSLTIncoming"> <soapenv:Body> <hel:name>John Smith</hel:name> </soapenv:Body> </soapenv:Envelope> |
Click the Save All button on the toolbar.
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. The first test run will populate Output.xml with the real output. Subsequent test runs will compare the real output against the content of Output.xml
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:
<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/ XMLSchema-instance" xsi:schemaLocation="http://schemas.xmlsoap.org/soap/envelope/ http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://xml.netbeans.org/ schema/HelloXSLTOutgoing"> <SOAP-ENV:Header/> <SOAP-ENV:Body> <ns:greeting xmlns:ns="http://xml.netbeans.org/schema/ HelloXSLTOutgoing">Hello John Smith</ns:greeting> </SOAP-ENV:Body> </SOAP-ENV:Envelope> |
Notice the line
<ns:greeting xmlns:ns="http://xml.netbeans.org/schema/HelloXSLTOutgoing">Hello John Smith</ns:greeting> |
The XSL Transformation Service received the name, concatenated it with the string 'Hello' and sent the reply message.
Run the test again. The test is marked as passed.
You have successfully created, deployed and tested an XSL Transformation Service.
Now that you have successfully created the Request-Reply XSL Transformation Service, continue with the Service Bridge type.