本文整理汇总了Java中org.apache.http.client.HttpResponseException类的典型用法代码示例。如果您正苦于以下问题:Java HttpResponseException类的具体用法?Java HttpResponseException怎么用?Java HttpResponseException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpResponseException类属于org.apache.http.client包,在下文中一共展示了HttpResponseException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendResponseMessage
import org.apache.http.client.HttpResponseException; //导入依赖的package包/类
public void sendResponseMessage(HttpResponse response) throws IOException {
if (!Thread.currentThread().isInterrupted()) {
StatusLine status = response.getStatusLine();
if (status.getStatusCode() == 416) {
if (!Thread.currentThread().isInterrupted()) {
sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), null);
}
} else if (status.getStatusCode() >= 300) {
if (!Thread.currentThread().isInterrupted()) {
sendFailureMessage(status.getStatusCode(), response.getAllHeaders(), null,
new HttpResponseException(status.getStatusCode(), status
.getReasonPhrase()));
}
} else if (!Thread.currentThread().isInterrupted()) {
Header header = response.getFirstHeader(AsyncHttpClient.HEADER_CONTENT_RANGE);
if (header == null) {
this.append = false;
this.current = 0;
} else {
Log.v(LOG_TAG, "Content-Range: " + header.getValue());
}
sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(),
getResponseData(response.getEntity()));
}
}
}
示例2: sendResponseMessage
import org.apache.http.client.HttpResponseException; //导入依赖的package包/类
@Override
public final void sendResponseMessage(HttpResponse response) throws IOException {
StatusLine status = response.getStatusLine();
Header[] contentTypeHeaders = response.getHeaders("Content-Type");
if (contentTypeHeaders.length != 1) {
//malformed/ambiguous HTTP Header, ABORT!
sendFailureMessage(status.getStatusCode(), response.getAllHeaders(), null, new HttpResponseException(status.getStatusCode(), "None, or more than one, Content-Type Header found!"));
return;
}
Header contentTypeHeader = contentTypeHeaders[0];
boolean foundAllowedContentType = false;
for (String anAllowedContentType : getAllowedContentTypes()) {
try {
if (Pattern.matches(anAllowedContentType, contentTypeHeader.getValue())) {
foundAllowedContentType = true;
}
} catch (PatternSyntaxException e) {
}
}
if (!foundAllowedContentType) {
//Content-Type not in allowed list, ABORT!
sendFailureMessage(status.getStatusCode(), response.getAllHeaders(), null, new HttpResponseException(status.getStatusCode(), "Content-Type not allowed!"));
return;
}
super.sendResponseMessage(response);
}
示例3: testConvertMovie
import org.apache.http.client.HttpResponseException; //导入依赖的package包/类
@Test
public void testConvertMovie() throws AirtableException, HttpResponseException {
Table<Movie> movieTable = base.table("Movies", Movie.class);
Movie movie = movieTable.find("recFj9J78MLtiFFMz");
assertNotNull(movie);
assertEquals(movie.getId(),"recFj9J78MLtiFFMz");
assertEquals(movie.getName(),"The Godfather");
assertEquals(movie.getPhotos().size(),2);
assertEquals(movie.getDirector().size(),1);
assertEquals(movie.getActors().size(),2);
assertEquals(movie.getGenre().size(),1);
//TODO Test für Datum
}
示例4: testConvertAttachement
import org.apache.http.client.HttpResponseException; //导入依赖的package包/类
@Test
public void testConvertAttachement() throws AirtableException, HttpResponseException {
Table<Movie> movieTable = base.table("Movies", Movie.class);
Movie movie = movieTable.find("recFj9J78MLtiFFMz");
assertNotNull(movie);
assertEquals(movie.getPhotos().size(),2);
Attachment photo1 = movie.getPhotos().get(0);
assertNotNull(photo1);
Attachment photo2 = movie.getPhotos().get(0);
assertNotNull(photo2);
assertEquals(photo1.getId(),"attk3WY5B28GVcFGU");
assertEquals(photo1.getUrl(),"https://dl.airtable.com/9UhUUeAtSym1PzBdA0q0_AlPacinoandMarlonBrando.jpg");
assertEquals(photo1.getFilename(),"AlPacinoandMarlonBrando.jpg");
assertEquals(photo1.getSize(),35698,0);
assertEquals(photo1.getType(),"image/jpeg");
assertEquals(photo1.getThumbnails().size(),2);
}
示例5: testConvertThumbnails
import org.apache.http.client.HttpResponseException; //导入依赖的package包/类
@Test
public void testConvertThumbnails() throws AirtableException, HttpResponseException {
Table<Movie> movieTable = base.table("Movies", Movie.class);
Movie movie = movieTable.find("recFj9J78MLtiFFMz");
assertNotNull(movie);
assertEquals(movie.getPhotos().get(0).getThumbnails().size(),2);
assertEquals(movie.getPhotos().get(1).getThumbnails().size(),2);
Map<String, Thumbnail> thumbnails = movie.getPhotos().get(1).getThumbnails();
Thumbnail thumb = thumbnails.get("small");
assertEquals(thumb.getUrl(),"https://dl.airtable.com/rlQ8MyQ4RuqN7rT03ALq_small_The%20Godfather%20poster.jpg");
assertEquals(thumb.getHeight(),36.0, 0);
assertEquals(thumb.getWidth(),24.0, 0);
}
示例6: testSelectTableSorted
import org.apache.http.client.HttpResponseException; //导入依赖的package包/类
@Test
public void testSelectTableSorted() throws AirtableException, HttpResponseException {
Table table = base.table("Movies", Movie.class);
List<Movie> retval = table.select(new Sort("Name", Sort.Direction.asc));
assertNotNull(retval);
assertEquals(9, retval.size());
Movie mov = retval.get(0);
assertEquals("Billy Madison", mov.getName());
retval = table.select(new Sort("Name", Sort.Direction.desc));
assertNotNull(retval);
assertEquals(9, retval.size());
mov = retval.get(0);
assertEquals("You've Got Mail", mov.getName());
}
示例7: fieldsParamTest
import org.apache.http.client.HttpResponseException; //导入依赖的package包/类
@Test
public void fieldsParamTest() throws AirtableException, HttpResponseException {
Table<Movie> movieTable = base.table("Movies", Movie.class);
String[] fields = new String[1];
fields[0] = "Name";
List<Movie> listMovies = movieTable.select(fields);
assertNotNull(listMovies);
assertNotNull(listMovies.get(0).getName());
assertNull(listMovies.get(0).getDirector());
assertNull(listMovies.get(0).getActors());
assertNull(listMovies.get(0).getDescription());
}
示例8: getResponseAsString
import org.apache.http.client.HttpResponseException; //导入依赖的package包/类
public static Optional<String> getResponseAsString(HttpRequestBase httpRequest, HttpClient client) {
Optional<String> result = Optional.empty();
final int waitTime = 60000;
try {
ResponseHandler<String> responseHandler = new BasicResponseHandler();
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(waitTime).setConnectTimeout(waitTime)
.setConnectionRequestTimeout(waitTime).build();
httpRequest.setConfig(requestConfig);
result = Optional.of(client.execute(httpRequest, responseHandler));
} catch (HttpResponseException httpResponseException) {
LOG.error("getResponseAsString(): caught 'HttpResponseException' while processing request <{}> :=> <{}>", httpRequest,
httpResponseException.getMessage());
} catch (IOException ioe) {
LOG.error("getResponseAsString(): caught 'IOException' while processing request <{}> :=> <{}>", httpRequest, ioe.getMessage());
} finally {
httpRequest.releaseConnection();
}
return result;
}
示例9: setHeadersAndExecute
import org.apache.http.client.HttpResponseException; //导入依赖的package包/类
private HttpResponse setHeadersAndExecute(HttpUriRequest request, Map<String, String> headers) throws IOException {
setHeaders(request, headers);
HttpResponse response = client.execute(request);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusNotOk(statusCode)) {
String body = null;
if (response.getEntity() != null) {
try {
body = readStream(response.getEntity().getContent());
EntityUtils.consume(response.getEntity());
} catch (IOException e) {
// Ignore
}
}
String message = String.format("Received %d %s response from Xray", statusCode, statusLine);
if (StringUtils.isNotBlank(body)) {
message += ". " + body;
}
throw new HttpResponseException(statusCode, message);
}
return response;
}
示例10: sendResponseMessage
import org.apache.http.client.HttpResponseException; //导入依赖的package包/类
public void sendResponseMessage(HttpResponse response) throws IOException {
if (!Thread.currentThread().isInterrupted()) {
StatusLine status = response.getStatusLine();
byte[] responseBody = getResponseData(response.getEntity());
if (!Thread.currentThread().isInterrupted()) {
if (status.getStatusCode() >= 300) {
sendFailureMessage(status.getStatusCode(), response.getAllHeaders(),
responseBody, new HttpResponseException(status.getStatusCode(),
status.getReasonPhrase()));
} else {
sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(),
responseBody);
}
}
}
}
示例11: sendResponseMessage
import org.apache.http.client.HttpResponseException; //导入依赖的package包/类
@Override
public void sendResponseMessage(HttpResponse response) throws IOException {
// do not process if request has been cancelled
if (!Thread.currentThread().isInterrupted()) {
StatusLine status = response.getStatusLine();
byte[] responseBody;
responseBody = getResponseData(response.getEntity());
// additional cancellation check as getResponseData() can take non-zero time to process
if (!Thread.currentThread().isInterrupted()) {
if (status.getStatusCode() >= 300) {
sendFailureMessage(status.getStatusCode(), response.getAllHeaders(), responseBody, new HttpResponseException(status.getStatusCode(), status.getReasonPhrase()));
} else {
sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), responseBody);
}
}
}
}
示例12: sendResponseMessage
import org.apache.http.client.HttpResponseException; //导入依赖的package包/类
@Override
public void sendResponseMessage(HttpResponse response) throws IOException {
if (!Thread.currentThread().isInterrupted()) {
StatusLine status = response.getStatusLine();
if (status.getStatusCode() == HttpStatus.SC_REQUESTED_RANGE_NOT_SATISFIABLE) {
//already finished
if (!Thread.currentThread().isInterrupted())
sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), null);
} else if (status.getStatusCode() >= 300) {
if (!Thread.currentThread().isInterrupted())
sendFailureMessage(status.getStatusCode(), response.getAllHeaders(), null, new HttpResponseException(status.getStatusCode(), status.getReasonPhrase()));
} else {
if (!Thread.currentThread().isInterrupted()) {
Header header = response.getFirstHeader(AsyncHttpClient.HEADER_CONTENT_RANGE);
if (header == null) {
append = false;
current = 0;
} else
Log.v(LOG_TAG, AsyncHttpClient.HEADER_CONTENT_RANGE + ": " + header.getValue());
sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), getResponseData(response.getEntity()));
}
}
}
}
开发者ID:benniaobuguai,项目名称:android-project-gallery,代码行数:25,代码来源:RangeFileAsyncHttpResponseHandler.java
示例13: sendResponseMessage
import org.apache.http.client.HttpResponseException; //导入依赖的package包/类
@Override
public void sendResponseMessage(HttpResponse response) throws IOException {
if (!Thread.currentThread().isInterrupted()) {
StatusLine status = response.getStatusLine();
if (status.getStatusCode() == HttpStatus.SC_REQUESTED_RANGE_NOT_SATISFIABLE) {
//already finished
if (!Thread.currentThread().isInterrupted())
sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), null);
} else if (status.getStatusCode() >= 300) {
if (!Thread.currentThread().isInterrupted())
sendFailureMessage(status.getStatusCode(), response.getAllHeaders(), null, new HttpResponseException(status.getStatusCode(), status.getReasonPhrase()));
} else {
if (!Thread.currentThread().isInterrupted()) {
Header header = response.getFirstHeader(AsyncHttpClient.HEADER_CONTENT_RANGE);
if (header == null) {
append = false;
current = 0;
} else {
Log.v(LOG_TAG, AsyncHttpClient.HEADER_CONTENT_RANGE + ": " + header.getValue());
}
sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), getResponseData(response.getEntity()));
}
}
}
}
示例14: readContent
import org.apache.http.client.HttpResponseException; //导入依赖的package包/类
/**
* Reads content.
* @param httpClient HTTP client
* @param since since date
* @return content reference
* @throws IOException if reading content fails
* @throws URISyntaxException if file url is an invalid URI
*/
public SimpleDataReference readContent(CloseableHttpClient httpClient, Date since) throws IOException, URISyntaxException {
HttpGet method = new HttpGet(fileUrl.toExternalForm());
method.setConfig(DEFAULT_REQUEST_CONFIG);
method.setHeader("User-Agent", HttpConstants.getUserAgent());
HttpClientContext context = creds!=null && !creds.isEmpty()? createHttpClientContext(fileUrl, creds): null;
try (CloseableHttpResponse httpResponse = httpClient.execute(method,context); InputStream input = httpResponse.getEntity().getContent();) {
if (httpResponse.getStatusLine().getStatusCode()>=400) {
throw new HttpResponseException(httpResponse.getStatusLine().getStatusCode(), httpResponse.getStatusLine().getReasonPhrase());
}
Date lastModifiedDate = readLastModifiedDate(httpResponse);
MimeType contentType = readContentType(httpResponse);
boolean readBody = since==null || lastModifiedDate==null || lastModifiedDate.getTime()>=since.getTime();
SimpleDataReference ref = new SimpleDataReference(broker.getBrokerUri(), broker.getEntityDefinition().getLabel(), fileUrl.toExternalForm(), lastModifiedDate, fileUrl.toURI());
ref.addContext(contentType, readBody? IOUtils.toByteArray(input): null);
return ref;
}
}
示例15: scrap
import org.apache.http.client.HttpResponseException; //导入依赖的package包/类
/**
* Scrap HTML page for URL's
* @param root root of the page
* @return list of found URL's
* @throws IOException if error reading data
* @throws URISyntaxException if invalid URL
*/
public List<URL> scrap(URL root) throws IOException, URISyntaxException {
ContentAnalyzer analyzer = new ContentAnalyzer(root);
HttpGet method = new HttpGet(root.toExternalForm());
method.setConfig(DEFAULT_REQUEST_CONFIG);
method.setHeader("User-Agent", HttpConstants.getUserAgent());
HttpClientContext context = creds!=null && !creds.isEmpty()? createHttpClientContext(root, creds): null;
try (CloseableHttpResponse httpResponse = httpClient.execute(method, context); InputStream input = httpResponse.getEntity().getContent();) {
if (httpResponse.getStatusLine().getStatusCode()>=400) {
throw new HttpResponseException(httpResponse.getStatusLine().getStatusCode(), httpResponse.getStatusLine().getReasonPhrase());
}
String content = IOUtils.toString(input, "UTF-8");
return analyzer.analyze(content);
}
}