View Source

{section}
{column}

h1. Summary

This tutorial explains how you can implement a Petals service with an annotated Java class, with a top-down approach.
Unlike services that are only configured or proxyfied in Petals, such a service is literally executed in the bus.
The approach presented here aims at creating a Java implementation from a WSDL definition.

\\
Technically, this tutorial shows the creation of a service-unit for the [Petals-SE-Jsr181|petalscomponents:Petals-SE-Jsr181] component in *provides* mode.

{info}
*Level:* Easy
*Estimated time:* 10 minutes
*Expected skills:* develop in Java
{info}
{column}
{column:width=350px}
{panel:title=Table of contents}{toc}{panel}
{column}
{section}

h1. Creating the Service-Unit project

h2. Getting started

Start Petals Studio.
In the menu, select *File > New > Petals Service Provider*.
If you do not see it, go into *File > New > Other...* Then, select *Petals Service Provider* 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-se-jsr181*.
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.2 of the Jsr181 component.
Which gives us:

!petals-studio-tuto-jsr181-1.jpg!

\\
Click *Next*.

h2. 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-studio-tuto-jsr181-2.jpg!

!petals-studio-tuto-jsr181-3.jpg!

\\
{note}
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*
{note}

\\
Then, click *Next*.


h2. 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 WSDL, we will choose the top-down one.
Select the radio button *Start with a WSDL definition* and provide the URL of the WSDL definition.
If it is stored on the local file disk, you can click *Browse...* to select it with a file dialog.

\\ !petals-studio-tuto-jsr181-wsdl-1.jpg!

\\
Click *Finish* to complete the wizard.


h2. 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).
In the same directory, you can see the WSDL interface you provided in the wizard. It was imported with all its dependencies (e.g. referenced XML schemas or other WSDL interfaces).
And there are annotated Java classes that were generated from the WSDL.

\\
!petals-studio-tuto-jsr181-wsdl-2.jpg!

h1. Updating, packaging and deploying

h2. Further edition and packaging

After completion, the service implementation has been open in the Java editor.
Complete the method implementations (it is basic Java development).

!petals-studio-tuto-jsr181-wsdl-3.jpg!

\\
Then, you can directly package the project.
The generated jbi.xml was already complete.
However, it is *possible (but not required)* to update the WSDL and create a new complete jbi.xml.
To do that, right-click the project and select *Petals > Generate WSDL(s)*.

\\
!petals-studio-tuto-jsr181-wsdl-4.jpg!

\\
A dialog appears to ask you whether a new jbi.xml should be generated too.
Clicking *No* only generates WSDL definitions from the classes that are annotated with _@WebService_.
Clicking *Yes* will in addition generate a new jbi.xml.

!petals-studio-tuto-jsr181-5.jpg!

\\
{info}
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.
{info}

\\
The created project being a [Service-Unit project|Working with Service Unit projects], you can [package it as any Service-Unit project|Working with Service Unit projects#Export for Petals].
It results in the creation of a Service Assembly for the Petals-SE-Jsr181 component. Its location depends on your export choices.

h2. 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.