Tabnine Logo
HttpServletRequest
Code IndexAdd Tabnine to your IDE (free)

How to use
HttpServletRequest
in
javax.servlet.http

Best Java code snippets using javax.servlet.http.HttpServletRequest (Showing top 20 results out of 47,529)

Refine searchRefine arrow

  • HttpServletResponse
  • HttpSession
  • PrintWriter
  • ActionMapping
  • FilterChain
  • ServletContext
  • ServletException
  • WebApplicationContextUtils
origin: apache/incubator-dubbo

@Override
public void handle(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException {
  String uri = request.getRequestURI();
  HessianSkeleton skeleton = skeletonMap.get(uri);
  if (!request.getMethod().equalsIgnoreCase("POST")) {
    response.setStatus(500);
  } else {
    RpcContext.getContext().setRemoteAddress(request.getRemoteAddr(), request.getRemotePort());
    Enumeration<String> enumeration = request.getHeaderNames();
    while (enumeration.hasMoreElements()) {
      String key = enumeration.nextElement();
      if (key.startsWith(Constants.DEFAULT_EXCHANGER)) {
        RpcContext.getContext().setAttachment(key.substring(Constants.DEFAULT_EXCHANGER.length()),
            request.getHeader(key));
      }
    }
    try {
      skeleton.invoke(request.getInputStream(), response.getOutputStream());
    } catch (Throwable e) {
      throw new ServletException(e);
    }
  }
}
origin: stanfordnlp/CoreNLP

/**
 * {@inheritDoc}
 */
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 if (request.getCharacterEncoding() == null) {
  request.setCharacterEncoding("utf-8");
 }
 response.setContentType("text/json; charset=UTF-8");
 PrintWriter out = response.getWriter();
 String raw = request.getParameter("q");
 if (raw == null || "".equals(raw)) {
  out.println("{ok:false, entailments:[], triples=[], msg=\"\"}");
 } else {
  doGet(out, raw);
 }
 out.close();
}
origin: stackoverflow.com

 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  String username = request.getParameter("username");
  String password = request.getParameter("password");
  User user = userService.find(username, password);

  if (user != null) {
    request.getSession().setAttribute("user", user); // Login user.
    response.sendRedirect("home"); // Redirect to home page.
  } else {
    request.setAttribute("message", "Unknown username/password. Please retry."); // Store error message in request scope.
    request.getRequestDispatcher("/WEB-INF/login.jsp").forward(request, response); // Forward to JSP page to redisplay login form with error.
  }
}
origin: stackoverflow.com

 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  try {
    List<Product> products = productService.list(); // Obtain all products.
    request.setAttribute("products", products); // Store products in request scope.
    request.getRequestDispatcher("/WEB-INF/products.jsp").forward(request, response); // Forward to JSP page to display them in a HTML table.
  } catch (SQLException e) {
    throw new ServletException("Retrieving products failed!", e);
  }
}
origin: spring-projects/spring-framework

private static String getRequestUri(HttpServletRequest request) {
  String uri = (String) request.getAttribute(WebUtils.INCLUDE_REQUEST_URI_ATTRIBUTE);
  if (uri == null) {
    uri = request.getRequestURI();
  }
  return uri;
}
origin: Red5/red5-server

if (applicationContext == null) {
  ServletContext ctx = getServletContext();
  applicationContext = WebApplicationContextUtils.getWebApplicationContext(ctx);
  if (applicationContext == null) {
    applicationContext = (WebApplicationContext) ctx.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
log.debug("Request - method: {} content type: {} path: {}", new Object[] { req.getMethod(), req.getContentType(), req.getServletPath() });
if (!REQUEST_METHOD.equals(req.getMethod()) || req.getContentLength() == 0) {
if (enforceContentTypeCheck && !CONTENT_TYPE.equals(req.getContentType())) {
  handleBadRequest(String.format("Bad request, unsupported content type: %s.", req.getContentType()), resp);
  return;
String uri = req.getRequestURI().trim();
log.debug("URI: {}", uri);
String path = req.getServletPath();
      } else {
        resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
        resp.setHeader("Connection", "Keep-Alive");
        resp.setHeader("Cache-Control", "no-cache");
        resp.flushBuffer();
        break;
origin: pentaho/pentaho-kettle

@Test
public void testGetStatusServletEscapesHtmlWhenTransNotFound() throws ServletException, IOException {
 HttpServletRequest mockHttpServletRequest = mock( HttpServletRequest.class );
 HttpServletResponse mockHttpServletResponse = mock( HttpServletResponse.class );
 StringWriter out = new StringWriter();
 PrintWriter printWriter = new PrintWriter( out );
 when( mockHttpServletRequest.getContextPath() ).thenReturn( GetStatusServlet.CONTEXT_PATH );
 when( mockHttpServletRequest.getParameter( anyString() ) ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST );
 when( mockHttpServletResponse.getWriter() ).thenReturn( printWriter );
 getStatusServlet.doGet( mockHttpServletRequest, mockHttpServletResponse );
 assertFalse( ServletTestUtils.hasBadText( ServletTestUtils.getInsideOfTag( "TITLE", out.toString() ) ) ); // title will more reliably be plain text
}
origin: apache/incubator-dubbo

@Override
public void handle(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException {
  String uri = request.getRequestURI();
  HttpInvokerServiceExporter skeleton = skeletonMap.get(uri);
  if (!request.getMethod().equalsIgnoreCase("POST")) {
    response.setStatus(500);
  } else {
    RpcContext.getContext().setRemoteAddress(request.getRemoteAddr(), request.getRemotePort());
    try {
      skeleton.handleRequest(request, response);
    } catch (Throwable e) {
      throw new ServletException(e);
    }
  }
}
origin: DeemOpen/zkui

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain fc) throws IOException, ServletException {
  HttpServletRequest request = (HttpServletRequest) req;
  HttpServletResponse response = (HttpServletResponse) res;
  if (!request.getRequestURI().contains("/login") && !request.getRequestURI().contains("/acd/appconfig")) {
    RequestDispatcher dispatcher;
    HttpSession session = request.getSession();
    if (session != null) {
      if (session.getAttribute("authName") == null || session.getAttribute("authRole") == null) {
        response.sendRedirect("/login");
        return;
      }
    } else {
      request.setAttribute("fail_msg", "Session timed out!");
      dispatcher = request.getRequestDispatcher("/Login");
      dispatcher.forward(request, response);
      return;
    }
  }
  fc.doFilter(req, res);
}
origin: apache/hive

 @Override
 protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
  throws ServletException, IOException {
  String absoluteDiskPath = getServletContext().getRealPath(req.getPathInfo());
  File requestedFile = new File(absoluteDiskPath);
  // async-profiler version 1.4 writes 'Started [cpu] profiling' to output file when profiler is running which
  // gets replaced by final output. If final output is not ready yet, the file size will be <100 bytes (in all modes).
  if (requestedFile.length() < 100) {
   LOG.info("{} is incomplete. Sending auto-refresh header..", requestedFile);
   resp.setHeader("Refresh", "2," + req.getRequestURI());
   resp.getWriter().write("This page will auto-refresh every 2 second until output file is ready..");
  } else {
   super.doGet(req, resp);
  }
 }
}
origin: Red5/red5-server

/** {@inheritDoc} */
@Override
public void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  log.debug("Servicing Request");
  if (codecFactory == null) {
    ServletContext ctx = getServletContext();
    log.debug("Context path: {}", ctx.getContextPath());
    //attempt to lookup the webapp context		
    webAppCtx = WebApplicationContextUtils.getRequiredWebApplicationContext(ctx);
    //now try to look it up as an attribute
    if (webAppCtx == null) {
      log.debug("Webapp context was null, trying lookup as attr.");
      webAppCtx = (WebApplicationContext) ctx.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
    }
    //lookup the server and codec factory
    if (webAppCtx != null) {
      server = (IServer) webAppCtx.getBean("red5.server");
      codecFactory = (RemotingCodecFactory) webAppCtx.getBean("remotingCodecFactory");
    } else {
      log.debug("No web context");
    }
  }
  log.debug("Remoting request {} {}", req.getContextPath(), req.getServletPath());
  if (APPLICATION_AMF.equals(req.getContentType())) {
    serviceAMF(req, resp);
  } else {
    resp.getWriter().write("Red5 : Remoting Gateway");
  }
}
origin: apache/geode

 @Override
 public void call(HttpServletRequest request, HttpServletResponse response)
   throws IOException {
  HttpSession session = request.getSession();
  // Hack to expose the session to our test context
  session.getServletContext().setAttribute("session", session);
  session.setAttribute("lastAccessTime", session.getLastAccessedTime());
  try {
   Thread.sleep(100);
  } catch (InterruptedException ex) {
  }
  session.setAttribute("somethingElse", 1);
  request.getSession();
  response.getWriter().write("done");
 }
};
origin: spring-projects/spring-framework

@RequestMapping
public void myHandle(HttpServletResponse response, HttpServletRequest request) throws IOException {
  if (this.servletContext == null || this.servletConfig == null || this.session == null ||
      this.request == null || this.webRequest == null) {
    throw new IllegalStateException();
  }
  response.getWriter().write("myView");
  request.setAttribute("servletContext", this.servletContext);
  request.setAttribute("servletConfig", this.servletConfig);
  request.setAttribute("sessionId", this.session.getId());
  request.setAttribute("requestUri", this.request.getRequestURI());
  request.setAttribute("locale", this.webRequest.getLocale());
}
origin: javaee-samples/javaee7-samples

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  response.getWriter().write("Public resource invoked\n");
  if (request.getParameter("doLogout") != null) {
    request.logout();
  }
}
origin: apache/incubator-druid

@Override
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException,
                                             ServletException
{
 HttpServletRequest request = (HttpServletRequest) req;
 if (request.getHeader(AUTH_HDR) == null || request.getHeader(AUTH_HDR).equals(SECRET_USER)) {
  chain.doFilter(req, resp);
 } else {
  HttpServletResponse response = (HttpServletResponse) resp;
  response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Failed even fake authentication.");
 }
}
origin: spring-projects/spring-framework

@Test
public void forceEncodingAlwaysSetsEncoding() throws Exception {
  HttpServletRequest request = mock(HttpServletRequest.class);
  request.setCharacterEncoding(ENCODING);
  given(request.getAttribute(WebUtils.ERROR_REQUEST_URI_ATTRIBUTE)).willReturn(null);
  given(request.getAttribute(filteredName(FILTER_NAME))).willReturn(null);
  HttpServletResponse response = mock(HttpServletResponse.class);
  FilterChain filterChain = mock(FilterChain.class);
  CharacterEncodingFilter filter = new CharacterEncodingFilter(ENCODING, true);
  filter.init(new MockFilterConfig(FILTER_NAME));
  filter.doFilter(request, response, filterChain);
  verify(request).setAttribute(filteredName(FILTER_NAME), Boolean.TRUE);
  verify(request).removeAttribute(filteredName(FILTER_NAME));
  verify(response).setCharacterEncoding(ENCODING);
  verify(filterChain).doFilter(request, response);
}
origin: spring-projects/spring-framework

@Test
public void requestUriPreserveEncoding() throws Exception {
  this.request.setContextPath("/app");
  this.request.setRequestURI("/app/path%20with%20spaces/");
  HttpServletRequest actual = filterAndGetWrappedRequest();
  assertEquals("/app", actual.getContextPath());
  assertEquals("/app/path%20with%20spaces/", actual.getRequestURI());
  assertEquals("http://localhost/app/path%20with%20spaces/", actual.getRequestURL().toString());
}
origin: gocd/gocd

@Override
protected void doFilterInternal(HttpServletRequest request,
                HttpServletResponse response,
                FilterChain filterChain) throws ServletException, IOException {
  final HttpSession session = request.getSession();
  LOGGER.debug("Session info for url: {}, Current session: {}, Requested session id: {}", request.getRequestURI(), session.getId(), request.getRequestedSessionId());
  filterChain.doFilter(request, response);
}
origin: jenkinsci/jenkins

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
  HttpServletRequest req = (HttpServletRequest) request;
  /* allow signup from the Jenkins home page, or /manage, which is where a /configureSecurity form redirects to */
  if(req.getRequestURI().equals(req.getContextPath()+"/") || req.getRequestURI().equals(req.getContextPath() + "/manage")) {
    if (needsToCreateFirstUser()) {
      ((HttpServletResponse)response).sendRedirect("securityRealm/firstUser");
    } else {// the first user already created. the role of this filter is over.
      PluginServletFilter.removeFilter(this);
      chain.doFilter(request,response);
    }
  } else
    chain.doFilter(request,response);
}
origin: spring-projects/spring-framework

@Override
@Nullable
public Object getAttribute(String name, int scope) {
  Assert.notNull(name, "Attribute name must not be null");
  switch (scope) {
    case PAGE_SCOPE:
      return getAttribute(name);
    case REQUEST_SCOPE:
      return this.request.getAttribute(name);
    case SESSION_SCOPE:
      HttpSession session = this.request.getSession(false);
      return (session != null ? session.getAttribute(name) : null);
    case APPLICATION_SCOPE:
      return this.servletContext.getAttribute(name);
    default:
      throw new IllegalArgumentException("Invalid scope: " + scope);
  }
}
javax.servlet.httpHttpServletRequest

Javadoc

Extends the javax.servlet.ServletRequest interface to provide request information for HTTP servlets.

The servlet container creates an HttpServletRequest object and passes it as an argument to the servlet's service methods (doGet, doPost, etc).

Most used methods

  • getHeader
    Returns the value of the specified request header as a String. If the request did not include a head
  • getParameter
  • getRequestURI
    Returns the part of this request's URL from the protocol name up to the query string in the first li
  • getSession
    Returns the current HttpSession associated with this request or, if there is no current session and
  • getMethod
    Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT
  • getAttribute
  • getContextPath
    Returns the portion of the request URI that indicates the context of the request. The context path a
  • getQueryString
    Returns the query string that is contained in the request URL after the path. This method returns nu
  • setAttribute
  • getPathInfo
    Returns any extra path information associated with the URL the client sent when it made this request
  • getRequestURL
    Reconstructs the URL the client used to make the request. The returned URL contains a protocol, serv
  • getRemoteAddr
  • getRequestURL,
  • getRemoteAddr,
  • getServletPath,
  • getInputStream,
  • getParameterMap,
  • getCookies,
  • getServerName,
  • getHeaderNames,
  • getScheme,
  • getServerPort

Popular in Java

  • Making http post requests using okhttp
  • compareTo (BigDecimal)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • getExternalFilesDir (Context)
  • BufferedImage (java.awt.image)
    The BufferedImage subclass describes an java.awt.Image with an accessible buffer of image data. All
  • RandomAccessFile (java.io)
    Allows reading from and writing to a file in a random-access manner. This is different from the uni-
  • SecureRandom (java.security)
    This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
  • Connection (java.sql)
    A connection represents a link from a Java application to a database. All SQL statements and results
  • LinkedList (java.util)
    Doubly-linked list implementation of the List and Dequeinterfaces. Implements all optional list oper
  • List (java.util)
    An ordered collection (also known as a sequence). The user of this interface has precise control ove
  • Top plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now