In this blog, we will review native REST service support added in 12.2.1. And you can refer to post to find information about same from 12.13 perspective.
Before discussing further, we will first see how 12.2.1 provides the backward compatibility with 12.1.3. In 12.1.3, REST Proxy Service converts native REST payload to SOAP before calling a Pipeline/Split-Join and REST Business Service convert SOAP to REST native payload i.e. the internal communication happen using WSDL interfaces only.
In 12.13, while creating REST binding as Proxy or Business service check the option as shown below and other steps remain same.
We can see WSDL and WADL gets created in your project.
To access REST resource use url like http://localhost:<<OSB Port>/<<proxy endpoint>>/<<resource name>> so it will be http://localhost:7003/restDemo/REST1213WayPS/employees
To access design-time WADL use url like http://localhost:<<OSB Port>/sbresource?WADL/<>/<> so it will be http://localhost:7003/sbresource?WADL/RESTIn1213way/WSDL/REST1213WayPS
To access effective WADL use url like http://localhost:<<OSB Port>/sbresource?(PROXY or BIZ)/<<project path>>/<<proxy or biz service name>> so it will be http://localhost:7003/sbresource?PROXY/RESTIn1213way/ProxyServices/REST1213WayPS
Now in 12.2.1, we have native REST support and no need of creating WSDL for internal communication. This native support is broadly classified into following categories:
- Un-typed Proxy/Business Service – For which method information is available at design time so no WADL is involved.
- Typed Proxy/Business Service – For which the method information is available at design time so WADL is used/created having this information.
REST binding can be used to create both Proxy and Business services that fall into above categories. In this post, we discuss from Proxy Service perspective and same can be followed for business services.
Creating Typed Proxy Service:
We use REST binding to create native REST service. So drag REST binding from Components to Proxy Services swim lane or right click to choose REST option.
Provide name for REST binding and do not select WSDL interfaces check box as we are creating native REST services. Click Next.
Create a new REST resource as shown below.
Create a REST method using following steps by clicking + icon in Methods.
Now verify that WADL file is generated automatically with method information as defined above. Now create pipeline using the following steps.
Connect Proxy Service, Pipeline and Business Service as shown below. Use the same business service as we used earlier.
Finish the message flow as shown below.
Deploy and test your project in Service Bus console. Observe that you can see all media types supported by REST service are shown in Accept choice list.
Now we will see how to use an existing WADL to create Typed REST services.
Again drag the REST binding from Components to Proxy Services swim lane or right click in swim lane to choose REST option.
Provide name for REST binding and do not select WSDL interfaces check box as we are creating native REST services. Click Next.
Choose REST1213WayPS.wadl. This confirms that WADLs generated by 1213 REST services are supported here. Observe that REST methods are populated automatically from selected WADL.
Click Finish and verify that new WADL is generated again for this Proxy Service.
Now finish pipeline message flow as above using WADL created in above step.
To access REST resource use url http://localhost:7003/restDemo/typedService/typedEmployees
To access design-time WADL use url http://localhost:7003/sbresource?WADL/RESTTypedServices/TypedRestService
To access effective WADL use url http://localhost:7003/sbresource?PROXY/RESTTypedServices/TypedRestService
Observations:
- WADL is always created for Typed native REST services when one is not chosen during creation.
- No where we are able to give the input/output message structure (XML or JSON schema) for REST methods. I think this may be improved in later releases.
- When a native REST Proxy Service supports multiple content types (XML, JSON), automatic payload conversion (XML to JSON and vice-versa) is not happening as we see in WSDL based REST services. I will try to cover more on this in later posts.
- Content-Type HTTP header is used by OSB for content parsing and we can see this set automatically when media type is chosen in test console.
- Value given for soa:name in WADL is populated for $operation context variable in pipeline.
- 1213 WADL is not supported for creating pipelines but can be used to create Proxy, however a new WADL will be generated by OSB as we saw above.
Creating Un-typed Proxy Service:
Create a Proxy Service using following steps. Observe the usage of Transport and no where we define REST resource or methods.
Create pipeline using following steps and observe that we are not selecting any WADL as we did earlier.
Connect all these pieces as shown below and complete Message Flow as we did earlier.
Deploy and test your project in Service Bus console. Observe that you can see all media types supported by REST service are shown in Media Type choice list as we have not specified supported types any where. Service Bus uses the Content-Type HTTP header for parsing the payload and you can see this is set automatically when we choose the media type in Test Console.
To access REST resource use url http://localhost:7003/restDemo/untypedService
Observations:
- No WADL is used during creation of Un-typed native REST services.
- Again, no where we are able to give the input/output message structure (XML or JSON schema) for REST methods.
- Again, no automatic payload conversion will happen when REST Proxy supports multiple Content Types.
- Content-Type HTTP header is used by OSB for content parsing and we can see this set automatically when media type is chosen in test console.
In above 2 sections, we created both Proxy and Pipeline separately and we can observe that WADL is optional for REST based pipelines. So even Pipelines are classified into Typed and Un-typed depending on usage of WADL.
So now the Q arises about compatibility between Proxy and Pipelines as both of them can be Typed /Un-Typed. Since Typed is more restrictive having REST methods we will be able to call both Un-Typed and Typed pipelines provided they used same WADL. In the same way, Un-Typed will be able to call both Un-typed and Typed Pipelines.
The source code used in this post can be downloaded from here and please note that you need to create DB connection pool to run this project with JNDI eis/DB/LocalDB.
Reference:
hi Siva,
Nice post Im new to OSB can you please help me in understanding how to convert SOAP Proxy to REST.Means procesdure.
Thanks In Advance
Siraj
Hi,
I am new to OSB 12c . Can any body help me .. I want to convert Text to XML. I have used nXSD and MFL translate but .. parameters values are not mapping with WSDL Target
Is XML conversion happening fine? Then you can do it 2 steps: first convert to XML which can be some intermediate XML and then convert this XML to wsdl target XML . This approach should work…..
Yes XML to text happening fine. In Response we have Text and again we have used nXSD translate from Native to XML having an XQuery resource….( in XQuery Parameter value is not mapping to Target XML.) Is there any tutorial or post regarding this …
typically mismatch can occur with targetnamespace and sequence of xml elements which you can verify..did not remember any post in this area..
Thank you very much Sir, We have used intermediate XML. but If there is any best solution regarding this then please let me know or please provide new example on your blog..
Removed intermediate xml . bcz issue was of namespace… it is done through mfl translate.. Still stuck at nXSD translate(issue highlighted in URI). https://community.oracle.com/message/14733258#14733258
Hello, I have a problem, when I make a request, I always get “The invocation resulted in an error: Invalid HTTP method: null.” this error. I have tried some of google’s apis but result is this again.
I’m just trying to test a Rest service first, soo it is just a business service right now.
Could you help me on this?
Did you just create business service using rest adapter and testing it? can you check rest methods usage in that. error is about invalid http method. If its’ correct, also check if the actual rest service supports that.
Hi All,
Regarding Media Type used in Rest Service using OSB:
I am trying to use Media Type as text/xml with POST verb in OSB, but it is giving me the error stating “media type text/xml is not supported in WADL”.
But in Oracle Document it is mentioned that text/xml is supported. Please let me know what needs to be done in this case.
could you try with application/xml
Hi Siva,
I am able to use application/xml as media type but my requirement is text/xml. Can you please check.
could you let me know why you are choosing text/xml?
Our source system is sending the request with mediaType as text/xml
Hi Siva, Can you revisit and make corrections, Hope you find what are the mistakes in flow explanation, i got so much confused but now able to correlate flow explanation. if needed let me know will tell what are the errors.
That will be help ful for quick changes and also for other readers..
Siva this is excellent post. It helped me with my first native REST in 12.2.
I wonder if you have an example of how to deal with errors returned by a plsql procedure. Currently when my POST fails due to any database error the http return code is still 200. I would like this to actually be showing a 500 or other error code.
are you making use of db adapter for using plsql?
Yes. Actually I’m using the Oracle E-Business Suite adapter but it works the same as just DB adapter.
My adapter calls stored procedure accepting bunch of parameters and outputting few others (including status – failed, success, duplicate). In all cases my http return code is always 200 which is kind of correct since the http call worked but I would like to force 409 or 500 in not success cases.
This adapter is exposed as REST API (POST) accepting parameters as needed by the plsql procedure.
Currently I do not have pipeline. Do I have to introduce the pipeline for this to work?
In that case, you need a pipeline, examine the status from pl/sql procedure and do raise error.
Hi Siva,
Any idea how this can be achieved in BPEL 12.2.1 -Orchestrate a set of RESTful state transitions (Hypermedia as the Engine of Application State (HATEOAS) approach).? Or implement HATEOAS approach for set of services using Oracle Service Bus 12.2.1. I have seen Oracle docs to use http link header but wondering how we can expose set of REST service using HATEOAS approach. Can you suggest an approach to provide a set of HATEOAS REST api over service bus? For ex: Employees{empid? provide the basic info on a particular employee with a self link on more information like Addresses etc. Hope you got it.
Hi John, I understand the HATEOAS approach you are talking about. Frankly, i never gave a thought about it from OSB perspective. I used ADF BC REST services recently where this kind of support is built-in.
Excellent explanation. Thanks Siva.
I am trying to access a rest java project which returns XML file, now I want to convert the response to JSON format. Coudl you please advice how the rest proxy binding need to be done for this, I need to pass the query parameters by using http GET method. I did the rest binding on the business service but I am gettign the 406 error from the business service, where it would be wrong?
406 error indicates not understood by server. how are you giving the query parameters and are you using native REST ?