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.

12 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
  4. Hi,
    I wanted to know, can we have payload type as JSON while exposing BPEL process as RESTful service?

    ReplyDelete
  5. Hi Satya..

    Here is my issue. Im invoking a Proxyservice(Messaging Service) using Http-Binding.
    In SOA composite invoke, It is adding the namespaces to the payload. This causing the issue. And if im passing the same payload without namespaces then its working fine.

    Non Recoverable System Fault :
    faultName: {{http://schemas.oracle.com/bpel/extension}remoteFault} messageType: {{http://schemas.oracle.com/bpel/extension}RuntimeFaultMessage} parts: {{ summary=oracle.fabric.common.FabricInvocationException: Unable to access the following endpoint(s): REPLACE_WITH_ACTUAL_URL ,detail=Unable to access the following endpoint(s): REPLACE_WITH_ACTUAL_URL ,}

    Best Regards,
    Ranganath.

    ReplyDelete
  6. Hi Sathya,

    When I run your code, it works fine. But when I am developing the same code. I am getting below error. I have compared the adf-config.xml

    On the same server, your code is working fine.
    The code that I developed, is deploying without any issues, but when I check the flow instance, i can see that it is erring out with below error message.

    Your thoughts would be highly appreciated.

    Error Message
    =============


    Case "CallRest.Request-Response" processing started


    Evaluation of xpath condition "No Filter" resulted true


    Transformed message part "Input" using "../Transformations/opaqueElement_To_Input1.xsl"


    Error during invoking 2-way operation "Request-Response" on target service "CallRest"
    oracle.fabric.common.FabricException: Error in getting XML input stream: oramds:/deployed-composites/default/InvokeRest_rev1.0/CallRest.wsdl: oracle.mds.core.MetadataNotFoundException: MDS-00013: no metadata found for metadata object "/deployed-composites/default/InvokeRest_rev1.0/CallRest.wsdl"
    MDS-00201: PDocument not found in MetadataStore : [store-type=FileMetadataStore app-name=soa-infra repository-name=mds-soa partition-name=soa-infra] : Error in getting XML input stream: oramds:/deployed-composites/default/InvokeRest_rev1.0/CallRest.wsdl: oracle.mds.core.MetadataNotFoundException: MDS-00013: no metadata found for metadata object "/deployed-composites/default/InvokeRest_rev1.0/CallRest.wsdl"
    MDS-00201: PDocument not found in MetadataStore : [store-type=FileMetadataStore app-name=soa-infra repository-name=mds-soa partition-name=soa-infra]


    ReplyDelete