keskiviikko 10. huhtikuuta 2013

Tutorial 1 part 32 - Calling external web service 2

Using the java program to launch external scripts
In a previous part of this tutorial we created an external service for launching scripts. We can make use of it.
You will need to copy the WSDL url from the WebLogic Console.
Open WebLogic console->Deployments-> press next until you see the service -> open it up by pressing the + sign next to the name->Click on the name->Select testing->Open again with + sign->select WSDL

 Click on the link “?WSDL” and copy the URL to clipboard.

Go back to composite.xml and drag and drop the web service adapter to the “External Service” lanes.
A dialog box will open. Copy the url from clipboard to the URL field there and press TAB once.

If you decided to copy wsdl to the project (see checkbox above) you will also see this:

Draw a line from GeoFenceEvent Handler to the newly added service.

Double-click the GeoFenceEventHandler process open. We are now ready to add last missing piece – invoking the external action scripts.
Add an invoke operation inside the while loop (before the IncrementLoopCounter assignment) and draw line from it to ScriptRunner (Note ScriptRunner may be on either side of the main area and you may need to scroll up to see it). A wizard with dialogs will open. Name the invoke and create local input and output variable.

We still need to prepare the input variable with right parameters.
Input parameter settings for variable argument web service.
Making this works is actually far above tutorial level, but I wanted to make the script wrapper a service that takes variable number of arguments and in this phase it is coming back to us.
First we need to check what type of service the jDeveloper has created for us. Go to WLS Console and browse to the deployed shellscriptwrapper service. Open up the test client. You will see that the parameters do not have any namespace.

This is one reason why we need to make an additional variable in our BPEL script and this variable needs to be a sequence of string elements where the elements do not have any namespace. As I said this goes quite far beyond tutorials and you may well work years before encountering issue like this.
So let’s fix this.
Create a new xml schema – I called mine internal.xsd
File->New->XML->XML schema

Make sure target namespace is empty.

Add an element – call it for example argHelper and add a sequence to it. Add element called arg to it. It is important that the arg element has exactly the same name as your variable number argument in the generated web service (shell script wrapper)

And now finally we are ready to add the assignment operation to the BPEL flow.

Add assignment operation before the invoke and open it. Rename it AssignScriptRunnerParameters or similar. Go to Copy Rules and open up the local variables and there the InvokeScriptRunner_Input variable and the parameters under it. You can see the needed parameters invoke parameters that need to be assigned with values that are fetched from the database.

Drag and drop function on top of the script parameter. A dialog will open.
First add the script parameter from InvokeGetActions_OuputVarible there. We will need to edit this later little bit to refer to the right row as indicated by the “i”-variable.

Edit the row to be:

The args bit is a little bit more complex as our service takes variable arguments.
First we need to create a helper variable using the helper element we created in the new xml schema. You can safely create this in the local scope so use the (x) icon to open up the variables wizard and press the +-button to start creating a new variable. Call it for example ArgTemp and make its type to be an element and assign the element definition from the xml schema internal.xsd.

Now we are ready to proceed with the actual assignments.

First assignment is easy. We will just copy the assetid from the input variable to the arg parameter in the InvokeScriptRunner_InputVariable. If you remember this represents the license plate of the car having left the geofence.

Next will be copying param1 and param2 from the InvokeGetActions to the arg variable length list.
First draw a line from the param1 to the ArgTemp variable.

Then open the left side and edit it to index by the i-iterator.

Next draw a line from the ArgTemp->arg variable to the InvokeSriptRunner_InputVariable.parameters. This creates a copy operation.

We need to change this to an append operation

You need to do the same for param2. First copy in to ArgHelper->arg, add indexing by i-iterator and then from ArgTemp->arg to InvokeSriptRunner_InputVariable.parameters.
That’s it for assignments. We can now invoke the external scrips and last but not least we need to prepare the output.

Ei kommentteja:

Lähetä kommentti