List of usage examples for javax.servlet.http HttpServletRequest getRequestURL
public StringBuffer getRequestURL();
From source file:com.sap.prd.mobile.ios.ota.webapp.BaseServlet.java
/** * Returns the Application Base URL based on the request. * @return the URL//from w ww .j a v a2 s. c o m * @throws MalformedURLException */ public URL getApplicationBaseUrl(HttpServletRequest request) throws MalformedURLException { String requestUrl = request.getRequestURL().toString(); //e.g. "http://host:8765/ota-service/HTML/UmVmZXJlcj1odHRw..." String contextPath = request.getContextPath().toString(); //e.g. "/ota-service" or "" if root context String result; if (!isEmpty(contextPath)) { int idx = requestUrl.indexOf(contextPath); if (idx < 0) throw new IllegalStateException(format("Cannot find '%s' in '%s'", contextPath, requestUrl)); result = requestUrl.substring(0, idx + contextPath.length()); //e.g. "http://host:8765/ota-service" } else { //root context int idx = requestUrl.indexOf("//"); idx = requestUrl.indexOf("/", idx + "//".length()); result = requestUrl.substring(0, idx); //e.g. "http://host:8765" } return new URL(result); }
From source file:com.web.mavenproject6.other.GlobalExceptionHandler.java
@ExceptionHandler(Exception.class) public ModelAndView handleIOException(HttpServletRequest req, Map<String, Object> model, Exception ex) { ModelAndView mav = new ModelAndView(); mav.addObject("exception", ex); mav.addObject("url", req.getRequestURL()); mav.setViewName("thy/error/Exception"); return mav;//from w ww . j av a 2s . c o m }
From source file:cn.bc.web.util.DebugUtils.java
public static StringBuffer getDebugInfo(HttpServletRequest request, HttpServletResponse response) { @SuppressWarnings("rawtypes") Enumeration e;//from w ww. j a v a2s . co m String name; StringBuffer html = new StringBuffer(); //session HttpSession session = request.getSession(); html.append("<div><b>session:</b></div><ul>"); html.append(createLI("Id", session.getId())); html.append(createLI("CreationTime", new Date(session.getCreationTime()).toString())); html.append(createLI("LastAccessedTime", new Date(session.getLastAccessedTime()).toString())); //session:attributes e = session.getAttributeNames(); html.append("<li>attributes:<ul>\r\n"); while (e.hasMoreElements()) { name = (String) e.nextElement(); html.append(createLI(name, String.valueOf(session.getAttribute(name)))); } html.append("</ul></li>\r\n"); html.append("</ul>\r\n"); //request html.append("<div><b>request:</b></div><ul>"); html.append(createLI("URL", request.getRequestURL().toString())); html.append(createLI("QueryString", request.getQueryString())); html.append(createLI("Method", request.getMethod())); html.append(createLI("CharacterEncoding", request.getCharacterEncoding())); html.append(createLI("ContentType", request.getContentType())); html.append(createLI("Protocol", request.getProtocol())); html.append(createLI("RemoteAddr", request.getRemoteAddr())); html.append(createLI("RemoteHost", request.getRemoteHost())); html.append(createLI("RemotePort", request.getRemotePort() + "")); html.append(createLI("RemoteUser", request.getRemoteUser())); html.append(createLI("ServerName", request.getServerName())); html.append(createLI("ServletPath", request.getServletPath())); html.append(createLI("ServerPort", request.getServerPort() + "")); html.append(createLI("Scheme", request.getScheme())); html.append(createLI("LocalAddr", request.getLocalAddr())); html.append(createLI("LocalName", request.getLocalName())); html.append(createLI("LocalPort", request.getLocalPort() + "")); html.append(createLI("Locale", request.getLocale().toString())); //request:headers e = request.getHeaderNames(); html.append("<li>Headers:<ul>\r\n"); while (e.hasMoreElements()) { name = (String) e.nextElement(); html.append(createLI(name, request.getHeader(name))); } html.append("</ul></li>\r\n"); //request:parameters e = request.getParameterNames(); html.append("<li>Parameters:<ul>\r\n"); while (e.hasMoreElements()) { name = (String) e.nextElement(); html.append(createLI(name, request.getParameter(name))); } html.append("</ul></li>\r\n"); html.append("</ul>\r\n"); //response html.append("<div><b>response:</b></div><ul>"); html.append(createLI("CharacterEncoding", response.getCharacterEncoding())); html.append(createLI("ContentType", response.getContentType())); html.append(createLI("BufferSize", response.getBufferSize() + "")); html.append(createLI("Locale", response.getLocale().toString())); html.append("<ul>\r\n"); return html; }
From source file:org.cloudifysource.rest.controllers.AdminAPIController.java
@ExceptionHandler(NotFoundHttpException.class) @ResponseStatus(value = HttpStatus.NOT_FOUND) public void resolveNotFound(Writer writer, Exception e, HttpServletRequest request) throws IOException { String requestURL = request.getRequestURL().toString(); logger.log(Level.INFO, "Cannot find URL: " + requestURL, e); writer.write("{\"status\":\"error\", \"error\":\"" + "Cannot find URL: " + requestURL + "cause: " + e.getMessage() + "\"}"); }
From source file:org.osiam.resources.controller.GroupController.java
private void setLocation(HttpServletRequest request, HttpServletResponse response) { String requestUrl = request.getRequestURL().toString(); response.setHeader("Location", requestUrl); }
From source file:com.bsb.cms.commons.page.filter.PageFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest hRequest = (HttpServletRequest) request; String uri = hRequest.getRequestURL().toString(); if (uri.toLowerCase().endsWith(".jsp")) { chain.doFilter(request, response); return;/*from w w w . ja v a2 s . com*/ } /* if (!(uri.toLowerCase().endsWith("list.htm"))) {//TODO //if (!(uri.toLowerCase().contains("list"))) {//TODO PageContext.removeContext(); chain.doFilter(request, response); return; }*/ if (!(uri.equals(PageContext.getLastUrl()))) PageContext.removeContext(); String pagec = hRequest.getParameter("page");//? //String pageSize = hRequest.getParameter("pageSize");//?? String pageSize = hRequest.getParameter("rows");//??. easyui String sortField = hRequest.getParameter("sort");//sortField String order = hRequest.getParameter("order");//desc/asc pageSize = (StringUtils.isEmpty(pageSize)) ? "10" : pageSize; PageContext.setLastUrl(uri); PageContext page = PageContext.getContext();//----------- if (pagec == null) page.setCurrentPage(1); else page.setCurrentPage(Integer.parseInt(pagec)); page.setPageSize(Integer.parseInt(pageSize)); page.setPagination(true); if ("DESC".equalsIgnoreCase(order)) { page.setSortDESC(true); } else if ("ASC".equalsIgnoreCase(order)) { page.setSortDESC(false); } if ((sortField != null) && (!("".equals(sortField)))) PageContext.initSort(sortField); request.setAttribute("page", page);//----------------- chain.doFilter(request, response); }
From source file:com.artivisi.belajar.restful.ui.controller.PermissionController.java
@RequestMapping(value = "/permission", method = RequestMethod.POST) @ResponseStatus(HttpStatus.CREATED)/*w w w.j a v a2s.c o m*/ public void create(@RequestBody @Valid Permission x, HttpServletRequest request, HttpServletResponse response) { belajarRestfulService.save(x); String requestUrl = request.getRequestURL().toString(); URI uri = new UriTemplate("{requestUrl}/{id}").expand(requestUrl, x.getId()); response.setHeader("Location", uri.toASCIIString()); }
From source file:com.artivisi.belajar.restful.ui.controller.MenuController.java
@RequestMapping(value = "/menu", method = RequestMethod.POST) @ResponseStatus(HttpStatus.CREATED)//from w w w. j a v a 2s . c o m public void create(@RequestBody @Valid Menu x, HttpServletRequest request, HttpServletResponse response) { belajarRestfulService.save(x); String requestUrl = request.getRequestURL().toString(); URI uri = new UriTemplate("{requestUrl}/{id}").expand(requestUrl, x.getId()); response.setHeader("Location", uri.toASCIIString()); }
From source file:com.redhat.rhn.frontend.servlets.EnvironmentFilter.java
private void redirectToSecure(HttpServletRequest request, HttpServletResponse response) throws IOException { String originalUrl = request.getRequestURL().toString(); String secureUrl = "https://" + originalUrl.substring(7); response.sendRedirect(secureUrl);//from ww w. j a v a 2 s . c om return; }
From source file:edu.uiowa.icts.bluebutton.web.DefaultController.java
@RequestMapping("/**") public void mappingNotFound(HttpServletRequest request, HttpServletResponse response) throws MappingNotFoundException { throw new MappingNotFoundException(request.getRequestURL().toString()); }