Thursday 20 August 2015

Authorized REST request to MCS with SoapUI

In my former post I explained how to do a REST request to a Mobile Cloud Service API using an Unauthorized access. To do so you need to add an HTTP Header property using a Base64 encoded key. But how to do that for authorized access. Using Postman you should be able to add HTTP  Basic authentication, provide the access details and update the request. In SoapUI, it's more or less the same trick: just provide the HTTP Basic Authentication details, and SoapUI does the encoding for you:
Now if you run this and open up the SoapUI Log: you'll see log entries with the message that is send over the line to MCS.
Thu Aug 20 15:19:59 CEST 2015:DEBUG:>> "GET /mobile/custom/incidentreport_M10/incidents/?contact=Lynn HTTP/1.1[\r][\n]"
Thu Aug 20 15:19:59 CEST 2015:DEBUG:>> "Accept-Encoding: gzip,deflate[\r][\n]"
Thu Aug 20 15:19:59 CEST 2015:DEBUG:>> "oracle-mobile-backend-id: 01d3b3a2-7a6b-42c8-b314-d6e8c8f3e898[\r][\n]"
Thu Aug 20 15:19:59 CEST 2015:DEBUG:>> "Host: unit23585.oracleads.com:7201[\r][\n]"
Thu Aug 20 15:19:59 CEST 2015:DEBUG:>> "Connection: Keep-Alive[\r][\n]"
Thu Aug 20 15:19:59 CEST 2015:DEBUG:>> "User-Agent: Apache-HttpClient/4.1.1 (java 1.5)[\r][\n]"
Thu Aug 20 15:19:59 CEST 2015:DEBUG:>> "Authorization: Basic am9lX20xMDpuNlApIXBOdTQkMA==[\r][\n]"
Thu Aug 20 15:19:59 CEST 2015:DEBUG:>> "[\r][\n]"

Here You see in the last line that SoapUI encoded the username/password details into the Authorization header property. Below you'll see the response:
Thu Aug 20 15:20:00 CEST 2015:DEBUG:<< "HTTP/1.1 200 OK[\r][\n]"
Thu Aug 20 15:20:00 CEST 2015:DEBUG:<< "Connection: keep-alive[\r][\n]"
Thu Aug 20 15:20:00 CEST 2015:DEBUG:<< "Date: Thu, 20 Aug 2015 13:20:00 GMT[\r][\n]"
Thu Aug 20 15:20:00 CEST 2015:DEBUG:<< "Content-Length: 486[\r][\n]"
Thu Aug 20 15:20:00 CEST 2015:DEBUG:<< "Content-Type: text/html; charset=utf-8[\r][\n]"
Thu Aug 20 15:20:00 CEST 2015:DEBUG:<< "Set-Cookie: JSESSIONID=3W1cVVJQTgGmGZMXQy2G3pVG0QvWByQWtmJr212Mh5nQ9hB0yy4b!-920535662; path=/; HttpOnly[\r][\n]"
Thu Aug 20 15:20:00 CEST 2015:DEBUG:<< "oracle-mobile-runtime-version: 15.3.3-201507070814[\r][\n]"
Thu Aug 20 15:20:00 CEST 2015:DEBUG:<< "X-ORACLE-DMS-ECID: 5a67a51e479fa73b:43dd1c99:14f4a5d80d0:-8000-000000000000729a[\r][\n]"
Thu Aug 20 15:20:00 CEST 2015:DEBUG:<< "X-Powered-By: Servlet/2.5 JSP/2.1[\r][\n]"
Thu Aug 20 15:20:00 CEST 2015:DEBUG:<< "X-Powered-By: Express[\r][\n]"
Thu Aug 20 15:20:00 CEST 2015:DEBUG:<< "[\r][\n]"
Thu Aug 20 15:20:00 CEST 2015:DEBUG:<< "{[\n]"
Thu Aug 20 15:20:00 CEST 2015:DEBUG:<< "  "Body" : {[\n]"
Thu Aug 20 15:20:00 CEST 2015:DEBUG:<< "    "GetIncidentsByCustomerResponse" : {[\n]"
Thu Aug 20 15:20:00 CEST 2015:DEBUG:<< "      "Incident" : [ {[\n]"
Thu Aug 20 15:20:00 CEST 2015:DEBUG:<< "        "Date" : "2015-07-22 17:02:14 GMT",[\n]"
Thu Aug 20 15:20:00 CEST 2015:DEBUG:<< "        "Id" : 10,[\n]"
Thu Aug 20 15:20:00 CEST 2015:DEBUG:<< "        "ImageLink" : "storage/collections/2e029813-d1a9-4957-a69a-fbd0d7431d77/objects/6cdaa3a8-097e-49f7-9bd2-88966c45668f?user=lynn1014",[\n]"
Thu Aug 20 15:20:00 CEST 2015:DEBUG:<< "        "Priority" : "Medium",[\n]"
Thu Aug 20 15:20:00 CEST 2015:DEBUG:<< "        "Status" : "InProgress",[\n]"
Thu Aug 20 15:20:00 CEST 2015:DEBUG:<< "        "TechnicianAssigned" : "joe@fixit.com",[\n]"
Thu Aug 20 15:20:00 CEST 2015:DEBUG:<< "        "Title" : "Leaking Water Heater",[\n]"
Thu Aug 20 15:20:00 CEST 2015:DEBUG:<< "        "UserName" : "Lynn"[\n]"
Thu Aug 20 15:20:00 CEST 2015:DEBUG:<< "      } ][\n]"
Thu Aug 20 15:20:00 CEST 2015:DEBUG:<< "    }[\n]"
Thu Aug 20 15:20:00 CEST 2015:DEBUG:<< "  }[\n]"
Thu Aug 20 15:20:00 CEST 2015:DEBUG:<< "}"

Now, currently MCS supports basic authentication, but I've learned that in the next release OAuth will be supported.

No comments :