Java Code Examples for org.apache.commons.httpclient.params.HttpMethodParams#setSoTimeout()
The following examples show how to use
org.apache.commons.httpclient.params.HttpMethodParams#setSoTimeout() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpUtil.java From orion.server with Eclipse Public License 1.0 | 6 votes |
public static ServerStatus configureHttpMethod(HttpMethod method, Cloud cloud) throws JSONException { method.addRequestHeader(new Header("Accept", "application/json")); method.addRequestHeader(new Header("Content-Type", "application/json")); //set default socket timeout for connection HttpMethodParams params = method.getParams(); params.setSoTimeout(DEFAULT_SOCKET_TIMEOUT); params.setContentCharset("UTF-8"); method.setParams(params); if (cloud.getAccessToken() != null){ method.addRequestHeader(new Header("Authorization", "bearer " + cloud.getAccessToken().getString("access_token"))); return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK); } JSONObject errorJSON = new JSONObject(); try { errorJSON.put(CFProtocolConstants.V2_KEY_REGION_ID, cloud.getRegion()); errorJSON.put(CFProtocolConstants.V2_KEY_REGION_NAME, cloud.getRegionName() != null ? cloud.getRegionName() : ""); errorJSON.put(CFProtocolConstants.V2_KEY_ERROR_CODE, "CF-NotAuthenticated"); errorJSON.put(CFProtocolConstants.V2_KEY_ERROR_DESCRIPTION, "Not authenticated"); } catch (JSONException e) { // do nothing } return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_UNAUTHORIZED, "Not authenticated", errorJSON, null); }
Example 2
Source File: HttpMessageTransport.java From jrpip with Apache License 2.0 | 6 votes |
/** * @return the http response code returned from the server. Response code 200 means success. */ public static int fastFailPing(AuthenticatedUrl url, int timeout) throws IOException { PingRequest pingRequest = null; try { HttpClient httpClient = getHttpClient(url); pingRequest = new PingRequest(url.getPath()); HttpMethodParams params = pingRequest.getParams(); params.setSoTimeout(timeout); httpClient.executeMethod(pingRequest); return pingRequest.getStatusCode(); } finally { if (pingRequest != null) { pingRequest.releaseConnection(); } } }
Example 3
Source File: HttpMessageTransport.java From jrpip with Apache License 2.0 | 6 votes |
public static Cookie[] requestNewSession(AuthenticatedUrl url) { CreateSessionRequest createSessionRequest = null; try { HttpClient httpClient = getHttpClient(url); createSessionRequest = new CreateSessionRequest(url.getPath()); HttpMethodParams params = createSessionRequest.getParams(); params.setSoTimeout(PING_TIMEOUT); httpClient.executeMethod(createSessionRequest); return httpClient.getState().getCookies(); } catch (Exception e) { throw new RuntimeException("Failed to create session", e); } finally { if (createSessionRequest != null) { createSessionRequest.releaseConnection(); } } }
Example 4
Source File: DefaultDiamondSubscriber.java From diamond with Apache License 2.0 | 6 votes |
private void configureHttpMethod(boolean skipContentCache, CacheData cacheData, long onceTimeOut, HttpMethod httpMethod) { if (skipContentCache && null != cacheData) { if (null != cacheData.getLastModifiedHeader() && Constants.NULL != cacheData.getLastModifiedHeader()) { httpMethod.addRequestHeader(Constants.IF_MODIFIED_SINCE, cacheData.getLastModifiedHeader()); } if (null != cacheData.getMd5() && Constants.NULL != cacheData.getMd5()) { httpMethod.addRequestHeader(Constants.CONTENT_MD5, cacheData.getMd5()); } } httpMethod.addRequestHeader(Constants.ACCEPT_ENCODING, "gzip,deflate"); // 设置HttpMethod的参数 HttpMethodParams params = new HttpMethodParams(); params.setSoTimeout((int) onceTimeOut); // /////////////////////// httpMethod.setParams(params); httpClient.getHostConfiguration().setHost(diamondConfigure.getDomainNameList().get(this.domainNamePos.get()), diamondConfigure.getPort()); }
Example 5
Source File: DefaultDiamondSubscriber.java From diamond with Apache License 2.0 | 6 votes |
private void configureHttpMethod(boolean skipContentCache, CacheData cacheData, long onceTimeOut, HttpMethod httpMethod) { if (skipContentCache && null != cacheData) { if (null != cacheData.getLastModifiedHeader() && Constants.NULL != cacheData.getLastModifiedHeader()) { httpMethod.addRequestHeader(Constants.IF_MODIFIED_SINCE, cacheData.getLastModifiedHeader()); } if (null != cacheData.getMd5() && Constants.NULL != cacheData.getMd5()) { httpMethod.addRequestHeader(Constants.CONTENT_MD5, cacheData.getMd5()); } } httpMethod.addRequestHeader(Constants.ACCEPT_ENCODING, "gzip,deflate"); // 设置HttpMethod的参数 HttpMethodParams params = new HttpMethodParams(); params.setSoTimeout((int) onceTimeOut); // /////////////////////// httpMethod.setParams(params); httpClient.getHostConfiguration().setHost(diamondConfigure.getDomainNameList().get(this.domainNamePos.get()), diamondConfigure.getPort()); }