當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpStatus.getMessage方法代碼示例

本文整理匯總了Java中org.eclipse.jetty.http.HttpStatus.getMessage方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpStatus.getMessage方法的具體用法?Java HttpStatus.getMessage怎麽用?Java HttpStatus.getMessage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jetty.http.HttpStatus的用法示例。


在下文中一共展示了HttpStatus.getMessage方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: toResponse

import org.eclipse.jetty.http.HttpStatus; //導入方法依賴的package包/類
@Override
public Response toResponse(final WebApplicationException e) {
	// If the message did not come with a status, we'll default to an internal
	// server error status.
	int status = e.getResponse() == null ? 500 : e.getResponse().getStatus();

	// Get a nice human readable message for our status code if the exception
	// doesn't already have a message
	final String msg = e.getMessage() == null ? HttpStatus.getMessage(status) : e.getMessage();

	// Create a JSON response with the provided hashmap
	return Response.status(status)
		.type(MediaType.APPLICATION_JSON_TYPE)
		.entity(ImmutableMap.of("error", msg))
		.build();
   }
 
開發者ID:deptofdefense,項目名稱:anet,代碼行數:17,代碼來源:WebExceptionMapper.java

示例2: rawRequest

import org.eclipse.jetty.http.HttpStatus; //導入方法依賴的package包/類
protected String rawRequest(String url, Map<String, String> params) throws InterruptedException, ExecutionException, TimeoutException, UnsupportedEncodingException {
    Request req = httpClient.newRequest(new String(url.getBytes("UTF-8"), "UTF-8"))
            .header(HttpHeader.CONTENT_ENCODING, "UTF-8")
            .method(HttpMethod.GET)
            .header(HttpHeader.ACCEPT_ENCODING, "UTF-8");
    req = req.param("app_token", APIKeys.getAPPKey());
    if (params != null) {
        for (String key : params.keySet()) {
            req = req.param(key, params.get(key));
        }
    }
    Main.log.info("GET {}, {}, {}", req, req.getQuery(), req.getParams());
    ContentResponse resp = req.send();
    if (resp.getStatus() != HttpStatus.OK_200) {
        throw new HttpRequestException(
                "Request ended with non-OK status: "
                + HttpStatus.getMessage(resp.getStatus()),
                resp.getRequest()
        );
    }
    return resp.getContentAsString();
}
 
開發者ID:psyriccio,項目名稱:VoteFlow,代碼行數:23,代碼來源:LawAPI.java

示例3: writeErrorPage

import org.eclipse.jetty.http.HttpStatus; //導入方法依賴的package包/類
@Override
protected void writeErrorPage(HttpServletRequest request, Writer writer, int code, String message, boolean showStacks) throws IOException {
    if (message == null)
        message=HttpStatus.getMessage(code);

    // Write a very short body (this makes people pushing with collectd happy).
    writer.write(String.valueOf(code));
    writer.write(" -- ");
    writer.write(message);

    // Log the request error.
    Throwable th = (Throwable)request.getAttribute(RequestDispatcher.ERROR_EXCEPTION);
    if (th != null) {
        final String http_request = request.getMethod() + ' ' + request.getRequestURI() + ' ' + request.getProtocol();
        LOG.log(Level.WARNING, http_request, th);
    }
}
 
開發者ID:groupon,項目名稱:monsoon,代碼行數:18,代碼來源:MonsoonErrorHandler.java

示例4: handleErrorPage

import org.eclipse.jetty.http.HttpStatus; //導入方法依賴的package包/類
@Override
protected void handleErrorPage(HttpServletRequest request, Writer writer, int code, String message) throws IOException {
    if (message == null)
        message = HttpStatus.getMessage(code);

    JsonObject obj = new JsonObject();
    obj.addProperty("code", code);
    obj.addProperty("message", message);
    writer.write(obj.toString());
}
 
開發者ID:Valandur,項目名稱:Web-API,代碼行數:11,代碼來源:ErrorHandler.java

示例5: message

import org.eclipse.jetty.http.HttpStatus; //導入方法依賴的package包/類
private static byte[] message(HttpConnection conn) {
  String msg;
  if (conn == null) {
    msg = "";
  } else {
    msg = conn.getHttpChannel().getResponse().getReason();
    if (msg == null) {
      msg = HttpStatus.getMessage(conn.getHttpChannel().getResponse().getStatus());
    }
  }
  return msg.getBytes(ISO_8859_1);
}
 
開發者ID:gerrit-review,項目名稱:gerrit,代碼行數:13,代碼來源:HiddenErrorHandler.java

示例6: handle

import org.eclipse.jetty.http.HttpStatus; //導入方法依賴的package包/類
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException {
    baseRequest.setHandled(true);
    String method = request.getMethod();
    if(!method.equals(HttpMethods.HEAD) && !method.equals(HttpMethods.GET) &&
            !method.equals(HttpMethods.POST) && !method.equals(PATCH_METHOD) && !method.equals(HttpMethods.PUT) &&
             !method.equals(HttpMethods.DELETE)) {
        return;
    }

    final String message;
    final ErrorCode error;
    final String note;
    if(response.getStatus() == HttpServletResponse.SC_NOT_FOUND) {
        message = "Path not found";
        if (!request.getRequestURI().contains("/v1/")) {
            note = "try including /v1/ in the path";
        } else {
            note = null;
        }
        error = ErrorCode.MALFORMED_REQUEST;
    } else {
        if (response instanceof Response) {
            note = ((Response)response).getReason();
        } else {
            note = null;
        }
        message = HttpStatus.getMessage(response.getStatus());
        error = ErrorCode.INTERNAL_ERROR;
    }

    response.setContentType(MediaType.APPLICATION_JSON);
    response.setHeader(HttpHeaders.CACHE_CONTROL, getCacheControl());

    StringBuilder builder = new StringBuilder();
    RestResponseBuilder.formatJsonError(builder, error.getFormattedValue(), message, note);
    builder.append('\n');

    response.setContentLength(builder.length());
    OutputStream out = response.getOutputStream();
    out.write(builder.toString().getBytes());
    out.close();
}
 
開發者ID:jaytaylor,項目名稱:sql-layer,代碼行數:44,代碼來源:JsonErrorHandler.java

示例7: requestStatus

import org.eclipse.jetty.http.HttpStatus; //導入方法依賴的package包/類
private String requestStatus(Request request, Response r, boolean uriIsSecret)
{
    String safeUri = safeUri(request, uriIsSecret);
    return request.getMethod() + " " + safeUri + ": " + r.getStatus() + " " + HttpStatus.getMessage(r.getStatus());
}
 
開發者ID:treasure-data,項目名稱:digdag,代碼行數:6,代碼來源:HttpOperatorFactory.java


注:本文中的org.eclipse.jetty.http.HttpStatus.getMessage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。