本文整理了Java中org.eclipse.jetty.server.Request
类的一些代码示例,展示了Request
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request
类的具体详情如下:
包路径:org.eclipse.jetty.server.Request
类名称:Request
[英]Jetty Request.
Implements javax.servlet.http.HttpServletRequest from the javax.servlet.http
package.
The standard interface of mostly getters, is extended with setters so that the request is mutable by the handlers that it is passed to. This allows the request object to be as lightweight as possible and not actually implement any significant behavior. For example
org.eclipse.jetty.servlet.ServletHandler
and the pathInfo matched against the servlet URL patterns and Request#setServletPath(String) called as a result.A request instance is created for each connection accepted by the server and recycled for each HTTP request received via that connection. An effort is made to avoid reparsing headers and cookies that are likely to be the same for requests from the same connection.
Request instances are recycled, which combined with badly written asynchronous applications can result in calls on requests that have been reset. The code is written in a style to avoid NPE and ISE when such calls are made, as this has often proved generate exceptions that distraction from debugging such bad asynchronous applications. Instead, request methods attempt to not fail when called in an illegal state, so that hopefully the bad application will proceed to a major state event (eg calling AsyncContext.onComplete) which has better asynchronous guards, true atomic state and better failure behaviour that will assist in debugging.
The form content that a request can process is limited to protect from Denial of Service attacks. The size in bytes is limited by ContextHandler#getMaxFormContentSize() or if there is no context then the "org.eclipse.jetty.server.Request.maxFormContentSize" Serverattribute. The number of parameters keys is limited by ContextHandler#getMaxFormKeys() or if there is no context then the "org.eclipse.jetty.server.Request.maxFormKeys" Server attribute.
If IOExceptions or timeouts occur while reading form parameters, these are thrown as unchecked Exceptions: ether RuntimeIOException, BadMessageException or RuntimeException as appropriate.
[中]码头请求。
实现javax。servlet。http。来自javax.servlet.http
包的HttpServletRequest。
大多数getter的标准接口是通过setter扩展的,因此请求可以通过传递给它的处理程序进行修改。这使得请求对象尽可能轻量级,而不是真正实现任何重要的行为。例如
*请求#getContextPath()方法将返回null,直到请求被传递给ContextHandler,ContextHandler将请求#getPathInfo()与上下文路径匹配,并因此调用请求#setContextPath(String)。
*HTTP会话方法都将返回空会话,直到请求被传递到组织为止。日食码头。服务器一场SessionHandler,用于检查会话cookie并启用创建新会话的功能。
*请求#getServletPath()方法将返回null,直到请求被传递到org.eclipse.jetty.servlet.ServletHandler
并且pathInfo与servlet URL模式匹配,并因此调用请求#setServletPath(字符串)。
为服务器接受的每个连接创建一个请求实例,并为通过该连接接收的每个HTTP请求循环使用。我们努力避免对来自同一连接的请求重新分析可能相同的头和cookie。
请求实例被回收,再加上写得不好的异步应用程序,可能会导致对已重置请求的调用。代码的编写风格是在进行此类调用时避免NPE和ISE,因为这通常会产生异常,从而分散对此类糟糕的异步应用程序的调试。相反,请求方法试图在非法状态下调用时不失败,这样坏的应用程序就有希望继续执行一个主要的状态事件(例如调用AsyncContext.onComplete),它有更好的异步保护、真正的原子状态和更好的故障行为,这将有助于调试。
请求可以处理的表单内容仅限于防止拒绝服务攻击。字节大小受ContextHandler#getMaxFormContentSize()的限制,或者如果没有上下文,则使用“org.eclipse.jetty.server.Request.maxFormContentSize”服务器属性。参数键的数量受ContextHandler#getMaxFormKeys()的限制,或者如果没有上下文,则使用“org.eclipse.jetty.server.Request.maxFormKeys”服务器属性。
如果在读取表单参数时发生IOException或超时,这些异常将作为未检查的异常抛出:ether RuntimeIOException、BadMessageException或RuntimeException(视情况而定)。
代码示例来源:origin: gocd/gocd
private void respondWith503(Request baseRequest, HttpServletResponse response, String contentType, String body) throws IOException {
addHeaders(response);
response.setStatus(org.eclipse.jetty.http.HttpStatus.SERVICE_UNAVAILABLE_503);
response.setContentType(contentType);
response.getWriter().println(body);
baseRequest.setHandled(true);
}
代码示例来源:origin: AsyncHttpClient/async-http-client
if (httpRequest.getHeader("X-HEAD") != null) {
httpResponse.setContentLength(1);
if (httpRequest.getHeader("X-ISO") != null) {
httpResponse.setContentType(TestUtils.TEXT_HTML_CONTENT_TYPE_WITH_ISO_8859_1_CHARSET);
} else {
httpResponse.setContentType(TestUtils.TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET);
if (request.getMethod().equalsIgnoreCase("OPTIONS")) {
httpResponse.addHeader("Allow", "GET,HEAD,POST,OPTIONS,TRACE");
Enumeration<String> e = httpRequest.getHeaderNames();
String headerName;
while (e.hasMoreElements()) {
request.setHandled(true);
httpResponse.getOutputStream().flush();
代码示例来源:origin: jersey/jersey
private URI getRequestUri(final Request request, final URI baseUri) {
try {
final String serverAddress = getServerAddress(baseUri);
String uri = request.getRequestURI();
final String queryString = request.getQueryString();
if (queryString != null) {
uri = uri + "?" + ContainerUtils.encodeUnsafeCharacters(queryString);
}
return new URI(serverAddress + uri);
} catch (URISyntaxException ex) {
throw new IllegalArgumentException(ex);
}
}
代码示例来源:origin: apache/incubator-druid
@Override
public void log(Request request, Response response)
{
if (logger.isDebugEnabled()) {
logger.debug(
"%s %s %s %s",
request.getRemoteAddr(),
request.getMethod(),
request.getHttpURI().toString(),
request.getProtocol()
);
}
}
}
代码示例来源:origin: AsyncHttpClient/async-http-client
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException {
InputStream is = baseRequest.getInputStream();
int read;
do {
// drain upload
read = is.read();
} while (read >= 0);
response.setStatus(200);
response.getOutputStream().flush();
response.getOutputStream().close();
baseRequest.setHandled(true);
}
};
代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-all-server
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
if (baseRequest.isHandled())
return;
if(!HttpMethods.GET.equals(request.getMethod()))
if(!HttpMethods.HEAD.equals(request.getMethod()))
LOG.info(resource+" aliased to "+resource.getAlias());
return;
baseRequest.setHandled(true);
if (!request.getPathInfo().endsWith(URIUtil.SLASH))
response.sendRedirect(response.encodeRedirectURL(URIUtil.addPaths(request.getRequestURI(),URIUtil.SLASH)));
return;
baseRequest.setHandled(true);
return;
response.setStatus(HttpStatus.NOT_MODIFIED_304);
baseRequest.getResponse().getHttpFields().put(HttpHeaders.ETAG_BUFFER,etag);
return;
response.setDateHeader(HttpHeaders.LAST_MODIFIED,last_modified);
if (_etags)
baseRequest.getResponse().getHttpFields().put(HttpHeaders.ETAG_BUFFER,etag);
代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-all-server
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException
String method = request.getMethod();
if(!method.equals(HttpMethods.GET) && !method.equals(HttpMethods.POST) && !method.equals(HttpMethods.HEAD))
connection.getRequest().setHandled(true);
return;
if (error_page!=null && request.getServletContext()!=null)
String old_error_page=(String)request.getAttribute(ERROR_PAGE);
if (old_error_page==null || !old_error_page.equals(error_page))
return;
LOG.warn("No error page "+error_page);
connection.getRequest().setHandled(true);
response.setContentType(MimeTypes.TEXT_HTML_8859_1);
if (_cacheControl!=null)
response.setHeader(HttpHeaders.CACHE_CONTROL, _cacheControl);
ByteArrayISO8859Writer writer= new ByteArrayISO8859Writer(4096);
handleErrorPage(request, writer, connection.getResponse().getStatus(), connection.getResponse().getReason());
writer.flush();
response.setContentLength(writer.size());
writer.writeTo(response.getOutputStream());
writer.destroy();
代码示例来源:origin: apache/nifi
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
baseRequest.setHandled(true);
if ("Fetch".equalsIgnoreCase(request.getMethod())) {
final int status = Integer.valueOf(target.substring("/status".length() + 1));
response.setStatus(status);
response.setContentType("text/plain");
response.setContentLength(target.length());
try (PrintWriter writer = response.getWriter()) {
writer.print(target);
writer.flush();
}
} else {
response.setStatus(404);
response.setContentType("text/plain");
response.setContentLength(target.length());
}
}
}
代码示例来源:origin: at.bestsolution.efxclipse.eclipse/org.eclipse.jetty.server
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException
String method = request.getMethod();
if (!HttpMethod.GET.is(method) && !HttpMethod.POST.is(method) && !HttpMethod.HEAD.is(method))
baseRequest.setHandled(true);
return;
if (error_page!=null && request.getServletContext()!=null)
String old_error_page=(String)request.getAttribute(ERROR_PAGE);
if (old_error_page==null || !old_error_page.equals(error_page))
return;
LOG.warn("No error page "+error_page);
LOG.warn(Log.EXCEPTION, e);
return;
if (LOG.isDebugEnabled())
LOG.debug("No Error Page mapping for request({} {}) (using default)",request.getMethod(),request.getRequestURI());
baseRequest.setHandled(true);
HttpField accept = baseRequest.getHttpFields().getField(HttpHeader.ACCEPT);
if (accept == null || accept.contains("text/html") || accept.contains("*/*"))
代码示例来源:origin: AsyncHttpClient/async-http-client
public void handle(String s, Request request, HttpServletRequest req, final HttpServletResponse resp) throws IOException {
resp.setContentType("text/plain;charset=utf-8");
resp.setStatus(200);
final AsyncContext asyncContext = request.startAsync();
final PrintWriter writer = resp.getWriter();
executorService.submit(() -> {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
logger.error("Failed to sleep for 100 ms.", e);
}
logger.info("Delivering part1.");
writer.write("part1");
writer.flush();
});
executorService.submit(() -> {
try {
Thread.sleep(200);
} catch (InterruptedException e) {
logger.error("Failed to sleep for 200 ms.", e);
}
logger.info("Delivering part2.");
writer.write("part2");
writer.flush();
asyncContext.complete();
});
request.setHandled(true);
}
};
代码示例来源:origin: neo4j/neo4j
@Override
public void handle(
String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response )
throws IOException
{
response.setContentType( "text/plain; charset=utf-8" );
response.setStatus( HttpServletResponse.SC_OK );
PrintWriter out = response.getWriter();
writeBatch( out, firstBatchSize );
out.flush();
latch.start();
innerBarrier.reached();
latch.finish();
writeBatch( out, otherBatchSize );
baseRequest.setHandled(true);
}
代码示例来源:origin: AsyncHttpClient/async-http-client
@Override
public void handle(String pathInContext, org.eclipse.jetty.server.Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException {
final boolean expectGet = (httpRequest.getHeader("x-expect-get") != null);
final boolean expectPost = (httpRequest.getHeader("x-expect-post") != null);
if (expectGet) {
final String method = request.getMethod();
if (!"GET".equals(method)) {
httpResponse.sendError(500, "Incorrect method. Expected GET, received " + method);
return;
httpResponse.setStatus(200);
httpResponse.getOutputStream().write("OK".getBytes());
httpResponse.getOutputStream().flush();
return;
} else if (expectPost) {
final String method = request.getMethod();
if (!"POST".equals(method)) {
httpResponse.sendError(500, "Incorrect method. Expected POST, received " + method);
String header = httpRequest.getHeader("x-redirect");
if (header != null) {
代码示例来源:origin: kiegroup/droolsjbpm-integration
@Override
public void handle( Request request, HttpServletResponse response ) {
method.set(request.getMethod());
outputParams.put("name", request.getParameter("name"));
outputParams.put("number", request.getParameter("number"));
response.setStatus(HTTP_OK);
}
};
代码示例来源:origin: AsyncHttpClient/async-http-client
public void handle(String s, Request r, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
if ("GET".equalsIgnoreCase(request.getMethod())) {
String qs = request.getQueryString();
if (isNonEmpty(qs)) {
for (String qnv : qs.split("&")) {
String nv[] = qnv.split("=");
response.addHeader(nv[0], nv[1]);
}
response.setStatus(HttpServletResponse.SC_OK);
} else {
response.sendError(HttpServletResponse.SC_NOT_ACCEPTABLE);
}
} else { // this handler is to handle POST request
response.sendError(HttpServletResponse.SC_FORBIDDEN);
}
r.setHandled(true);
}
}
代码示例来源:origin: kiegroup/droolsjbpm-integration
@Override
public void handle( Request request, HttpServletResponse response ) {
response.setStatus(HTTP_OK);
header.set(request.getHeader("Accept"));
}
};
代码示例来源:origin: AsyncHttpClient/async-http-client
public void handle(String target, Request baseRequest, HttpServletRequest req, HttpServletResponse resp) throws IOException {
ServletInputStream in = req.getInputStream();
byte[] b = new byte[8192];
int count;
int total = 0;
while ((count = in.read(b)) != -1) {
b = new byte[8192];
total += count;
}
resp.setStatus(200);
resp.addHeader("X-TRANSFERRED", String.valueOf(total));
resp.getOutputStream().flush();
resp.getOutputStream().close();
baseRequest.setHandled(true);
}
};
代码示例来源:origin: AsyncHttpClient/async-http-client
public void handle(String s, org.eclipse.jetty.server.Request r, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
if ("HEAD".equalsIgnoreCase(request.getMethod())) {
response.setStatus(HttpServletResponse.SC_FOUND); // 302
response.setHeader("Location", request.getPathInfo() + "_moved");
} else if ("GET".equalsIgnoreCase(request.getMethod())) {
response.setStatus(HttpServletResponse.SC_OK);
} else {
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
}
r.setHandled(true);
}
}
代码示例来源:origin: AsyncHttpClient/async-http-client
public void handle(String s, org.eclipse.jetty.server.Request r, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
if ("GET".equalsIgnoreCase(request.getMethod())) {
response.addHeader("target", r.getHttpURI().getPath());
response.setStatus(HttpServletResponse.SC_OK);
} else {
// this handler is to handle POST request
response.sendError(HttpServletResponse.SC_FORBIDDEN);
}
r.setHandled(true);
}
}
代码示例来源:origin: kiegroup/droolsjbpm-integration
@Override
public void handle( Request request, HttpServletResponse response ) {
method.set(request.getMethod());
response.setStatus(HTTP_OK);
}
};
代码示例来源:origin: SonarSource/sonarqube
@Override
public void handle(String target, Request request, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException {
if ("/ping".equals(target)) {
request.setHandled(true);
httpServletResponse.getWriter().print("ping");
} else if ("/restart".equals(target)) {
writeTimeToFile("restartAskedAt");
request.setHandled(true);
processCommands.askForRestart();
httpServletResponse.getWriter().print("ok");
} else if ("/kill".equals(target)) {
writeTimeToFile("killedAt");
System.exit(0);
}
}
});
内容来源于网络,如有侵权,请联系作者删除!