當前位置: 首頁>>代碼示例>>Java>>正文


Java ResponseHandler.handleResponse方法代碼示例

本文整理匯總了Java中org.apache.http.client.ResponseHandler.handleResponse方法的典型用法代碼示例。如果您正苦於以下問題:Java ResponseHandler.handleResponse方法的具體用法?Java ResponseHandler.handleResponse怎麽用?Java ResponseHandler.handleResponse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.http.client.ResponseHandler的用法示例。


在下文中一共展示了ResponseHandler.handleResponse方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: sendGetCommand

import org.apache.http.client.ResponseHandler; //導入方法依賴的package包/類
/**
 * sendGetCommand
 *
 * @param url
 * @param parameters
 * @return
 */
public Map<String, String> sendGetCommand(String url, Map<String, Object> parameters)
        throws ManagerResponseException {
    Map<String, String> response = new HashMap<String, String>();
    CloseableHttpClient httpclient = HttpClients.createDefault();
    HttpGet httpget = new HttpGet(url);
    try {
        CloseableHttpResponse httpResponse = httpclient.execute(httpget, localContext);
        ResponseHandler<String> handler = new CustomResponseErrorHandler();
        String body = handler.handleResponse(httpResponse);
        response.put(BODY, body);
        httpResponse.close();

    } catch (Exception e) {
        throw new ManagerResponseException(e.getMessage(), e);
    }

    return response;
}
 
開發者ID:oncecloud,項目名稱:devops-cstack,代碼行數:26,代碼來源:RestUtils.java

示例2: sendDeleteCommand

import org.apache.http.client.ResponseHandler; //導入方法依賴的package包/類
/**
 * sendDeleteCommand
 *
 * @param url
 * @return
 */
public Map<String, String> sendDeleteCommand(String url, Map<String, Object> credentials)
        throws ManagerResponseException {
    Map<String, String> response = new HashMap<String, String>();
    CloseableHttpClient httpclient = HttpClients.createDefault();

    HttpDelete httpDelete = new HttpDelete(url);
    CloseableHttpResponse httpResponse;
    try {
        httpResponse = httpclient.execute(httpDelete, localContext);
        ResponseHandler<String> handler = new CustomResponseErrorHandler();
        String body = handler.handleResponse(httpResponse);
        response.put("body", body);
        httpResponse.close();
    } catch (Exception e) {
        throw new ManagerResponseException(e.getMessage(), e);
    }

    return response;
}
 
開發者ID:oncecloud,項目名稱:devops-cstack,代碼行數:26,代碼來源:RestUtils.java

示例3: connect

import org.apache.http.client.ResponseHandler; //導入方法依賴的package包/類
public Map<String, String> connect(String url, Map<String, Object> parameters) throws ManagerResponseException {

        Map<String, String> response = new HashMap<String, String>();
        CloseableHttpClient httpclient = HttpClients.createDefault();
        List<NameValuePair> nvps = new ArrayList<>();
        nvps.add(new BasicNameValuePair("j_username", (String) parameters.get("login")));
        nvps.add(new BasicNameValuePair("j_password", (String) parameters.get("password")));
        localContext = HttpClientContext.create();
        localContext.setCookieStore(new BasicCookieStore());
        HttpPost httpPost = new HttpPost(url);
        try {
            httpPost.setEntity(new UrlEncodedFormEntity(nvps));
            CloseableHttpResponse httpResponse = httpclient.execute(httpPost, localContext);
            ResponseHandler<String> handler = new CustomResponseErrorHandler();
            String body = handler.handleResponse(httpResponse);
            response.put(BODY, body);
            httpResponse.close();
        } catch (Exception e) {
            authentificationUtils.getMap().clear();
            throw new ManagerResponseException(e.getMessage(), e);
        }

        return response;
    }
 
開發者ID:oncecloud,項目名稱:devops-cstack,代碼行數:25,代碼來源:RestUtils.java

示例4: sendPostCommand

import org.apache.http.client.ResponseHandler; //導入方法依賴的package包/類
/**
 * sendPostCommand
 *
 * @param url
 * @param credentials
 * @param entity
 * @return
 * @throws ClientProtocolException
 */
public Map<String, Object> sendPostCommand(String url, Map<String, Object> credentials, String entity)
        throws ManagerResponseException {
    Map<String, Object> response = new HashMap<String, Object>();
    CloseableHttpClient httpclient = HttpClients.createDefault();
    HttpPost httpPost = new HttpPost(url);
    httpPost.setHeader("Accept", "application/json");
    httpPost.setHeader("Content-type", "application/json");
    try {
        StringEntity stringEntity = new StringEntity(entity);
        httpPost.setEntity(stringEntity);
        CloseableHttpResponse httpResponse = httpclient.execute(httpPost, localContext);
        ResponseHandler<String> handler = new CustomResponseErrorHandler();
        String body = handler.handleResponse(httpResponse);
        response.put(BODY, body);
        httpResponse.close();
    } catch (Exception e) {
        throw new ManagerResponseException(e.getMessage(), e);
    }

    return response;
}
 
開發者ID:oncecloud,項目名稱:devops-cstack,代碼行數:31,代碼來源:RestUtils.java

示例5: sendPutCommand

import org.apache.http.client.ResponseHandler; //導入方法依賴的package包/類
/**
 * sendPutCommand
 *
 * @param url
 * @param parameters
 * @return
 * @throws ClientProtocolException
 */
public Map<String, Object> sendPutCommand(String url, Map<String, Object> credentials,
        Map<String, String> parameters) throws ManagerResponseException {
    Map<String, Object> response = new HashMap<String, Object>();
    CloseableHttpClient httpclient = HttpClients.createDefault();

    HttpPut httpPut = new HttpPut(url);
    httpPut.setHeader("Accept", "application/json");
    httpPut.setHeader("Content-type", "application/json");

    try {
        ObjectMapper mapper = new ObjectMapper();
        StringEntity entity = new StringEntity(mapper.writeValueAsString(parameters));
        httpPut.setEntity(entity);
        CloseableHttpResponse httpResponse = httpclient.execute(httpPut, localContext);
        ResponseHandler<String> handler = new CustomResponseErrorHandler();
        String body = handler.handleResponse(httpResponse);
        response.put(BODY, body);

        httpResponse.close();
    } catch (Exception e) {
        throw new ManagerResponseException(e.getMessage(), e);
    }

    return response;
}
 
開發者ID:oncecloud,項目名稱:devops-cstack,代碼行數:34,代碼來源:RestUtils.java

示例6: sendGetCommand

import org.apache.http.client.ResponseHandler; //導入方法依賴的package包/類
/**
 * sendGetCommand
 * 
 * @param url
 * @param log
 * @return
 * @throws MojoExecutionException
 * @throws CheckException
 */
public Map<String, String> sendGetCommand( String url, Log log )
    throws CheckException
{
    Map<String, String> response = new HashMap<String, String>();
    CloseableHttpClient httpclient = HttpClients.createDefault();
    HttpGet httpget = new HttpGet( url );
    try
    {
        CloseableHttpResponse httpResponse = httpclient.execute( httpget, localContext );
        ResponseHandler<String> handler = new ResponseErrorHandler();
        String body = handler.handleResponse( httpResponse );
        response.put( "body", body );
        httpResponse.close();

    }
    catch ( Exception e )
    {
        log.warn( "GET request failed!" );

        throw new CheckException( "Send GET to server failed!", e );
    }

    return response;
}
 
開發者ID:oncecloud,項目名稱:devops-cstack,代碼行數:34,代碼來源:RestUtils.java

示例7: execute

import org.apache.http.client.ResponseHandler; //導入方法依賴的package包/類
public <T> T execute(HttpHost target, HttpRequest request,
        ResponseHandler<? extends T> responseHandler, HttpContext context)
        throws IOException, ClientProtocolException {
    HttpResponse response = execute(target, request, context);
    try {
        return responseHandler.handleResponse(response);
    } finally {
        HttpEntity entity = response.getEntity();
        if (entity != null) EntityUtils.consume(entity);
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:12,代碼來源:DecompressingHttpClient.java

示例8: execute

import org.apache.http.client.ResponseHandler; //導入方法依賴的package包/類
@Override public <T> T execute(HttpHost host, HttpRequest request,
    ResponseHandler<? extends T> handler, HttpContext context) throws IOException {
  HttpResponse response = execute(host, request, context);
  try {
    return handler.handleResponse(response);
  } finally {
    consumeContentQuietly(response);
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:10,代碼來源:OkApacheClient.java

示例9: saveBotCam

import org.apache.http.client.ResponseHandler; //導入方法依賴的package包/類
public Long saveBotCam(BotCamera botCamera) {
    HttpEntity entity = MultipartEntityBuilder
            .create()
            .addPart("file", new ByteArrayBody(botCamera.getScreenShot(), "botSnapshot"))
            .build();

    Long idResponse = -1L;

    try {
        HttpPost httpPost = new HttpPost(apiUrl + BotCameraController.ENDPOINT_ROINT + "/" + botCamera.getPlayerBot().getName());
        httpPost.setEntity(entity);
        HttpResponse response = uploadHttpClient.execute(httpPost);
        ResponseHandler<String> handler = new BasicResponseHandler();

        if(response != null &&
            response.getStatusLine() != null &&
            response.getStatusLine().getStatusCode() == HttpStatus.OK.value()) {

            final String rawResult = handler.handleResponse(response);

            idResponse = Long.parseLong(rawResult);
        } else {
            log.error("Failed to upload pictar!");
            log.error("Headers received: " + Arrays.stream(response.getAllHeaders()).map(header -> new String(header.getName() + ": " + header.getValue()))
                                                                                    .reduce("", (result, next) -> System.lineSeparator() + next));
            log.error("Body received: " + System.lineSeparator() + handler.handleResponse(response));
        }
    } catch (IOException e) {
        log.error("Failed to upload pictar!");
        log.error(e.getMessage());
    }

    return idResponse;
}
 
開發者ID:corydissinger,項目名稱:mtgo-best-bot,代碼行數:35,代碼來源:BotCameraService.java

示例10: connect

import org.apache.http.client.ResponseHandler; //導入方法依賴的package包/類
/**
 * @param url
 * @param parameters
 * @param log
 * @return
 * @throws MojoExecutionException
 */
public Map<String, String> connect( String url, Map<String, Object> parameters, Log log )
    throws MojoExecutionException
{

    Map<String, String> response = new HashMap<String, String>();
    CloseableHttpClient httpclient = HttpClients.createDefault();
    List<NameValuePair> nvps = new ArrayList<>();
    nvps.add( new BasicNameValuePair( "j_username", (String) parameters.get( "login" ) ) );
    nvps.add( new BasicNameValuePair( "j_password", (String) parameters.get( "password" ) ) );
    localContext = HttpClientContext.create();
    localContext.setCookieStore( new BasicCookieStore() );
    HttpPost httpPost = new HttpPost( url );

    try
    {
        httpPost.setEntity( new UrlEncodedFormEntity( nvps ) );
        CloseableHttpResponse httpResponse = httpclient.execute( httpPost, localContext );
        ResponseHandler<String> handler = new ResponseErrorHandler();
        String body = handler.handleResponse( httpResponse );
        response.put( "body", body );
        httpResponse.close();
        isConnected = true;
        log.info( "Connection successful" );
    }
    catch ( Exception e )
    {
        log.error( "Connection failed!  : " + e.getMessage() );
        isConnected = false;
        throw new MojoExecutionException(
                                          "Connection failed, please check your manager location or your credentials" );
    }

    return response;
}
 
開發者ID:oncecloud,項目名稱:devops-cstack,代碼行數:42,代碼來源:RestUtils.java

示例11: sendPostCommand

import org.apache.http.client.ResponseHandler; //導入方法依賴的package包/類
/**
 * @param url
 * @param parameters
 * @return
 * @throws MojoExecutionException
 * @throws CheckException
 */
public Map<String, Object> sendPostCommand( String url, Map<String, String> parameters, Log log )
    throws CheckException
{
    Map<String, Object> response = new HashMap<String, Object>();
    CloseableHttpClient httpclient = HttpClients.createDefault();

    HttpPost httpPost = new HttpPost( url );
    httpPost.setHeader( "Accept", "application/json" );
    httpPost.setHeader( "Content-type", "application/json" );

    try
    {
        ObjectMapper mapper = new ObjectMapper();
        StringEntity entity = new StringEntity( mapper.writeValueAsString( parameters ) );
        httpPost.setEntity( entity );
        CloseableHttpResponse httpResponse = httpclient.execute( httpPost, localContext );
        ResponseHandler<String> handler = new ResponseErrorHandler();
        String body = handler.handleResponse( httpResponse );
        response.put( "body", body );
        httpResponse.close();
    }
    catch ( Exception e )
    {
        log.warn( "POST request failed!" );

        throw new CheckException( "Send POST to server failed!", e );
    }

    return response;
}
 
開發者ID:oncecloud,項目名稱:devops-cstack,代碼行數:38,代碼來源:RestUtils.java

示例12: execute

import org.apache.http.client.ResponseHandler; //導入方法依賴的package包/類
public <T> T execute(HttpHost target, HttpRequest request,
        ResponseHandler<? extends T> responseHandler, HttpContext context)
        throws IOException {
    HttpResponse resp = execute(target, request, context);
    return responseHandler.handleResponse(resp);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:7,代碼來源:AutoRetryHttpClient.java


注:本文中的org.apache.http.client.ResponseHandler.handleResponse方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。