Tags

, , , , , ,

In this post I will explain a very useful feature of OSB which we call a Java class, I’ll show how to use the component called Java Callout for this feature..

As the idea is just to explain how to call Java code, I make a simple concatenation of names to exemplify our post.

In Eclipse create a Java Project named BlogUans, then add the package br.com.uanscarvalho and then create a class called LerNome and within one lendoNome method passing a string and returns a concatenation of “Hello” with the name as follows:

Imagem Blog UansCarvalho

Now right click on BlogUans and then the option Export …

Imagem Blog UansCarvalho

Then click the JAR file option and click Next> as follows:

Imagem Blog UansCarvalho

On the next screen click Browse .. then give the name for your JAR file and select the location where it will be saved and click Finish

Imagem Blog UansCarvalho

Now we have our BlogUans.jar file generated.

Now the OSB, below OSBProject create a folder named Lib and drag your file into this folder.

Imagem Blog UansCarvalho

Now click with the right button on your WSDL folder above (If you do not feel free to create or not the folder), click New and then File

Then give the name of your Java Filename as JavaCallout.wsdl and click Finish

Imagem Blog UansCarvalho

Copy now the content below into your WSDL file we created above.

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="JavaCallout"
 targetNamespace="http://xmlns.oracle.com/UansBlogApplication/JavaCallout/"
 xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
 xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
 xmlns:tns="http://xmlns.oracle.com/UansBlogApplication/JavaCallout/"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema">

 <wsdl:types>
 <xsd:schema targetNamespace="http://xmlns.oracle.com/UansBlogApplication/JavaCallout/"
 elementFormDefault="unqualified">
 
 
 <xsd:element name="obterNomeRequest">
 <xsd:complexType>
 <xsd:sequence>
 <xsd:element name="nome" type="xsd:string" minOccurs="1" maxOccurs="1"/> 
 </xsd:sequence>
 </xsd:complexType>
 </xsd:element>

 <xsd:element name="obterNomeResponse">
 <xsd:complexType>
 <xsd:sequence>
 <xsd:element name="mensagem" type="xsd:string" minOccurs="1" maxOccurs="1"/>
 </xsd:sequence>
 </xsd:complexType>
 </xsd:element>

 </xsd:schema>
 </wsdl:types>

 <wsdl:message name="obterNomeRequest">
 <wsdl:part name="parameters" element="tns:obterNomeRequest"/>
 </wsdl:message>
 <wsdl:message name="obterNomeResponse">
 <wsdl:part name="parameters" element="tns:obterNomeResponse"/>
 </wsdl:message>

 <wsdl:portType name="JavaCalloutPortType"> 
 <wsdl:operation name="obterNome">
 <wsdl:input message="tns:obterNomeRequest"/>
 <wsdl:output message="tns:obterNomeResponse"/>
 </wsdl:operation>
 </wsdl:portType>
 
 <wsdl:binding name="JavaCalloutBinding" type="tns:JavaCalloutPortType">
 <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
 
 <wsdl:operation name="obterNome">
 <soap:operation style="document" soapAction="obterNome"/>
 <wsdl:input>
 <soap:body use="literal"/>
 </wsdl:input>
 <wsdl:output>
 <soap:body use="literal"/>
 </wsdl:output>
 </wsdl:operation>
 
 </wsdl:binding>
 
 <wsdl:service name="JavaCallout">
 <wsdl:port name="JavaCalloutSoapPort" binding="tns:JavaCalloutBinding">
 <soap:address location="http://example.uanscarvalho.com.br/JavaCalloutProxy"/>
 </wsdl:port>
 </wsdl:service>
 
</wsdl:definitions>

This is the WSDL we use to create our Proxy

Note: Here there is nothing more, will only be a WSDL with an element in the Request and also returning a message in our Response

Now in its Proxy folder (If you do not feel free to create or not the folder) click the right button and click New, and then click Proxy Service

File Name name it JavaCalloutProxy and click Finish

Imagem Blog UansCarvalho

Now on the General tab click Browse in WSDL Web Service option and then click JavaCalloutSoapPort(port) as indicated below, then click OK

Imagem Blog UansCarvalho

Now the Message Flow tab drag an Operational Branch below JavaCalloutProxy as follows:

Imagem Blog UansCarvalho

Below the operation obterNome get drag Pipeline Pair

Imagem Blog UansCarvalho

Now drag a Stage below the Request Pipeline and rename it to stage_request and then drag another Stage below the Response Pipeline and rename it to stage_response.

Imagem Blog UansCarvalho

Now within your stage_request drag an Assign and below drag a Java Callout

Imagem Blog UansCarvalho

Then click the Assign first and variable in the Properties tab place name, and then click <Expression>

Imagem Blog UansCarvalho

In the box that opens expand the body that will be in Variable Structures on your right until you get the nome as below and drag to your left and then click OK

Imagem Blog UansCarvalho

Will be as follows:

Imagem Blog UansCarvalho

Now click on Java Callout box below and click Browse, then open a box where we select our BlogUans.jar, then click OK

Imagem Blog UansCarvalho

In the new box that opens click on our method as below and click OK

Imagem Blog UansCarvalho

Below click Expression: * and place the value data($nome) that will be our value Request to pass to the Java method, then Result Value set the value mensagem to be where we store our Response JAVA

Imagem Blog UansCarvalho

Now the stage_response drag a Replace and enter the following values:

  • XPath: .
  • In Variable: body
  • Expression:
    <jav:obterNomeResponse>
     <mensagem>{$mensagem}</mensagem>
    </jav:obterNomeResponse>
  • Replace node contents

Imagem Blog UansCarvalho

Save everything, and do Publish your Proxy

Go on sbconsole and run your JavaCalloutProxy passing UANS value in the request as follows:

Imagem Blog UansCarvalho

See below for the answer:

Olá UANS

Imagem Blog UansCarvalho

Doubts ? Leave your comment and download the Projet  :-)

 

Hugs and see you soon

/:-D