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

How to use
getContextPath
method
in
javax.servlet.http.HttpServletRequest

Best Java code snippets using javax.servlet.http.HttpServletRequest.getContextPath (Showing top 20 results out of 11,376)

Refine searchRefine arrow

  • HttpServletRequest.getRequestURI
  • HttpServletRequest.getServletPath
  • HttpServletRequest.getPathInfo
  • HttpServletResponse.sendRedirect
  • HttpServletRequest.getQueryString
  • HttpServletRequest.getMethod
origin: spring-projects/spring-security

public boolean matches(HttpServletRequest request) {
  String uri = request.getRequestURI();
  String query = request.getQueryString();
  if (query != null) {
    uri += "?" + query;
  }
  if ("".equals(request.getContextPath())) {
    return uri.equals(processUrl);
  }
  return uri.equals(request.getContextPath() + processUrl);
}
origin: SonarSource/sonarqube

 @Override
 public String apply(HttpServletRequest request) {
  return format("%s%s?%s", request.getContextPath(), API_QUALITY_PROFILE_EXPORT, request.getQueryString());
 }
}
origin: SonarSource/sonarqube

/**
 * @return part of request URL after servlet path
 */
private static String getPluginKeyAndResourcePath(HttpServletRequest request) {
 return StringUtils.substringAfter(request.getRequestURI(), request.getContextPath() + request.getServletPath() + "/");
}
origin: stackoverflow.com

 public static String getURL(HttpServletRequest req) {

  String scheme = req.getScheme();             // http
  String serverName = req.getServerName();     // hostname.com
  int serverPort = req.getServerPort();        // 80
  String contextPath = req.getContextPath();   // /mywebapp
  String servletPath = req.getServletPath();   // /servlet/MyServlet
  String pathInfo = req.getPathInfo();         // /a/b;c=123
  String queryString = req.getQueryString();          // d=789

  // Reconstruct original requesting URL
  StringBuilder url = new StringBuilder();
  url.append(scheme).append("://").append(serverName);

  if (serverPort != 80 && serverPort != 443) {
    url.append(":").append(serverPort);
  }

  url.append(contextPath).append(servletPath);

  if (pathInfo != null) {
    url.append(pathInfo);
  }
  if (queryString != null) {
    url.append("?").append(queryString);
  }
  return url.toString();
}
origin: SonarSource/sonarqube

private static boolean shouldRequestBeChecked(HttpServletRequest request) {
 if (UPDATE_METHODS.contains(request.getMethod())) {
  String path = request.getRequestURI().replaceFirst(request.getContextPath(), "");
  return path.startsWith(API_URL);
 }
 return false;
}
origin: hs-web/hsweb-framework

public ActionEnter(HttpServletRequest request, String rootPath) {
  this.request = request;
  this.rootPath = rootPath;
  this.actionType = request.getParameter("action");
  this.contextPath = request.getContextPath();
  this.configManager = ConfigManager.getInstance(this.rootPath, this.contextPath, request.getRequestURI());
}
origin: igniterealtime/Openfire

final String requestPath = ( httpServletRequest.getContextPath() + httpServletRequest.getServletPath() + httpServletRequest.getPathInfo() ).toLowerCase();
origin: stackoverflow.com

@WebServlet(name = "LogoutServlet", urlPatterns = {"/logout"})
public class LogoutServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 HttpSession session = request.getSession(false);
 // Destroys the session for this user.
 if (session != null)
   session.invalidate();
 // Redirects back to the initial page.
 response.sendRedirect(request.getContextPath());
}
}
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: ZHENFENG13/My-Blog

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object o) throws Exception {
  String contextPath = request.getContextPath();
  // System.out.println(contextPath);
  String uri = request.getRequestURI();
  LOGGE.info("UserAgent: {}", request.getHeader(USER_AGENT));
  LOGGE.info("用户访问地址: {}, 来路地址: {}", uri, IPKit.getIpAddrByRequest(request));
  //请求拦截处理
  UserVo user = TaleUtils.getLoginUser(request);
  if (null == user) {
    Integer uid = TaleUtils.getCookieUid(request);
    if (null != uid) {
      //这里还是有安全隐患,cookie是可以伪造的
      user = userService.queryUserById(uid);
      request.getSession().setAttribute(WebConst.LOGIN_SESSION_KEY, user);
    }
  }
  if (uri.startsWith(contextPath + "/admin") && !uri.startsWith(contextPath + "/admin/login") && null == user) {
    response.sendRedirect(request.getContextPath() + "/admin/login");
    return false;
  }
  //设置get请求的token
  if (request.getMethod().equals("GET")) {
    String csrf_token = UUID.UU64();
    // 默认存储30分钟
    cache.hset(Types.CSRF_TOKEN.getType(), csrf_token, uri, 30 * 60);
    request.setAttribute("_csrf_token", csrf_token);
  }
  return true;
}
origin: Red5/red5-server

/** {@inheritDoc} */
public String getPath() {
  String path = request.getContextPath();
  if (request.getPathInfo() != null) {
    path += request.getPathInfo();
  }
  if (path.charAt(0) == '/') {
    path = path.substring(1);
  }
  return path;
}
origin: jamesdbloom/mockserver

private void setPath(HttpRequest httpRequest, HttpServletRequest httpServletRequest) {
  httpRequest.withPath(httpServletRequest.getPathInfo() != null && httpServletRequest.getContextPath() != null ? httpServletRequest.getPathInfo() : httpServletRequest.getRequestURI());
}
origin: neo4j/neo4j

final String path = request.getContextPath() + ( request.getPathInfo() == null ? "" : request.getPathInfo() );
if ( request.getMethod().equals( "OPTIONS" ) || whitelisted( path ) )
origin: jenkinsci/jenkins

String authorization = req.getHeader("Authorization");
String path = req.getServletPath();
if(authorization==null || req.getUserPrincipal() !=null || path.startsWith("/secured/")
|| !Jenkins.getInstance().isUseSecurity()) {
path = req.getContextPath()+"/secured"+path;
String q = req.getQueryString();
if(q!=null)
  path += '?'+q;
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: javamelody/javamelody

public static String buildLogMessage(HttpServletRequest httpRequest, long duration,
    boolean systemError, int responseSize) {
  final StringBuilder msg = new StringBuilder();
  msg.append("remoteAddr = ").append(httpRequest.getRemoteAddr());
  final String forwardedFor = httpRequest.getHeader("X-Forwarded-For");
  if (forwardedFor != null) {
    msg.append(", forwardedFor = ").append(forwardedFor);
  }
  msg.append(", request = ").append(
      httpRequest.getRequestURI().substring(httpRequest.getContextPath().length()));
  if (httpRequest.getQueryString() != null) {
    msg.append('?').append(httpRequest.getQueryString());
  }
  msg.append(' ').append(httpRequest.getMethod());
  msg.append(": ").append(duration).append(" ms");
  if (systemError) {
    msg.append(", erreur");
  }
  msg.append(", ").append(responseSize / 1024).append(" Ko");
  return msg.toString();
}
origin: SonarSource/sonarqube

private static void doHttpFilter(HttpServletRequest httpRequest, HttpServletResponse httpResponse, FilterChain chain) throws IOException, ServletException {
 // SONAR-6881 Disable OPTIONS and TRACE methods
 if (!ALLOWED_HTTP_METHODS.contains(httpRequest.getMethod())) {
  httpResponse.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
  return;
 }
 // WARNING, headers must be added before the doFilter, otherwise they won't be added when response is already committed (for instance when a WS is called)
 // Clickjacking protection
 // See https://www.owasp.org/index.php/Clickjacking_Protection_for_Java_EE
 // The protection is disabled on purpose for integration in external systems like VSTS (/integration/vsts/index.html).
 String path = httpRequest.getRequestURI().replaceFirst(httpRequest.getContextPath(), "");
 if (!path.startsWith("/integration/")) {
  httpResponse.addHeader("X-Frame-Options", "SAMEORIGIN");
 }
 // Cross-site scripting
 // See https://www.owasp.org/index.php/List_of_useful_HTTP_headers
 httpResponse.addHeader("X-XSS-Protection", "1; mode=block");
 // MIME-sniffing
 // See https://www.owasp.org/index.php/List_of_useful_HTTP_headers
 httpResponse.addHeader("X-Content-Type-Options", "nosniff");
 chain.doFilter(httpRequest, httpResponse);
}
origin: cloudfoundry/uaa

  private String getUri(HttpServletRequest request) {
    if (request.getContextPath() != null && request.getContextPath().length() > 0) {
      return request.getServletPath();
    }
    return request.getRequestURI();
  }
}
origin: SonarSource/sonarqube

@Before
public void setUp() throws Exception {
 when(request.getContextPath()).thenReturn("");
 when(request.getRequestURI()).thenReturn("/measures");
}
origin: cloudfoundry/uaa

protected String extractPath(HttpServletRequest request) {
  String query = request.getQueryString();
  try {
    query = query == null ? "" : "?" + URLDecoder.decode(query, UTF_8.name());
  } catch (UnsupportedEncodingException e) {
    throw new IllegalStateException("Cannot decode query string: " + query);
  }
  String path = request.getRequestURI() + query;
  String context = request.getContextPath();
  path = path.substring(context.length());
  if (path.startsWith("/")) {
    // In the root context we have to remove this as well
    path = path.substring(1);
  }
  return path;
}
javax.servlet.httpHttpServletRequestgetContextPath

Javadoc

Returns the portion of the request URI that indicates the context of the request. The context path always comes first in a request URI. The path starts with a "/" character but does not end with a "/" character. For servlets in the default (root) context, this method returns "". The container does not decode this string.

It is possible that a servlet container may match a context by more than one context path. In such cases this method will return the actual context path used by the request and it may differ from the path returned by the javax.servlet.ServletContext#getContextPath() method. The context path returned by javax.servlet.ServletContext#getContextPath()should be considered as the prime or preferred context path of the application.

Popular methods of HttpServletRequest

  • 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
  • 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
  • getServletPath
    Returns the part of this request's URL that calls the servlet. This path starts with a "/" character
  • getRemoteAddr,
  • getServletPath,
  • getInputStream,
  • getParameterMap,
  • getCookies,
  • getServerName,
  • getHeaderNames,
  • getScheme,
  • getServerPort

Popular in Java

  • Making http requests using okhttp
  • setContentView (Activity)
  • runOnUiThread (Activity)
  • requestLocationUpdates (LocationManager)
  • Runnable (java.lang)
    Represents a command that can be executed. Often used to run code in a different Thread.
  • BigInteger (java.math)
    An immutable arbitrary-precision signed integer.FAST CRYPTOGRAPHY This implementation is efficient f
  • Dictionary (java.util)
    Note: Do not use this class since it is obsolete. Please use the Map interface for new implementatio
  • HashSet (java.util)
    HashSet is an implementation of a Set. All optional operations (adding and removing) are supported.
  • ZipFile (java.util.zip)
    This class provides random read access to a zip file. You pay more to read the zip file's central di
  • LoggerFactory (org.slf4j)
    The LoggerFactory is a utility class producing Loggers for various logging APIs, most notably for lo
  • Github Copilot alternatives
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