Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

MAF and REST

Andrew_PatersonJul 22 2014 — edited Jul 23 2014

Does anyone know the requirements/limitations for the RESTServiceAdapter? 

I have spent the last day or so investigating different options and seem to have it whittled down to the lack of Content-Length in the response, or possibly Connection: close

For example, a REST services that works will return the following raw http response

HTTP/1.1 200 OK

Access-Control-Allow-Origin: *

Content-Type: application/json

Date: Tue, 22 Jul 2014 10:48:27 GMT

Content-Length: 225

{"ip":"122.109.131.63","country_code":"AU","country_name":"Australia","region_code":"05","region_name":"South Australia","city":"Adelaide","zipcode":"","latitude":-34.0287,"longitude":138.0986,"metro_code":"","area_code":""}

Conversely, a REST service that DOESN'T work will return the following raw http response

HTTP/1.1 200 OK

Date: Tue, 22 Jul 2014 10:56:02 GMT

Server:

Connection: close

Host: 192.168.0.4:8080

Content-Type: application/json

{"ip":"122.109.131.63","country_code":"AU","country_name":"Australia","region_code":"05","region_name":"South Australia","city":"Adelaide","zipcode":"","latitude":-34.0287,"longitude":138.0986,"metro_code":"","area_code":""}

The code I am using is as follows and will output the correct string for the first sample, but is empty in the second sample.

RestServiceAdapter restServiceAdapter = Model.createRestServiceAdapter();

  // Clear any previously set request properties, if any

  restServiceAdapter.clearRequestProperties();


  // Set the connection name

  restServiceAdapter.setConnectionName("GeoIPOAG");


   // Specify the type of request

  restServiceAdapter.setRequestType(RestServiceAdapter.REQUEST_TYPE_GET);    // switching to POST makes no difference, get the same results

   // Specify the number of retries

  restServiceAdapter.setRetryLimit(0);

  // ADDED this to see if it had any effect - it doesn't

//restServiceAdapter.addRequestProperty("Connection","Keep-Alive");

restServiceAdapter.addRequestProperty("Content-Type", "application/json");         // Set this as recommend in MAF dev guide but has no effect

  restServiceAdapter.addRequestProperty("Accept", "application/json");                // Set this as recommend in MAF dev guide but has no effect

  // Set the URI which is defined after the endpoint in the connections.xml.

  // The request is the endpoint + the URI being set

  restServiceAdapter.setRequestURI("/json/122.109.131.63");

     // Execute SEND and RECEIVE operation

        try {

            System.out.println("\nInvoking REST Service on GET and details are " + restServiceAdapter.getRequestURI());

           

            // For GET request, there is no payload

            String response = (restServiceAdapter.send(""));

       

            System.out.println("\n**********************************************************************************************");

        System.out.println("\nResponse from GET was " + response);

            System.out.println("\n**********************************************************************************************");

           

        } catch (Exception e) {

           

            e.printStackTrace();

        }

This post has been answered by Andrew_Paterson on Jul 23 2014
Jump to Answer
Comments
Post Details
Added on Jul 22 2014
1 comment
442 views