本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}