List of usage examples for javax.servlet.http HttpServletRequest getRequestURL
public StringBuffer getRequestURL();
From source file:org.openmrs.module.idcards.web.controller.TemplateFormController.java
/** * Handles the user's submission of the form. *///w ww .j av a2 s . c om @RequestMapping(method = RequestMethod.POST, params = "action=saveAndPrintEmpty") public void onSaveAndPrintEmpty(@ModelAttribute("template") IdcardsTemplate template, HttpServletRequest request, HttpServletResponse response) throws IOException { if (Context.isAuthenticated()) { IdcardsService service = (IdcardsService) Context.getService(IdcardsService.class); service.saveIdcardsTemplate(template); try { StringBuffer requestURL = request.getRequestURL(); String baseURL = requestURL.substring(0, requestURL.indexOf("/module")); PrintEmptyIdcardsServlet.generateOutput(template, baseURL, response, Collections.nCopies(10, 0), null); } catch (Exception e) { log.error("Unable to print cards", e); e.printStackTrace(response.getWriter()); } } }
From source file:com.all.backend.web.controller.PasswordResetServerController.java
@RequestMapping("/reset/{key}") public String showResetPasswordView(@PathVariable String key, Model model, HttpServletRequest request) { log.info("\nACTION:PasswordReset"); User user = registrationService.getUserForPasswordResetRequest(key); if (user != null) { StringBuffer requestURL = request.getRequestURL(); String url = requestURL.substring(0, requestURL.lastIndexOf("/") + 1); log.debug("url: " + url); model.addAttribute("submitUrl", url); model.addAttribute("userFullName", user.getFullName()); model.addAttribute("key", key); return "resetPassword.jsp"; }//from w w w.j a va 2 s.c o m return "expiredPassword.jsp"; }
From source file:de.fau.amos4.web.EmployeeFormController.java
@ExceptionHandler(Exception.class) public ModelAndView handleError(HttpServletRequest req, Exception exception) { // TODO: Add logging! ModelAndView mav = new ModelAndView(); mav.addObject("url", req.getRequestURL()); mav.addObject("message", exception.getMessage()); // TODO: Implement stacktrace display function. return mav;/*from ww w. ja v a 2 s .c o m*/ }
From source file:io.mapzone.controller.vm.http.HttpResponseForwarder.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 w ww . j a va2s .c o m protected String rewriteUrlFromResponse(HttpServletRequest servletRequest, String theUrl) { // TODO document example paths final String targetUri = requestForwarder.targetUri.get(); if (theUrl.startsWith(targetUri)) { String curUrl = servletRequest.getRequestURL().toString();// no query String pathInfo = servletRequest.getPathInfo(); if (pathInfo != null) { assert curUrl.endsWith(pathInfo); curUrl = curUrl.substring(0, curUrl.length() - pathInfo.length());// take // pathInfo // off } theUrl = curUrl + theUrl.substring(targetUri.length()); } return theUrl; }
From source file:com.tecapro.inventory.common.servlet.BaseServlet.java
@Override protected void process(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { try {/*from w w w .j a v a 2s. c om*/ super.process(request, response); } catch (Throwable e) { System.out.println("RequestURL: " + request.getRequestURL()); e.printStackTrace(); LogUtil logUtil = (LogUtil) WebApplicationContextUtils.getWebApplicationContext(getServletContext()) .getBean(BEAN_NAME_LOG_UTIL); logUtil.errorLog(LOG, BaseServlet.class.getSimpleName(), "process", null, "RequestURL: " + request.getRequestURL()); BaseForm zform = (BaseForm) request.getAttribute(BaseForm.class.getSimpleName()); if (zform != null) { errorLog(zform, request, e, "process"); // process error ErrorInfoValue errorValue = new ErrorInfoValue(); List<String> idList = new ArrayList<String>(); idList.add(Constants.SYSTEM_ERROR_CODE); errorValue.setIdList(idList); MessageUtil msgUtil = (MessageUtil) WebApplicationContextUtils .getWebApplicationContext(getServletContext()).getBean(BEAN_NAME_MESSAGE_UTIL); errorValue.setErrorMessage(msgUtil.getMessage(Constants.SYSTEM_ERROR_CODE, new String[] {})); // check request ajax if (Constants.REQUEST_AJAX.equals(zform.getType())) { request.setAttribute("type", Constants.REQUEST_AJAX); // Set header info response.setContentType(Constants.CONTENT_TYPE_AJAX); response.setCharacterEncoding(Constants.Text.UTF_8); PrintWriter out = response.getWriter(); Gson gson = new Gson(); // create data JSON to response Map<String, Object> mapData = new HashMap<String, Object>(); // check error mapData.put("value", errorValue); out.print(gson.toJson(mapData)); out.flush(); out.close(); } else { zform.setError(errorValue); // forward error screen getServletContext().getRequestDispatcher("/WEB-INF/pages/common/system-error.jsp") .forward(request, response); } } } }
From source file:edu.duke.cabig.c3pr.utils.web.filter.GzipFilter.java
/** * Performs the filtering for a request. *//*from w w w . jav a 2 s.co m*/ protected void doFilter(final HttpServletRequest request, final HttpServletResponse response, final FilterChain chain) throws Exception { if (!isIncluded(request) && acceptsEncoding(request, "gzip")) { // Client accepts zipped content if (LOG.isDebugEnabled()) { LOG.debug(request.getRequestURL() + ". Writing with gzip compression"); } // Create a gzip stream final ByteArrayOutputStream compressed = new ByteArrayOutputStream(); final GZIPOutputStream gzout = new GZIPOutputStream(compressed); // Handle the request final GenericResponseWrapper wrapper = new GenericResponseWrapper(response, gzout); chain.doFilter(request, wrapper); wrapper.flush(); gzout.close(); //return on error or redirect code, because response is already committed int statusCode = wrapper.getStatus(); if (statusCode != HttpServletResponse.SC_OK) { return; } //Saneness checks byte[] compressedBytes = compressed.toByteArray(); boolean shouldGzippedBodyBeZero = ResponseUtil.shouldGzippedBodyBeZero(compressedBytes, request); boolean shouldBodyBeZero = ResponseUtil.shouldBodyBeZero(request, wrapper.getStatus()); if (shouldGzippedBodyBeZero || shouldBodyBeZero) { compressedBytes = new byte[0]; } try { // Write the zipped body ResponseUtil.addGzipHeader(response); response.setContentLength(compressedBytes.length); } catch (ResponseHeadersNotModifiableException e) { return; } response.getOutputStream().write(compressedBytes); } else { // Client does not accept zipped content - don't bother zipping if (LOG.isDebugEnabled()) { LOG.debug(request.getRequestURL() + ". Writing without gzip compression because the request does not accept gzip."); } chain.doFilter(request, response); } }
From source file:it.jugpadova.controllers.EventController.java
private String buildChannelLink(HttpServletRequest req) { StringBuffer channelLink = req.getRequestURL(); if (req.getQueryString() != null) { channelLink.append('?').append(req.getQueryString()); }// w w w . j a v a 2 s. co m return channelLink.toString(); }
From source file:de.betterform.agent.web.servlet.XFormsInspectorServlet.java
private void sendError(HttpServletRequest request, HttpServletResponse response, HttpSession session, Exception e, String message) throws ServletException, IOException { session.setAttribute("betterform.exception", e); session.setAttribute("betterform.exception.message", message); session.setAttribute("betterform.referer", request.getRequestURL()); String path = null;// w w w .j a va 2s. c o m try { path = "/" + Config.getInstance().getProperty(WebFactory.ERROPAGE_PROPERTY); } catch (XFormsConfigException ce) { ce.printStackTrace(); } getServletContext().getRequestDispatcher(path).forward(request, response); }
From source file:de.highbyte_le.weberknecht.ControllerCore.java
private void doRedirect(HttpServletRequest request, HttpServletResponse response, String redirectDestination) throws MalformedURLException { URL reqURL = new URL(request.getRequestURL().toString()); URL dest = new URL(reqURL, redirectDestination); response.setHeader("Location", dest.toExternalForm()); response.setStatus(303); //303 - "see other" (http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html) }
From source file:com.cloudbees.servlet.filters.PrivateAppFilterIntegratedTest.java
@Before @Override// ww w . ja v a2s . c o m public void setUp() throws Exception { super.setUp(); Tomcat tomcat = getTomcatInstance(); // Must have a real docBase - just use temp org.apache.catalina.Context context = tomcat.addContext("", System.getProperty("java.io.tmpdir")); privateAppFilter = new PrivateAppFilter(); privateAppFilter.setSecretKey(secretKey); privateAppFilter.setEnabled(true); FilterDef filterDef = new FilterDef(); filterDef.setFilter(privateAppFilter); filterDef.setFilterName(PrivateAppFilter.class.getName()); context.addFilterDef(filterDef); FilterMap filterMap = new FilterMap(); filterMap.setFilterName(PrivateAppFilter.class.getName()); filterMap.addURLPattern("*"); context.addFilterMap(filterMap); context.addFilterDef(filterDef); Tomcat.addServlet(context, "hello-servlet", new HttpServlet() { @Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { System.out.println(req.getRequestURL()); IoUtils2.flush(req.getInputStream(), System.out); Enumeration<String> headers = req.getHeaderNames(); while (headers.hasMoreElements()) { String header = headers.nextElement(); System.out.println(" " + header + ": " + req.getHeader(header)); } resp.addHeader("x-response", "hello"); resp.getWriter().println("Hello world!"); } }); context.addServletMapping("/*", "hello-servlet"); tomcat.start(); httpClient = new DefaultHttpClient(); httpHost = new HttpHost("localhost", getPort()); }