|
Lines 13-18
Link Here
|
| 13 |
import java.io.IOException; |
13 |
import java.io.IOException; |
| 14 |
import javax.servlet.http.HttpServletResponse; |
14 |
import javax.servlet.http.HttpServletResponse; |
| 15 |
import org.apache.commons.httpclient.*; |
15 |
import org.apache.commons.httpclient.*; |
|
|
16 |
import org.apache.commons.httpclient.params.HttpMethodParams; |
| 16 |
import org.eclipse.core.runtime.Status; |
17 |
import org.eclipse.core.runtime.Status; |
| 17 |
import org.eclipse.orion.server.cf.CFActivator; |
18 |
import org.eclipse.orion.server.cf.CFActivator; |
| 18 |
import org.eclipse.orion.server.cf.CFProtocolConstants; |
19 |
import org.eclipse.orion.server.cf.CFProtocolConstants; |
|
Lines 22-30
Link Here
|
| 22 |
import org.json.JSONObject; |
23 |
import org.json.JSONObject; |
| 23 |
|
24 |
|
| 24 |
public class HttpUtil { |
25 |
public class HttpUtil { |
|
|
26 |
/** |
| 27 |
* Default socket connection timeout. |
| 28 |
*/ |
| 29 |
private static final int DEFAULT_SOCKET_TIMEOUT = 300000;//five minutes |
| 30 |
|
| 25 |
public static void configureHttpMethod(HttpMethod method, Target target) throws JSONException { |
31 |
public static void configureHttpMethod(HttpMethod method, Target target) throws JSONException { |
| 26 |
method.addRequestHeader(new Header("Accept", "application/json")); |
32 |
method.addRequestHeader(new Header("Accept", "application/json")); |
| 27 |
method.addRequestHeader(new Header("Content-Type", "application/json")); |
33 |
method.addRequestHeader(new Header("Content-Type", "application/json")); |
|
|
34 |
//set default socket timeout for connection |
| 35 |
HttpMethodParams params = method.getParams(); |
| 36 |
params.setSoTimeout(DEFAULT_SOCKET_TIMEOUT); |
| 37 |
method.setParams(params); |
| 28 |
if (target.getCloud().getAccessToken() != null) |
38 |
if (target.getCloud().getAccessToken() != null) |
| 29 |
method.addRequestHeader(new Header("Authorization", "bearer " + target.getCloud().getAccessToken().getString("access_token"))); |
39 |
method.addRequestHeader(new Header("Authorization", "bearer " + target.getCloud().getAccessToken().getString("access_token"))); |
| 30 |
} |
40 |
} |