List of usage examples for javax.servlet.http HttpServletRequest getPathInfo
public String getPathInfo();
From source file:org.apache.hadoop.gateway.AuditLoggingTest.java
@Test /**/*from w w w. ja v a 2 s . co m*/ * One NoOp filter in chain. Single audit event with same with specified request URI is expected: * * action=access request_type=uri outcome=unavailable */ public void testNoopFilter() throws ServletException, IOException, URISyntaxException { FilterConfig config = EasyMock.createNiceMock(FilterConfig.class); EasyMock.replay(config); HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class); ServletContext context = EasyMock.createNiceMock(ServletContext.class); GatewayConfig gatewayConfig = EasyMock.createNiceMock(GatewayConfig.class); EasyMock.expect(request.getMethod()).andReturn(METHOD).anyTimes(); EasyMock.expect(request.getPathInfo()).andReturn(PATH).anyTimes(); EasyMock.expect(request.getContextPath()).andReturn(CONTEXT_PATH).anyTimes(); EasyMock.expect(request.getRemoteAddr()).andReturn(ADDRESS).anyTimes(); EasyMock.expect(request.getRemoteHost()).andReturn(HOST).anyTimes(); EasyMock.expect(request.getServletContext()).andReturn(context).anyTimes(); EasyMock.expect(context.getAttribute(GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE)).andReturn(gatewayConfig) .anyTimes(); EasyMock.expect(gatewayConfig.getHeaderNameForRemoteAddress()).andReturn("Custom-Forwarded-For").anyTimes(); EasyMock.replay(request); EasyMock.replay(context); EasyMock.replay(gatewayConfig); HttpServletResponse response = EasyMock.createNiceMock(HttpServletResponse.class); EasyMock.replay(response); FilterChain chain = EasyMock.createNiceMock(FilterChain.class); EasyMock.replay(chain); Filter filter = EasyMock.createNiceMock(Filter.class); EasyMock.replay(filter); GatewayFilter gateway = new GatewayFilter(); gateway.addFilter("path", "filter", filter, null, null); gateway.init(config); gateway.doFilter(request, response, chain); gateway.destroy(); assertThat(CollectAppender.queue.size(), is(1)); Iterator<LoggingEvent> iterator = CollectAppender.queue.iterator(); LoggingEvent accessEvent = iterator.next(); verifyAuditEvent(accessEvent, CONTEXT_PATH + PATH, ResourceType.URI, Action.ACCESS, ActionOutcome.UNAVAILABLE, null, "Request method: GET"); }
From source file:com.jd.survey.web.settings.SectorsController.java
@Secured({ "ROLE_ADMIN" }) @RequestMapping(method = RequestMethod.POST, produces = "text/html") public String createPost(@RequestParam(value = "_proceed", required = false) String proceed, @Valid Sector sector, BindingResult bindingResult, Principal principal, Model uiModel, HttpServletRequest httpServletRequest) { log.info("create(): handles " + RequestMethod.POST.toString()); try {/*from w ww . j a va2s .co m*/ User user = userService.user_findByLogin(principal.getName()); if (!user.isAdmin()) { log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo() + " attempted by user login:" + principal.getName() + "from IP:" + httpServletRequest.getLocalAddr()); return "accessDenied"; } if (proceed != null) { if (bindingResult.hasErrors()) { populateEditForm(uiModel, sector, user); return "admin/sectors/create"; } if (surveySettingsService.dataset_findByName(sector.getName()) != null && !surveySettingsService .dataset_findByName(sector.getName()).getId().equals(sector.getId())) { bindingResult.rejectValue("name", "field_unique"); populateEditForm(uiModel, sector, user); return "admin/sectors/update"; } uiModel.asMap().clear(); sector = surveySettingsService.sector_merge(sector); return "redirect:/admin/sectors/" + encodeUrlPathSegment(sector.getId().toString(), httpServletRequest); } else { return "redirect:/admin/sectors"; } } catch (Exception e) { log.error(e.getMessage(), e); throw (new RuntimeException(e)); } }
From source file:de.zazaz.iot.bosch.indego.ifttt.IftttIndegoAdapter.java
/** * This creates a HTTP server instance for receiving IFTTT commands. * /*from www.ja va2 s .co m*/ * @return the HTTP server instance */ private Server buildHttpServer() { if (configuration.getIftttReceiverPort() == 0) { return null; } HttpServlet servlet = new HttpServlet() { private static final long serialVersionUID = 1L; @Override protected void doGet(HttpServletRequest req_, HttpServletResponse resp_) throws ServletException, IOException { if (req_.getPathInfo() .startsWith(String.format("/%s/command/", configuration.getIftttReceiverSecret()))) { handleIftttCommand(req_, resp_); resp_.setContentType("text/html"); resp_.setStatus(HttpStatus.SC_OK); } else { super.doGet(req_, resp_); } } }; Server result = new Server(configuration.getIftttReceiverPort()); ServletHandler handler = new ServletHandler(); result.setHandler(handler); handler.addServletWithMapping(new ServletHolder(servlet), "/*"); try { result.start(); } catch (Exception ex) { LOG.fatal("Was not able to start the command server", ex); return null; } return result; }
From source file:uk.ac.ebi.phenotype.web.proxy.ExternalUrlConfiguratbleProxyServlet.java
private String rewriteUrlFromRequest(HttpServletRequest servletRequest) { StringBuilder uri = new StringBuilder(500); uri.append(this.targetUri.toString()); // Handle the path given to the servlet if (servletRequest.getPathInfo() != null) {// ex: /my/path.html uri.append(servletRequest.getPathInfo()); }/*from ww w . j a v a2s . co m*/ // Handle the query string String queryString = servletRequest.getQueryString();// ex:(following // '?'): // name=value&foo=bar#fragment if (queryString != null && queryString.length() > 0) { uri.append('?'); int fragIdx = queryString.indexOf('#'); String queryNoFrag = (fragIdx < 0 ? queryString : queryString.substring(0, fragIdx)); uri.append(encodeUriQuery(queryNoFrag)); if (fragIdx >= 0) { uri.append('#'); uri.append(encodeUriQuery(queryString.substring(fragIdx + 1))); } } return uri.toString().replaceAll(" ", "%20"); }
From source file:com.sonicle.webtop.core.app.servlet.Login.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { boolean redirect = false; if (logger.isTraceEnabled()) { logger.trace("X-REQUEST-URI: {}", request.getHeader("X-REQUEST-URI")); logger.trace("requestUrl: {}", request.getRequestURL().toString()); logger.trace("pathInfo: {}", request.getPathInfo()); logger.trace("baseUrl: {}", getBaseUrl(request)); logger.trace("forwardServletPath: {}", getRequestForwardServletPath(request)); }//from w w w . j a v a 2 s. c o m if (ServletUtils.isForwarded(request)) { String forwardServletPath = getRequestForwardServletPath(request); if (StringUtils.startsWithIgnoreCase(forwardServletPath, Login.URL) || StringUtils.startsWithIgnoreCase(forwardServletPath, Logout.URL)) { redirect = true; } if (StringUtils.startsWithIgnoreCase(forwardServletPath, PushEndpoint.URL)) { WebUtils.getAndClearSavedRequest(request); redirect = true; } } else { String requestUrl = request.getRequestURL().toString(); if (StringUtils.endsWithIgnoreCase(requestUrl, Login.URL)) { redirect = true; } } if (redirect) { WebUtils.issueRedirect(request, response, "/"); } else { super.doGet(request, response); } }
From source file:de.mpg.escidoc.services.pidcache.web.MainServlet.java
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { logger.info("PID cache GET request"); try {/* www . j ava 2 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 ("/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:com.jd.survey.web.settings.SurveyDefinitionPageController.java
@Secured({ "ROLE_ADMIN", "ROLE_SURVEY_ADMIN" }) @RequestMapping(value = "/{id}", params = "create", produces = "text/html") public String createGet(@PathVariable("id") Long surveyDefinitionId, Principal principal, Model uiModel, HttpServletRequest httpServletRequest) { try {/*from w w w . ja va 2s .c o m*/ User user = userService.user_findByLogin(principal.getName()); if (!securityService.userIsAuthorizedToManageSurvey(surveyDefinitionId, user)) { log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo() + " attempted by user login:" + principal.getName() + "from IP:" + httpServletRequest.getLocalAddr()); return "accessDenied"; } SurveyDefinition surveyDefinition = surveySettingsService.surveyDefinition_findById(surveyDefinitionId); SurveyDefinitionPage surveyDefinitionPage = new SurveyDefinitionPage(surveyDefinition); populateEditForm(uiModel, surveyDefinitionPage, user); return "settings/surveyDefinitionPages/create"; } catch (Exception e) { log.error(e.getMessage(), e); throw (new RuntimeException(e)); } }
From source file:com.janrain.backplane.server.Backplane1Controller.java
/** * Handle all other errors/*w w w . ja va2s . c om*/ */ @ExceptionHandler @ResponseBody public Map<String, String> handle(final Exception e, HttpServletRequest request, HttpServletResponse response) { String path = request.getPathInfo(); logger.error("Error handling backplane request for " + path + ": " + e.getMessage(), bpConfig.getDebugException(e)); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return new HashMap<String, String>() { { put(ERR_MSG_FIELD, bpConfig.isDebugMode() ? e.getMessage() : "Error processing request."); } }; }
From source file:com.igeekinc.indelible.indeliblefs.iscsi.IndelibleiSCSIMgmtServlet.java
public JSONObject export(HttpServletRequest req, HttpServletResponse resp, Map<String, String[]> paramMap) throws JSONException, IndelibleMgmtException { JSONObject returnObject = new JSONObject(); JSONObject exportObject = new JSONObject(); returnObject.put("export", exportObject); String path = req.getPathInfo(); FilePath reqPath = FilePath.getFilePath(path); String[] exportTargetNameArr = paramMap.get("target"); if (reqPath == null || exportTargetNameArr == null || exportTargetNameArr.length < 1 || reqPath.getNumComponents() < 3) throw new IndelibleMgmtException(IndelibleMgmtException.kInvalidArgument, null); String exportTargetName = exportTargetNameArr[0]; if (reqPath == null || exportTargetName == null || reqPath.getNumComponents() < 3) throw new IndelibleMgmtException(IndelibleMgmtException.kInvalidArgument, null); // Should be an absolute path reqPath = reqPath.removeLeadingComponent(); String fsIDStr = reqPath.getComponent(0); IndelibleFSVolumeIF volume = getVolume(fsIDStr); FilePath exportPath = reqPath.removeLeadingComponent(); try {// www . j ava 2 s. c o m target.exportIndelibleFSFile(volume, exportPath, exportTargetName, null); exportObject.put("targetname", exportTargetName); } catch (ObjectNotFoundException e) { Logger.getLogger(getClass()).error(new ErrorLogMessage("Caught exception"), e); } catch (PermissionDeniedException e) { Logger.getLogger(getClass()).error(new ErrorLogMessage("Caught exception"), e); } catch (RemoteException e) { Logger.getLogger(getClass()).error(new ErrorLogMessage("Caught exception"), e); } catch (ForkNotFoundException e) { Logger.getLogger(getClass()).error(new ErrorLogMessage("Caught exception"), e); } catch (IOException e) { Logger.getLogger(getClass()).error(new ErrorLogMessage("Caught exception"), e); } try { target.writeConfig(); } catch (RemoteException e) { Logger.getLogger(getClass()).error(new ErrorLogMessage("Caught exception"), e); } catch (PermissionDeniedException e) { Logger.getLogger(getClass()).error(new ErrorLogMessage("Caught exception"), e); } catch (FileExistsException e) { Logger.getLogger(getClass()).error(new ErrorLogMessage("Caught exception"), e); } catch (ForkNotFoundException e) { Logger.getLogger(getClass()).error(new ErrorLogMessage("Caught exception"), e); } catch (IOException e) { Logger.getLogger(getClass()).error(new ErrorLogMessage("Caught exception"), e); } return returnObject; }
From source file:org.realityforge.proxy_servlet.AbstractProxyServlet.java
/** * For a redirect response from the target server, this translates {@code theUrl} to redirect to * and translates it to one the original client can use. *///from ww w .j a va 2s.com private String rewriteUrlFromResponse(final HttpServletRequest servletRequest, final String url) { if (url.startsWith(_target)) { String curUrl = servletRequest.getRequestURL().toString(); //no query final String pathInfo = servletRequest.getPathInfo(); if (null != pathInfo) { assert curUrl.endsWith(pathInfo); //take pathInfo off curUrl = curUrl.substring(0, curUrl.length() - pathInfo.length()); } return curUrl + url.substring(_target.length()); } else { return url; } }