|
|
@ -19,6 +19,7 @@ package org.wso2.carbon.device.application.mgt.handler.util;
|
|
|
|
|
|
|
|
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
import com.google.gson.JsonObject;
|
|
|
|
import com.google.gson.JsonObject;
|
|
|
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.apache.http.HttpResponse;
|
|
|
|
import org.apache.http.HttpResponse;
|
|
|
@ -27,6 +28,8 @@ import org.apache.http.client.methods.HttpGet;
|
|
|
|
import org.apache.http.client.methods.HttpPost;
|
|
|
|
import org.apache.http.client.methods.HttpPost;
|
|
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
|
import org.apache.http.impl.client.HttpClients;
|
|
|
|
import org.apache.http.impl.client.HttpClients;
|
|
|
|
|
|
|
|
import org.json.JSONException;
|
|
|
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.ProxyResponse;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.ProxyResponse;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
@ -201,17 +204,29 @@ public class HandlerUtil {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Gson gson = new Gson();
|
|
|
|
|
|
|
|
resp.setStatus(proxyResponse.getCode());
|
|
|
|
resp.setStatus(proxyResponse.getCode());
|
|
|
|
resp.setContentType("application/json");
|
|
|
|
resp.setContentType("application/json");
|
|
|
|
resp.setCharacterEncoding("UTF-8");
|
|
|
|
resp.setCharacterEncoding("UTF-8");
|
|
|
|
proxyResponse.setExecutorResponse(null);
|
|
|
|
|
|
|
|
try (PrintWriter writer = resp.getWriter()) {
|
|
|
|
JSONObject response = new JSONObject();
|
|
|
|
if (proxyResponse.getCode() == HttpStatus.SC_OK){
|
|
|
|
String redirectUrl = proxyResponse.getUrl();
|
|
|
|
writer.write(gson.toJson(proxyResponse.getData()));
|
|
|
|
String responseData = proxyResponse.getData();
|
|
|
|
} else{
|
|
|
|
|
|
|
|
writer.write(proxyResponse.getData());
|
|
|
|
if (!StringUtils.isEmpty(redirectUrl)){
|
|
|
|
|
|
|
|
response.put("url", redirectUrl);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!StringUtils.isEmpty(responseData)){
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
JSONObject responseDataJsonObj = new JSONObject(responseData);
|
|
|
|
|
|
|
|
response.put("data", responseDataJsonObj);
|
|
|
|
|
|
|
|
} catch (JSONException e) {
|
|
|
|
|
|
|
|
log.debug("Response data is not valid json string");
|
|
|
|
|
|
|
|
response.put("data", responseData);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try (PrintWriter writer = resp.getWriter()) {
|
|
|
|
|
|
|
|
writer.write(response.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|