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