List of usage examples for javax.servlet.http HttpServletRequest getServletPath
public String getServletPath();
From source file:org.keycloak.example.OfflineAccessPortalServlet.java
private HttpFacade getFacade(final HttpServletRequest servletRequest) { return new HttpFacade() { @Override/*from www.j a v a2 s . c om*/ public Request getRequest() { return new Request() { private InputStream inputStream; @Override public String getMethod() { return servletRequest.getMethod(); } @Override public String getURI() { return servletRequest.getRequestURL().toString(); } @Override public String getRelativePath() { return servletRequest.getServletPath(); } @Override public boolean isSecure() { return servletRequest.isSecure(); } @Override public String getQueryParamValue(String param) { return servletRequest.getParameter(param); } @Override public String getFirstParam(String param) { return servletRequest.getParameter(param); } @Override public Cookie getCookie(String cookieName) { // not needed return null; } @Override public String getHeader(String name) { return servletRequest.getHeader(name); } @Override public List<String> getHeaders(String name) { // not needed return null; } @Override public InputStream getInputStream() { return getInputStream(false); } @Override public InputStream getInputStream(boolean buffered) { if (inputStream != null) { return inputStream; } if (buffered) { try { return inputStream = new BufferedInputStream(servletRequest.getInputStream()); } catch (IOException e) { throw new RuntimeException(e); } } try { return servletRequest.getInputStream(); } catch (IOException e) { throw new RuntimeException(e); } } @Override public String getRemoteAddr() { return servletRequest.getRemoteAddr(); } @Override public void setError(AuthenticationError error) { servletRequest.setAttribute(AuthenticationError.class.getName(), error); } @Override public void setError(LogoutError error) { servletRequest.setAttribute(LogoutError.class.getName(), error); } }; } @Override public Response getResponse() { throw new IllegalStateException("Not yet implemented"); } @Override public X509Certificate[] getCertificateChain() { throw new IllegalStateException("Not yet implemented"); } }; }
From source file:com.rxx.base.interceptor.ActionInterceptor.java
/** * action,basebasepath//from w w w. ja v a 2 s .c o m * @param request HttpServletRequest * @param response HttpServletResponse * @param handler * @throws Exception * @return true */ @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { String modelId = request.getParameter(MODEL_ID); // if (StringUtil.isInteger(modelId)) { request.getSession().setAttribute(SessionConst.MODEL_ID_SESSION.toString(), modelId); request.getSession().setAttribute(SessionConst.MODEL_TITLE_SESSION.toString(), request.getParameter("modelTitle")); } request.setAttribute(BASE, Const.BASE); request.setAttribute(BASE_PATH, request.getScheme() + "://" + request.getServerName() + (request.getServerPort() == 80 ? "" : ":" + request.getServerPort()) + Const.BASE); request.setAttribute(BASE_URL, request.getScheme() + "://" + request.getServerName() + (request.getServerPort() == 80 ? "" : ":" + request.getServerPort()) + request.getContextPath() + request.getServletPath() + (request.getQueryString() == null ? "" : "?" + request.getQueryString())); return true; }
From source file:com.sun.faban.harness.webclient.CLIServlet.java
String[] getPathComponents(HttpServletRequest request) { String pathInfo = request.getPathInfo(); StringTokenizer pathTokens = null; int tokenCount = 0; if (pathInfo != null) { pathTokens = new StringTokenizer(pathInfo, "/"); tokenCount = pathTokens.countTokens(); }/* w ww . ja v a 2 s . c om*/ String[] comps = new String[tokenCount + 1]; comps[0] = request.getServletPath(); int i = 1; while (pathTokens != null && pathTokens.hasMoreTokens()) { comps[i] = pathTokens.nextToken(); if (comps[i] != null && comps[i].length() > 0) ++i; } if (i != comps.length) { String[] comps0 = new String[i]; System.arraycopy(comps, 0, comps0, 0, i); comps = comps0; } return comps; }
From source file:de.zib.vold.userInterface.RESTController.java
/** * Handles Post requests.// w ww . j av a 2 s .co m * * This method is used by clients to submit new keys, refresh their registration or delete them. * * @param clientIpAddress The ip of the sending client, it's extracted from the request itself. * @param args The URL arguments of the request. * @param request Request informations * @return A map of keys with its lifetime, whereas the livetime is zero if an error for that key occured. */ @RequestMapping(method = RequestMethod.POST) public ResponseEntity<Map<String, String>> refresh(@ModelAttribute("clientIpAddress") String clientIpAddress, @RequestParam MultiValueMap<String, String> args, @RequestHeader(value = "TIMESTAMP", defaultValue = "unset") String timeStampHeader, HttpServletRequest request) { final long timeStamp; if (timeStampHeader.equals("unset")) timeStamp = DateTime.now().getMillis(); else timeStamp = Long.parseLong(timeStampHeader); // guard { logger.debug("POST: " + args.toString()); checkState(); } Map<String, String> invalidKeys = new HashMap<String, String>(); // get actual scope String scope; { scope = request.getRequestURI(); String removepath = removePrefix + request.getContextPath() + request.getServletPath(); scope = scope.substring(removepath.length(), scope.length()); } // process each key { for (Map.Entry<String, List<String>> entry : args.entrySet()) { URIKey urikey; String source; Key k; // build key { urikey = URIKey.fromURIString(entry.getKey(), enc); File path_correction = new File(scope + "/" + urikey.getKey().get_scope()); k = new Key(path_correction.getPath(), urikey.getKey().get_type(), urikey.getKey().get_keyname()); if (null == urikey.getSource()) { source = clientIpAddress; } else { source = urikey.getSource(); } } // handle write request for that key { try { frontend.refresh(source, k, timeStamp); } catch (VoldException e) { logger.error("Could not handle write request for key " + entry.getKey() + ". ", e); invalidKeys.put(entry.getKey(), "ERROR: " + e.getMessage()); } } } } return new ResponseEntity<Map<String, String>>(invalidKeys, HttpStatus.OK); }
From source file:airlift.servlet.rest.RestServlet.java
/** * Reconstruct uri.//from ww w . ja va2 s .c o m * * @param _appName the _app name * @param _request the _request * @return the string */ public String reconstructUri(String _appName, HttpServletRequest _request) { String pathInfo = (_request.getPathInfo() == null) ? "" : _request.getPathInfo(); String path = _request.getServletPath() + pathInfo; path = path.replaceFirst("/$", "").replaceFirst("^/", ""); return _appName + "/" + path; }
From source file:com.qlkh.client.server.proxy.ProxyServlet.java
/** * Retrieves all of the cookies from the servlet request and sets them on * the proxy request//from w w w. ja v a 2 s . c o m * * @param httpServletRequest The request object representing the client's * request to the servlet engine * @param httpMethodProxyRequest The request that we are about to send to * the proxy host */ @SuppressWarnings("unchecked") private void setProxyRequestCookies(HttpServletRequest httpServletRequest, HttpMethod httpMethodProxyRequest) { // Get an array of all of all the cookies sent by the client Cookie[] cookies = httpServletRequest.getCookies(); if (cookies == null) { return; } for (Cookie cookie : cookies) { cookie.setDomain(stringProxyHost); cookie.setPath(httpServletRequest.getServletPath()); httpMethodProxyRequest.setRequestHeader("Cookie", cookie.getName() + "=" + cookie.getValue() + "; Path=" + cookie.getPath()); } }
From source file:net.paoding.rose.web.RequestPath.java
public RequestPath(HttpServletRequest request) { // method//from www .ja va 2s. c o m setMethod(parseMethod(request)); // ctxpath setCtxpath(request.getContextPath()); String invocationCtxpath = null; // includeinvocationCtxPathincludectxpath // dispather, uri, ctxpath String uri; if (WebUtils.isIncludeRequest(request)) { setDispatcher(Dispatcher.INCLUDE); uri = (String) request.getAttribute(WebUtils.INCLUDE_REQUEST_URI_ATTRIBUTE); invocationCtxpath = ((String) request.getAttribute(WebUtils.INCLUDE_CONTEXT_PATH_ATTRIBUTE)); setRosePath((String) request.getAttribute(WebUtils.INCLUDE_SERVLET_PATH_ATTRIBUTE)); } else { uri = request.getRequestURI(); this.setRosePath(request.getServletPath()); if (request.getAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE) == null) { this.setDispatcher(Dispatcher.REQUEST); } else { this.setDispatcher(Dispatcher.FORWARD); } } if (uri.startsWith("http://") || uri.startsWith("https://")) { int start = uri.indexOf('/', 9); if (start == -1) { uri = ""; } else { uri = uri.substring(start); } } if (uri.indexOf('%') != -1) { try { String encoding = request.getCharacterEncoding(); if (encoding == null || encoding.length() == 0) { encoding = "UTF-8"; } uri = URLDecoder.decode(uri, encoding); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } this.setUri(uri); // requestPathctxpathincludeinvocationCtxpath if (getCtxpath().length() <= 1) { setRosePath(getUri()); } else { setRosePath( getUri().substring((invocationCtxpath == null ? getCtxpath() : invocationCtxpath).length())); } }
From source file:com.google.gwt.jolokia.server.servlet.ProxyServlet.java
/** * Copy cookie from the proxy to the servlet client. Replaces cookie path to * local path and renames cookie to avoid collisions. *//*from w w w . ja va 2 s . co m*/ protected void copyProxyCookie(HttpServletRequest servletRequest, HttpServletResponse servletResponse, Header header) { List<HttpCookie> cookies = HttpCookie.parse(header.getValue()); String path = getServletContext().getServletContextName(); if (path == null) { path = ""; } path += servletRequest.getServletPath(); for (HttpCookie cookie : cookies) { // set cookie name prefixed w/ a proxy value so it won't collide w/ // other cookies String proxyCookieName = getCookieNamePrefix() + cookie.getName(); Cookie servletCookie = new Cookie(proxyCookieName, cookie.getValue()); servletCookie.setComment(cookie.getComment()); servletCookie.setMaxAge((int) cookie.getMaxAge()); servletCookie.setPath(path); // set to the path of the proxy servlet // don't set cookie domain servletCookie.setSecure(cookie.getSecure()); servletCookie.setVersion(cookie.getVersion()); servletResponse.addCookie(servletCookie); } }
From source file:com.edgenius.wiki.webapp.servlet.InstallServlet.java
/** * 15/09/2008: this is not true in below comments, as I remove skinTag dependent (move style into static/styles rather than skin/default/styles)/ * But I still keep this code as it is not harmful. * <br> /*from ww w . j a v a2 s. c om*/ * JSP page rely on SkinTag, which is rely on the Global.contextPath. Some pages display before context path is decided, which is saved * into global.xml only saveURLInfo() after data root is created. So use this method to temporarily put contenxtPath to Global static. */ private void resetContextPath(HttpServletRequest request) { String url = request.getRequestURL().toString(); String servletPath = request.getServletPath(); url = url.substring(0, url.length() - servletPath.length()); Global.resetURLInfo(url); }