SummaryThis tutorial explains how you can implement a Petals service with an annotated Java class, with a bottom-up approach.
|
Creating the Service-Unit project
Getting started
Start Petals Studio.
In the menu, select File > New > Service-Unit Project.
If you do not see it, go into File > New > Other... Then, select Service-Unit Project under the Petals category.
A wizard opens up, showing three drop-down lists.
In the Use Case list, select Manual Implementation.
In the Petals Component list, select Jsr-181 // petals-bc-jsr181.
In the Component Usage list, select Provide or Import a Service in Petals ESB.
In the Component Version list, select the version of the Petals-SE-Jsr181 that you are using in Petals.
In the scope of this tutorial, we are going to work with the version 1.1 of the Jsr181 component.
Which gives us:
Click Next.
Defining the project name
This page defines the name and the location of the project that will be created.
Indeed, this wizard will result in the creation of a project containing all the required elements for a Jsr181 service-unit.
Enter a project name for your project.
If you do not want your project to be created in the default workspace, uncheck Use default location.
Then click Browse... and select the location where the project will be created.
Petals service-units have a naming convention. For a service-unit which provides a service, the convention is su-<Protocol or Technology>-<Service name>-provide |
Then, click Next.
Specifying the creation mode
With the Jsr181 tooling, there are two approaches: a top-down one and a bottom-up one.
Since we want to start from a Java implementation, we will choose the bottom-up one.
Select the radio button Start with a Java implementation and provide the fully qualified name of a Java class.
A fully qualified name is made up of the package name (entirely in lower case) and the simple classe name (starts with an upper-case letter).
Click Next.
Specifying the CDK parameters
The CDK is the Petals framework to develop JBI components.
The Petals-SE-Jsr181 component was developed with this framework.
This page requires information related to the CDK.
By default, you have nothing to do here.
The meaning of all the CDK parameters for Jsr181 can be found in the documentation of the Petals-SE-Jsr181 component.
Click Finish to complete the wizard.
Checking the result
When the wizard has completed, a new project has been created and is visible in your workspace.
It contains a jbi.xml file, located under src/main/jbi.
This hierarchy allows you to work with Apache Maven then (a pom.xml was also created at the root of the project).
Notice that there is no other file in the directory. And the jbi.xml is marked with a warning, saying there is no WSDL file. This WSDL file will be generated once the Java implementation is complete.
And obviously, there is an annotated Java class, whose name is the one given in the wizard.
This class contains a base of definition, showing some of the available annotations.
Updating, packaging and deploying
Further edition and packaging
After completion, the service implementation has been open in the Java editor.
Add method declarations, implementations and annotations. The main class must be annotated with @WebService.
Other annotations are optional, but recommended to generate a WSDL that will ease the creation of clients (e.g. avoid arg0, arg1 as parameter names).
Once the Java implementation is complete, it is time to generate the associated WSDL.
To do that, right-click the project and select Petals > Generate WSDL(s).
A dialog shows up, asking whether a new jbi.xml should be generated.
Clicking No only generates WSDL definitions from the classes that are annotated with @WebService. The jbi.xml will have to be edited manually.
Clicking Yes will in addition generate a new jbi.xml that references the WSDL.
Be careful, all the WSDL definitions of the jbi directory will be deleted. And take note that the new jbi.xml will erase the previous one, thus loosing hand-made modifications. |
It is possible to define several @WebService annotated classes in a same project. When generating the WSDL(s), a WSDL will be created for each class. If a new jbi.xml is also generated, there will be one provides block per annotated class. |
The created project being a Service-Unit project, you can package it as any Service-Unit project.
It results in the creation of a Service Assembly for the Petals-SE-Jsr181 component. Its location depends on your export choices.
Deployment
The deployment of the created service assembly can be achieved with the Petals web console.
Or you can do it by dropping the service assembly in the install directory of your Petals installation.
This second option should only be used in development steps.
First, make sure the Petals-SE-Jsr181 is installed in your Petals environment.
Then, install the service assembly in your Petals, using one of the two ways indicated above.
There is no need to update configuration of the Jsr181 component to make it work.
Using the default settings is enough to make the service-unit work.