List of usage examples for javax.servlet.http HttpServletRequest getRequestURI
public String getRequestURI();
From source file:com.assemblade.rest.AuthenticationFilter.java
@Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest httpServletRequest = ((HttpServletRequest) servletRequest); String address = httpServletRequest.getRequestURI(); if (address.endsWith("/login") || address.endsWith("/login/changepassword")) { filterChain.doFilter(servletRequest, servletResponse); } else {/*w w w .ja va 2 s . c om*/ String token = httpServletRequest.getParameter(OAuthConstants.CONSUMER_KEY); if (StringUtils.isEmpty(token)) { ((HttpServletResponse) servletResponse).setStatus(401); } else { try { AccessToken accessToken = accessTokenManager.getAccessToken(token); if (accessToken == null) { ((HttpServletResponse) servletResponse).setStatus(401); } else { if (checkOauthAuthentication(httpServletRequest, accessToken)) { User user = new User(); user.setUserId(accessToken.getUid()); user = directoryService.getAdminSession().get(user); if (user == null) { ((HttpServletResponse) servletResponse).setStatus(401); } else { Authentication authentication = new Authentication(); authentication.setUser(user); authentication.setBaseUrl(accessToken.getBaseUrl()); AuthenticationHolder.setAuthentication(authentication); filterChain.doFilter(servletRequest, servletResponse); AuthenticationHolder.resetAuthentication(); } } else { ((HttpServletResponse) servletResponse).setStatus(401); } } } catch (StorageException e) { ((HttpServletResponse) servletResponse).setStatus(500); } } } }
From source file:com.ms.app.web.commons.valve.BaseWebUserBuilderValve.java
protected PipelineResult getToLogin(HttpServletRequest request) { String url = loginUrl;/* ww w .j a va2 s .com*/ String uri = request.getRequestURI(); // ????returnurl if (request.getParameterMap().isEmpty() && !StringUtils.contains("/login", uri)) { url = loginUrl + "?returnurl=" + uri; } return PipelineResult.gotoFinally("gotoLogin", url); }
From source file:com.bitranger.parknshop.admin.CtrlIndex.java
@RequestMapping(value = "/redirect/ad/detail", method = RequestMethod.GET) public void redAd(HttpServletRequest request, HttpServletResponse resp) { // detail?id=???? System.out.println("CtrlIndex.red()"); System.out.println(request.getRequestURI()); System.out.println(request.getQueryString()); }
From source file:com.iwancool.dsm.admin.filter.DsmSecurityInterceptor.java
/** * controller?/* w ww . ja va 2 s . c o m*/ */ @SuppressWarnings("unchecked") @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { String requestPath = request.getRequestURI().substring(request.getContextPath().length()); //??? if (excludeUrls.contains(requestPath)) return true; // if (!SessionUtils.isLogin(request)) { request.setAttribute("msg", ""); request.getRequestDispatcher("/login/index").forward(request, response); return false; } List<PermissionModel> permissionList = (List<PermissionModel>) SessionUtils.getAttr(request, SessionUtils.ADMIN_PERMISSION_CACHE_KEY); return true; //return hasPermission(permissionList, requestPath); }
From source file:com.autentia.intra.servlet.DocRootServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String uri = request.getRequestURI(); log.debug("doGet - uri='" + uri + "'"); int i = uri.indexOf(URL_PREFIX); if (i != -1) { String relPath = uri.substring(i + URL_PREFIX.length()); relPath = URLDecoder.decode(relPath, "UTF-8"); log.debug("doGet - relPath='" + relPath + "'"); File f = new File(ConfigurationUtil.getDefault().getDocumentRootPath() + relPath); if (f.exists()) { response.setContentLength((int) f.length()); String mime = request.getParameter(ARG_MIME); if (mime != null && !mime.equals("")) { response.setContentType(mime); }//from www. j a v a2 s . c om OutputStream out = response.getOutputStream(); InputStream in = new FileInputStream(f); byte[] buffer = new byte[8192]; int nr; while ((nr = in.read(buffer)) != -1) { out.write(buffer, 0, nr); } in.close(); } else { response.sendError(HttpServletResponse.SC_NOT_FOUND); } } else { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Bad URL prefix for servlet: check your web.xml file"); } }
From source file:com.cpjit.swagger4j.support.internal.DefaultApiViewWriter.java
/** * @since 1.2.2/* w w w.j av a 2 s . c om*/ */ protected String buildResourcePath(HttpServletRequest request, Properties config) { String uri = request.getRequestURI(); String suffix = (String) config.get("suffix"); if (suffix != null) { int index = uri.lastIndexOf(suffix); if (index > 0) { uri = uri.substring(0, index); } } String path = uri.substring(uri.indexOf("statics") + 7); path = "com/cpjit/swagger4j/support/internal/statics" + path; return path; }
From source file:com.roche.iceboar.demo.JnlpServlet.java
/** * This method handle all HTTP requests for *.jnlp files (defined in web.xml). Method check, is name correct * (allowed), read file from disk, replace #{codebase} (it's necessary to be generated based on where application * is deployed), #{host} () and write to the response. * <p>// w w w .ja v a 2 s . c o m * You can use this class in your code for downloading JNLP files. * Return a content of requested jnlp file in response. * * @throws IOException when can't close some stream */ @Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { String contextPath = request.getContextPath(); String requestURI = request.getRequestURI(); String host = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort(); String codebase = host + contextPath; String filename = StringUtils.removeStart(requestURI, contextPath); response.setContentType("application/x-java-jnlp-file"); response.addHeader("Pragma", "no-cache"); response.addHeader("Expires", "-1"); OutputStreamWriter out = new OutputStreamWriter(response.getOutputStream()); InputStream in = JnlpServlet.class.getResourceAsStream(filename); if (in == null) { error(response, "Can't open: " + filename); return; } BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String line = reader.readLine(); while (line != null) { line = line.replace("#{codebase}", codebase); line = line.replace("#{host}", host); out.write(line); out.write("\n"); line = reader.readLine(); } out.flush(); out.close(); reader.close(); }
From source file:org.consultjr.mvc.core.components.ApplicationInterceptor.java
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { String queryString = request.getQueryString(); String uri = request.getRequestURI(); StringBuffer url = request.getRequestURL(); HttpSession session = this.getSession(request); Enumeration attributes = session.getAttributeNames(); Map<String, Object> sessionAttributes = new HashMap<>(); logger.debug("URL: {}", url); logger.debug("URI: {}", uri); logger.debug("QUERY STRING: {}", queryString); logger.debug("Handler Object: {}", handler); while (attributes.hasMoreElements()) { String name = (String) attributes.nextElement(); sessionAttributes.put(name, session.getAttribute(name)); }/* www .j a v a 2s . c o m*/ logger.debug("Session: {}", sessionAttributes); return true; }
From source file:com.autentia.tnt.servlet.DocServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String uri = request.getRequestURI(); log.debug("doGet - uri='" + uri + "'"); int i = uri.indexOf(URL_PREFIX); if (i != -1) { String relPath = uri.substring(i + URL_PREFIX.length()); relPath = URLDecoder.decode(relPath, "UTF-8"); log.debug("doGet - relPath='" + relPath + "'"); File f = new File(ConfigurationUtil.getDefault().getUploadPath() + relPath); if (f.exists()) { response.setContentLength((int) f.length()); String mime = request.getParameter(ARG_MIME); if (mime != null && !mime.equals("")) { response.setContentType(mime); }/*from w w w. j ava 2s . c o m*/ OutputStream out = response.getOutputStream(); InputStream in = null; try { in = new FileInputStream(f); byte[] buffer = new byte[8192]; int nr; while ((nr = in.read(buffer)) != -1) { out.write(buffer, 0, nr); } } finally { if (in != null) { in.close(); } } } else { response.sendError(HttpServletResponse.SC_NOT_FOUND); } } else { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Bad URL prefix for servlet: check your web.xml file"); } }
From source file:ca.uhn.fhir.rest.server.IncomingRequestAddressStrategy.java
@Override public String determineServerBase(ServletContext theServletContext, HttpServletRequest theRequest) { String requestFullPath = StringUtils.defaultString(theRequest.getRequestURI()); String servletPath;//from w w w . ja va 2 s . co m if (myServletPath != null) { servletPath = myServletPath; } else { servletPath = StringUtils.defaultString(theRequest.getServletPath()); } StringBuffer requestUrl = theRequest.getRequestURL(); String servletContextPath = StringUtils.defaultString(theRequest.getContextPath()); String requestPath = requestFullPath.substring(servletContextPath.length() + servletPath.length()); if (requestPath.length() > 0 && requestPath.charAt(0) == '/') { requestPath = requestPath.substring(1); } int startOfPath = requestUrl.indexOf("//"); int requestUrlLength = requestUrl.length(); if (startOfPath != -1 && (startOfPath + 2) < requestUrlLength) { startOfPath = requestUrl.indexOf("/", startOfPath + 2); } if (startOfPath == -1) { startOfPath = 0; } int contextIndex; if (servletPath.length() == 0 || servletPath.equals("/")) { if (requestPath.length() == 0) { contextIndex = requestUrlLength; } else { contextIndex = requestUrl.indexOf(requestPath, startOfPath); } } else { //servletContextPath can start with servletPath contextIndex = requestUrl.indexOf(servletPath + "/", startOfPath); if (contextIndex == -1) { contextIndex = requestUrl.indexOf(servletPath, startOfPath); } } String fhirServerBase; int length = contextIndex + servletPath.length(); if (length > requestUrlLength) { length = requestUrlLength; } fhirServerBase = requestUrl.substring(0, length); return fhirServerBase; }