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