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


Java HttpResponseException.getMessage方法代码示例

本文整理汇总了Java中org.apache.http.client.HttpResponseException.getMessage方法的典型用法代码示例。如果您正苦于以下问题:Java HttpResponseException.getMessage方法的具体用法?Java HttpResponseException.getMessage怎么用?Java HttpResponseException.getMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.client.HttpResponseException的用法示例。


在下文中一共展示了HttpResponseException.getMessage方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: uploadFile

import org.apache.http.client.HttpResponseException; //导入方法依赖的package包/类
public WebResponse uploadFile(String path, String fname, InputStream in, 
              String stoken) throws ClientProtocolException, IOException {
  
  HttpPost post = new HttpPost(path);
  MultipartEntityBuilder builder = MultipartEntityBuilder.create();
  builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
  StringBody fn = new StringBody(fname, ContentType.MULTIPART_FORM_DATA);
  
  builder.addPart("fname", fn);
  builder.addBinaryBody("file", in, ContentType.APPLICATION_XML, fname);
  
  BasicCookieStore cookieStore = new BasicCookieStore();
  
  if (stoken != null) {
    BasicClientCookie cookie = new BasicClientCookie(
                Constants.SECURE_TOKEN_NAME, stoken);
    cookie.setDomain(TestConstants.JETTY_HOST);
    cookie.setPath("/");
    cookieStore.addCookie(cookie);
  }
  
  TestConstants.LOG.debug("stoken=" + stoken);
  HttpClient client = HttpClientBuilder.create().
                  setDefaultCookieStore(cookieStore).build();
  HttpEntity entity = builder.build();
  
  post.setEntity(entity);
  HttpResponse response = client.execute(post);
  
  String body;
  ResponseHandler<String> handler = new BasicResponseHandler();
  try {
    body = handler.handleResponse(response);
  } catch (HttpResponseException e) {
    return new WebResponse(e.getStatusCode(), e.getMessage());
  }
  
  return new WebResponse(response.getStatusLine().getStatusCode(), body);
}
 
开发者ID:osbitools,项目名称:OsBiToolsWs,代码行数:40,代码来源:BasicWebUtils.java

示例2: ModelResponseException

import org.apache.http.client.HttpResponseException; //导入方法依赖的package包/类
public ModelResponseException(Throwable paramThrowable)
{
  if ((paramThrowable instanceof HttpResponseException))
  {
    HttpResponseException localHttpResponseException = (HttpResponseException)paramThrowable;
    if (localHttpResponseException.getStatusCode() == 404){
  	  statusCode = STATUS_CODE_NETWORK_404;
    }else{
  	  statusCode = localHttpResponseException.getStatusCode();
    }
    msg = localHttpResponseException.getMessage();
  }
  if ((paramThrowable instanceof ConnectException))
  {
    statusCode = 983040;
    msg = paramThrowable.getMessage();
    return;
  }
  if ((paramThrowable instanceof UnknownHostException))
  {
    statusCode = 16711680;
    msg = paramThrowable.getMessage();
    return;
  }
  if ((paramThrowable instanceof UnknownHostException))
  {
    statusCode = 16711680;
    msg = paramThrowable.getMessage();
    return;
  }
  if (((paramThrowable instanceof SocketTimeoutException)) || ((paramThrowable instanceof ConnectTimeoutException)))
  {
    statusCode = 268369922;
    msg = paramThrowable.getMessage();
    return;
  }
  statusCode = -15;
  msg = ("unknown exception:" + paramThrowable.getClass().getName() + " | Message:" + paramThrowable.getMessage());
}
 
开发者ID:AndyGu,项目名称:ShanBay,代码行数:40,代码来源:ModelResponseException.java


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