Java Code Examples for org.apache.commons.httpclient.HttpMethod#setParams()
The following examples show how to use
org.apache.commons.httpclient.HttpMethod#setParams() .
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: 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 3
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 4
Source File: CloudMetadataScanner.java From zap-extensions with Apache License 2.0 | 5 votes |
private static HttpMethod createRequestMethod( HttpRequestHeader header, HttpBody body, HttpMethodParams params) throws URIException { HttpMethod httpMethod = new ZapGetMethod(); httpMethod.setURI(header.getURI()); httpMethod.setParams(params); params.setVersion(HttpVersion.HTTP_1_1); String msg = header.getHeadersAsString(); String[] split = Pattern.compile("\\r\\n", Pattern.MULTILINE).split(msg); String token = null; String name = null; String value = null; int pos = 0; for (int i = 0; i < split.length; i++) { token = split[i]; if (token.equals("")) { continue; } if ((pos = token.indexOf(":")) < 0) { return null; } name = token.substring(0, pos).trim(); value = token.substring(pos + 1).trim(); httpMethod.addRequestHeader(name, value); } if (body != null && body.length() > 0 && (httpMethod instanceof EntityEnclosingMethod)) { EntityEnclosingMethod post = (EntityEnclosingMethod) httpMethod; post.setRequestEntity(new ByteArrayRequestEntity(body.getBytes())); } httpMethod.setFollowRedirects(false); return httpMethod; }