summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Grover <joeygrover@gmail.com>2016-03-09 14:22:42 -0500
committerJoey Grover <joeygrover@gmail.com>2016-03-09 14:22:42 -0500
commitc2a20aec1c723e37558fd4ddcd65df40ad9b292f (patch)
tree93d397421c2114297833c8815bf3f1cf1362bfba
parent81564f2ce948db8426fe468a8b6bf088af14b067 (diff)
downloadsdl_android-c2a20aec1c723e37558fd4ddcd65df40ad9b292f.tar.gz
Updated OnSystemRequest to handle http requests different that proprietary
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/proxy/rpc/OnSystemRequest.java46
1 files changed, 34 insertions, 12 deletions
diff --git a/sdl_android_lib/src/com/smartdevicelink/proxy/rpc/OnSystemRequest.java b/sdl_android_lib/src/com/smartdevicelink/proxy/rpc/OnSystemRequest.java
index fa96cd1cf..21165063c 100644
--- a/sdl_android_lib/src/com/smartdevicelink/proxy/rpc/OnSystemRequest.java
+++ b/sdl_android_lib/src/com/smartdevicelink/proxy/rpc/OnSystemRequest.java
@@ -52,18 +52,40 @@ public class OnSystemRequest extends RPCNotification {
JSONObject httpJson;
String tempBody = null;
Headers tempHeaders = null;
-
- try{
- JSONObject bulkJson = new JSONObject(new String(bulkData));
- httpJson = bulkJson.getJSONObject("HTTPRequest");
- tempBody = getBody(httpJson);
- tempHeaders = getHeaders(httpJson);
- }catch(JSONException e){
- Log.e("OnSystemRequest", "HTTPRequest in bulk data was malformed.");
- e.printStackTrace();
- }catch(NullPointerException e){
- Log.e("OnSystemRequest", "Invalid HTTPRequest object in bulk data.");
- e.printStackTrace();
+ if(RequestType.PROPRIETARY.equals(this.getRequestType())){
+ try{
+ JSONObject bulkJson = new JSONObject(new String(bulkData));
+
+ httpJson = bulkJson.getJSONObject("HTTPRequest");
+ tempBody = getBody(httpJson);
+ tempHeaders = getHeaders(httpJson);
+ }catch(JSONException e){
+ Log.e("OnSystemRequest", "HTTPRequest in bulk data was malformed.");
+ e.printStackTrace();
+ }catch(NullPointerException e){
+ Log.e("OnSystemRequest", "Invalid HTTPRequest object in bulk data.");
+ e.printStackTrace();
+ }
+ }else if(RequestType.HTTP.equals(this.getRequestType())){
+ //Builds the body from the policy snapshot
+ StringBuilder bodyBuilder = new StringBuilder();
+ bodyBuilder.append("{\"data\":");
+ //Not sure if this is right
+ bodyBuilder.append(new String(bulkData));
+ bodyBuilder.append("\"]}");
+ tempBody = bodyBuilder.toString();
+
+ tempHeaders = new Headers();
+ tempHeaders.setContentType("application/json");
+ tempHeaders.setConnectTimeout(7);
+ tempHeaders.setDoOutput(true);
+ tempHeaders.setDoInput(true);
+ tempHeaders.setUseCaches(false);
+ tempHeaders.setRequestMethod("POST");
+ tempHeaders.setReadTimeout(7);
+ tempHeaders.setInstanceFollowRedirects(false);
+ tempHeaders.setCharset("utf-8");
+ tempHeaders.setContentLength(body.length()); //TODO check if right
}
this.body = tempBody;