當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。