In previous post, we are introduced to native REST services (Typed and Un-typed) support in 12.2.1. But we can observe following issues there:
- We used only GET method for demonstration and typically this would not be the case as REST service can also support other HTTP methods (POST, PUT and DELETE).
- No branching in Typed REST Services when multiple HTTP methods are supported.
- No branching in Un-Typed REST Services when multiple HTTP methods are supported.
In this post, we will try to cover above aspects. Note that all of this discussion is related to native REST services unless stated otherwise.
Branching in Typed REST Services:
Add POST method support for typedEmployees resource as shown below.
Since Typed REST Service uses WADL and contains Operation name annotated with soa:name, we can simply make use of Operational Branch.
You can use URL like below to access REST Service.
http://localhost:7003/restDemo/typedService/typedEmployees
Branching in Un-Typed REST Services:
Since Un-Typed REST services does not use WADL, we can’t use Operational Branch as above. So in this release, OSB introduced a new node called REST Branch for this purpose.
Add REST Branch in pipeline by dragging it from Components.
For each REST branch, give supported Media Types, Resource Path and HTTP method mandatorily.
Use + icon to add media types and give other information as shown below. This means we are creating a REST resource called untypedEmployees which supports GET and supported media types are application/xml, application/ json.
Modify REST branch name in General section of Properties. We can add more branches using highlighted icon below.
We can add POST method support for same resource path as shown below.
Test Proxy as shown below. Note that we had specified required parameters in HTTP headers.
You can use URL like below to access this REST Service and make sure that Content-Type is passed without fail.
http://localhost:7003/restDemo/untypedService/untypedEmployees
Observations:
- OSB parses payload based on HTTP header Content-Type in request. We can Use Log activity to see $body contents. Refer to this post to enable logging.
- When Content-Type is application/xml, $body is logged as below.
PostPipelinePair, request-ab047b9.N47e0f03.0.15591b0ca2c.N7d1d, Stage1, REQUEST] CreateEmployeeLog: <soapenv:Body xmlns:soapenv="http://schemas. xmlsoap.org/soap/envelope/">[[<a><b>1233333</b></a></soapenv:Body>]]
- When Content-Type is application/json, $body is logged as below.
[PostPipelinePair, request-ab047b9.N47e0f03.0.15591b0ca2c.N7d1d, Stage1, REQUEST] CreateEmployeeLog: <soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/ soap/envelope/">{"a":1234,"b":3455}</soapenv:Body>
- OSB binds a globally-scoped object called process and can be used as process.body or process.var which is similar to $body and $xyz XPath variables. This notation is used for Java Script expressions. Use Log activity as below in Java Script expressions to verify the same.
- When Content-Type is application/xml, process.body is logged as below
[PostPipelinePair, request-ab047b9.N47e0f03.0.15591b0ca2c.N7d1d, Stage1, REQUEST] CreateEmployeeLog: <a>[[<b>1233333</b></a>]]
- When Content-Type is application/json, process.body is logged as below
[PostPipelinePair, request-ab047b9.N47e0f03.0.15591b0ca2c.N7d1d, Stage1, REQUEST] CreateEmployeeLog: {"a":1234,"b":3455}
- Though REST service supports JSON/XML payload, there is no automatic conversion takes place at runtime and to be done programmatically in native REST services.
- When using End-to-End XML, use XQuery/XSLT for transformation.
- When using End-to-End JSON, use Java script for transformation.
References:
Greatt read
Hi thanks for sharing..
I have a doubt. At this case, I can use the result of the first method/branch to enrich the second branch/method?
For exemple: I need call oauth endpoint and save the access token and call other rest endpoint.
Can I use this aproach?
Thanks a lot.
Hi, svgonugu. I am trying to make rest service from a database reference (calling a procedure with parameters). I need to set the default value for the proxy service of rest service. Do you know how to configure the default value? I try by setting the default value in the xsd of proxy service but it doesn’t work. I also try to replace the body in request of pipeline and it doesn’t work either. I get the same error saying the procedure needs the parameters. So do you know how to configure the default value for rest service of proxy services? I really need your help. Please. Thank you.
Hi,
We are using version 12.1.3 , but I dont see REST branch option in that . Could you suggest if it is possible to implement the same using a normal branching activity? I am unable to get the results as expected.
in 12.1.3 its only operation branch which can be used. because inside OSB its all WSDL and XML. we have this support only from 12.2.1
Where can i find OSB from the beginnig? I’m new to OSB.
Documentation link: https://docs.oracle.com/en/middleware/fusion-middleware/index.html
11g Tutorial: https://wp.me/pEWnt-f1
12c tutorial: https://wp.me/pEWnt-hL
Thanks a lot!
Halo svgonugu. I have downloaded 12c tutorial above. Do you have tutorial on how to create the wsdl that used in the tutorial? Because I can not test the tutorial if I dont have the wsdl project before. Thank you.
you want the wsdl used for tutorial? or tutorial on how to create wsdl. if its later, i don’t have one to share.
thanks for the reply. Yes, I need the tutorial on how to make the wsdl. Anyway, thank you so much for your 12c tutorial. It really helps a lot.