List of usage examples for javax.servlet.http HttpServletRequest getRequestURL
public StringBuffer getRequestURL();
From source file:com.firstclarity.magnolia.study.blossom.sample.CommentsComponent.java
@RequestMapping("/comments") public String handleRequest(ModelMap model, HttpServletRequest request, @RequestParam("action") String action, Content content) throws RepositoryException { if ("add".equals(action)) { writeComment(request, content);/* www . j a v a2s .c om*/ return "redirect:" + request.getRequestURL(); } if ("delete".equals(action)) { deleteComment(request, content); return "redirect:" + request.getRequestURL(); } model.addAttribute("comments", readComments(content)); return "mymodule/components/comments.jsp"; }
From source file:com.shenit.commons.utils.HttpUtils.java
/** * ??/*ww w .j a va 2s . c o m*/ * * @param uri * @param req * @return */ public static String toUrl(String uri, HttpServletRequest req) { StringBuffer buffer = req.getRequestURL(); boolean isSsl = buffer.indexOf(URL_SSL_PREFIX) > -1; String base = buffer.substring(0, buffer.indexOf(SLASH, URL_SSL_PREFIX.length() - (isSsl ? 0 : 1))); return StringUtils.isEmpty(uri) ? base : base + uri; }
From source file:net.ljcomputing.core.controler.GlobalExceptionController.java
/** * Handle all constraint violation exceptions. * * @param req the req/* ww w . ja v a 2 s. c om*/ * @param exception the exception * @return the error info */ @Order(Ordered.HIGHEST_PRECEDENCE) @ExceptionHandler(ConstraintViolationException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) public @ResponseBody ErrorInfo handleAllConstraintViolationExceptions(HttpServletRequest req, Exception exception) { ConstraintViolationException cve = (ConstraintViolationException) exception; logger.warn("A required value is missing : {}:", req.getRequestURL().toString()); return new ErrorInfo(getCurrentTimestamp(), HttpStatus.BAD_REQUEST, req.getRequestURL().toString(), cve); }
From source file:com.jaspersoft.jasperserver.api.security.externalAuth.sso.SsoTicketValidatorImpl.java
protected URI constructValidationUrl(final String ticket) throws AuthenticationServiceException { final Map<String, String> urlParameters = new HashMap<String, String>(); try {/*from www . j a v a 2s . c om*/ logger.debug("Constructing SSO token validation URL (ticket: " + ticket + ")"); final ExternalAuthProperties externalAuthProperties = getExternalAuthProperties(); String ticketParamName = externalAuthProperties.getTicketParameterName(); urlParameters.put(ticketParamName, ticket); String serviceParameterName = externalAuthProperties.getServiceParameterName(); if (serviceParameterName != null && serviceParameterName.length() > 0) { // in case of SOAP the service does not have to match the request. in that case we will specify the service if (getService() != null && getService().length() > 0) { urlParameters.put(serviceParameterName, getService()); } else { HttpServletRequest req = ((ServletRequestAttributes) RequestContextHolder .getRequestAttributes()).getRequest(); StringBuffer requestURL = req.getRequestURL(); urlParameters.put(serviceParameterName, requestURL.toString()); } } URIBuilder uriBuilder = new URIBuilder(externalAuthProperties.getSsoServerTicketValidationUrl()); for (Map.Entry<String, String> param : urlParameters.entrySet()) { uriBuilder.setParameter(param.getKey(), param.getValue()); } return uriBuilder.build(); } catch (URISyntaxException e) { logger.error("Failed to construct the token validation URL (ticket: " + ticket + ")", e); throw new AuthenticationServiceException(e.getMessage(), e); } }
From source file:esg.node.filters.UrlResolvingFilter.java
@SuppressWarnings("unchecked") public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (filterConfig == null) return;/* w w w. j a v a2 s.co m*/ boolean success = false; //firewall off any errors so that nothing stops the show... try { if (urlResolvingDAO != null) { //This filter should only appy to specific requests //in particular requests for data files (*.nc) HttpServletResponse res = (HttpServletResponse) response; HttpServletRequest req = (HttpServletRequest) request; String url = req.getRequestURL().toString().trim(); Matcher m = urlPattern.matcher(url); if (m.matches()) { System.out.println("Executing Url Filter For: " + url); String resourcePath = urlResolvingDAO.resolveDRSUrl(url); //if(null != resourcePath) { // File resolvedResource = new File(resourcePath); // if(!resolvedResource.exists()) { // log.error("The resolved resource does not exist! ["+url+" -> "+resourcePath+"]"); // ((HttpServletResponse)response).sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, // "Requested Resource Not Present! ["+url+"]"); // return; // } // String contentType = "application/x-netcdf"; // //ServletUtil.returnFile(req, res, resolvedResource, contentType); // //} //This would not work... threw IllegalStateException... //filterConfig.getServletContext().getRequestDispatcher(urlResolvingDAO.resolveUrl(url)).forward(request,response); log.debug("*Passing through chain..."); chain.doFilter(request, response); } else { log.debug("No url resolving for: " + url); } } else { log.error("DAO is null :[" + urlResolvingDAO + "]"); HttpServletResponse resp = (HttpServletResponse) response; resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Invalid State Of ESG Url Resolving Filter"); } } catch (Throwable t) { log.error(t); HttpServletResponse resp = (HttpServletResponse) response; resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Caught unforseen Exception in ESG Url Resolving Filter"); } log.debug("Passing through chain..."); chain.doFilter(request, response); }
From source file:com.pedra.storefront.filters.UrlEncoderFilter.java
@Override protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain filterChain) throws ServletException, IOException { if (LOG.isDebugEnabled()) { LOG.debug(" The incoming URL : [" + request.getRequestURL().toString() + "]"); }//w w w.ja v a 2 s. c om final List<UrlEncoderData> urlEncodingAttributes = getUrlEncoderFacade().variablesForUrlEncoding(); if (urlEncodingAttributes != null && !urlEncodingAttributes.isEmpty()) { final HttpSession session = request.getSession(false); final UrlEncoderPatternData patternData = getUrlEncoderFacade().patternForUrlEncoding( request.getRequestURL().toString(), request.getContextPath(), (session != null && session.isNew())); final String patternBeforeProcessing = getSessionService() .getAttribute(WebConstants.URL_ENCODING_ATTRIBUTES); final String pattern = "/" + patternData.getPattern(); if (!StringUtils.equalsIgnoreCase(patternBeforeProcessing, pattern)) { if (patternData.isRedirectRequired()) { String redirectUrl = StringUtils.replace(request.getRequestURL().toString(), patternBeforeProcessing, pattern); final String queryString = request.getQueryString(); if (StringUtils.isNotBlank(queryString)) { redirectUrl = redirectUrl + "?" + queryString; } response.sendRedirect(redirectUrl); } else { getUrlEncoderFacade().updateUrlEncodingData(); } } getSessionService().setAttribute(WebConstants.URL_ENCODING_ATTRIBUTES, pattern); final UrlEncodeHttpRequestWrapper wrappedRequest = new UrlEncodeHttpRequestWrapper(request, patternData.getPattern()); wrappedRequest.setAttribute(WebConstants.URL_ENCODING_ATTRIBUTES, pattern); wrappedRequest.setAttribute("originalContextPath", request.getContextPath()); if (LOG.isDebugEnabled()) { LOG.debug("ContextPath=[" + wrappedRequest.getContextPath() + "]" + " Servlet Path= [" + wrappedRequest.getServletPath() + "]" + " Request Url= [" + wrappedRequest.getRequestURL() + "]"); } filterChain.doFilter(wrappedRequest, response); } else { if (LOG.isDebugEnabled()) { LOG.debug(" No URL attributes defined"); } request.setAttribute(WebConstants.URL_ENCODING_ATTRIBUTES, ""); filterChain.doFilter(request, response); } }
From source file:com.acc.storefront.filters.UrlEncoderFilter.java
@Override protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain filterChain) throws ServletException, IOException { if (LOG.isDebugEnabled()) { LOG.debug(" The incoming URL : [" + request.getRequestURL().toString() + "]"); }/*from w ww. j a v a 2 s. c o m*/ final List<UrlEncoderData> urlEncodingAttributes = getUrlEncoderFacade().variablesForUrlEncoding(); if (urlEncodingAttributes != null && !urlEncodingAttributes.isEmpty()) { final HttpSession session = request.getSession(false); final UrlEncoderPatternData patternData = getUrlEncoderFacade().patternForUrlEncoding( request.getRequestURI().toString(), request.getContextPath(), (session != null && session.isNew())); final String patternBeforeProcessing = getSessionService() .getAttribute(WebConstants.URL_ENCODING_ATTRIBUTES); final String pattern = "/" + patternData.getPattern(); if (!StringUtils.equalsIgnoreCase(patternBeforeProcessing, pattern)) { if (patternData.isRedirectRequired()) { String redirectUrl = StringUtils.replace(request.getRequestURL().toString(), patternBeforeProcessing + "/", pattern + "/"); final String queryString = request.getQueryString(); if (StringUtils.isNotBlank(queryString)) { redirectUrl = redirectUrl + "?" + queryString; } response.sendRedirect(redirectUrl); } else { getUrlEncoderFacade().updateUrlEncodingData(); } } getSessionService().setAttribute(WebConstants.URL_ENCODING_ATTRIBUTES, pattern); final UrlEncodeHttpRequestWrapper wrappedRequest = new UrlEncodeHttpRequestWrapper(request, patternData.getPattern()); wrappedRequest.setAttribute(WebConstants.URL_ENCODING_ATTRIBUTES, pattern); wrappedRequest.setAttribute("originalContextPath", StringUtils.isBlank(request.getContextPath()) ? "/" : request.getContextPath()); if (LOG.isDebugEnabled()) { LOG.debug("ContextPath=[" + wrappedRequest.getContextPath() + "]" + " Servlet Path= [" + wrappedRequest.getServletPath() + "]" + " Request Url= [" + wrappedRequest.getRequestURL() + "]"); } filterChain.doFilter(wrappedRequest, response); } else { if (LOG.isDebugEnabled()) { LOG.debug(" No URL attributes defined"); } request.setAttribute(WebConstants.URL_ENCODING_ATTRIBUTES, ""); filterChain.doFilter(request, response); } }
From source file:com.rockagen.gnext.Filter.AccessFilter.java
/** * Save access log//from w w w .ja v a 2 s . com * @param request {@link HttpServletRequest} */ private void accessLog(HttpServletRequest request) { AccessLog al = new AccessLog(); al.setIp(getIp(request)); al.setMethod(request.getMethod()); al.setReferer(request.getHeader("Referer")); al.setTimeAt(new Date()); al.setUrl(request.getRequestURL().toString()); al.setUserAgent(request.getHeader("User-Agent")); // Translate params Map<String, String> params = translateParaeters(request.getParameterMap()); // protect sensitive value filterParameters(params); al.setParams(params); mongoTemplate.save(al); }
From source file:org.osiam.resources.controller.UserController.java
@RequestMapping(method = RequestMethod.POST) @ResponseStatus(HttpStatus.CREATED)/*from w ww .j a va 2s . co m*/ @ResponseBody public User create(HttpServletRequest request, HttpServletResponse response) throws IOException { User user = jsonInputValidator.validateJsonUser(request); User createdUser = scimUserProvisioning.create(user); String requestUrl = request.getRequestURL().toString(); URI uri = new UriTemplate("{requestUrl}{internalId}").expand(requestUrl + "/", createdUser.getId()); response.setHeader("Location", uri.toASCIIString()); Meta newMeta = new Meta.Builder(createdUser.getMeta()).setLocation(uri.toASCIIString()).build(); return new User.Builder(createdUser).setMeta(newMeta).build(); }
From source file:io.kamax.mxisd.controller.DefaultExceptionHandler.java
@ExceptionHandler(RemoteLoginException.class) public String handle(HttpServletRequest request, HttpServletResponse response, RemoteLoginException e) { if (e.getErrorBodyMsgResp() != null) { response.setStatus(e.getStatus()); log.info("Request {} {} - Error {}: {}", request.getMethod(), request.getRequestURL(), e.getErrorCode(), e.getError());/*from w ww . ja va2s . co m*/ return gson.toJson(e.getErrorBodyMsgResp()); } return handleGeneric(request, response, e); }