org.mortbay.jetty.Request类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(15.6k)|赞(0)|评价(0)|浏览(260)

本文整理了Java中org.mortbay.jetty.Request类的一些代码示例,展示了Request类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request类的具体详情如下:
包路径:org.mortbay.jetty.Request
类名称:Request

Request介绍

[英]Jetty Request.

Implements javax.servlet.HttpServletRequest from the javax.servlet 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 behaviour. For example

  • The getContextPath method will return null, until the requeset has been passed to a ContextHandler which matches the getPathInfo with a context path and calls setContextPath as a result.
  • the HTTP session methods will all return null sessions until such time as a request has been passed to a org.mortbay.jetty.servlet.SessionHandler which checks for session cookies and enables the ability to create new sessions.
  • The getServletPath method will return null until the request has been passed to a org.mortbay.jetty.servlet.ServletHandler and the pathInfo matched against the servlet URL patterns and setServletPath called as a result.
    A request instance is created for each HttpConnection 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.
    [中]码头请求。
    实现javax。servlet。来自javax的HttpServletRequest。servlet包。
    大多数getter的标准接口是通过setter扩展的,因此请求可以通过传递给它的处理程序进行修改。这使得请求对象尽可能轻量级,而不是真正实现任何重要的行为。例如
    *getContextPath方法将返回null,直到requeset被传递给ContextHandler,ContextHandler将getPathInfo与上下文路径匹配,并因此调用setContextPath。
    *HTTP会话方法都将返回空会话,直到请求被传递到组织为止。莫特贝。码头。servlet。SessionHandler,用于检查会话cookie并启用创建新会话的功能。
    *getServletPath方法将返回null,直到请求被传递到组织。莫特贝。码头。servlet。ServletHandler和pathInfo与servlet URL模式匹配,结果调用了setServletPath。
    为服务器接受的每个HttpConnection创建一个请求实例,并为通过该连接接收的每个HTTP请求循环使用。我们努力避免对来自同一连接的请求重新分析可能相同的头和cookie。

代码示例

代码示例来源:origin: Netflix/eureka

protected void sendOkResponseWithContent(Request request, HttpServletResponse response, Applications apps)
    throws IOException {
  String content = XmlXStream.getInstance().toXML(apps);
  response.setContentType("application/xml");
  response.setStatus(HttpServletResponse.SC_OK);
  response.getWriter().println(content);
  response.getWriter().flush();
  request.setHandled(true);
  System.out.println("Eureka port: " + port + ". " + System.currentTimeMillis() +
      ". Eureka resource mock, sent response for request path: " + request.getPathInfo() +
      ", apps count: " + apps.getRegisteredApplications().size());
}

代码示例来源:origin: Netflix/eureka

private void sendOkResponseWithContent(Request request, HttpServletResponse response, String content)
      throws IOException {
    response.setContentType("application/json; charset=UTF-8");
    response.setStatus(HttpServletResponse.SC_OK);
    response.getOutputStream().write(content.getBytes("UTF-8"));
    response.getOutputStream().flush();
    request.setHandled(true);
    System.out.println("Eureka resource mock, sent response for request path: " + request.getPathInfo() +
        " with content" + content);
  }
}

代码示例来源:origin: org.mortbay.jetty/jetty-embedded

public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException
  {
    Request base_request = (request instanceof Request) ? (Request)request:HttpConnection.getCurrentConnection().getRequest();
    base_request.setHandled(true);
    
    response.setContentType("text/html");
    response.setStatus(HttpServletResponse.SC_OK);
    response.getWriter().println("<h1>Hello OneHandler</h1>");
  }
}

代码示例来源:origin: org.mortbay.jetty/com.springsource.org.mortbay.jetty.server

public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException
  Request base_request = request instanceof Request?(Request)request:HttpConnection.getCurrentConnection().getRequest();
  if (base_request.isHandled() || !request.getMethod().equals(HttpMethods.GET))
    return;
  base_request.setHandled(true);
    if (!request.getPathInfo().endsWith(URIUtil.SLASH))
      response.sendRedirect(URIUtil.addPaths(request.getRequestURI(),URIUtil.SLASH));
      return;
      response.sendError(HttpServletResponse.SC_FORBIDDEN);
      return;
    if (if_modified>0 && last_modified/1000<=if_modified/1000)
      response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
      return;

代码示例来源:origin: org.mortbay.jetty/com.springsource.org.mortbay.jetty.server

public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException
  Request base_request = request instanceof Request?(Request)request:HttpConnection.getCurrentConnection().getRequest();
  if (response.isCommitted() || base_request.isHandled())
    return;
  base_request.setHandled(true);
  String method=request.getMethod();
  if (_serveIcon && _favicon!=null && method.equals(HttpMethods.GET) && request.getRequestURI().equals("/favicon.ico"))
    if (request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE)==_faviconModified)
      response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
    else
      response.setStatus(HttpServletResponse.SC_OK);
      response.setContentType("image/x-icon");
      response.setContentLength(_favicon.length);

代码示例来源:origin: org.mortbay.jetty/jetty-security

log.debug("HTAccessHandler pathInContext="+pathInContext,null,null);
String credentials=request.getHeader(HttpHeaders.AUTHORIZATION);
    response.sendError(HttpServletResponse.SC_FORBIDDEN);
    base_request.setHandled(true);
    return;
      response.sendError(HttpServletResponse.SC_FORBIDDEN);
      base_request.setHandled(true);
      return;
      response.sendError(HttpServletResponse.SC_FORBIDDEN);
      base_request.setHandled(true);
      return;
      response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
      base_response.complete();
      base_request.setHandled(true);
      return;
      base_request.setAuthType(Constraint.__BASIC_AUTH);
      base_request.setUserPrincipal(getPrincipal(user, getUserRealm()));
    response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    base_request.setHandled(true);

代码示例来源:origin: org.paxml/PaxmlSelenium

res.setStatus(HttpServletResponse.SC_OK);
res.setContentType("binary/x-paxml");
res.setHeader("Content-Disposition", "attachment; filename=\"" + path +"\"");
res.setHeader("Pragma", "");
res.setHeader("Cache-control", "");
IOUtils.copy(in, res.getOutputStream());
((Request) request).setHandled(true);

代码示例来源:origin: org.sonatype.plexus/plexus-jetty6

( request instanceof Request ) ? (Request) request : HttpConnection.getCurrentConnection().getRequest();
base_request.setHandled( true );
Writer writer = new OutputStreamWriter( buf, StringUtil.__ISO_8859_1 );
writer.write( "Request Dump from:" + label );
writer.write( "\npathInfo=" + request.getPathInfo() + "\n\n" );
writer.write( "Header:\n" );
writer.write( request.toString() );
writer.write( "\n\nParameters:\n" );
Enumeration names = request.getParameterNames();
while ( names.hasMoreElements() )
  String[] values = request.getParameterValues( name );
  if ( values == null || values.length == 0 )

代码示例来源:origin: telefonicaid/fiware-cygnus

@Override
public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch)
  throws IOException, ServletException {
  HttpConnection connection = HttpConnection.getCurrentConnection();
    Request baseRequest = (request instanceof Request) ? (Request) request : connection.getRequest();
    baseRequest.setHandled(true);
  response.setContentType("text/html;charset=utf-8");
  int port = request.getLocalPort();
  String uri = request.getRequestURI();
  String method = request.getMethod();
  LOGGER.info("Management interface request. Method: " + method + ", URI: " + uri);
          NameMappingsHandlers.get(request, response, nameMappingsConfFile);
        } else {
          response.setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED);
          response.getWriter().println(method + " " + uri + " not implemented");

代码示例来源:origin: aseldawy/spatialhadoop2

ServletException {
response.addHeader("Access-Control-Allow-Origin", "*");
response.addHeader("Access-Control-Allow-Credentials", "true");
((Request) request).setHandled(true);
 LOG.info("Received request: '"+request.getRequestURL()+"'");
 if (target.endsWith("/generate_image.cgi")) {
  LOG.info("Generating image");
  response.setStatus(HttpServletResponse.SC_OK);
  response.setContentType("text/plain;charset=utf-8");
  response.getWriter().println("Image request received successfully");

代码示例来源:origin: org.mortbay.jetty/com.springsource.org.mortbay.jetty.server

Request base_request=(request instanceof Request)?(Request)request:HttpConnection.getCurrentConnection().getRequest();
if( !isStarted() || _shutdown || (dispatch==REQUEST && base_request.isHandled()))
  return;
old_context=base_request.getContext();
        base_request.setHandled(true);
        if (request.getQueryString()!=null)
          response.sendRedirect(URIUtil.addPaths(request.getRequestURI(),URIUtil.SLASH)+"?"+request.getQueryString());
        else 
          response.sendRedirect(URIUtil.addPaths(request.getRequestURI(),URIUtil.SLASH));
        return;
  old_context_path=base_request.getContextPath();
  old_servlet_path=base_request.getServletPath();
  old_path_info=base_request.getPathInfo();
  base_request.setContext(_scontext);
  if (dispatch!=INCLUDE && target.startsWith("/"))
      base_request.setContextPath("");
    else
      base_request.setContextPath(_contextPath);
    base_request.setServletPath(null);
    base_request.setPathInfo(target);
      base_request.addEventListener(((EventListener)LazyList.get(_requestAttributeListeners,i)));
        base_request.removeEventListener(((EventListener)LazyList.get(_requestAttributeListeners,i)));

代码示例来源:origin: tcplugins/tcWebHooks

@Override
public void service(ServletRequest req, ServletResponse res)
    throws ServletException, IOException {
  System.out.println("Handling Proxy request for " + ((Request) req).getUri().toString());
  if ( authRequired )
    String proxyAuthorization = request.getHeader( "Proxy-Authorization" );
    if ( proxyAuthorization != null && proxyAuthorization.startsWith( "Basic " ) )
    response.addHeader( "Proxy-Authenticate", "Basic realm=\"Jetty Proxy Authorization\"" );
    response.setStatus( HttpServletResponse.SC_PROXY_AUTHENTICATION_REQUIRED );
    System.out.println("Proxy Auth Creds not supplied");

代码示例来源:origin: org.mortbay.jetty/com.springsource.org.mortbay.jetty.server

public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException
{
  if (_newContextURL==null)
    return;
  
  Request base_request=(request instanceof Request)?(Request)request:HttpConnection.getCurrentConnection().getRequest();
  
  String url = _newContextURL;
  if (!_discardPathInfo && request.getPathInfo()!=null)
    url=URIUtil.addPaths(url, request.getPathInfo());
  if (!_discardQuery && request.getQueryString()!=null)
    url+="?"+request.getQueryString();
  
  response.sendRedirect(url);
  if (_permanent)
    response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
  
  base_request.setHandled(true);
}

代码示例来源:origin: org.motechproject/motech-testing-utils

@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  requests.put(request.getContextPath(), collectRequestInfo(request));
  response.setStatus(HttpServletResponse.SC_OK);
  response.getWriter().write(OK);
  Request baseRequest = (Request) request;
  baseRequest.setHandled(true);
}

代码示例来源:origin: org.mortbay.jetty/com.springsource.org.mortbay.jetty.server

final Request base_request=(request instanceof Request)?((Request)request):HttpConnection.getCurrentConnection().getRequest();
final String old_servlet_name=base_request.getServletName();
final String old_servlet_path=base_request.getServletPath();
final String old_path_info=base_request.getPathInfo();
final Map old_role_map=base_request.getRoleMap();
      base_request.setServletName(servlet_holder.getName());
      base_request.setRoleMap(servlet_holder.getRoleMap());
      if(Log.isDebugEnabled())Log.debug("servlet="+servlet_holder);
        base_request.setAttribute(Dispatcher.__INCLUDE_SERVLET_PATH,servlet_path);
        base_request.setAttribute(Dispatcher.__INCLUDE_PATH_INFO, path_info);
        base_request.setServletPath(servlet_path);
        base_request.setPathInfo(path_info);
      base_request.setServletName(servlet_holder.getName());
      chain=getFilterChain(type, null,servlet_holder);
    base_request.setHandled(true);
    if (chain!=null)
      chain.doFilter(request, response);
  base_request.setHandled(false);
  throw e;
  base_request.setServletName(old_servlet_name);
  base_request.setRoleMap(old_role_map);
  if (type!=INCLUDE)

代码示例来源:origin: org.mortbay.jetty/com.springsource.org.mortbay.jetty.server

public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException
{
  HttpConnection.getCurrentConnection().getRequest().setHandled(true);
  response.setContentType(MimeTypes.TEXT_HTML_8859_1);
  ByteArrayISO8859Writer writer= new ByteArrayISO8859Writer(4096);
  HttpConnection connection = HttpConnection.getCurrentConnection();
  handleErrorPage(request, writer, connection.getResponse().getStatus(), connection.getResponse().getReason());
  writer.flush();
  response.setContentLength(writer.size());
  writer.writeTo(response.getOutputStream());
  writer.destroy();
}

代码示例来源:origin: pentaho/pentaho-kettle

public void handle( String target, HttpServletRequest request, HttpServletResponse response, int dispatch )
   throws IOException, ServletException {
  if ( target.contains( "/Callback" ) ) {
   CustomLocalServerReceiver.this.error = request.getParameter( "error" );
   if ( CustomLocalServerReceiver.this.code == null ) {
    CustomLocalServerReceiver.this.code = request.getParameter( "code" );
   }
   if ( CustomLocalServerReceiver.this.url != null && CustomLocalServerReceiver.this.error != null
     && CustomLocalServerReceiver.this.error.equals( "access_denied" ) ) {
    response.sendRedirect( CustomLocalServerReceiver.this.url );
   } else {
    super.handle( target, request, response, dispatch );
   }
   ( (Request) request ).setHandled( true );
  }
 }
}

代码示例来源:origin: jpotts/alfresco-api-java-examples

@Override
public void handle(
  String target, HttpServletRequest request, HttpServletResponse response, int dispatch)
  throws IOException {
 if (!CALLBACK_PATH.equals(target)) {
  return;
 }
 writeLandingHtml(response);
 response.flushBuffer();
 ((Request) request).setHandled(true);
 String error = request.getParameter("error");
 if (error != null) {
  System.out.println("Authorization failed. Error=" + error);
  System.out.println("Quitting.");
  System.exit(1);
 }
 code = request.getParameter("code");
 synchronized (LocalServerReceiver.this) {
  LocalServerReceiver.this.notify();
 }
}

代码示例来源:origin: aseldawy/spatialhadoop2

public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch)
    throws IOException, ServletException {
  // Bypass cross-site scripting (XSS)
  response.addHeader("Access-Control-Allow-Origin", "*");
  response.addHeader("Access-Control-Allow-Credentials", "true");
  ((Request) request).setHandled(true);
  try {
    if (target.startsWith("/dynamic/showImage.cgi")) {
      displayImage(target, response);
    } else {
      LOG.info("Received request: '"+request.getRequestURL()+"'");
      tryToLoadStaticResource(target, response);
    }
  } catch (Exception e) {
    e.printStackTrace();
    //reportError(response, "Error placing the request", e);
  }
}

代码示例来源:origin: aseldawy/spatialhadoop2

((Request) request).setHandled(true);
 LOG.info("Received request: '" + request.getRequestURL() + "'");
 if (target.startsWith("/hdfs/") && request.getMethod().equals("GET")) {
  handleHDFSFetch(request, response);
 } else if (target.endsWith("/LISTSTATUS.cgi") && request.getMethod().equals("GET")){
  handleListFiles(request, response);
 } else if (target.endsWith("/VISUALIZE.cgi") && request.getMethod().equals("POST")){

相关文章