org.apache.http.impl.EnglishReasonPhraseCatalog Java Examples

The following examples show how to use org.apache.http.impl.EnglishReasonPhraseCatalog. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: APIUtil.java    From rest-client with Apache License 2.0 6 votes vote down vote up
/**
* 
* @Title: getReason 
* @Description: Get HTTP status reason 
* @param @param code
* @param @return 
* @return String
* @throws
 */
public static String getReason(int code)
{
    ReasonPhraseCatalog catalog = EnglishReasonPhraseCatalog.INSTANCE;
    String reason = StringUtils.EMPTY;

    try
    {
        reason = catalog.getReason(code, Locale.getDefault());
        if (StringUtils.isEmpty(reason))
        {
            return StringUtils.EMPTY;
        }
    }
    catch(Exception e)
    {
        log.error(e.getMessage(), e);
    }

    return reason;
}
 
Example #2
Source File: SpanHttpDeriverUtil.java    From hawkular-apm with Apache License 2.0 6 votes vote down vote up
/**
 * Method returns list of http status codes.
 *
 * @param binaryAnnotations zipkin binary annotations
 * @return http status codes
 */
public static List<HttpCode> getHttpStatusCodes(List<BinaryAnnotation> binaryAnnotations) {
    if (binaryAnnotations == null) {
        return Collections.emptyList();
    }

    List<HttpCode> httpCodes = new ArrayList<>();

    for (BinaryAnnotation binaryAnnotation: binaryAnnotations) {
        if (Constants.ZIPKIN_BIN_ANNOTATION_HTTP_STATUS_CODE.equals(binaryAnnotation.getKey()) &&
                binaryAnnotation.getValue() != null) {

            String strHttpCode = binaryAnnotation.getValue();
            Integer httpCode = toInt(strHttpCode.trim());

            if (httpCode != null) {
                String description = EnglishReasonPhraseCatalog.INSTANCE.getReason(httpCode, Locale.ENGLISH);
                httpCodes.add(new HttpCode(httpCode, description));
            }
        }

    }
    return httpCodes;
}
 
Example #3
Source File: HttpAssertionFacadeImplTest.java    From cukes with Apache License 2.0 6 votes vote down vote up
private Response generateResponse(String contentType, int status, byte[] content) {
    final BasicStatusLine statusLine = new BasicStatusLine(
        new ProtocolVersion("HTTP", 1, 1),
        status,
        EnglishReasonPhraseCatalog.INSTANCE.getReason(status, Locale.ENGLISH));

    final BasicHttpResponse httpResponse = new BasicHttpResponse(statusLine);
    httpResponse.addHeader("Content-Type", contentType);

    final HttpResponseDecorator httpResponseDecorator = new HttpResponseDecorator(httpResponse, content);
    final RestAssuredResponseImpl restResponse = new RestAssuredResponseImpl();
    restResponse.setStatusCode(status);
    restResponse.parseResponse(
        httpResponseDecorator,
        content,
        false,
        new ResponseParserRegistrar()
    );

    return restResponse;
}
 
Example #4
Source File: CaldavConnection.java    From davmail with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Send Http response with given status, headers, content type and content.
 * Close connection if keepAlive is false
 *
 * @param status      Http status
 * @param headers     Http headers
 * @param contentType MIME content type
 * @param content     response body as byte array
 * @param keepAlive   keep connection open
 * @throws IOException on error
 */
public void sendHttpResponse(int status, Map<String, String> headers, String contentType, byte[] content, boolean keepAlive) throws IOException {
    sendClient("HTTP/1.1 " + status + ' ' + EnglishReasonPhraseCatalog.INSTANCE.getReason(status, Locale.ENGLISH));
    if (status != HttpStatus.SC_UNAUTHORIZED) {
        sendClient("Server: DavMail Gateway " + DavGateway.getCurrentVersion());
        String scheduleMode;
        // enable automatic scheduling over EWS, can be disabled
        if (Settings.getBooleanProperty("davmail.caldavAutoSchedule", true)
                && !(session instanceof DavExchangeSession)) {
            scheduleMode = "calendar-auto-schedule";
        } else {
            scheduleMode = "calendar-schedule";
        }
        sendClient("DAV: 1, calendar-access, " + scheduleMode + ", calendarserver-private-events, addressbook");
        SimpleDateFormat formatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.ENGLISH);
        // force GMT timezone
        formatter.setTimeZone(ExchangeSession.GMT_TIMEZONE);
        String now = formatter.format(new Date());
        sendClient("Date: " + now);
        sendClient("Expires: " + now);
        sendClient("Cache-Control: private, max-age=0");
    }
    if (headers != null) {
        for (Map.Entry<String, String> header : headers.entrySet()) {
            sendClient(header.getKey() + ": " + header.getValue());
        }
    }
    if (contentType != null) {
        sendClient("Content-Type: " + contentType);
    }
    closed = closed || !keepAlive;
    sendClient("Connection: " + (closed ? "close" : "keep-alive"));
    if (content != null && content.length > 0) {
        sendClient("Content-Length: " + content.length);
    } else if (headers == null || !"chunked".equals(headers.get("Transfer-Encoding"))) {
        sendClient("Content-Length: 0");
    }
    sendClient("");
    if (content != null && content.length > 0) {
        // full debug trace
        if (wireLogger.isDebugEnabled()) {
            wireLogger.debug("> " + new String(content, StandardCharsets.UTF_8));
        }
        sendClient(content);
    }
}
 
Example #5
Source File: BlockingHttpClient.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
private String getReason(final int statusCode) {
  String reason = EnglishReasonPhraseCatalog.INSTANCE.getReason(statusCode, ENGLISH);
  return reason == null ? "Unrecognized HTTP error" : reason;
}