当前位置: 首页>>代码示例>>Java>>正文


Java HttpMethodParams类代码示例

本文整理汇总了Java中org.apache.commons.httpclient.params.HttpMethodParams的典型用法代码示例。如果您正苦于以下问题:Java HttpMethodParams类的具体用法?Java HttpMethodParams怎么用?Java HttpMethodParams使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


HttpMethodParams类属于org.apache.commons.httpclient.params包,在下文中一共展示了HttpMethodParams类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: get

import org.apache.commons.httpclient.params.HttpMethodParams; //导入依赖的package包/类
@Override
public HttpResponse get(URL urlObj, String userName, String password, int timeout) {
  HttpClient client = new HttpClient();
  HttpMethod method = new GetMethod(urlObj.toString());

  client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
      new DefaultHttpMethodRetryHandler());
  client.getParams().setSoTimeout(1000 * timeout);
  client.getParams().setConnectionManagerTimeout(1000 * timeout);
  if (userName != null && password != null) {
    setBasicAuthorization(method, userName, password);
  }
  try {
    int response = client.executeMethod(method);
    return new HttpResponse(response, method.getResponseBody());
  } catch (IOException e) {
    throw new RuntimeException("Failed to get " + urlObj.toString(), e);
  } finally {
    method.releaseConnection();
  }
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:22,代码来源:LogiURLFetchService.java

示例2: addRequestHeaders

import org.apache.commons.httpclient.params.HttpMethodParams; //导入依赖的package包/类
/**
 * Sets the <tt>Expect</tt> header if it has not already been set, 
 * in addition to the "standard" set of headers.
 *
 * @param state the {@link HttpState state} information associated with this method
 * @param conn the {@link HttpConnection connection} used to execute
 *        this HTTP method
 *
 * @throws IOException if an I/O (transport) error occurs. Some transport exceptions
 *                     can be recovered from.
 * @throws HttpException  if a protocol exception occurs. Usually protocol exceptions 
 *                    cannot be recovered from.
 */
protected void addRequestHeaders(HttpState state, HttpConnection conn)
throws IOException, HttpException {
    LOG.trace("enter ExpectContinueMethod.addRequestHeaders(HttpState, HttpConnection)");
    
    super.addRequestHeaders(state, conn);
    // If the request is being retried, the header may already be present
    boolean headerPresent = (getRequestHeader("Expect") != null);
    // See if the expect header should be sent
    // = HTTP/1.1 or higher
    // = request body present

    if (getParams().isParameterTrue(HttpMethodParams.USE_EXPECT_CONTINUE) 
    && getEffectiveVersion().greaterEquals(HttpVersion.HTTP_1_1) 
    && hasRequestContent())
    {
        if (!headerPresent) {
            setRequestHeader("Expect", "100-continue");
        }
    } else {
        if (headerPresent) {
            removeRequestHeader("Expect");
        }
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:38,代码来源:ExpectContinueMethod.java

示例3: post

import org.apache.commons.httpclient.params.HttpMethodParams; //导入依赖的package包/类
@Override
public HttpResponse post(URL urlObj, byte[] payload, String userName, String password,
                         int timeout) {
  HttpClient client = new HttpClient();
  PostMethod method = new PostMethod(urlObj.toString());
  method.setRequestEntity(new ByteArrayRequestEntity(payload));
  method.setRequestHeader("Content-type", "application/json");
  client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
      new DefaultHttpMethodRetryHandler());
  client.getParams().setSoTimeout(1000 * timeout);
  client.getParams().setConnectionManagerTimeout(1000 * timeout);
  if (userName != null && password != null) {
    setBasicAuthorization(method, userName, password);
  }
  try {
    int response = client.executeMethod(method);
    return new HttpResponse(response, method.getResponseBody());
  } catch (IOException e) {
    throw new RuntimeException("Failed to process post request URL: " + urlObj, e);
  } finally {
    method.releaseConnection();
  }

}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:25,代码来源:LogiURLFetchService.java

示例4: doPut

import org.apache.commons.httpclient.params.HttpMethodParams; //导入依赖的package包/类
public String doPut(String url, String charset, String jsonObj) {
    String resStr = null;
    HttpClient htpClient = new HttpClient();
    PutMethod putMethod = new PutMethod(url);
    putMethod.getParams().setParameter(
            HttpMethodParams.HTTP_CONTENT_CHARSET, charset);
    try {
        putMethod.setRequestEntity(new StringRequestEntity(jsonObj,
                "application/json", charset));
        int statusCode = htpClient.executeMethod(putMethod);
        if (statusCode != HttpStatus.SC_OK) {
            log.error("Method failed: " + putMethod.getStatusLine());
            return null;
        }
        byte[] responseBody = putMethod.getResponseBody();
        resStr = new String(responseBody, charset);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        putMethod.releaseConnection();
    }
    return resStr;
}
 
开发者ID:BriData,项目名称:DBus,代码行数:24,代码来源:HttpRequest.java

示例5: fastFailPing

import org.apache.commons.httpclient.params.HttpMethodParams; //导入依赖的package包/类
/**
 * @return the http response code returned from the server. Response code 200 means success.
 */
public static int fastFailPing(AuthenticatedUrl url) throws IOException
{
    PingRequest pingRequest = null;
    try
    {
        HttpClient httpClient = getHttpClient(url);
        pingRequest = new PingRequest(url.getPath());
        HttpMethodParams params = pingRequest.getParams();
        params.setSoTimeout(PING_TIMEOUT);
        httpClient.executeMethod(pingRequest);
        return pingRequest.getStatusCode();
    }
    finally
    {
        if (pingRequest != null)
        {
            pingRequest.releaseConnection();
        }
    }
}
 
开发者ID:goldmansachs,项目名称:jrpip,代码行数:24,代码来源:FastServletProxyFactory.java

示例6: getHttpClient

import org.apache.commons.httpclient.params.HttpMethodParams; //导入依赖的package包/类
public static HttpClient getHttpClient(AuthenticatedUrl url)
{
    HttpClient httpClient = new HttpClient(HTTP_CONNECTION_MANAGER);
    httpClient.getHostConfiguration().setHost(url.getHost(), url.getPort());
    httpClient.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, NoRetryRetryHandler.getInstance());
    url.setCredentialsOnClient(httpClient);
    return httpClient;
}
 
开发者ID:goldmansachs,项目名称:jrpip,代码行数:9,代码来源:FastServletProxyFactory.java

示例7: requestNewSession

import org.apache.commons.httpclient.params.HttpMethodParams; //导入依赖的package包/类
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();
        }
    }
}
 
开发者ID:goldmansachs,项目名称:jrpip,代码行数:25,代码来源:FastServletProxyFactory.java

示例8: createPostMethod

import org.apache.commons.httpclient.params.HttpMethodParams; //导入依赖的package包/类
private PostMethod createPostMethod(KalturaParams kparams,
		KalturaFiles kfiles, String url) {
	PostMethod method = new PostMethod(url);
       method.setRequestHeader("Accept","text/xml,application/xml,*/*");
       method.setRequestHeader("Accept-Charset","utf-8,ISO-8859-1;q=0.7,*;q=0.5");
       
       if (!kfiles.isEmpty()) {        	
           method = this.getPostMultiPartWithFiles(method, kparams, kfiles);        	
       } else {
           method = this.addParams(method, kparams);            
       }
       
       if (isAcceptGzipEncoding()) {
		method.addRequestHeader(HTTP_HEADER_ACCEPT_ENCODING, ENCODING_GZIP);
	}
       

	// Provide custom retry handler is necessary
	method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
			new DefaultHttpMethodRetryHandler (3, false));
	return method;
}
 
开发者ID:ITYug,项目名称:kaltura-ce-sakai-extension,代码行数:23,代码来源:KalturaClientBase.java

示例9: buildMultipartPostRequest

import org.apache.commons.httpclient.params.HttpMethodParams; //导入依赖的package包/类
public PostRequest buildMultipartPostRequest(File file, String filename, String siteId, String containerId) throws IOException
{
    Part[] parts = 
        { 
            new FilePart("filedata", file.getName(), file, "text/plain", null), 
            new StringPart("filename", filename),
            new StringPart("description", "description"), 
            new StringPart("siteid", siteId), 
            new StringPart("containerid", containerId) 
        };

    MultipartRequestEntity multipartRequestEntity = new MultipartRequestEntity(parts, new HttpMethodParams());

    ByteArrayOutputStream os = new ByteArrayOutputStream();
    multipartRequestEntity.writeRequest(os);

    PostRequest postReq = new PostRequest(UPLOAD_URL, os.toByteArray(), multipartRequestEntity.getContentType());
    return postReq;
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:20,代码来源:UploadWebScriptTest.java

示例10: createGetMethod

import org.apache.commons.httpclient.params.HttpMethodParams; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private HttpMethod createGetMethod(HttpServletRequest req, String uri) throws ServletException,
        NotLoggedInException {

    GetMethod get = new GetMethod(uri);
    addUserNameToHeader(get, req);
    addAcceptEncodingHeader(get, req);

    get.getParams().setContentCharset("UTF-8");
    HttpMethodParams params = new HttpMethodParams();
    Enumeration e = req.getParameterNames();
    while (e.hasMoreElements()) {
        String paramName = (String) e.nextElement();
        for (String value : req.getParameterValues(paramName)) {
            params.setParameter(paramName, value);
        }
    }
    get.setParams(params);
    return get;
}
 
开发者ID:openNaEF,项目名称:openNaEF,代码行数:21,代码来源:ForwarderServlet.java

示例11: createDeleteMethod

import org.apache.commons.httpclient.params.HttpMethodParams; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private HttpMethod createDeleteMethod(HttpServletRequest req, String redirectUrl) throws IOException, ServletException, NotLoggedInException {
    DeleteMethod delete = new DeleteMethod(redirectUrl);
    addUserNameToHeader(delete, req);
    addAcceptEncodingHeader(delete, req);

    delete.getParams().setContentCharset("UTF-8");
    HttpMethodParams params = new HttpMethodParams();
    Enumeration e = req.getParameterNames();
    while (e.hasMoreElements()) {
        String paramName = (String) e.nextElement();
        String[] values = req.getParameterValues(paramName);
        for (String value : values) {
            params.setParameter(paramName, value);
        }
    }
    delete.setParams(params);

    return delete;
}
 
开发者ID:openNaEF,项目名称:openNaEF,代码行数:21,代码来源:ForwarderServlet.java

示例12: recycle

import org.apache.commons.httpclient.params.HttpMethodParams; //导入依赖的package包/类
/**
 * Recycles the HTTP method so that it can be used again.
 * Note that all of the instance variables will be reset
 * once this method has been called. This method will also
 * release the connection being used by this HTTP method.
 * 
 * @see #releaseConnection()
 * 
 * @deprecated no longer supported and will be removed in the future
 *             version of HttpClient
 */
public void recycle() {
    LOG.trace("enter HttpMethodBase.recycle()");

    releaseConnection();

    path = null;
    followRedirects = false;
    doAuthentication = true;
    queryString = null;
    getRequestHeaderGroup().clear();
    getResponseHeaderGroup().clear();
    getResponseTrailerHeaderGroup().clear();
    statusLine = null;
    effectiveVersion = null;
    aborted = false;
    used = false;
    params = new HttpMethodParams();
    responseBody = null;
    recoverableExceptionCount = 0;
    connectionCloseForced = false;
    hostAuthState.invalidate();
    proxyAuthState.invalidate();
    cookiespec = null;
    requestSent = false;
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:37,代码来源:HttpMethodBase.java

示例13: testNoncompliantPostMethodString

import org.apache.commons.httpclient.params.HttpMethodParams; //导入依赖的package包/类
/**
 * Tests if client is able to recover gracefully when HTTP server or
 * proxy fails to send 100 status code when expected. The client should
 * resume sending the request body after a defined timeout without having
 * received "continue" code.
 */
public void testNoncompliantPostMethodString() throws Exception {
    this.server.setRequestHandler(new HttpRequestHandler() {
        public boolean processRequest(SimpleHttpServerConnection conn,
                SimpleRequest request) throws IOException {
            ResponseWriter out = conn.getWriter();
            out.println("HTTP/1.1 200 OK");
            out.println("Connection: close");
            out.println("Content-Length: 0");
            out.println();
            out.flush();
            return true;
        }
    });

    PostMethod method = new PostMethod("/");
    method.getParams().setBooleanParameter(
            HttpMethodParams.USE_EXPECT_CONTINUE, true);
    method.setRequestEntity(new StringRequestEntity(
            "This is data to be sent in the body of an HTTP POST.", null, null));
    client.executeMethod(method);
    assertEquals(200, method.getStatusCode());
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:29,代码来源:TestNoncompliant.java

示例14: testNoncompliantHeadWithResponseBody

import org.apache.commons.httpclient.params.HttpMethodParams; //导入依赖的package包/类
/**
 * Test if a response to HEAD method from non-compliant server that contains
 * an unexpected body content can be correctly redirected
 */
public void testNoncompliantHeadWithResponseBody() throws Exception {
    final String body = "Test body";
    this.server.setRequestHandler(new HttpRequestHandler() {
        public boolean processRequest(SimpleHttpServerConnection conn,
                SimpleRequest request) throws IOException {
            ResponseWriter out = conn.getWriter();
            out.println("HTTP/1.1 200 OK");
            out.println("Connection: close");
            out.println("Content-Length: " + body.length());
            out.println();
            out.print(body);
            out.flush();
            return true;
        }
    });
    HeadMethod method = new HeadMethod("/");
    method.getParams().setIntParameter(
            HttpMethodParams.HEAD_BODY_CHECK_TIMEOUT, 50);
    client.executeMethod(method);
    assertEquals(200, method.getStatusCode());
    method.releaseConnection();
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:27,代码来源:TestNoncompliant.java

示例15: getPostResponseHeader

import org.apache.commons.httpclient.params.HttpMethodParams; //导入依赖的package包/类
public static String getPostResponseHeader(String url,String argJson,List<UHeader> headerList,String headerName){
  	String info = "";
  	try {
   	HttpClient client = new HttpClient();
	PostMethod method = new PostMethod(url);
	client.getParams().setContentCharset("UTF-8");
	if(headerList.size()>0){
		for(int i = 0;i<headerList.size();i++){
			UHeader header = headerList.get(i);
			method.setRequestHeader(header.getHeaderTitle(),header.getHeaderValue());
		}
	}
	method.getParams().setParameter(
			HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
	if(argJson != null && !argJson.trim().equals("")) {
		RequestEntity requestEntity = new StringRequestEntity(argJson,"application/json","UTF-8");
		method.setRequestEntity(requestEntity);
	}
	method.releaseConnection();
	Header h =  method.getResponseHeader(headerName);
	info = h.getValue();
} catch (IOException e) {
	e.printStackTrace();
}
  	return info;
  }
 
开发者ID:noseparte,项目名称:Spring-Boot-Server,代码行数:27,代码来源:HttpUtils.java


注:本文中的org.apache.commons.httpclient.params.HttpMethodParams类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。