To illustrate the intended usage pattern of RestBC within GlassfishESB, we will use a simple use-case scneario. In this scenario, user wants to invoke Yahoo's Search API from within a BPEL orchestration to search for web results of a particular phrase of interest. So from CASA editor assembly view, the flow looks something like below diagram:
Like other binding components in GlassESB, we first need to define a WSDL definition for the Yahoo Search service that we want to invoke. This step currently does not have tooling support yet, so we just have to handwrite the WSDL file ourselves. The end result looks something like below:
Notice in the picture above that, this invocation is a request/reply pattern. Request and Response messages are defined by fixed XML schemas, Request.xsd and Response.xsd, respectively. Basically, these two XSD files models the Restful request and reply, and with NetBeans IDE tooling support later, these two XSD files will be automatically imported to the WSDL binding file whenever a Rest binding is selected.
There are also Rest binding information present in the WSDL file itself. The idea is that binding information can be present in both the WSDL file and the XML instance message on the NMR bus itself, and they could be redundant information, and the information in the XML instance message overrides whatever information is present in the WSDL file. This allows user to dynamically invoke Rest service without having to define everything in the WSDL file, but also allows the option to just use the infromation specified in WSDL binding (for the case where information does not need to change).
Let's see what information can be sent over the NMR bus as defined by the Request.xsd and Response.xsd.
Request.xsd:
Response.xsd:
Currently on the request side, we can specify things such as HTTP parameters, headers, content-types, entity, etc. And on the response side, we allow user to have access to response status, response headers, content-types, entity. Note: this is just a first draft of xsd, we will add more complete options to them later.
So after we have definied the WSDL file, next step is to import this WSDL into BPEL editor as a PartnerLink. In the below picture, we are constructing a Request using the BPEL mapper for the invocation of Yahoo Search API. Basically to make a Yahoo search request, you would have to supply an "appid" and "query" string as input to be encoded in the URL, so in the BPEL mapper, you would have to supply these to the "Param" element of the Request part. See diagram below:
After invocation is made and a response is returned back to BPEL control, we can access all the information from the Response XML object from the BPEL mapper, things such as status code, response header, entity body, etc. In this scenario, we simply are marshalling the Yahoo Search results entity body from a DOM to String object, and return it back. See below:
Now we are done, basically the above are the essential steps users have to go through to make a Rest request/response call. After this, user can basically build the CASA project, and deploy and test it. If you would like to try out the example described on this page, you can download the necessary component binary and NetBeans project at the bottom of this page.