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


Java HttpResponseException类代码示例

本文整理汇总了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()));
        }
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:27,代码来源:RangeFileAsyncHttpResponseHandler.java

示例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);
}
 
开发者ID:LanguidSheep,项目名称:sealtalk-android-master,代码行数:27,代码来源:BinaryHttpResponseHandler.java

示例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
              
}
 
开发者ID:Sybit-Education,项目名称:airtable.java,代码行数:18,代码来源:TableConverterTest.java

示例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);
    
}
 
开发者ID:Sybit-Education,项目名称:airtable.java,代码行数:24,代码来源:TableConverterTest.java

示例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);
    
}
 
开发者ID:Sybit-Education,项目名称:airtable.java,代码行数:17,代码来源:TableConverterTest.java

示例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());

}
 
开发者ID:Sybit-Education,项目名称:airtable.java,代码行数:19,代码来源:TableSelectJacksonOMTest.java

示例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());

}
 
开发者ID:Sybit-Education,项目名称:airtable.java,代码行数:17,代码来源:TableParameterTest.java

示例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;
}
 
开发者ID:dockstore,项目名称:write_api_service,代码行数:20,代码来源:ResourceUtilities.java

示例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;
}
 
开发者ID:JFrogDev,项目名称:jfrog-idea-plugin,代码行数:24,代码来源:XrayImpl.java

示例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);
            }
        }
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:17,代码来源:AsyncHttpResponseHandler.java

示例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);
            }
        }
    }
}
 
开发者ID:LanguidSheep,项目名称:sealtalk-android-master,代码行数:18,代码来源:AsyncHttpResponseHandler.java

示例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()));
            }
        }
    }
}
 
开发者ID:yiwent,项目名称:Mobike,代码行数:26,代码来源:RangeFileAsyncHttpResponseHandler.java

示例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;
  }
}
 
开发者ID:Esri,项目名称:geoportal-server-harvester,代码行数:27,代码来源:WafFile.java

示例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);
  }
}
 
开发者ID:Esri,项目名称:geoportal-server-harvester,代码行数:23,代码来源:HtmlUrlScrapper.java


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