List of usage examples for javax.servlet.http HttpServletRequest getPathInfo
public String getPathInfo();
From source file:sample.ContextFilter.java
private String currentUrl(HttpServletRequest request) { StringBuilder url = new StringBuilder(); url.append(request.getServletPath()); String pathInfo = request.getPathInfo(); if (pathInfo != null) { url.append(pathInfo);/*from ww w. ja va 2 s . c o m*/ } return url.toString(); }
From source file:MyServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { ServletOutputStream out = res.getOutputStream(); res.setContentType("text/plain"); String file = req.getPathInfo(); if (file == null) { out.println("Extra path info was null; should be a resource to view"); return;//from w w w . j a v a 2s . c o m } URL url = getServletContext().getResource(file); if (url == null) { out.println("Resource " + file + " not found"); return; } URLConnection con = null; try { con = url.openConnection(); con.connect(); } catch (IOException e) { out.println("Resource " + file + " could not be read: " + e.getMessage()); return; } }
From source file:com.bt.aloha.batchtest.ultramonkey.Servlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { LOG.debug(request.getPathInfo() + ":" + request.getQueryString()); Properties resultProperties = new Properties(); resultProperties.put("local.host.name", request.getLocalName()); resultProperties.put("local.host.port", Integer.toString(request.getLocalPort())); resultProperties.put("remote.host.name", request.getRemoteHost()); resultProperties.put("remote.host.port", Integer.toString(request.getRemotePort())); resultProperties.put("makeCall.count", Integer.toString(makeCallCount)); resultProperties.put("terminateCall.count", Integer.toString(terminateCallCount)); resultProperties.put("incomingCall.count", Integer.toString(((ServiceImpl) service).getIncomingCount())); String result = "something or rather"; String resultKey = "callid"; if (request.getPathInfo().equalsIgnoreCase("/makecall")) { makeCallCount++;//from ww w . j a va 2s. c o m String caller = request.getParameter("caller"); String callee = request.getParameter("callee"); result = this.service.makeCall(caller, callee); } else if (request.getPathInfo().equalsIgnoreCase("/terminatecall")) { terminateCallCount++; String callid = request.getParameter("callid"); service.terminateCall(callid); result = callid; } else if (request.getPathInfo().equalsIgnoreCase("/reset")) { makeCallCount = 0; terminateCallCount = 0; ((ServiceImpl) service).setIncomingCount(0); } else if (request.getPathInfo().equalsIgnoreCase("/status")) { result = "Sample SpringRing web application"; resultKey = "status"; } else { response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } resultProperties.put(resultKey, result); resultProperties.store(response.getOutputStream(), "Response generated on:"); }
From source file:edu.cornell.library.scholars.webapp.controller.api.DistributeDataApiController.java
private String findDistributorForAction(HttpServletRequest req, Model model) throws NoSuchActionException { String action = req.getPathInfo(); if (action == null || action.isEmpty()) { throw new NoSuchActionException("'action' path was not provided."); }/*from www . ja va2s . c om*/ if (action.startsWith("/")) { action = action.substring(1); } List<String> uris = createSelectQueryContext(model, DISTRIBUTOR_FOR_SPECIFIED_ACTION) .bindVariableToPlainLiteral("action", action).execute().toStringFields("distributor").flatten(); Collections.sort(uris); log.debug("Found URIs for action '" + action + "': " + uris); if (uris.isEmpty()) { throw new NoSuchActionException("Did not find a DataDistributor for '" + action + "'"); } if (uris.size() > 1) { log.warn("Found more than one DataDistributor for '" + action + "': " + uris); } return uris.get(0); }
From source file:com.cloudera.oryx.als.serving.web.RecommendToAnonymousServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { CharSequence pathInfo = request.getPathInfo(); if (pathInfo == null) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No path"); return;//from www .j ava2 s . c o m } Iterator<String> pathComponents = SLASH.split(pathInfo).iterator(); Pair<String[], float[]> itemIDsAndValue; try { itemIDsAndValue = parseItemValuePairs(pathComponents); } catch (NoSuchElementException nsee) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, nsee.toString()); return; } if (itemIDsAndValue.getFirst().length == 0) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No items"); return; } String[] itemIDs = itemIDsAndValue.getFirst(); float[] values = itemIDsAndValue.getSecond(); OryxRecommender recommender = getRecommender(); RescorerProvider rescorerProvider = getRescorerProvider(); try { Rescorer rescorer = rescorerProvider == null ? null : rescorerProvider.getRecommendToAnonymousRescorer(itemIDs, recommender, getRescorerParams(request)); output(response, recommender.recommendToAnonymous(itemIDs, values, getHowMany(request), rescorer)); } catch (NotReadyException nre) { response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, nre.toString()); } catch (NoSuchItemException nsie) { response.sendError(HttpServletResponse.SC_NOT_FOUND, nsie.toString()); } catch (IllegalArgumentException iae) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, iae.toString()); } }
From source file:fr.immotronic.ubikit.pems.modbus.impl.APIServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String[] pathInfo = req.getPathInfo().split("/"); // Expected path info is /command/command_param_1/command_param_2/...etc. // Notes: if the request is valid (e.g. looks like /command/command_params), // pathInfo[0] contains an empty string, // pathInfo[1] contains "command", // pathInfo[2] and next each contains a command parameter. Command parameters are "/"-separated. if (pathInfo != null && pathInfo.length > 1) { }//from w w w . ja v a2s . c o m resp.getWriter().write(WebApiCommons.errorMessage(WebApiCommons.Errors.invalid_query)); }
From source file:com.cloudbees.jenkins.plugins.bitbucket.hooks.BitbucketSCMSourcePushHookReceiver.java
@Override public boolean process(HttpServletRequest req, HttpServletResponse resp, FilterChain chain) throws IOException, ServletException { String pathInfo = req.getPathInfo(); if (pathInfo != null && pathInfo.startsWith("/" + FULL_PATH)) { chain.doFilter(req, resp);// www . j av a 2s . co m return true; } return false; }
From source file:common.web.servlets.StaticFilesServlet.java
@Override protected long getLastModified(HttpServletRequest request) { String name = getResourceName(request.getPathInfo()); if (name == null) return -1; File file = new File(realPath, name); if (file.exists()) { return file.lastModified(); } else {/*from ww w .ja va 2 s . c o m*/ if (logger.isDebugEnabled()) { logger.debug("resource not found:" + request.getPathInfo()); } return -1; } }
From source file:alpine.servlets.FileSystemResourceServlet.java
@Override protected StaticResource getStaticResource(HttpServletRequest request) throws IllegalArgumentException { final String pathInfo = request.getPathInfo(); if (pathInfo == null || pathInfo.isEmpty() || "/".equals(pathInfo)) { throw new IllegalArgumentException(); }// w ww. j av a2 s.c om String name = ""; try { name = URLDecoder.decode(pathInfo.substring(1), StandardCharsets.UTF_8.name()); } catch (UnsupportedEncodingException e) { LOGGER.error(e.getMessage()); } final ServletContext context = request.getServletContext(); final File file = (absolute) ? new File(directory, name) : new File(context.getRealPath("/"), name).getAbsoluteFile(); return !file.exists() ? null : new StaticResource() { @Override public long getLastModified() { return file.lastModified(); } @Override public InputStream getInputStream() throws IOException { return new FileInputStream(file); } @Override public String getFileName() { return file.getName(); } @Override public long getContentLength() { return file.length(); } }; }
From source file:cat.calidos.morfeu.webapp.GenericHttpServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String path = req.getPathInfo(); log.trace("GenericMorfeuServlet::doGet {}", path); Map<String, String> params = normaliseParams(req.getParameterMap()); params.put(METHOD, req.getMethod()); params = processParams(params);//w w w . j a v a 2 s.co m ControlComponent controlComponent = getControl(path, params); handleResponse(resp, controlComponent); }