List of usage examples for javax.servlet.http HttpServletRequest getPathInfo
public String getPathInfo();
From source file:org.eclipse.jgit.lfs.server.LfsProtocolServlet.java
@Override protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { Writer w = new BufferedWriter(new OutputStreamWriter(res.getOutputStream(), UTF_8)); Reader r = new BufferedReader(new InputStreamReader(req.getInputStream(), UTF_8)); LfsRequest request = gson.fromJson(r, LfsRequest.class); String path = req.getPathInfo(); res.setContentType(CONTENTTYPE_VND_GIT_LFS_JSON); LargeFileRepository repo = null;//from w ww. j a va 2 s . c o m try { repo = getLargeFileRepository(request, path); if (repo == null) { String error = MessageFormat.format(LfsText.get().lfsFailedToGetRepository, path); LOG.error(error); throw new LfsException(error); } res.setStatus(SC_OK); TransferHandler handler = TransferHandler.forOperation(request.operation, repo, request.objects); gson.toJson(handler.process(), w); } catch (LfsValidationError e) { sendError(res, w, SC_UNPROCESSABLE_ENTITY, e.getMessage()); } catch (LfsRepositoryNotFound e) { sendError(res, w, SC_NOT_FOUND, e.getMessage()); } catch (LfsRepositoryReadOnly e) { sendError(res, w, SC_FORBIDDEN, e.getMessage()); } catch (LfsRateLimitExceeded e) { sendError(res, w, SC_RATE_LIMIT_EXCEEDED, e.getMessage()); } catch (LfsBandwidthLimitExceeded e) { sendError(res, w, SC_BANDWIDTH_LIMIT_EXCEEDED, e.getMessage()); } catch (LfsInsufficientStorage e) { sendError(res, w, SC_INSUFFICIENT_STORAGE, e.getMessage()); } catch (LfsUnavailable e) { sendError(res, w, SC_SERVICE_UNAVAILABLE, e.getMessage()); } catch (LfsUnauthorized e) { sendError(res, w, SC_UNAUTHORIZED, e.getMessage()); } catch (LfsException e) { sendError(res, w, SC_INTERNAL_SERVER_ERROR, e.getMessage()); } finally { w.flush(); } }
From source file:org.ngrinder.script.controller.DavSvnController.java
/** * Request Handler.//from ww w . ja v a 2 s .co m * * @param request * request * @param response * response * @throws ServletException * occurs when servlet has a problem. * @throws IOException * occurs when file system has a problem. */ @Override public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (LOGGER.isTraceEnabled()) { logRequest(request); } try { final String head = DAVPathUtil.head(request.getPathInfo()); final User currentUser = userContext.getCurrentUser(); // check the security. If the other user tries to the other user's // repo, deny it. if (!StringUtils.equals(currentUser.getUserId(), head)) { SecurityContextHolder.getContext().setAuthentication(null); response.sendError(HttpServletResponse.SC_UNAUTHORIZED, head + " is not accessible by " + currentUser.getUserId()); return; } // To make it understand Asian Language.. request = new MyHttpServletRequestWrapper(request); DAVRepositoryManager repositoryManager = new DAVRepositoryManager(getDAVConfig(), request); ServletDAVHandler handler = DAVHandlerExFactory.createHandler(repositoryManager, request, response); handler.execute(); } catch (DAVException de) { response.setContentType(XML_CONTENT_TYPE); handleError(de, response); } catch (SVNException svne) { StringWriter sw = new StringWriter(); svne.printStackTrace(new PrintWriter(sw)); /** * truncate status line if it is to long */ String msg = sw.getBuffer().toString(); if (msg.length() > 128) { msg = msg.substring(0, 128); } SVNErrorCode errorCode = svne.getErrorMessage().getErrorCode(); if (errorCode == SVNErrorCode.FS_NOT_DIRECTORY || errorCode == SVNErrorCode.FS_NOT_FOUND || errorCode == SVNErrorCode.RA_DAV_PATH_NOT_FOUND) { response.sendError(HttpServletResponse.SC_NOT_FOUND, msg); } else if (errorCode == SVNErrorCode.NO_AUTH_FILE_PATH) { response.sendError(HttpServletResponse.SC_FORBIDDEN, msg); } else if (errorCode == SVNErrorCode.RA_NOT_AUTHORIZED) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED, msg); } else { String errorBody = generateStandardizedErrorBody(errorCode.getCode(), null, null, svne.getMessage()); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); response.setContentType(XML_CONTENT_TYPE); response.getWriter().print(errorBody); } } catch (Throwable th) { StringWriter sw = new StringWriter(); th.printStackTrace(new PrintWriter(sw)); String msg = sw.getBuffer().toString(); LOGGER.debug("Error in DavSVN Controller", th); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg); } finally { response.flushBuffer(); } }
From source file:org.dataone.proto.trove.mn.rest.base.AbstractWebController.java
protected void debugRequest(HttpServletRequest request) { /* see values with just a plain old request object being sent through */ logger.debug("request RequestURL: " + request.getRequestURL()); logger.debug("request RequestURI: " + request.getRequestURI()); logger.debug("request PathInfo: " + request.getPathInfo()); logger.debug("request PathTranslated: " + request.getPathTranslated()); logger.debug("request QueryString: " + request.getQueryString()); logger.debug("request ContextPath: " + request.getContextPath()); logger.debug("request ServletPath: " + request.getServletPath()); logger.debug("request toString:" + request.toString()); Enumeration<String> attributeNames = request.getAttributeNames(); while (attributeNames.hasMoreElements()) { String attributeName = attributeNames.nextElement(); logger.debug("request " + attributeName + ": " + request.getAttribute(attributeName)); }// w ww . ja v a2 s. co m /* values of proxyServletWrapper request object to be sent through */ logger.info(""); /* uncomment to see what the parameters of servlet passed in are */ Map<String, String[]> parameterMap = request.getParameterMap(); for (Object key : parameterMap.keySet()) { String[] values = parameterMap.get((String) key); for (int i = 0; i < values.length; ++i) { logger.info("request ParameterMap: " + (String) key + " = " + values[i]); } } logger.debug(""); }
From source file:de.mpg.mpdl.inge.pidcache.web.MainServlet.java
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { logger.info("PID cache GET request"); try {//from w w w . j a va2 s . c o m if (!authenticate(req, resp)) { logger.warn("Unauthorized request from " + req.getRemoteHost()); return; } PidCacheService pidCacheService = new PidCacheService(); if (GwdgPidService.GWDG_PIDSERVICE_VIEW.equals(req.getPathInfo()) || GwdgPidService.GWDG_PIDSERVICE_VIEW.concat("/").equals(req.getPathInfo())) { if (req.getParameter("pid") == null) { resp.sendError(HttpServletResponse.SC_NO_CONTENT, "PID parameter failed."); } resp.getWriter().append(pidCacheService.retrieve(req.getParameter("pid"))); } else if (GwdgPidService.GWDG_PIDSERVICE_FIND.equals(req.getPathInfo()) || GwdgPidService.GWDG_PIDSERVICE_FIND.concat("/").equals(req.getPathInfo())) { if (req.getParameter("url") == null) { resp.sendError(HttpServletResponse.SC_NO_CONTENT, "URL parameter failed."); } resp.getWriter().append(pidCacheService.search(req.getParameter("url"))); } else if ("/cache/size".equals(req.getPathInfo())) { resp.getWriter().append("There are " + pidCacheService.getCacheSize() + " PID stored in cache"); } else if ("/queue/size".equals(req.getPathInfo())) { resp.getWriter().append("There are " + pidCacheService.getQueueSize() + " PID actually in queue"); } else { resp.sendError(HttpServletResponse.SC_NOT_FOUND, req.getPathInfo()); } } catch (Exception e) { throw new ServletException("Error processing request", e); } }
From source file:cn.vlabs.duckling.vwb.VWBContext.java
private String getRequestURL(HttpServletRequest request) { String url = getBaseURL() + request.getServletPath(); if (request.getPathInfo() != null) url += request.getPathInfo();// ww w . ja v a2s . co m if (request.getQueryString() != null) url = url + "?" + request.getQueryString(); return url; }
From source file:net.oneandone.jasmin.main.Servlet.java
private void gone(HttpServletRequest request, HttpServletResponse response) throws IOException { LOG.warn("gone: " + request.getPathInfo()); response.sendError(HttpServletResponse.SC_GONE); }
From source file:com.jd.survey.web.settings.SurveyDefinitionPageController.java
@Secured({ "ROLE_ADMIN", "ROLE_SURVEY_ADMIN" }) @RequestMapping(value = "/{id}", method = RequestMethod.DELETE, produces = "text/html") public String delete(@PathVariable("id") Long id, Principal principal, Model uiModel, HttpServletRequest httpServletRequest) { log.info("delete(): id=" + id); try {/*from w w w . j a v a 2 s . co m*/ User user = userService.user_findByLogin(principal.getName()); if (!securityService.userIsAuthorizedToManageSurvey(id, user)) { log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo() + " attempted by user login:" + principal.getName() + "from IP:" + httpServletRequest.getLocalAddr()); return "accessDenied"; } SurveyDefinitionPage surveyDefinitionPage = surveySettingsService.surveyDefinitionPage_findById(id); surveySettingsService.surveyDefinitionPage_remove(surveyDefinitionPage); uiModel.asMap().clear(); return "redirect:/settings/surveyDefinitions/" + encodeUrlPathSegment( surveyDefinitionPage.getSurveyDefinition().getId().toString(), httpServletRequest); } catch (Exception e) { log.error(e.getMessage(), e); throw (new RuntimeException(e)); } }
From source file:com.credit.common.web.servlet.filter.csrf.CsrfPreventionFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { ServletResponse wResponse = null;//from w w w. j a va 2 s . c o m if (request instanceof HttpServletRequest && response instanceof HttpServletResponse) { HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse res = (HttpServletResponse) response; boolean skipNonceCheck = false; String path = req.getServletPath(); if (req.getPathInfo() != null) { path = path + req.getPathInfo(); } for (String entr : entryPoints) { if (entr.equalsIgnoreCase(path) || path.endsWith("jsp") || path.endsWith("list") || path.endsWith("List")) // TODO { skipNonceCheck = true; break; } if (entr.indexOf("*") > 0) { entr = entr.replace("*", ""); if (path.startsWith(entr)) { skipNonceCheck = true; break; } } } HttpSession session = getSession(req); @SuppressWarnings("unchecked") LruCache<String> nonceCache = (session == null) ? null : (LruCache<String>) session.getAttribute(Constants.CSRF_NONCE_SESSION_ATTR_NAME); if (!skipNonceCheck) { String previousNonce = req.getParameter(Constants.CSRF_NONCE_REQUEST_PARAM); if (nonceCache == null || previousNonce == null || !nonceCache.contains(previousNonce)) { res.sendError(denyStatus); return; } } if (nonceCache == null) { nonceCache = new LruCache<String>(nonceCacheSize); if (session == null) { session = req.getSession(true); } session.setAttribute(Constants.CSRF_NONCE_SESSION_ATTR_NAME, nonceCache); } String newNonce = generateNonce(); nonceCache.add(newNonce); request.setAttribute(Constants.CSRF_NONCE_REQUEST_PARAM, newNonce); wResponse = new CsrfResponseWrapper(res, newNonce); } else { wResponse = response; } chain.doFilter(request, wResponse); }
From source file:com.telefonica.euro_iaas.sdc.puppetwrapper.auth.OpenStackAuthenticationFilter.java
public final void doFilter(final ServletRequest req, final ServletResponse res, final FilterChain chain) throws IOException, ServletException { final boolean info = logger.isInfoEnabled(); final HttpServletRequest request = (HttpServletRequest) req; final HttpServletResponse response = (HttpServletResponse) res; String header = request.getHeader(OPENSTACK_HEADER_TOKEN); String pathInfo = request.getPathInfo(); MDC.put("txId", ((HttpServletRequest) req).getSession().getId()); if (pathInfo.equals("/") || pathInfo.equals("/extensions")) { /**/*from w w w.ja va 2 s . c o m*/ * It is not needed to authenticate these operations */ logger.info("Operation does not need to Authenticate"); } else { if (header == null) { header = ""; } try { String token = header; if ("".equals(token)) { String str = "Missing token header"; logger.info(str); throw new BadCredentialsException(str); } String tenantId = request.getHeader(OPENSTACK_HEADER_TENANTID); String txId = request.getHeader("txId"); if (txId != null) { MDC.put("txId", txId); } // String tenantId = request.getPathInfo().split("/")[3]; if (info) { logger.info("OpenStack Authentication Authorization header " + "found for user '" + token + "' and tenant " + tenantId); } UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(token, tenantId); authRequest.setDetails(authenticationDetailsSource.buildDetails(request)); Authentication authResult = authenticationManager.authenticate(authRequest); if (info) { logger.info("Authentication success: " + authResult); } PaasManagerUser user = (PaasManagerUser) authResult.getPrincipal(); logger.info("User: " + user.getUsername()); logger.info("Token: " + user.getToken()); logger.info("Tenant: " + user.getTenantId()); logger.info("TenantName - Org: " + user.getTenantName()); SecurityContextHolder.getContext().setAuthentication(authResult); // SecurityContextHolder.setStrategyName("MODE_INHERITABLETHREADLOCAL"); rememberMeServices.loginSuccess(request, response, authResult); onSuccessfulAuthentication(request, response, authResult); } catch (AuthenticationException failed) { SecurityContextHolder.clearContext(); if (info) { logger.info("Authentication request for failed: " + failed); } rememberMeServices.loginFail(request, response); onUnsuccessfulAuthentication(request, response, failed); if (ignoreFailure) { chain.doFilter(request, response); } else { authenticationEntryPoint.commence(request, response, failed); } return; } response.addHeader("Www-Authenticate", "Keystone uri='" + keystoneURL + "'"); } // TODO jesuspg: question:add APIException chain.doFilter(request, response); }
From source file:com.aipo.container.protocol.AipoDataServiceServlet.java
protected RestHandler getRestHandler(HttpServletRequest servletRequest) { // TODO Rework to allow sub-services String path = servletRequest.getPathInfo(); // TODO - This shouldnt be on BaseRequestItem String method = servletRequest.getParameter(X_HTTP_METHOD_OVERRIDE); if (method == null) { method = servletRequest.getMethod(); }// w w w .ja va 2 s . co m // Always returns a non-null handler. return dispatcher.getRestHandler(path, method.toUpperCase()); }