Friday, November 22, 2013

Oracle SOA 11g HTTP POST Send/Receive (with example)

In this post let us see how to send and consume HTTP POST request using SOA 11g.

Sample attached with this post will send a file in base64encoded format as a HTTP POST request and the same will be consumed by another BPEL process which is exposed to consume the file in HTTP protocol.

We will use the following XML schema (XSD) to build our HTTP POST service;
Exposing a SOA 11g BPEL process as a HTTP service (POST):

Step 1: Create a SOA Project with empty composite and name it "HttpPostRestService"

Step 2: Drag and Drop a HTTP Binding adapter on the "Exposed Services" swimlane in the SOA composite (SCA)

Step 3: Choose Next in the Welcome page of the wizard


Step 4: Enter service name

Step 5: Choose "Define from operation and schema (specified later)" option

Step 6: Choose the following options and click Next

Type: Service [You will choose "Reference" if you need to consume a HTTP REST service]
Operation Type: Request-Response [For 2-way communication. Choose One-way if the service doesn't return a response]
Operation Name: Defaults to Request-Response [You can change it as you please]
Verb: POST [This specifies the HTTP method. You have 2 options GET/POST]
Payload Type: XML [For HTTP POST, you get 2 options url-encoded and XML. Since our payload will be huge, url-encoded will not make sense due to size restrictions]


Step 7: In the Messages dialog, select the RestPost.xsd, <Input> and <Response> XML elements for "Request Message Schema" & "Response Message Schema" respectively.

Step 8: In the summary page, click "Finish" to complete service

Now that we have completed the HTTP binding service adapter which will expose the SOA 11g BPEL process as a HTTP service, you can choose to build a BPEL process which will consume the POST message for further processing.

Deploy the completed process and obtain the HTTP service URL from EM console. We will invoke this service from another SOA composite.

Consuming a HTTP (POST) service in SOA 11g BPEL process:

Step 1: Create a SOA Project with empty composite and name it "InvokeHttpPostService"

Step 2: Drag and Drop a HTTP Binding adapter on to the "External References" swimlane in the SOA composite (SCA)

Step 3: Choose Next in the Welcome page of the wizard


Step 4: Enter service name

Step 5: Choose "Define from operation and schema (specified later)" option

Step 6: Choose the following options and click Next

Type: Reference [Since we are consuming a HTTP service - POST]
Operation Type: Request-Response [Default selection for references]
Operation Name: Request-Response [Default]
Verb: POST [This specifies the HTTP method that will be invoked]
Payload Type: XML
Endpoint: Provide the HTTP URL for the REST service to be invoked.


Step 7: In the Messages dialog, select the RestPost.xsd, <Input> and <Response> XML elements for "Request Message Schema" & "Response Message Schema" respectively.

Step 8: In the summary screen, click Finish to complete the service adapter

Now, build and complete your SOA composite which will invoke a HTTP service using POST method.

Source code can be downloaded here

Let me know your thoughts in comments section.

9 comments:

  1. Thanks for the guide! I'm trying to work through it right now. I was wondering where you defined your message schemas in step 7?

    ReplyDelete
    Replies
    1. Hi Stephen,

      It was the first step in this post where I describe the XSD used. Also source code link is provided in the post if you want to take a sneak peek. Hope that helps.

      Delete
    2. Hi

      I have downloaded the source code and trying to run "PostRestService". What is the input I need to pass while testing the web service ?

      I see that you have used file adapater and provided a file naming convention ..can you explain the use of it.

      Thanks

      Delete
    3. Farooq,

      The input is a image file in this example. There are two BPEL projects where one reads an image file and calls a REST (POST) service. The rest service will inturn write the image file using the file adapter. Hope that helps. I just wanted to complicate the use-case by passing a binary object in this example. Hope that helps.

      Delete
  2. Hi Sathya, I followed your blog and implemented similar way, tried invoking HtttpAdapter from BPEL, I see the below error when invoking the service:

    oracle.fabric.common.FabricException: Error in getting XML input stream: oramds:/deployed-composites/default/CIGA_CC_ISO_REQ_INTERFACE_rev1.0/CCHttpService.wsdl: oracle.mds.exception.MDSException: MDS-00054: The file to be loaded oramds:/deployed-composites/default/ISO_REQ_INTERFACE_rev1.0/CCHttpService.wsdl does not exist.: Error in getting XML input stream: oramds:/deployed-composites/default/ISO_REQ_INTERFACE_rev1.0/CCHttpService.wsdl: oracle.mds.exception.MDSException: MDS-00054: The file to be loaded oramds:/deployed-composites/default/CIGA_CC_ISO_REQ_INTERFACE_rev1.0/CCHttpService.wsdl does not exist.

    wsdl file exist in the project and if it does not exist, i will not be able to compile & deploy the project.
    Could you please share your thoughts on this?

    ReplyDelete
    Replies
    1. Hi Ravindranath,

      Are you getting this during deploy time or run-time? In any case, the error tells me that the deployer/container is not able to reference the WSDL from MDS. Check your adf-config.xml and update the MDS store connection settings..

      Delete
  3. Hi Sathya,

    Very useful information and it worked well with your code attached. I have a requirement to use some of the key values from File. For example number of rows, Headers i can get those info only if i get to see the values in File.

    Since we are not defining XSD and its Opaque Schema how can i get those values and at the same time i have to pass the xml over Http as input stream.

    Can i 1st convert the file to xml instead of opaque schema, if i did that then how can conver the xml back to opaque schema to pass it over http service.

    Do you have suggestions for this scenario?

    Regards
    Renganathan

    ReplyDelete
    Replies
    1. In File Adapter, you can either define payload as opaque - in which case you can't read the file contents, or define an nxsd schema. You can define nxsd only in case of positional/delimited flat files (structured). Once you define nxsd, File adapter will translate your file to xml and vice versa. Look at file adapter in SOA documentation for details.

      Delete
    2. Hi Sathya,

      Thanks for your reply.

      I have below requirements

      1. to count the number of rows in the file so i have to use XSD to idenify the data. -

      2. Have to send the file over http , in order to do that have to convert the file into input stream in that case i need to go for Opaque schema.

      How do i achieve this together in SOA 11g. I read a blog where in 12c they have a translator activity to transfer the xml to opque & vice versa.

      Is it possible to do this in 11g also ???

      Also does does the HTTP adapter accepts only base64 encoding or any other input stream can also be passed.

      Regards
      Renga

      Delete