本文整理匯總了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());
}