Saturday, December 15, 2012

OSB 11g - Call Asynchronous Web Service from OSB over http protocol

In my previous post, I explained how we can call Asynchronous web service from Oracle Service Bus using soa-direct protocol.  But in many scenario’s we need to invoke asynchronous web service from Oracle Service Bus using http protocol.

In this post I am going to explain how we can invoke Asynchronous web service (Async Composite) from Oracle Service Bus over http protocol and route the call back response from Asynchronous web service to another proxy service which in turn call another composite (Second Composite).

Call Async Composite
Call Asynchronous Composite
Follow below steps to invoke Asynchronous Composite from OSB.

Create an Asynchronous Composite. Name it “AsyncComposite” and deploy it on SOA server.
Create a new OSB project and add three folders to it.
          resources
          proxyServices
          businessServices
OSB Project
OSB Project
          Click on “resources” folder. Choose “XML Schema” from “Select Resource Type”, name it as “AsyncCompositeSchema” and add it to resources folder. Similar ways choose “WSDL” from “Select Resource Type”, name it as “AsyncCompositeWSDL” and add it to resources folder.
resources folder
resources folder
Now create business service to invoke Asynchronous Composite. To do this click on “businessServices” folder, choose “Business Service” from “Select Resource Type”, name it as “CallAsyncCompositeBS”.

Choose “WSDL Web Service” as “Service Type” and browse to above added WSDL file. Then select the port and submit it.
Async Business Service
BusinessService
        Accept defaults and save this business Service.
       
             Now create proxy service to invoke above created business service. To do this click on “proxyServices” folder, choose “Proxy Service” from “Select Resource Type”, name it as “CallAsyncCompositeProxy”.
       
      Choose “Business Service” as “Service Type” and browse to above created Business Service. Accept defaults and save this proxy service.
Proxy Service
Proxy Service

      Follow below steps to get response back from Asynchronous Composite.

      Create a synchronous or one-way composite, name it “SecondComposite” and deploy it to SOA server. You can create either synchronous or One-way as we created this composite to show that our call back proxy is working.

      Go to OSB project that we created above and click on “resources” folder. Add XSD and WSDL of SecondComposite to resources folder.
osb resources
resources folder
      Now create business service to invoke Synchronous Composite. To do this click on “businessServices” folder, choose “Business Service” from “Select Resource Type”, name it as “CallSyncCompositeBS”.

     Choose “WSDL Web Service” as “Service Type” and browse to above added WSDL file. Then select the port and submit it.

     Accept defaults and save this business Service.
   
     Now create proxy service to invoke above created business service. To do this click on “proxyServices” folder, choose “Proxy Service” from “Select Resource Type”, name it as “CallSyncCompositeProxy”.

Note down the “Endpoint URI “. In our case it is   “/CallAsyncService/proxyServices/CallSyncCompositeProxy”.
Endpoint URI
Endpoint URI

Now we will complete the sample. We will configure “CallAsyncCompositeProxy” to send the call back response from Asynchronous Composite to CallSyncCompositeProxy.

     Go to CallAsyncCompositeProxy and click on “Edit Message Flow”.
Osb Proxy Message Flow
Proxy Message Flow
     Right Click on route node and choose “Edit Route”.
Proxy Message Flow
Proxy Service Message Flow
      Add Assign activity to flow.
Assign Header
Assign Activity
Inside assign replace soap header to below one.
<soap-env:Header xmlns:ns1="http://schemas.xmlsoap.org/ws/2003/03/addressing">
        <ns1:MessageID>ws:uniqueAddress</ns1:MessageID>
        <ns1:ReplyTo>
        <ns1:Address>http://localhost:8011/CallAsyncService/proxyServices/CallSyncCompositeProxy</ns1:Address>
         </ns1:ReplyTo>
 </soap-env:Header>

Remember ReplyTo address refers to CallSyncCompositeProxy endpoints.
Change SOAP Header
SOAP Header
Edited Message Flow
Edited Message Flow
 Below are testing results
Test Console
Test Console
composite Instance
EM Console

Saturday, December 1, 2012

SOA 11g- How to move file from one location to other using File Adapter

We usually deal with files in our projects. We can perform multiple operations using file adapter like poll, read, write etc. But in some scenario we need to simply move file from one location to other without reading its content.
In this post I will explain how we can move file without reading its content using file adapter.
Follow below steps to move file from one directory to other directory.
  • Create a composite named “MoveFile” and create “One-Way” BPEL process.
One Way Bpel Process
One-Way BPEL Process

  • Drag & Drop File adapter from Component Palette to the External Reference swim lane. This will open adapter configuration wizard.
  • Enter Service name in Service Name field.  We named it “MoveFile” and click next.
  • Select Define from operation and schema (specified later), and click Next. The Operation page is displayed.
  • Synchronous Read File”.
Choose Sync Read Operation
Sync Read Operation

  • Enter a dummy physical path for the directory for incoming files, and then click next. We will assign this value at runtime.
Incoming File Path
Incoming File path

  • Enter a dummy file name, and then click next.
dummy file name
File Name

  • Select native format translation is not required (Schema is opaque), and then click Next. The Finish page is displayed.
Choose Native Format
Choose Schema

  • Open “MoveFile_file.jca” and modify the endpoint interaction.
          Earlier
<adapter-config name="MoveFile" adapter="File Adapter" wsdlLocation="MoveFile.wsdl" xmlns="http://platform.integration.oracle/blocks/adapter/fw/metadata">

   <connection-factory location="eis/FileAdapter"/>

  <endpoint-interaction portType="SynchRead_ptt" operation="SynchRead">

    <interaction-spec className="oracle.tip.adapter.file.outbound.FileReadInteractionSpec">

      <property name="DeleteFile" value="true"/>

      <property name="PhysicalDirectory" value="dummy"/>

      <property name="FileName" value="dummy"/>

    </interaction-spec>

  </endpoint-interaction>

</adapter-config>


   New
<adapter-config name="MoveFile" adapter="File Adapter"

                wsdlLocation="MoveFile.wsdl"

                xmlns="http://platform.integration.oracle/blocks/adapter/fw/metadata">

 <connection-factory location="eis/FileAdapter"/>

 <endpoint-interaction portType="SynchRead_ptt" operation="SynchRead">

    <interaction-spec className="oracle.tip.adapter.file.outbound.FileIoInteractionSpec">
   <property name="SourcePhysicalDirectory" value="SourceDirectory"/>

   <property name="SourceFileName" value="SourceFileName.txt"/>

   <property name="TargetPhysicalDirectory" value="TargetDirectory"/>

   <property name="TargetFileName" value="TragetFileName.txt"/>

   <property name="Type" value="MOVE"/>

  </interaction-spec>

 </endpoint-interaction>

</adapter-config>

File Adapter JCA File
Jca file
  • Now wire BPEL process to “MoveFile” file adapter.
wire bpel to adapter
BPEL Process

  • Open BPEL process, add one invoke activity and link it to MoveFile adapter.
Bpel Flow
BPEL Process Flow

  • Create 4 string variable with suitable name.
    <variable name="sourceDirectory" type="xsd:string"/>
    <variable name="sourceFileName" type="xsd:string"/>
    <variable name="targetDirectory" type="xsd:string"/>

    <variable name="targetFileName" type="xsd:string"/>
  • Populate above created string variables with required values.
Assign values
Assign Activity

  • Pass these parameters as headers to the invoke operation, for this open bpel process in source mode and add below 4 input Properties to invoke.
     <invoke name="Invoke_MoveFile"
            inputVariable="Invoke_MoveFile_SynchRead_InputVariable"
            outputVariable="Invoke_MoveFile_SynchRead_OutputVariable"
            partnerLink="MoveFile" portType="ns1:SynchRead_ptt"
            operation="SynchRead" bpelx:invokeAsDetail="no">
      <bpelx:inputProperty name="jca.file.SourceDirectory"
                           variable="sourceDirectory"/>
      <bpelx:inputProperty name="jca.file.SourceFileName"
                           variable="sourceFileName"/>
      <bpelx:inputProperty name="jca.file.TargetDirectory"
                           variable="targetDirectory"/>
      <bpelx:inputProperty name="jca.file.TargetFileName"
                           variable="targetFileName"/>

    </invoke>

  • Use below parameters for BPEL 2.0
     <bpelx:toProperties>
          <bpelx:toProperty name="jca.file.SourceDirectory"
                          variable="sourceDirectory"/>
        <bpelx:toProperty name="jca.file.SourceFileName"
                          variable="sourceFileName"/>
        <bpelx:toProperty name="jca.file.TargetDirectory"
                          variable="targetDirectory"/>
        <bpelx:toProperty name="jca.file.TargetFileName"
                          variable="targetFileName"/>
      </bpelx:toProperties>
  • Deploy the process and test it.