Soa 12.2.1 New Feature – End to End JSON and Javascript Example

SOA 12.2.1 provides support for end-to-end JSON and Javascript. We don’t have do internal mapping between XML and JSON as in 12.1.3.

As part of this post, let us implement a simple REST service to demonstrate this new feature – End to End JSON with Javascript.

Let us create a very simple SOA Composite which exposes a JSON based REST interface, manipulates the values using Javascript and calls an external JSON based service.

 

End to End JSON with Javascript
Rest Service

External JSON Service Setup

For external JSON based REST service let us use a  dummy JSON Server.

Start Json Server
Start Json Server

Content of db.json file.

{
 "posts": [
 {
 "id": 1,
 "title": "SOA Composite Sensor",
 "author": "Krishna Hanumantharao"
 },
 {
 "title": "OSB Result Cache",
 "author": "Girish Patel",
 "id": 2
 }
 ],
 "comments": [
 {
 "id": 1,
 "body": "some comment",
 "postId": 1
 }
 ],
 "profile": {
 "name": "Krishna"
 }
 }

Result of get query from the REST service

Output from REST GET Query
Output from REST GET Query

Create Reference

With the dummy REST service setup, let us create SOA Application and create a reference to external REST service. Drag and drop a “REST” adapter to reference section.

Create External Reference
Create External Reference

Configure Resources

Create Resource
Create Resource

Create Method Reference with highlighted values for GET. Specify parameter name as “id”.

Create Method Reference for Get
Create Method Reference for Get

Create Method Reference with highlighted values for POST.

Create Method for Post
Create Method Reference for Post

Screen with configured details. Click “Finish” to create the reference.

Reference Configuration
Resources Configuration

Create Service Entry

Drag and drop a “REST” adapter to service section. Configure to have following values.

While doing  GET method configuration, create  a “parameter” with name “id”.

Service Entry Configuration
Service Entry Configuration

Create BPEL Component

Drag and drop a BPEL component and configure with highlighted value.

Create BPEL Component
Create BPEL Component

click on plus sign to add REST methods. Add both the methods available in service entry wadl.

BPEL Interface Get metho
BPEL Interface getPost  method
BPEL Interface REST Methods
BPEL Interface Methods

Wire the BPEL component to External reference. As we have two methods, created BPEL component will have pick activity.

BPEL Pick Activity
Created BPEL

Create five variables.

Create Variables
Create Variables

Click on OnMessage in “getPost” branch. Copy the user passed value, available in “rest.query.id” to “id” variable.

rest.query.id -> variable defined during creation of REST service entry interface.

Capture Input Value
Capture Input Value

Add an Invoke activity in each branch. Configure Invoke for “getPost” interface

Configure Get Input
Configure Get Input

As part of configuration, pass the value passed by user, stored in “id” var  to “rest.query.id” variable.

Set value for REST Query Param
Set value for REST Query Param

rest.query.id ->variable defined during creation of external REST service reference

Add a assign activity after the invoke. Output of external REST service will be available in GET_OP variable. Copy the value to Output variable of our REST Service.

Assign Output
Assign Output

This completes the “GET” branch.

 

Similarly configure Invoke for “doPost” interface

Configure Post Input
Configure Post Input

For “POST”, let us define the input of our REST service to be the following. Here name is split into firstname and lastname. We will concatenate and pass it as single name to the external REST Service.

{
id: 3,
firstname: "Ken",
lastname: "Ben",
title: "Introduction to Coherence"
}

Add an assign activity below receive . Add copy rules to copy

id -> id

concat(firstname, lastname) -> author

title ->title

Set Variables for POST - REST Query
Set Variables for POST

That completes POST branch.

Now, let us deploy and test it.

Test GET interface

Give the value of “1” or “2”. We should get details of record for that id in JSON format.

REST Get Results
REST Get Results

Test POST interface

Let us give following value. POST will add a new record .

{
"id": 3,
"firstname": "Ken",
"lastname": "Ben",
"title": "Introduction to Coherence"
}

After testing with the above input ,verify the result by invoking “GET” to see the newly added record

End to End JSON with Javascript
Newly Added Record

This completes the creation and testing  of a very simple SOA Composite which exposes a JSON based REST interface, manipulates the values using Javascript and calls an external JSON based service.

Please refer “Using Javascript and JSON in BPEL Component” for more information on using Javascript.

 

 

34 thoughts on “Soa 12.2.1 New Feature – End to End JSON and Javascript Example

  1. hey can you tell where are you defining the input for the POST that json you mentioned, where exactly in the composite we have to put it?

    1. Do you mean the following POST input?.

      {
      id: 3,
      firstname: “Ken”,
      lastname: “Ben”,
      title: “Introduction to Coherence”
      }

      It doesn’t need to be defined in the composite. As we have defined the input and output parameters to be JSON object, we can pass any valid JSON object. The above JSON needs to be used while testing.

      1. but when you are making assignments, it has to be somewhere in receive and response from where i can make the mappings.

        like you are making assignments doPost_InputVar.id with Post_IP.id in the picture above how can i have the elements pf id, full name etc without specifying the input json.

        1. I am not sure whether you are asking where specifically, “id”, “first name”, etc are defined.
          Unlike XML, we are not using a JSON schema which defines all the elements. When you create a service entity, you will see variables of type JSON object are created.

          In this case , for POST, a variable called RestSvc_doPost_InputVar , of type JSON Object is created. In this blog, we are making an assumption that Input JSON will have fields like “id”, “firstname”, “lastname” etc and we accordingly access those inside bpel as process.RestSvc_doPost_Inputvar.id , process.RestSvc_doPost_Inputvar.fullname,etc.

          The external rest service, has fields like id, author and title as part of the JSON object. There is no specific definition for id, author, title inside soa composite. We set values to those using the Post_IP.id, Post_IP.author, etc.

          Unfortunately , I dont have the sample project. Try creating the project and if you get an error , send me the project.

          1. hi thanks for the reply,
            I am not getting an error, but my issue is i am creating a POST request and i want to specify few child elements for it using JSON, so how can i specify them, like you specified id fname, lname etc.

          2. You can define your own JSON object with field you like. For example, this is another JSON with different fields.

            {
            BookId: 3,
            AuthorName: “Ken”,
            AuthorLastName: “Ben”,
            BookTitle: “Introduction to Coherence”,
            AnotherField: “someValue”,
            YetAnotherField: “somevalue”

            }
            While Testing, assuming the above will be passed as input to your service, you can access the passed JSON object in assign activity like
            process.RestSvc_doPost_Inputvar.BookId
            process.RestSvc_doPost_Inputvar.AuthorName
            process.RestSvc_doPost_Inputvar.AnotherField
            process.RestSvc_doPost_Inputvar.YetAnotherField

            Hope this helps.

  2. Hi Krishna,

    I have a question on rest string conversion issue which i am going through in my recent project. I am using Jdev version 12.1.3. Client wants us to send null data for one of the json fields in the format “city”:”” . But instead the rest adapter is converting the empty field value to “city”:null . Is there a property in the adapter that i am missing or any way we can manipulate/transform the value as per the requirement using xslt/xquery or java class.

    Thanks,
    Venkat

  3. Is it necessary to pass the input parameters in get method ?
    As in my requirement there will be dynamic value changing in the URI-
    Example – http:\\localhost:9091\api\resourcepath\{dynamic_value}*x

    Also how to pass this dynamic value in the URI path while calling Rest adapter as a reference.

  4. First off I would like to say terrific blog!
    I had a quick question that I’d like to ask if you don’t mind.
    I was interested to know how you center yourself and clear your head before writing.
    I’ve had a difficult time clearing my thoughts in getting my thoughts out.
    I truly do enjoy writing but it just seems
    like the first 10 to 15 minutes tend to be wasted simply just trying
    to figure out how to begin. Any suggestions or tips?
    Kudos!

  5. The best in class, Depoxito manage to pay for you high-end
    experience that take in hand the look and character of genuine VIP standarts,
    we manage to pay for you the best glamorous to high-level experience of VIPs expect
    in any top end casino, grand alive casino royale
    pay for you the new studio design element including the grand blackjack, offering our VIP Customer the best experience of a Salon privee table.

    New style table in addition to feature across the room like grand roulette upgraded on our provider playtechs mini prestige roulette which
    delivering more interesting and richer playing experience.
    The further experience contains a sum of seven tables including five blackjack tables, one
    roulette table and one baccarat table. Grand stimulate casino royale has been high hand-engineered to fit the needs of our customer to using it, and contains unique elements that is specially expected
    to maximize the impact value we got from our customers and diversify it to the existing network.

    Soon, Depoxito will develop an enlarged authenticity technology upon alive casino for
    our VIP member, these most highly developed technology ever seen in breathing casino including this greater than before reality.
    Which allow players to experience products upon an entire
    supplementary level which is never seen before literally leaping out of the game and
    taking the blackjack, baccarat, roulette and additional game into
    the collection entire level.
    Depoxito VIP Baccarat, we meet the expense of you the entirely exclusive sentient VIP Baccarat
    that is played gone in the works to 7 players at the similar table and our intensely trained pretty stir baccarat dealer.
    And of course our VIP supporter will feel as if they were in point of fact sitting at one of the summit casino baccarat table.
    This immersive gaming experience creates a hugely thrill-seeking announce that our VIP players
    will locate difficult to surpass.
    Here is the list of rouse casino game that depoxito provide,
    we have enough money the widest range of stir casino
    games upon the spread around including : blackjack unlimited,
    blackjack prestige, roulette, baccarat, poker, hi-lo, sic bo, and grand enliven casino royale such as Grand
    Baccarat, Grand Blackjack and Grand Roulette for our VIP member.

    And of course as a advocate of Depoxito you can enjoy every the games that we have enough money to you, every you dependence to accomplish is just visit our site depoxito and register it by yourself takes occurring
    to 3 minutes and next youre satisfactory to produce an effect
    any game that you want.
    Be our VIP, innate our VIP member of course decided you the best assistance you can get from us all you craving to
    be a VIP enthusiast is no question easy. all you dependence is
    just save playing upon our site, accrual and conduct yourself once a VIP later the
    amount that our company had written, keep playing and our customer benefits will
    log on you that you are promoted to become a VIP zealot on our site.

  6. Hi Krishna

    We have a JSON Object like this formed after a DB Call.

    “{\”recordid\”:[{\”$\”:100}],\”returnmessage\”:[{\”$\”:\”success”\”}],\”returncode\”:[{\”$\”:0}],\”name\”:[{\”$\”:\”oracle\”}]}”

    We are not able to figure out how to remove the $ and the /above. We saw one of your post on Oracle community forum
    (https://community.oracle.com/thread/4076203) and downloaded that code and over there you did something like this .

    process.outputVar=process.Inv_getReqMessage_OV.parameters.return[0];
    process.outputVar = process.outputVar.return[“response”][0][“$”];

    When we try to do the same over here , we get errors
    The JSON that we are hoping to get is something like below and cannot figure out how to write the javascript assignment to get this response.

    {processResponse
    {
    “recordid” :100,
    “returnmessage”:”success”,
    “returncode” : 0
    “name” : “oracle”
    }
    }

    any pointers on this please?

  7. Mabosway alternating sites and mobile sports login contacts –
    There are lots of online gambling agent sites scattered upon the internet.
    Each of these sites has offers and features
    provided, including the types of gambling games available.
    Many online gambling sites deserted come up with the money for 1 to 3 types of games and definitely have excellent
    games they offer.

    Mabosway.com is an online gambling agent site that offers not lonely 1
    or 3 types of gambling games but 7 engaging types
    of gambling games that you can play. This proves
    that Mabosway is the most unlimited betting site that offers not single-handedly
    online soccer gambling, but Casino, Poker, Toto 4D, Bola Tangkas, Fish Hunter and online cockfighting gambling.
    This site is known as Mabosway Indonesia for members who
    arrive from Indonesia.

    Various types of online gambling games are fully
    supported by the maximum promote from Mabosway.com.
    One of them is the Customer serve feature which
    is 24 hours standby to relieve enlargement and withdrawal
    transactions for members. How to register is as well as easy to do, especially for beginner bettors who are starting to bet for the first time.

    How to Apply for Mabosway

    How to register mabosway is completely easy for unknown people who want to start playing online gambling.
    You on your own have to click the colleague NOW button on the home
    page which will go directly to the registration form page.
    After successfully registering you will get a user ID as
    an identity in the game. After whatever is done, you are officially associated and become
    a member.

    After you officially become a member you are offered
    to choose the type of online gambling game that you
    can play. Here are 5 types of favorite online gambling games that you can sham at Mabosway.com.

  8. That has for ages been so, for Baccarat was played since Middle
    Ages. The game of Baccarat is something similar and
    would seem rather mysterious for you when you initially try playing it.
    A way to quickly obtain the baccarat bonus is to indulge in some high
    stakes baccarat.

  9. Aw, this was an extremely nice post. Finding the time and actual
    effort to produce a really good article… but what can I say… I procrastinate a lot and don’t seem to get anything done.

  10. This is the perfect website for everyone who
    would like to find out about this topic. You realize a whole
    lot its almost hard to argue with you (not that I really will need to…HaHa).
    You definitely put a fresh spin on a topic that’s been written about for a long time.

    Wonderful stuff, just wonderful!

  11. This is a great tip especially to those fresh to the blogosphere.
    Brief but very accurate information… Appreciate your sharing this one.
    A must read post!

  12. We are a bunch of volunteers and starting a brand new scheme in our community.
    Your website provided us with valuable info to work
    on. You have done an impressive job and our entire neighborhood can be grateful to
    you.

  13. When someone writes an post he/she retains the idea of a user in his/her brain that how a
    user can be aware of it. Therefore that’s why this article is amazing.
    Thanks!

  14. Superb blog yoou have hee but I was wanting
    to know if you knew of any message boards that cover the same topics
    talked about in this article? I’d really love to be a part of
    online community where I can get feed-back fromm other
    knowledgeable people that share the same interest.
    If you have any suggestions, please let me know. Bless you!

  15. What i do not understood is in fact how you’re now not really
    much more neatly-appreciated than you may be right now.
    You’re so intelligent. You know thus significantly when it comes to this subject, made me in my opinion imagine it from a
    lot of various angles. Its like women and men don’t seem to be interested
    unless it’s something to accomplish with Lady gaga!
    Your personal stuffs great. All the time care for it up!

  16. Superb blog! Do you have any tips and hints for aspiring writers?
    I’m planning to start my own site soon but I’m a little lost
    on everything. Would you suggest starting with a free platform like WordPress
    or go for a paid option? There are so many options out there that
    I’m completely overwhelmed .. Any suggestions? Cheers!

  17. excellent issues altogether, you simply received a brand new reader.
    What would you suggest in regards to your post that you simply made a few days
    in the past? Any certain?

  18. An interesting discussion is worth comment. I think that you ought to write more on this topic, it might not be a taboo matter but usually folks don’t discuss these issues.
    To the next! All the best!!

  19. you’re in point of fact a excellent webmaster. The website loading speed is incredible.
    It seems that you’re doing any unique trick. In addition, The
    contents are masterwork. you have done a wonderful activity
    on this topic!

  20. Just want to say your article is as amazing. The clarity
    to your submit is just nice and that i could assume you are a professional on this subject.

    Well with your permission allow me to grab your RSS feed to stay updated with drawing close post.

    Thank you a million and please carry on the rewarding work.

Leave a Reply

Your email address will not be published. Required fields are marked *