当前位置: 首页>>代码示例>>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;未经允许,请勿转载。