List of usage examples for javax.servlet.http HttpServletRequest getPathInfo
public String getPathInfo();
From source file:com.mindquarry.user.webapp.AuthenticationFilter.java
private String servletRelativeUri(HttpServletRequest request) { String servletRequestUri = request.getPathInfo(); if (servletRequestUri.startsWith("/")) return servletRequestUri.substring(1); else/*from w w w. j a va 2 s .co m*/ return servletRequestUri; }
From source file:de.micromata.genome.gwiki.web.GWikiServlet.java
@Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { if (GLog.isTraceEnabled() == true) { String lopi = "Req: ctpath: " + req.getContextPath() + "; spath: " + req.getServletPath() + "; pi: " + req.getPathInfo(); GLog.note(GWikiLogCategory.Wiki, lopi); }//from ww w.j av a2 s .com initWiki(req, resp); long start = System.currentTimeMillis(); GWikiWeb wiki = getWikiWeb(); GWikiContext ctx = new GWikiContext(wiki, this, req, resp); try { GWikiContext.setCurrent(ctx); String page = getWikiPage(ctx); final String method = req.getMethod(); if (StringUtils.equals(method, "GET") == false && StringUtils.equals(method, "POST") == false) { resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "Gwiki Method " + method + " not supported"); return; } if (page.startsWith("static/") == true) { serveStatic(page, ctx); return; } wiki.serveWiki(page, ctx); } catch (RuntimeIOException ex) { GLog.info(GWikiLogCategory.Wiki, "IO Error serving: " + ex.getMessage(), new LogExceptionAttribute(ex)); } catch (Exception ex) { if (isIgnorableAppServeIOException(ex) == true) { GLog.note(GWikiLogCategory.Wiki, "IO Error serving: " + ex.getMessage()); } else { GLog.error(GWikiLogCategory.Wiki, "GWikiWeb serve error: " + ex.getMessage(), new LogExceptionAttribute(ex)); } } finally { LoggingServiceManager.get().getStatsDAO().addPerformance(GWikiLogCategory.Wiki, "GWikiServlet.doPost", System.currentTimeMillis() - start, 0); GWikiContext.setCurrent(null); if (daoContext != null) { daoContext.getWikiSelector().deinitWiki(this, req, resp); } } }
From source file:com.jd.survey.web.settings.SectorsController.java
@Secured({ "ROLE_ADMIN" }) @RequestMapping(value = "/surveyTemplates/{id}", method = RequestMethod.DELETE, produces = "text/html") public String deletess(@PathVariable("id") Long id, Principal principal, Model uiModel, HttpServletRequest httpServletRequest) { log.info("delete(): id=" + id); try {/*w w w. j av a2s .c om*/ 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"; } SurveyTemplate surveyTemplate = (SurveyTemplate) surveySettingsService.surveyTemplate_findById(id); surveySettingsService.surveyTemplate_remove(surveyTemplate); uiModel.asMap().clear(); return "redirect:/admin/sectors"; } catch (Exception e) { log.error(e.getMessage(), e); throw (new RuntimeException(e)); } }
From source file:com.novartis.pcs.ontology.rest.servlet.OntologiesServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String mediaType = getExpectedMediaType(request); String pathInfo = StringUtils.trimToNull(request.getPathInfo()); boolean includeNonPublicXrefs = Boolean .parseBoolean(StringUtils.trimToNull(request.getParameter("nonpublic-xrefs"))); if (mediaType == null) { response.setStatus(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE); response.setContentLength(0);/* w w w . j a v a 2 s .c om*/ } else if (pathInfo != null && pathInfo.length() > 1) { String ontologyName = pathInfo.substring(1); if (mediaType.equals(MEDIA_TYPE_JSON)) { serialize(ontologyName, response); } else { export(ontologyName, includeNonPublicXrefs, mediaType, response); } } else { mediaType = getExpectedMediaType(request, Collections.singletonList(MEDIA_TYPE_JSON)); if (mediaType.equals(MEDIA_TYPE_JSON)) { serializeAll(response); } else { response.setStatus(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE); response.setContentLength(0); } } }
From source file:com.buglabs.bug.ws.program.ProgramServlet.java
/** * Implementation of doDelete that uninstalls supplied bundle */// w w w. java2 s.c o m protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String path = req.getPathInfo().replace('+', ' '); if (path == null) { resp.sendError(665, "Error: invalid program path."); return; } String[] toks = path.split("/"); try { Bundle b = findBundleByName(toks[toks.length - 1]); //TODO: Implement telling knapsack that bundles have changed log.log(LogService.LOG_ERROR, "IMPLEMENT ME."); //if (b != null && b.getState() != Bundle.UNINSTALLED) { if (b != null) { uninstallBundle(b); } } catch (BundleException e) { resp.sendError(0, "Error: Unable to remove bundle." + e.getMessage()); } }
From source file:edu.harvard.i2b2.fhir.FetchInterceptor.java
@Override public boolean incomingRequestPreProcessed(HttpServletRequest theRequest, HttpServletResponse theResponse) { ourLog.info("incomingRequestPreProcessed" + theRequest.getPathInfo()); return true;//from w ww .j a v a 2 s . c o m }
From source file:net.centro.rtb.monitoringcenter.MonitoringCenterServlet.java
private void handleHealthChecks(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException { String healthCheckName = null; String path = httpServletRequest.getPathInfo(); if (StringUtils.isNotBlank(path)) { String noLeadingSlash = path.substring(1); int indexOfSlash = noLeadingSlash.indexOf("/"); if (indexOfSlash != -1) { healthCheckName = noLeadingSlash.substring(indexOfSlash + 1); }//from w ww . ja v a 2s . c o m } if (StringUtils.isNotBlank(healthCheckName)) { try { HealthCheck.Result result = MonitoringCenter.runHealthCheck(healthCheckName); writeAsJson(httpServletRequest, httpServletResponse, result); } catch (NoSuchElementException e) { httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND); return; } } else { SortedMap<String, HealthCheck.Result> healthCheckResultsByNames = MonitoringCenter.runHealthChecks(); writeAsJson(httpServletRequest, httpServletResponse, healthCheckResultsByNames); } }
From source file:com.jd.survey.web.settings.SectorsController.java
@Secured({ "ROLE_ADMIN" }) @RequestMapping(params = "create", produces = "text/html") public String createSector(Principal principal, Model uiModel, HttpServletRequest httpServletRequest) { log.info("createForm(): handles param form"); try {/*from w w w . j a va2 s . c om*/ 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"; } Sector sector = new Sector(); populateEditForm(uiModel, sector, user); return "admin/sectors/create"; } catch (Exception e) { log.error(e.getMessage(), e); throw (new RuntimeException(e)); } }
From source file:io.wittmann.jiralist.servlet.ProxyServlet.java
/** * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) */// ww w .j a v a 2 s.c o m @Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { long requestId = requestCounter++; String proxyTo = "https://issues.jboss.org/rest/api/2"; if (req.getHeader("X-Proxy-To") != null) { proxyTo = req.getHeader("X-Proxy-To"); } String url = proxyTo + req.getPathInfo(); if (req.getQueryString() != null) { url += "?" + req.getQueryString(); } System.out.println("[" + requestId + "]: Proxying to: " + url); boolean isWrite = req.getMethod().equalsIgnoreCase("post") || req.getMethod().equalsIgnoreCase("put"); URL remoteUrl = new URL(url); HttpURLConnection remoteConn = (HttpURLConnection) remoteUrl.openConnection(); if (isWrite) { remoteConn.setDoOutput(true); } remoteConn.setRequestMethod(req.getMethod()); String auth = req.getHeader("Authorization"); if (auth != null) { remoteConn.setRequestProperty("Authorization", auth); } String ct = req.getHeader("Content-Type"); if (ct != null) { remoteConn.setRequestProperty("Content-Type", ct); } String cl = req.getHeader("Content-Length"); if (cl != null) { remoteConn.setRequestProperty("Content-Length", cl); } String accept = req.getHeader("Accept"); if (accept != null) { remoteConn.setRequestProperty("Accept", accept); } System.out.println("[" + requestId + "]: Request Info:"); System.out.println("[" + requestId + "]: Method: " + req.getMethod()); System.out.println("[" + requestId + "]: Has auth: " + (auth != null)); System.out.println("[" + requestId + "]: Content-Type: " + ct); System.out.println("[" + requestId + "]: Content-Length: " + cl); if (isWrite) { InputStream requestIS = null; OutputStream remoteOS = null; try { requestIS = req.getInputStream(); remoteOS = remoteConn.getOutputStream(); IOUtils.copy(requestIS, remoteOS); remoteOS.flush(); } catch (Exception e) { e.printStackTrace(); resp.sendError(500, e.getMessage()); return; } finally { IOUtils.closeQuietly(requestIS); IOUtils.closeQuietly(remoteOS); } } InputStream remoteIS = null; OutputStream responseOS = null; int responseCode = remoteConn.getResponseCode(); System.out.println("[" + requestId + "]: Response Info:"); System.out.println("[" + requestId + "]: Code: " + responseCode); if (responseCode == 400) { remoteIS = remoteConn.getInputStream(); responseOS = System.out; IOUtils.copy(remoteIS, responseOS); IOUtils.closeQuietly(remoteIS); resp.sendError(400, "Error 400"); } else { try { Map<String, List<String>> headerFields = remoteConn.getHeaderFields(); for (String headerName : headerFields.keySet()) { if (headerName == null) { continue; } if (EXCLUDE_HEADERS.contains(headerName)) { continue; } String headerValue = remoteConn.getHeaderField(headerName); resp.setHeader(headerName, headerValue); System.out.println("[" + requestId + "]: " + headerName + " : " + headerValue); } resp.setHeader("Cache-control", "no-cache, no-store, must-revalidate"); //$NON-NLS-2$ remoteIS = remoteConn.getInputStream(); responseOS = resp.getOutputStream(); int bytesCopied = IOUtils.copy(remoteIS, responseOS); System.out.println("[" + requestId + "]: Bytes Proxied: " + bytesCopied); resp.flushBuffer(); } catch (Exception e) { e.printStackTrace(); resp.sendError(500, e.getMessage()); } finally { IOUtils.closeQuietly(responseOS); IOUtils.closeQuietly(remoteIS); } } }
From source file:com.tasktop.c2c.server.scm.web.GitHandler.java
@Override public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final boolean containerSupportsChunkedIO = computeContainerSupportsChunkedIO(); String pathInfo = request.getPathInfo(); log.info("Git request: " + request.getMethod() + " " + request.getRequestURI() + " " + pathInfo); Repository repository = null;/*w ww . ja va2 s.c om*/ try { // only work on Git requests Matcher matcher = pathInfo == null ? null : GIT_COMMAND_PATTERN.matcher(pathInfo); if (matcher == null || !matcher.matches()) { log.info("Unexpected path: " + pathInfo); response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } String requestCommand = matcher.group(1); String requestPath = matcher.group(2); // sanity check on path, disallow path separator components if (requestPath == null || requestPath.contains("/") || requestPath.contains("..")) { badPathResponse(); } repository = repositoryResolver.open(request, requestPath); InputStream requestInput = request.getInputStream(); if (!containerSupportsChunkedIO) { requestInput = new ChunkedInputStream(requestInput); } MultiplexingOutputStream mox = createMultiplexingOutputStream(response, containerSupportsChunkedIO); // indicate that we're ok to handle the request // note that following this there will be a two-way communication with the process // that might still encounter errors. That's ok. startOkResponse(response, containerSupportsChunkedIO); // identify the git command GitCommand command = GitCommand.fromCommandName(requestCommand); if (command != null) { // permissions check if (!Security.hasOneOfRoles(command.getRoles())) { log.info("Access denied to " + Security.getCurrentUser() + " for " + command.getCommandName() + " on " + TenancyUtil.getCurrentTenantProjectIdentifer() + " " + requestPath); response.sendError(HttpServletResponse.SC_FORBIDDEN); return; } switch (command) { case RECEIVE_PACK: ReceivePack rp = new ReceivePack(repository); rp.setPostReceiveHook(postReceiveHook); rp.receive(requestInput, mox.stream(PacketType.STDOUT), mox.stream(PacketType.STDERR)); break; case UPLOAD_PACK: UploadPack up = new UploadPack(repository); up.upload(requestInput, mox.stream(PacketType.STDOUT), mox.stream(PacketType.STDERR)); break; default: response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } } // at this stage we're done with IO // send the exit value and closing chunk try { int exitValue = 0; if (exitValue != 0) { log.info("Exit value: " + exitValue); } mox.writeExitCode(exitValue); mox.close(); } catch (IOException e) { // ignore log.debug("Cannot complete writing exit state", e); } // clear interrupt status Thread.interrupted(); } catch (ErrorResponseException e) { createGitErrorResponse(response, containerSupportsChunkedIO, e.getMessage()); } catch (ServiceNotAuthorizedException e) { createGitErrorResponse(response, containerSupportsChunkedIO, e.getMessage()); } catch (ServiceNotEnabledException e) { createGitErrorResponse(response, containerSupportsChunkedIO, e.getMessage()); } finally { log.info("Git request complete"); if (repository != null) { repository.close(); } } }