Java 类org.apache.commons.httpclient.StatusLine 实例源码

项目:lib-commons-httpclient    文件:SimpleHttpServerConnection.java   
public SimpleResponse readResponse() throws IOException {
    try {
        String line = null;
        do {
            line = HttpParser.readLine(in, HTTP_ELEMENT_CHARSET);
        } while (line != null && line.length() == 0);

        if (line == null) {
            setKeepAlive(false);
            return null;
        }
        SimpleResponse response = new SimpleResponse(
                new StatusLine(line),
                HttpParser.parseHeaders(this.in, HTTP_ELEMENT_CHARSET),
                this.in);
        return response;
    } catch (IOException e) {
        close();
        throw e;
    }
}
项目:ffma    文件:PreservationRiskmanagementServiceImpl.java   
/**
 * This method tries to establish HTTP connection for passed URI
 * @param uri The URI to verify
 * @param responseLineList 
 *        This list collects response lines for broken URIs
 * @param brokenUriList
 *        This list collects broken URIs
 */
private void verifyUri(String uri, List<String> responseLineList, List<String> brokenUriList) {
    HttpClient client = new HttpClient();
    client.getHttpConnectionManager().getParams().
    setConnectionTimeout(10000);
    try {
        HttpMethod method = new GetMethod(uri);
        method.setFollowRedirects(true);
        client.executeMethod(method);
        int response = method.getStatusCode();
        if (response != 200) {
            StatusLine responseLine = method.getStatusLine();
            log.info("uri: " + uri + ", response: " + response + ", responseLine: " + responseLine.toString());
            brokenUriList.add(uri);
            responseLineList.add(responseLine.toString());
        }
        method.releaseConnection();
    } catch (IOException e) {
        log.info("Unable to connect to �" + uri + "� verification error: " + e);
        brokenUriList.add(uri);
        responseLineList.add(e.getMessage());
    } 
}
项目:bamboo    文件:HttpHeader.java   
public static HttpHeader parse(InputStream in, String targetUrl) throws IOException {
    String line = LaxHttpParser.readLine(in, "ISO-8859-1");
    if (line == null || !StatusLine.startsWithHTTP(line)) {
        return null;
    }
    HttpHeader result = new HttpHeader();
    result.status = parseStatusLine(line);
    for (Header header : LaxHttpParser.parseHeaders(in, ARCConstants.DEFAULT_ENCODING)) {
        switch (header.getName().toLowerCase()) {
            case "location":
                try {
                    result.rawLocation = header.getValue();
                    URL url = new URL(targetUrl);
                    result.location = new URL(url, header.getValue()).toString().replace(" ", "%20");
                } catch (MalformedURLException e) {
                    // skip it
                }
                break;
            case "content-type":
                result.contentType = header.getValue();
                break;
        }
    }
    return result;
}
项目:flex-blazeds    文件:ResponseFilter.java   
protected void checkStatusCode(ProxyContext context)
{
    int statusCode = context.getStatusCode();
    // FIXME: Why do this only for HTTP Proxy? Why not WebServices?
    if (statusCode >= 400 && statusCode != 401 & statusCode != 403 && !context.isSoapRequest())
    {
        StatusLine statusLine = context.getHttpMethod().getStatusLine();
        String reason = null;

        if (statusLine != null)
            reason = statusLine.toString();

        if (reason == null || "".equals(reason))
            reason = String.valueOf(statusCode);

        ProxyException pe = new ProxyException();
        pe.setMessage(STATUS_ERROR, new Object[] { reason });
        pe.setCode(ProxyException.CODE_SERVER_PROXY_REQUEST_FAILED);
        pe.setDetails(STATUS_ERROR, "1", new Object[] { reason });
        pe.setStatusCode(statusCode);
        throw pe;
    }
}
项目:httpclient3-ntml    文件:SimpleHttpServerConnection.java   
public SimpleResponse readResponse() throws IOException {
    try {
        String line = null;
        do {
            line = HttpParser.readLine(in, HTTP_ELEMENT_CHARSET);
        } while (line != null && line.length() == 0);

        if (line == null) {
            setKeepAlive(false);
            return null;
        }
        SimpleResponse response = new SimpleResponse(
                new StatusLine(line),
                HttpParser.parseHeaders(this.in, HTTP_ELEMENT_CHARSET),
                this.in);
        return response;
    } catch (IOException e) {
        close();
        throw e;
    }
}
项目:jive-utils    文件:Curl.java   
public String curl(String path) throws IOException {
    GetMethod method = new GetMethod(path);
    byte[] responseBody;
    StatusLine statusLine;
    try {
        client.executeMethod(method);

        responseBody = method.getResponseBody();
        statusLine = method.getStatusLine();
        if (statusLine.getStatusCode() == 200) {
            return new String(responseBody);
        } else {
            return null;
        }
    } finally {
        method.releaseConnection();
    }
}
项目:netarchivesuite-svngit-migration    文件:NetarchiveSuiteWARCRecordToSearchResultAdapter.java   
private CaptureSearchResult adaptWARCHTTPResponse(CaptureSearchResult result,
        WARCRecord rec) throws IOException {

    ArchiveRecordHeader header = rec.getHeader();
    // need to parse the documents HTTP message and headers here: WARCReader
    // does not implement this... yet..

       byte [] statusBytes = HttpParser.readRawLine(rec);
       int eolCharCount = getEolCharsCount(statusBytes);
       if (eolCharCount <= 0) {
           throw new RecoverableIOException("Failed to read http status where one " +
                   " was expected: " + 
                   ((statusBytes == null) ? "(null)" : new String(statusBytes)));
       }
       String statusLine = EncodingUtil.getString(statusBytes, 0,
           statusBytes.length - eolCharCount, ARCConstants.DEFAULT_ENCODING);
       if ((statusLine == null) ||
               !StatusLine.startsWithHTTP(statusLine)) {
          throw new RecoverableIOException("Failed parse of http status line.");
       }
       StatusLine status = new StatusLine(statusLine);
    result.setHttpCode(String.valueOf(status.getStatusCode()));

    Header[] headers = HttpParser.parseHeaders(rec,
               ARCConstants.DEFAULT_ENCODING);


    annotater.annotateHTTPContent(result,rec,headers,header.getMimetype());

    return result;
}
项目:JavaChatterRESTApi    文件:ChatterResponseTest.java   
@Test
public void testGetStatusLine() throws HttpException {
    String statusLineString = "HTTP/1.0 199 Status Text";
    HttpMethod method = mock(HttpMethod.class);
    StatusLine statusLine = new StatusLine(statusLineString);
    when(method.getStatusLine()).thenReturn(statusLine);

    ChatterResponse response = new ChatterResponse(method);
    assertEquals(statusLineString, response.getStatusLine());
}
项目:further-open-core    文件:HttpResponseTo.java   
/**
 * Provides access to the response status line.
 * 
 * @return the status line object from the latest response.
 * @since 2.0
 */
public StatusLine getStatusLine()
{
    return statusLine;
}