本文整理汇总了Java中org.apache.hadoop.http.HtmlQuoting.quoteHtmlChars方法的典型用法代码示例。如果您正苦于以下问题:Java HtmlQuoting.quoteHtmlChars方法的具体用法?Java HtmlQuoting.quoteHtmlChars怎么用?Java HtmlQuoting.quoteHtmlChars使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.hadoop.http.HtmlQuoting
的用法示例。
在下文中一共展示了HtmlQuoting.quoteHtmlChars方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doFilter
import org.apache.hadoop.http.HtmlQuoting; //导入方法依赖的package包/类
@Override
public void doFilter(HttpServletRequest request,
HttpServletResponse response, FilterChain chain) throws IOException,
ServletException {
String uri = HtmlQuoting.quoteHtmlChars(request.getRequestURI());
String redirectPath = containerLogPageRedirectPath(uri);
if (redirectPath != null) {
String redirectMsg =
"Redirecting to log server" + " : " + redirectPath;
PrintWriter out = response.getWriter();
out.println(redirectMsg);
response.setHeader("Location", redirectPath);
response.setStatus(HttpServletResponse.SC_TEMPORARY_REDIRECT);
return;
}
super.doFilter(request, response, chain);
}
示例2: handleRedirect
import org.apache.hadoop.http.HtmlQuoting; //导入方法依赖的package包/类
private void handleRedirect(HttpServletRequest servletRequest, HttpServletResponse httpServletResponse,
String activeServerAddress) throws IOException {
String requestURI = servletRequest.getRequestURI();
String queryString = servletRequest.getQueryString();
if ((queryString != null) && (!queryString.isEmpty())) {
requestURI += "?" + queryString;
}
String quotedUri = HtmlQuoting.quoteHtmlChars(requestURI);
if (quotedUri == null) {
quotedUri = "/";
}
String redirectLocation = activeServerAddress + quotedUri;
LOG.info("Not active. Redirecting to {}", redirectLocation);
// A POST/PUT/DELETE require special handling by sending HTTP 307 instead of the regular 301/302.
// Reference: http://stackoverflow.com/questions/2068418/whats-the-difference-between-a-302-and-a-307-redirect
if (isUnsafeHttpMethod(servletRequest)) {
httpServletResponse.setHeader(HttpHeaders.LOCATION, redirectLocation);
httpServletResponse.setStatus(HttpServletResponse.SC_TEMPORARY_REDIRECT);
} else {
httpServletResponse.sendRedirect(redirectLocation);
}
}
示例3: doFilter
import org.apache.hadoop.http.HtmlQuoting; //导入方法依赖的package包/类
@Override
public void doFilter(HttpServletRequest request,
HttpServletResponse response, FilterChain chain) throws IOException,
ServletException {
response.setCharacterEncoding("UTF-8");
String uri = HtmlQuoting.quoteHtmlChars(request.getRequestURI());
String queryString = request.getQueryString();
if (uri == null) {
uri = "/";
}
if (queryString != null) {
uri = uri + "?" + queryString;
}
RMWebApp rmWebApp = injector.getInstance(RMWebApp.class);
rmWebApp.checkIfStandbyRM();
if (rmWebApp.isStandby()
&& shouldRedirect(rmWebApp, uri)) {
String redirectPath = rmWebApp.getRedirectPath() + uri;
if (redirectPath != null && !redirectPath.isEmpty()) {
String redirectMsg =
"This is standby RM. The redirect url is: " + redirectPath;
PrintWriter out = response.getWriter();
out.println(redirectMsg);
response.setHeader("Location", redirectPath);
response.setStatus(HttpServletResponse.SC_TEMPORARY_REDIRECT);
return;
}
}
super.doFilter(request, response, chain);
}
示例4: doFilter
import org.apache.hadoop.http.HtmlQuoting; //导入方法依赖的package包/类
@Override
public void doFilter(HttpServletRequest request,
HttpServletResponse response, FilterChain chain) throws IOException,
ServletException {
response.setCharacterEncoding("UTF-8");
String uri = HtmlQuoting.quoteHtmlChars(request.getRequestURI());
if (uri == null) {
uri = "/";
}
RMWebApp rmWebApp = injector.getInstance(RMWebApp.class);
rmWebApp.checkIfStandbyRM();
if (rmWebApp.isStandby()
&& shouldRedirect(rmWebApp, uri)) {
String redirectPath = rmWebApp.getRedirectPath() + uri;
if (redirectPath != null && !redirectPath.isEmpty()) {
String redirectMsg =
"This is standby RM. The redirect url is: " + redirectPath;
PrintWriter out = response.getWriter();
out.println(redirectMsg);
response.setHeader("Location", redirectPath);
response.setStatus(HttpServletResponse.SC_TEMPORARY_REDIRECT);
return;
}
}
super.doFilter(request, response, chain);
}
示例5: doFilter
import org.apache.hadoop.http.HtmlQuoting; //导入方法依赖的package包/类
@Override
public void doFilter(HttpServletRequest request,
HttpServletResponse response, FilterChain chain) throws IOException,
ServletException {
response.setCharacterEncoding("UTF-8");
String uri = HtmlQuoting.quoteHtmlChars(request.getRequestURI());
if (uri == null) {
uri = "/";
}
RMWebApp rmWebApp = injector.getInstance(RMWebApp.class);
rmWebApp.checkIfStandbyRM();
if (rmWebApp.isStandby()
&& shouldRedirect(rmWebApp, uri)) {
String redirectPath = rmWebApp.getRedirectPath() + uri;
if (redirectPath != null && !redirectPath.isEmpty()) {
String redirectMsg =
"This is standby RM. Redirecting to the current active RM: "
+ redirectPath;
response.addHeader("Refresh", "3; url=" + redirectPath);
PrintWriter out = response.getWriter();
out.println(redirectMsg);
return;
}
}
super.doFilter(request, response, chain);
}
示例6: getHtmlEscapedURIWithQueryString
import org.apache.hadoop.http.HtmlQuoting; //导入方法依赖的package包/类
/**
* Get a HTML escaped uri with the query parameters of the request.
* @param request HttpServletRequest with the request details
* @return HTML escaped uri with the query paramters
*/
public static String getHtmlEscapedURIWithQueryString(
HttpServletRequest request) {
String urlEncodedQueryString = getURLEncodedQueryString(request);
if (urlEncodedQueryString != null) {
return HtmlQuoting.quoteHtmlChars(
request.getRequestURI() + "?" + urlEncodedQueryString);
}
return HtmlQuoting.quoteHtmlChars(request.getRequestURI());
}
示例7: doFilter
import org.apache.hadoop.http.HtmlQuoting; //导入方法依赖的package包/类
@Override
public void doFilter(HttpServletRequest request,
HttpServletResponse response, FilterChain chain) throws IOException,
ServletException {
response.setCharacterEncoding("UTF-8");
String uri = HtmlQuoting.quoteHtmlChars(request.getRequestURI());
if (uri == null) {
uri = "/";
}
RMWebApp rmWebApp = injector.getInstance(RMWebApp.class);
rmWebApp.checkIfStandbyRM();
if (rmWebApp.isStandby()
&& !uri.equals("/" + rmWebApp.wsName() + "/v1/cluster/info")
&& !uri.equals("/" + rmWebApp.name() + "/cluster")) {
String redirectPath = rmWebApp.getRedirectPath() + uri;
if (redirectPath != null && !redirectPath.isEmpty()) {
String redirectMsg =
"This is standby RM. Redirecting to the current active RM: "
+ redirectPath;
response.addHeader("Refresh", "3; url=" + redirectPath);
PrintWriter out = response.getWriter();
out.println(redirectMsg);
return;
}
}
super.doFilter(request, response, chain);
}
示例8: printTaskLog
import org.apache.hadoop.http.HtmlQuoting; //导入方法依赖的package包/类
private void printTaskLog(HttpServletResponse response,
OutputStream out, TaskAttemptID taskId,
long start, long end, boolean plainText,
TaskLog.LogName filter, boolean isCleanup)
throws IOException {
if (!plainText) {
out.write(("<br><b><u>" + filter + " logs</u></b><br>\n" +
"<pre>\n").getBytes());
}
try {
InputStream taskLogReader =
new TaskLog.Reader(taskId, filter, start, end, isCleanup);
byte[] b = new byte[65536];
int result;
while (true) {
result = taskLogReader.read(b);
if (result > 0) {
if (plainText) {
out.write(b, 0, result);
} else {
HtmlQuoting.quoteHtmlChars(out, b, 0, result);
}
} else {
break;
}
}
taskLogReader.close();
if( !plainText ) {
out.write("</pre><hr><br>\n".getBytes());
}
} catch (IOException ioe) {
if (filter == TaskLog.LogName.DEBUGOUT) {
if (!plainText) {
out.write("</pre><hr><br>\n".getBytes());
}
// do nothing
}
else {
String msg = "Failed to retrieve " + filter + " log for task: " +
taskId;
LOG.warn(msg, ioe);
response.sendError(HttpServletResponse.SC_GONE, msg);
}
}
}
示例9: containerLogPageRedirectPath
import org.apache.hadoop.http.HtmlQuoting; //导入方法依赖的package包/类
private String containerLogPageRedirectPath(HttpServletRequest request) {
String uri = HtmlQuoting.quoteHtmlChars(request.getRequestURI());
String redirectPath = null;
if (!uri.contains("/ws/v1/node") && uri.contains("/containerlogs")) {
String[] parts = uri.split("/");
String containerIdStr = parts[3];
String appOwner = parts[4];
String logType = null;
if (parts.length > 5) {
logType = parts[5];
}
if (containerIdStr != null && !containerIdStr.isEmpty()) {
ContainerId containerId = null;
try {
containerId = ContainerId.fromString(containerIdStr);
} catch (IllegalArgumentException ex) {
return redirectPath;
}
ApplicationId appId =
containerId.getApplicationAttemptId().getApplicationId();
Application app = nmContext.getApplications().get(appId);
Configuration nmConf = nmContext.getLocalDirsHandler().getConfig();
if (app == null
&& nmConf.getBoolean(YarnConfiguration.LOG_AGGREGATION_ENABLED,
YarnConfiguration.DEFAULT_LOG_AGGREGATION_ENABLED)) {
String logServerUrl =
nmConf.get(YarnConfiguration.YARN_LOG_SERVER_URL);
if (logServerUrl != null && !logServerUrl.isEmpty()) {
StringBuilder sb = new StringBuilder();
sb.append(logServerUrl);
sb.append("/");
sb.append(nmContext.getNodeId().toString());
sb.append("/");
sb.append(containerIdStr);
sb.append("/");
sb.append(containerIdStr);
sb.append("/");
sb.append(appOwner);
if (logType != null && !logType.isEmpty()) {
sb.append("/");
sb.append(logType);
}
redirectPath =
WebAppUtils.appendQueryParams(request, sb.toString());
} else {
injector.getInstance(RequestContext.class).set(
ContainerLogsPage.REDIRECT_URL, "false");
}
}
}
}
return redirectPath;
}
示例10: sendError
import org.apache.hadoop.http.HtmlQuoting; //导入方法依赖的package包/类
@Override
public void sendError(int sc, String msg) throws IOException {
statusCode = sc;
this.msg = msg;
super.sendError(sc, HtmlQuoting.quoteHtmlChars(msg));
}
示例11: printTaskLog
import org.apache.hadoop.http.HtmlQuoting; //导入方法依赖的package包/类
private void printTaskLog(HttpServletResponse response,
OutputStream out, TaskAttemptID taskId,
long start, long end, boolean plainText,
TaskLog.LogName filter, boolean isCleanup)
throws IOException {
if (!plainText) {
out.write(("<br><b><u>" + filter + " logs</u></b><br>\n" +
"<pre>\n").getBytes());
}
try {
InputStream taskLogReader =
new TaskLog.Reader(taskId, filter, start, end, isCleanup);
byte[] b = new byte[65536];
int result;
while (true) {
result = taskLogReader.read(b);
if (result > 0) {
if (plainText) {
out.write(b, 0, result);
} else {
HtmlQuoting.quoteHtmlChars(out, b, 0, result);
}
} else {
break;
}
}
taskLogReader.close();
if( !plainText ) {
out.write("</pre></td></tr></table><hr><br>\n".getBytes());
}
} catch (IOException ioe) {
if (filter == TaskLog.LogName.DEBUGOUT) {
if (!plainText) {
out.write("</pre><hr><br>\n".getBytes());
}
// do nothing
}
else {
String msg = "Failed to retrieve " + filter + " log for task: " +
taskId;
LOG.warn(msg, ioe);
response.sendError(HttpServletResponse.SC_GONE, msg);
}
}
}