List of usage examples for org.apache.http.client HttpResponseException HttpResponseException
public HttpResponseException(final int statusCode, final String s)
From source file:fm.last.musicbrainz.coverart.impl.DefaultCoverArtArchiveClientTest.java
@Test(expected = CoverArtException.class) public void releaseGroupNullMbidThrowsCoverArtException() throws Exception { doThrow(new HttpResponseException(HttpStatus.SC_BAD_REQUEST, "")).when(httpClient) .execute(any(HttpGet.class), eq(FetchJsonListingResponseHandler.INSTANCE)); client.getReleaseGroupByMbid(null);/* w w w . j a va 2s . c o m*/ }
From source file:com.lurencun.cfuture09.androidkit.http.async.BinaryHttpResponseHandler.java
@Override void sendResponseMessage(HttpResponse response) { StatusLine status = response.getStatusLine(); Header[] contentTypeHeaders = response.getHeaders("Content-Type"); byte[] responseBody = null; if (contentTypeHeaders.length != 1) { // malformed/ambiguous HTTP Header, ABORT! sendFailureMessage(new HttpResponseException(status.getStatusCode(), "None, or more than one, Content-Type Header found!"), responseBody); return;//ww w .java 2 s .com } Header contentTypeHeader = contentTypeHeaders[0]; boolean foundAllowedContentType = false; for (String anAllowedContentType : mAllowedContentTypes) { if (Pattern.matches(anAllowedContentType, contentTypeHeader.getValue())) { foundAllowedContentType = true; } } if (!foundAllowedContentType) { // ?? sendFailureMessage(new HttpResponseException(status.getStatusCode(), "Content-Type not allowed!"), responseBody); return; } try { HttpEntity entity = null; HttpEntity temp = response.getEntity(); if (temp != null) { entity = new BufferedHttpEntity(temp); } responseBody = EntityUtils.toByteArray(entity); } catch (IOException e) { sendFailureMessage(e, (byte[]) null); } if (status.getStatusCode() >= 300) { sendFailureMessage(new HttpResponseException(status.getStatusCode(), status.getReasonPhrase()), responseBody); } else { sendSuccessMessage(status.getStatusCode(), responseBody); } }
From source file:com.cndatacom.ordersystem.manager.BinaryHttpResponseHandler.java
void sendResponseMessage(HttpResponse response) { StatusLine status = response.getStatusLine(); Header[] contentTypeHeaders = response.getHeaders("Content-Type"); byte[] responseBody = null; if (contentTypeHeaders.length != 1) { //malformed/ambiguous HTTP Header, ABORT! sendFailureMessage(new HttpResponseException(status.getStatusCode(), "None, or more than one, Content-Type Header found!"), responseBody); return;//from w w w. j a v a 2 s. c o m } Header contentTypeHeader = contentTypeHeaders[0]; boolean foundAllowedContentType = false; for (String anAllowedContentType : mAllowedContentTypes) { if (anAllowedContentType.equals(contentTypeHeader.getValue())) { foundAllowedContentType = true; } } if (!foundAllowedContentType) { //Content-Type not in allowed list, ABORT! sendFailureMessage(new HttpResponseException(status.getStatusCode(), "Content-Type not allowed!"), responseBody); return; } try { HttpEntity entity = null; HttpEntity temp = response.getEntity(); if (temp != null) { entity = new BufferedHttpEntity(temp); } responseBody = EntityUtils.toByteArray(entity); } catch (IOException e) { sendFailureMessage(e, (byte[]) null); } if (status.getStatusCode() >= 300) { sendFailureMessage(new HttpResponseException(status.getStatusCode(), status.getReasonPhrase()), responseBody); } else { sendSuccessMessage(status.getStatusCode(), responseBody); } }
From source file:com.unifonic.sdk.resources.http.AccountResourceImpl.java
@Override public SenderID getSenderIDStatus(String senderID) throws IOException { ArrayList<NameValuePair> param = new ArrayList<NameValuePair>(); param.add(new BasicNameValuePair(PARAM_SENDER_ID, senderID)); OTSRestResponse response = sendRequest(accountUrl.urlGetSenderIDStatus(), param); if (response.getStatusCode() < 400) { Type type = new TypeToken<ResponseModel<SenderID>>() { }.getType();//from w w w.j av a 2s. com ResponseModel<SenderID> respData = GSON.fromJson(response.getData(), type); SenderID sender = respData.create(); sender.setSenderID(senderID); return sender; } else if (response.getStatusCode() == 400) { SenderID resp = GSON.fromJson(response.getData(), SenderID.class); return resp; } else { throw new HttpResponseException(response.getStatusCode(), response.getReasonPhrase()); } }
From source file:com.unifonic.sdk.resources.http.VoiceResourceImpl.java
@Override public CallsDetailsResponse getCallsDetails(Map<String, String> param) throws IOException { OTSRestResponse response = sendRequest(voiceUrl.urlGetCallsDetails(), param); if (response.getStatusCode() < 400) { Type type = new TypeToken<ResponseModel<CallsDetailsResponse>>() { }.getType();/* www. j av a 2 s . co m*/ ResponseModel<CallsDetailsResponse> respData = GSON.fromJson(response.getData(), type); return respData.create(); } else if (response.getStatusCode() == 400) { CallsDetailsResponse resp = GSON.fromJson(response.getData(), CallsDetailsResponse.class); return resp; } else { throw new HttpResponseException(response.getStatusCode(), response.getReasonPhrase()); } }
From source file:ea.compoment.http.BinaryHttpResponseHandler.java
@Override protected void sendResponseMessage(HttpResponse response) { StatusLine status = response.getStatusLine(); Header[] contentTypeHeaders = response.getHeaders("Content-Type"); byte[] responseBody = null; if (contentTypeHeaders.length != 1) { //malformed/ambiguous HTTP Header, ABORT! sendFailureMessage(new HttpResponseException(status.getStatusCode(), "None, or MORE than one, Content-Type Header found!"), responseBody); return;/* www.j a v a 2 s. c o m*/ } Header contentTypeHeader = contentTypeHeaders[0]; boolean foundAllowedContentType = false; for (String anAllowedContentType : mAllowedContentTypes) { if (Pattern.matches(anAllowedContentType, contentTypeHeader.getValue())) { foundAllowedContentType = true; } } if (!foundAllowedContentType) { //Content-Type not in allowed list, ABORT! sendFailureMessage(new HttpResponseException(status.getStatusCode(), "Content-Type not allowed!"), responseBody); return; } try { HttpEntity entity = null; HttpEntity temp = response.getEntity(); if (temp != null) { entity = new BufferedHttpEntity(temp); } responseBody = EntityUtils.toByteArray(entity); } catch (IOException e) { sendFailureMessage(e, (byte[]) null); } if (status.getStatusCode() >= 300) { sendFailureMessage(new HttpResponseException(status.getStatusCode(), status.getReasonPhrase()), responseBody); } else { sendSuccessMessage(status.getStatusCode(), responseBody); } }
From source file:cn.xdf.thinkutils.http2.BinaryHttpResponseHandler.java
@Override protected void sendResponseMessage(HttpResponse response) { StatusLine status = response.getStatusLine(); Header[] contentTypeHeaders = response.getHeaders("Content-Type"); byte[] responseBody = null; if (contentTypeHeaders.length != 1) { //malformed/ambiguous HTTP Header, ABORT! sendFailureMessage(new HttpResponseException(status.getStatusCode(), "None, or more than one, Content-Type Header found!"), responseBody); return;/*from w ww . j ava 2 s. co m*/ } Header contentTypeHeader = contentTypeHeaders[0]; boolean foundAllowedContentType = false; for (String anAllowedContentType : mAllowedContentTypes) { if (Pattern.matches(anAllowedContentType, contentTypeHeader.getValue())) { foundAllowedContentType = true; } } if (!foundAllowedContentType) { //Content-Type not in allowed list, ABORT! sendFailureMessage(new HttpResponseException(status.getStatusCode(), "Content-Type not allowed!"), responseBody); return; } try { HttpEntity entity = null; HttpEntity temp = response.getEntity(); if (temp != null) { entity = new BufferedHttpEntity(temp); } responseBody = EntityUtils.toByteArray(entity); } catch (IOException e) { sendFailureMessage(e, (byte[]) null); } if (status.getStatusCode() >= 300) { sendFailureMessage(new HttpResponseException(status.getStatusCode(), status.getReasonPhrase()), responseBody); } else { sendSuccessMessage(status.getStatusCode(), responseBody); } }
From source file:cn.caimatou.canting.utils.http.asynchttp.BinaryHttpResponseHandler.java
@Override void sendResponseMessage(HttpResponse response) { StatusLine status = response.getStatusLine(); Header[] contentTypeHeaders = response.getHeaders("Content-Type"); byte[] responseBody = null; if (contentTypeHeaders.length != 1) { //malformed/ambiguous HTTP Header, ABORT! sendFailureMessage(new HttpResponseException(status.getStatusCode(), "None, or more than one, Content-Type Header found!"), responseBody); return;/*from w w w .java2s .c o m*/ } Header contentTypeHeader = contentTypeHeaders[0]; boolean foundAllowedContentType = false; for (String anAllowedContentType : mAllowedContentTypes) { if (Pattern.matches(anAllowedContentType, contentTypeHeader.getValue())) { foundAllowedContentType = true; } } if (!foundAllowedContentType) { //Content-Type not in allowed list, ABORT! sendFailureMessage(new HttpResponseException(status.getStatusCode(), "Content-Type not allowed!"), responseBody); return; } try { HttpEntity entity = null; HttpEntity temp = response.getEntity(); if (temp != null) { entity = new BufferedHttpEntity(temp); } responseBody = EntityUtils.toByteArray(entity); } catch (IOException e) { sendFailureMessage(e, (byte[]) null); } if (status.getStatusCode() >= 300) { sendFailureMessage(new HttpResponseException(status.getStatusCode(), status.getReasonPhrase()), responseBody); } else { sendSuccessMessage(status.getStatusCode(), responseBody); } }
From source file:net.tsz.afinal.http.AjaxRequestHandler.java
private void handleResponse(HttpResponse response) { StatusLine status = response.getStatusLine(); if (status.getStatusCode() >= 300) { publishProgress(Update_failure,// w w w . j av a 2s . c o m new HttpResponseException(status.getStatusCode(), status.getReasonPhrase()), "response status code:" + status.getStatusCode()); } else { try { HttpEntity temp = response.getEntity(); Object responseBody = null; if (temp != null) { if (targetUrl != null) responseBody = mFileEntityHandler.handleEntity(temp, new EntityCallBackImpl(), targetUrl); else responseBody = mStrEntityHandler.handleEntity(temp, new EntityCallBackImpl(), charset); } publishProgress(Update_success, responseBody); } catch (IOException e) { publishProgress(Update_failure, e, (String) null); } } }
From source file:com.pyj.http.BinaryHttpResponseHandler.java
@Override void sendResponseMessage(HttpResponse response, int reqType) { StatusLine status = response.getStatusLine(); Header[] contentTypeHeaders = response.getHeaders("Content-Type"); byte[] responseBody = null; if (contentTypeHeaders.length != 1) { //malformed/ambiguous HTTP Header, ABORT! sendFailureMessage(new HttpResponseException(status.getStatusCode(), "None, or more than one, Content-Type Header found!"), responseBody, reqType); return;//from ww w . j a va 2 s .co m } Header contentTypeHeader = contentTypeHeaders[0]; boolean foundAllowedContentType = false; for (String anAllowedContentType : mAllowedContentTypes) { if (Pattern.matches(anAllowedContentType, contentTypeHeader.getValue())) { foundAllowedContentType = true; } } if (!foundAllowedContentType) { //Content-Type not in allowed list, ABORT! sendFailureMessage(new HttpResponseException(status.getStatusCode(), "Content-Type not allowed!"), responseBody, reqType); return; } try { HttpEntity entity = null; HttpEntity temp = response.getEntity(); if (temp != null) { entity = new BufferedHttpEntity(temp); } responseBody = EntityUtils.toByteArray(entity); } catch (IOException e) { sendFailureMessage(e, (byte[]) null, reqType); } if (status.getStatusCode() >= 300) { sendFailureMessage(new HttpResponseException(status.getStatusCode(), status.getReasonPhrase()), responseBody, reqType); } else { sendSuccessMessage(status.getStatusCode(), responseBody, reqType); } }