List of usage examples for javax.servlet.http HttpServletRequest getMethod
public String getMethod();
From source file:cats.twitter.webapp.controller.mvc.CORSFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { if (request.getHeader("Access-Control-Request-Method") != null && "OPTIONS".equals(request.getMethod())) { // CORS "pre-flight" request response.addHeader("Access-Control-Allow-Origin", "*"); response.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE"); response.addHeader("Access-Control-Allow-Headers", "Content-Type"); response.addHeader("Access-Control-Max-Age", "1800");//30 min }/*from ww w . ja v a 2 s. c o m*/ filterChain.doFilter(request, response); }
From source file:com.rockagen.gnext.Filter.AccessFilter.java
/** * Save access log// w w w . j a va 2 s.c o m * @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:eu.forgestore.ws.util.AjaxUserFilter.java
@Override protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception { HttpServletRequest req = WebUtils.toHttp(request); logger.info("=======> AjaxUserFilter:onAccessDenied <============= MEethod = " + req.getMethod()); if (req.getMethod().equals("OPTIONS")) { //useful to pass CORS Options //usually for most browsers in OPTIONS there is no JSESSION ID cookie, //therefore there is a problem with the authentication //still bypassing the OPTIONS here seams not an authorization problem return true; }//ww w . j a v a2s . c o m String xmlHttpRequest = req.getHeader("X-Requested-With"); if (xmlHttpRequest != null) { if (xmlHttpRequest.equalsIgnoreCase("XMLHttpRequest")) { HttpServletResponse res = WebUtils.toHttp(response); res.sendError(401); return false; } logger.info( "=======> AjaxUserFilter:onAccessDenied xmlHttpRequest X-Requested-With=" + xmlHttpRequest); } HttpServletResponse res = WebUtils.toHttp(response); res.sendError(401); // xmlHttpRequest = req.getHeader("Origin"); //USED FOR CORS support on 401 error // if ( xmlHttpRequest != null ){ // res.addHeader("Access-Control-Allow-Origin", xmlHttpRequest); // res.addHeader("Access-Control-Allow-Credentials", "true"); // // logger.info("=======> AjaxUserFilter:onAccessDenied xmlHttpRequest Origin="+xmlHttpRequest); // // } return false; //return super.onAccessDenied(request, response); }
From source file:io.github.gsteckman.doorcontroller.DoorRestInterface.java
/** * This method handles the UPnP defined HTTP methods SUBSCRIBE and UNSUBSCRIBE bound to the URL path /door/subscriptions. * @param req The request provided from the servlet container. * @param res The response object provided by the servlet container. * @throws IOException Thrown by HttpServletResponse.sendError if an error occurs writing the response. *//* w w w .j ava 2 s .c om*/ @RequestMapping("/door/subscriptions") public void process(HttpServletRequest req, HttpServletResponse res) throws IOException { if (SUBSCRIBE_METHOD.equals(req.getMethod())) { LOG.debug("SUBSCRIBE /door/subscriptions"); subMgr.processSubscribe(SUBSCRIPTION_KEY, req, res); } else if (UNSUBSCRIBE_METHOD.equals(req.getMethod())) { LOG.debug("UNSUBSCRIBE /door/subscriptions"); subMgr.processUnsubscribe(SUBSCRIPTION_KEY, req, res); } }
From source file:com.intel.rsa.podm.rest.filters.UrlValidationFilter.java
private boolean isUrlValid(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) { if (String.format("%s %s HTTP/1.1\n\r", httpServletRequest.getMethod(), httpServletRequest.getRequestURL()) .getBytes(StandardCharsets.UTF_8).length > URL_MAX_LENGTH_IN_BYTES) { logger.w("Requested URI exceeds maximum URI length which is set to {} octets", URL_MAX_LENGTH_IN_BYTES); setErrorResponse(httpServletResponse, ErrorResponse.URI_TOO_LONG); return false; }/*www.jav a 2s .c o m*/ String url = httpServletRequest.getRequestURL().toString(); UrlValidator urlValidator = new UrlValidator(UrlValidator.ALLOW_LOCAL_URLS); if (urlValidator.isValid(url) && isUrlDecodingPossible(url)) { return true; } else { setErrorResponse(httpServletResponse, ErrorResponse.MALFORMED_URI); return false; } }
From source file:com.sun.socialsite.web.filters.AnonymousAccessFilter.java
/** * If anonymous access not allowed then reject any request that does not * have either a SocialSite security token or an OAuth token. *///from w w w .ja va 2 s.c o m public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { log.debug("--- entering"); if (allowAnonymous) { chain.doFilter(req, res); } else { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) res; log.debug(request.getMethod() + " " + request.getRequestURL().toString()); log.debug("st=" + request.getParameter("st")); SecurityToken st = new AuthInfo(request).getSecurityToken(); if (st != null && (st instanceof SocialSiteToken || st instanceof OAuthSecurityToken || st instanceof AssertedToken)) { chain.doFilter(req, res); } else { response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "No suitable security token found in request"); } } log.debug("--- exiting"); }
From source file:am.ik.categolj2.core.web.accesslog.AccessLogMethodArgumentResolver.java
@Override public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class); String xTrack = StringUtils.substring((String) request.getAttribute("X-Track"), 0, 32); String method = request.getMethod(); String uri = StringUtils.substring(request.getRequestURI(), 0, 128); String query = StringUtils.substring(request.getQueryString(), 0, 128); String remoteAddress = RemoteAddresses.getRemoteAddress(request); String userAgent = UserAgents.getUserAgent(request); DateTime accessDate = dateFactory.newDateTime(); return new AccessLog(null, method, uri, query, remoteAddress, userAgent, xTrack, accessDate); }
From source file:net.gbmb.collector.FlowFilter.java
@Override public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception { LOGGER.debug("OUT FILTER {} / {} >> {}", httpServletRequest.getMethod(), httpServletRequest.getRequestURI(), httpServletResponse.getStatus()); }
From source file:jp.co.opentone.bsol.framework.web.extension.jsf.RequestLoggingPhaseListener.java
@Override public void beforePhase(PhaseEvent event) { HttpServletRequest req = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext() .getRequest();/*from w ww. j a va 2 s . co m*/ log.info("Requested: {} {}", req.getMethod(), req.getRequestURI()); Enumeration<?> enm = req.getHeaderNames(); log.info("Header:"); while (enm.hasMoreElements()) { String name = (String) enm.nextElement(); log.info(" {} = {}", name, req.getHeader(name)); } log.info(" Parameters:"); @SuppressWarnings("unchecked") Map<String, String[]> parameterMap = req.getParameterMap(); for (Map.Entry<String, String[]> e : parameterMap.entrySet()) { log.info(" {} = {}", e.getKey(), StringUtils.join(e.getValue())); } }
From source file:cn.sel.wetty.interceptor.AccessLogger.java
private void i(HttpServletRequest request) { String msg = String.format("%s -> %s\t[%s]\tHeaders:%s\tParameters:%s", request.getRemoteAddr(), request.getRequestURI(), request.getMethod(), getHeaders(request), request.getParameterMap()); LOGGER.info(msg);/*w w w . j a va 2 s . c om*/ }