本文整理汇总了Java中org.jboss.netty.handler.codec.http.HttpResponseStatus.getReasonPhrase方法的典型用法代码示例。如果您正苦于以下问题:Java HttpResponseStatus.getReasonPhrase方法的具体用法?Java HttpResponseStatus.getReasonPhrase怎么用?Java HttpResponseStatus.getReasonPhrase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jboss.netty.handler.codec.http.HttpResponseStatus
的用法示例。
在下文中一共展示了HttpResponseStatus.getReasonPhrase方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createErrorPage
import org.jboss.netty.handler.codec.http.HttpResponseStatus; //导入方法依赖的package包/类
/**
* Creates an error page.
*
* @param status The HTTP status.
* @param description The error description.
* @return The error page as a buffer.
*/
private ChannelBuffer createErrorPage(HttpResponseStatus status, String description) {
String title = status.getCode() + " " + status.getReasonPhrase();
StringBuilder builder = new StringBuilder();
builder.append("<!DOCTYPE html><html><head><title>");
builder.append(title);
builder.append("</title></head><body><h1>");
builder.append(title);
builder.append("</h1><p>");
builder.append(description);
builder.append("</p><hr /><address>");
builder.append(SERVER_IDENTIFIER);
builder.append(" Server</address></body></html>");
return ChannelBuffers.copiedBuffer(builder.toString(), Charset.defaultCharset());
}
示例2: getErrorHtml
import org.jboss.netty.handler.codec.http.HttpResponseStatus; //导入方法依赖的package包/类
private String getErrorHtml(HttpResponseStatus status, Throwable throwable) {
String stackTrace = null;
if (throwable != null) {
StringWriter sw = new StringWriter();
PrintWriter s = new PrintWriter(sw);
throwable.printStackTrace(s);
stackTrace = sw.toString();
}
return "<html>\n" + "<head>\n" + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>\n" + "<title>Error " + status.toString() + "</title>\n"
+ "</head>\n" + "<body>\n" + "<h2>HTTP ERROR: " + status.getCode() + "</h2>\n" + "<p>Problem accessing [" + request.getMethod() + "]" + request.getUri()
+ ". Reason:\n" + "<pre> " + status.getReasonPhrase() + (stackTrace != null ? "\n\n" + stackTrace : "") + "</pre></p>\n"
+ "<hr /><i><small>Powered by FastcatSearch</small></i>\n" + "</body>\n" + "</html>";
}
示例3: sendHttpResponse
import org.jboss.netty.handler.codec.http.HttpResponseStatus; //导入方法依赖的package包/类
private void sendHttpResponse(ActorRef sender, HttpResponseStatus status, String response) {
// headers
Map<String, List<String>> headers = new HashMap<String, List<String>>();
headers.put(HttpHeaders.Names.CONTENT_TYPE, Arrays.asList("text/plain"));
// response
if (StringUtils.isEmpty(response)) {
response = status.getReasonPhrase();
}
sender.tell(new HttpResponse(status.getCode(), headers,
response.getBytes(Charset.forName("UTF-8"))), getSelf());
}