本文整理汇总了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();
}
示例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();
}
示例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);
}
}
示例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());
}
示例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);
}
示例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();
}
示例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());
}