List of usage examples for javax.servlet.http HttpServletRequest getRequestURI
public String getRequestURI();
From source file:com.jsqlboxdemo.dispatcher.Dispatcher.java
public static void dispach(PageContext pageContext) throws Exception { HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); String uri = StringUtils.substringBefore(request.getRequestURI(), "."); String contextPath = request.getContextPath(); if (!StringUtils.isEmpty(contextPath)) uri = StringUtils.substringAfter(uri, contextPath); if (StringUtils.isEmpty(uri) || "/".equals(uri)) uri = "/home"; String[] paths = StringUtils.split(uri, "/"); String[] pathParams;/*from w w w. ja v a 2 s .c om*/ String resource = null; String operation = null; if (paths.length >= 2) {// /team/add/100... resource = paths[0]; operation = paths[1]; pathParams = new String[paths.length - 2]; for (int i = 2; i < paths.length; i++) pathParams[i - 2] = paths[i]; } else { // /home_default resource = paths[0]; pathParams = new String[0]; } if (operation == null) operation = "default"; StringBuilder controller = new StringBuilder("com.jsqlboxdemo.controller.").append(resource).append("$") .append(resource).append("_").append(operation); if ("POST".equals(request.getMethod())) controller.append("_post"); WebBox box; try { Class boxClass = Class.forName(controller.toString()); box = BeanBox.getPrototypeBean(boxClass); } catch (Exception e) { throw new ClassNotFoundException("There is no WebBox classs '" + controller + "' found."); } request.setAttribute("pathParams", pathParams); box.show(pageContext); }
From source file:org.focusns.common.web.WebUtils.java
public static Map<String, String> getMatrixParameters(HttpServletRequest request) { ///*www. j a va 2s.co m*/ Map<String, String> parameterMap = new LinkedHashMap<String, String>(); // String requestUri = request.getRequestURI(); if (requestUri.contains(";")) { String paramsString = requestUri.substring(requestUri.indexOf(";") + 1); String[] paramsPair = new String[] { paramsString }; if (paramsString.contains(",")) { paramsPair = StringUtils.tokenizeToStringArray(paramsString, ","); } for (String paramPair : paramsPair) { String[] nameAndValue = StringUtils.split(paramPair, "="); parameterMap.put(nameAndValue[0], nameAndValue[1]); } } return parameterMap; }
From source file:com.claresco.tinman.servlet.XapiServletUtility.java
/** * /*w ww .j a v a2 s .c o m*/ * Definition: * Splitting the URL array based on forward slash * * Params: * * */ protected static String[] getRequestURLArray(HttpServletRequest req) { String theURL = req.getRequestURI(); String[] urlArray; if (theURL.endsWith("/")) { urlArray = theURL.substring(0, theURL.length() - 2).split("/"); } else { urlArray = theURL.split("/"); } String[] returnURL = new String[urlArray.length - 1]; for (int i = 1; i < urlArray.length; i++) { returnURL[i - 1] = urlArray[i]; } return returnURL; }
From source file:com.adeptj.runtime.servlet.ErrorPages.java
static void renderErrorPage(HttpServletRequest req, HttpServletResponse resp) { String statusCode = StringUtils.substringAfterLast(req.getRequestURI(), Constants.SLASH); if (StringUtils.equals(TEMPLATE_ERROR, req.getRequestURI())) { ErrorPages.renderGenericErrorPage(req, resp); } else if (StringUtils.equals(STATUS_500, statusCode)) { ErrorPages.render500Page(req, resp); } else if (RequestUtil.hasException(req) && StringUtils.equals(STATUS_500, statusCode)) { ErrorPages.render500PageWithExceptionTrace(req, resp); } else if (Configs.of().undertow().getStringList(KEY_STATUS_CODES).contains(statusCode)) { ErrorPages.renderErrorPageForStatusCode(req, resp, statusCode); } else {//from ww w . jav a2 s .com ResponseUtil.sendError(resp, HttpServletResponse.SC_NOT_FOUND); } }
From source file:io.adeptj.runtime.servlet.ErrorPages.java
static void renderErrorPage(HttpServletRequest req, HttpServletResponse resp) { String statusCode = StringUtils.substringAfterLast(req.getRequestURI(), SLASH); if (StringUtils.equals(TEMPLATE_ERROR, req.getRequestURI())) { ErrorPages.renderGenericErrorPage(req, resp); } else if (StringUtils.equals(STATUS_500, statusCode)) { ErrorPages.render500Page(req, resp); } else if (RequestUtil.hasException(req) && StringUtils.equals(STATUS_500, statusCode)) { ErrorPages.render500PageWithExceptionTrace(req, resp); } else if (Configs.of().undertow().getStringList(KEY_STATUS_CODES).contains(statusCode)) { ErrorPages.renderErrorPageForStatusCode(req, resp, statusCode); } else {//from w w w . ja v a 2s . c om ResponseUtil.sendError(resp, HttpServletResponse.SC_NOT_FOUND); } }
From source file:com.app.framework.web.mvc.ActionMap.java
public static ActionMap Init(ServletRequest request, ServletResponse response) throws IOException { ActionMap actMap = null;/* w ww .j a va 2s. com*/ HttpServletRequest req = ((HttpServletRequest) request); String s1 = req.getContextPath(); String s2 = req.getRequestURI(); String s3 = req.getRequestURL().toString(); String fullUrl = getFullURL(req).toLowerCase(); if (fullUrl.contains(".css") || fullUrl.contains(".js") || fullUrl.contains(".html") || fullUrl.contains(".jpg") || fullUrl.contains(".png") || fullUrl.contains(".gif") || fullUrl.contains(".icon")) { return null; } Gson g = new Gson(); String requestedResource = s2.replace(s1 + "/", ""); String[] urlParts = requestedResource.split("/"); if (urlParts != null && urlParts.length >= 2) { String controller = urlParts[0]; String action = urlParts[1]; String jsonFilePath = req.getServletContext().getRealPath("/WEB-INF/action-map.json"); String json = FileUtils.readFileToString(new File(jsonFilePath), "utf-8"); Type listType = new TypeToken<Map<String, ControllerInfo>>() { }.getType(); Map<String, ControllerInfo> map = g.fromJson(json, listType); String method = req.getMethod(); if (map.containsKey(controller)) { actMap = new ActionMap(); ControllerInfo cInfo = map.get(controller); ActionInfo mInfo = cInfo.getActions().get(action).get(method); actMap.setController(cInfo.getControllerClassName()); actMap.setAction(mInfo.getMethodName()); actMap.setModel(mInfo.getModelClassName()); } } return actMap; }
From source file:com.trailmagic.image.ui.WebSupport.java
/** * If the request URI does not end with a /, redirects to the same URI * with a trailing /. Otherwise, does nothing. * * @param req the servlet request//w ww . ja va 2 s.co m * @param res the servlet response */ public static boolean handleDirectoryUrlRedirect(HttpServletRequest req, HttpServletResponse res) throws IOException { String uri = req.getRequestURI(); // if trailing / already, no work to do; we're done if (!uri.endsWith("/")) { StringBuffer newLocation = new StringBuffer(); newLocation.append(uri); newLocation.append("/"); if (req.getQueryString() != null) { newLocation.append("?"); newLocation.append(req.getQueryString()); } res.sendRedirect(newLocation.toString()); return true; } return false; }
From source file:com.doculibre.constellio.utils.WebappUtils.java
public static URL getContextPathURL(HttpServletRequest httpRequest) { StringBuffer requestURL = httpRequest.getRequestURL(); String contextPath = httpRequest.getContextPath(); String requestURI = httpRequest.getRequestURI(); String beforeContextPath = StringUtils.substringBefore(requestURL.toString(), requestURI); try {/*from w w w . ja v a 2 s. c o m*/ return new URL(beforeContextPath + contextPath); } catch (MalformedURLException e) { throw new RuntimeException(e); } }
From source file:com.databasepreservation.visualization.api.utils.ApiUtils.java
public static URI getUriFromRequest(HttpServletRequest request) throws RODAException { try {//from w w w. j ava 2 s . c o m return new URI(request.getRequestURI()); } catch (URISyntaxException e) { throw new GenericException("Error creating URI from String: " + e.getMessage()); } }
From source file:org.apache.hadoop.util.ServletUtil.java
/** * Parse the path component from the given request and return w/o decoding. * @param request Http request to parse// w ww. j a v a 2 s.c o m * @param servletName the name of servlet that precedes the path * @return path component, null if the default charset is not supported */ public static String getRawPath(final HttpServletRequest request, String servletName) { Preconditions.checkArgument(request.getRequestURI().startsWith(servletName + "/")); return request.getRequestURI().substring(servletName.length()); }