Example usage for javax.servlet.http HttpServletRequest getMethod

List of usage examples for javax.servlet.http HttpServletRequest getMethod

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getMethod.

Prototype

public String getMethod();

Source Link

Document

Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT.

Usage

From source file:net.gbmb.collector.FlowFilter.java

@Override
public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
        Object o) throws Exception {
    LOGGER.debug(" IN FILTER {} / {}", httpServletRequest.getMethod(), httpServletRequest.getRequestURI());
    if (acceptRequest) {
        return true;
    } else {//from   w  w w.  j av a  2s . c  o m
        // else return http status gone
        httpServletResponse.setStatus(HttpStatus.GONE.value());
        return false;
    }
}

From source file:eu.forgestore.ws.util.AjaxUserFilter.java

@Override
protected boolean isAccessAllowed(ServletRequest request, ServletResponse arg1, Object arg2) {
    logger.info("=======> AjaxUserFilter: isAccessAllowed <=============");
    Boolean b = super.isAccessAllowed(request, arg1, arg2);

    HttpServletRequest req = WebUtils.toHttp(request);
    logger.info("=======> AjaxUserFilter:onAccessDenied <============= Method = " + 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;
    }//from w ww . j  ava 2  s . co  m

    logger.info("=======> AjaxUserFilter: isAccessAllowed = " + b);
    return b;
}

From source file:ar.com.zauber.commons.spring.servlet.view.PermanentlyRedirectView.java

/** @see RedirectView#sendRedirect() */
@Override/*from w ww.  j  a  v a2 s  .com*/
protected final void sendRedirect(final HttpServletRequest request, final HttpServletResponse response,
        final String targetUrl, final boolean http10Compatible) throws IOException {

    if (request.getMethod().toLowerCase().equals("get")) {
        response.setStatus(301);
        response.setHeader("Location", response.encodeRedirectURL(targetUrl));
    } else {
        super.sendRedirect(request, response, targetUrl, http10Compatible);
    }
}

From source file:com.gcrm.security.AuthenticationFilter.java

@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response)
        throws AuthenticationException {
    if (!request.getMethod().equals("POST")) {
        throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod());
    }/*from w  ww  . ja  v  a 2  s .c o m*/

    String username = obtainUsername(request);
    String password = obtainPassword(request);

    // Validates username and password
    username = username.trim();

    String localValue = obtainLanguage(request);
    String[] locals = localValue.split("_");
    Locale locale = new Locale(locals[0], locals[1]);
    request.getSession().setAttribute("WW_TRANS_I18N_LOCALE", locale);
    request.getSession().setAttribute("locale", localValue);
    Locale.setDefault(locale);

    User user = UserUtil.getUser(username);
    Md5PasswordEncoder encoder = new Md5PasswordEncoder();
    password = encoder.encodePassword(password, AuthenticationFilter.SALT);
    if (user == null || !user.getPassword().equals(password)) {
        ResourceBundle rb = CommonUtil.getResourceBundle();
        String errorMessage = rb.getString("error.login.denied");
        throw new AuthenticationServiceException(errorMessage);
    }

    UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username,
            password);
    setDetails(request, authRequest);

    // return authRequest;
    return this.getAuthenticationManager().authenticate(authRequest);
}

From source file:de.yaio.services.metaextract.server.controller.MetaExtractController.java

protected String createRequestLogMessage(HttpServletRequest request) {
    return new StringBuilder("REST Request - ").append("[HTTP METHOD:").append(request.getMethod())
            .append("] [URL:").append(request.getRequestURL()).append("] [REQUEST PARAMETERS:")
            .append(getRequestMap(request)).append("] [REMOTE ADDRESS:").append(request.getRemoteAddr())
            .append("]").toString();
}

From source file:edu.northwestern.bioinformatics.studycalendar.web.template.SearchActivitiesController.java

protected ModelAndView handle(SearchActivitiesCommand command, BindException errors, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    if ("GET".equals(request.getMethod())) {
        Map<String, Object> model = new HashMap<String, Object>();

        String searchText = command.getSearchText() != null ? command.getSearchText() : EMPTY;
        ActivityType activityType = command.getActivityType();
        Source source = command.getSource();

        List<Activity> results = activityDao.getActivitiesBySearchText(searchText);

        results = filterBySource(results, source);
        results = filterByActivityType(results, activityType);

        model.put("activities", results);
        return new ModelAndView("template/ajax/activities", model);
    } else {//from  w w w  . jav  a  2  s.co  m
        getControllerTools().sendGetOnlyError(response);
        return null;
    }
}

From source file:com.adobe.acs.commons.quickly.impl.QuicklyFilter.java

@SuppressWarnings("squid:S3923")
private boolean accepts(final HttpServletRequest request) {
    if (!StringUtils.equalsIgnoreCase("get", request.getMethod())) {
        // Only inject on GET requests
        return false;
    } else if (StringUtils.startsWithAny(request.getRequestURI(), REJECT_PATH_PREFIXES)) {
        return false;
    } else if (StringUtils.equals(request.getHeader("X-Requested-With"), "XMLHttpRequest")) {
        // Do not inject into XHR requests
        return false;
    } else if (StringUtils.endsWith(request.getHeader("Referer"), "/editor.html" + request.getRequestURI())) {
        // Do not apply to pages loaded in the TouchUI editor.html
        return false;
    } else if (StringUtils.endsWith(request.getHeader("Referer"), "/cf")) {
        // Do not apply to pages loaded in the Content Finder
        return false;
    }/*from  w ww . ja va 2s.co m*/
    return true;
}

From source file:ar.com.zauber.commons.social.facebook.security.FacebookAuthenticationProcessingFilter.java

/**
 * @see AbstractAuthenticationProcessingFilter
 *      #attemptAuthentication(HttpServletRequest,
 *      HttpServletResponse)// ww  w  .j av a2 s  .  co  m
 */
@Override
public final Authentication attemptAuthentication(final HttpServletRequest request,
        final HttpServletResponse response) throws AuthenticationException, IOException, ServletException {
    if (!request.getMethod().equals("GET")) {
        throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod());
    }

    final FacebookCookie cookie = FacebookCookieFinder.getCookie(facebookApiKey, request);

    if (cookie == null) {
        throw new AuthenticationServiceException("not autenticated");
    } else {
        return this.getAuthenticationManager().authenticate(new FacebookAuthenticationToken(cookie.getFbUID()));
    }
}

From source file:com.iterzp.momo.filter.EncodingConvertFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {
    if (request.getMethod().equalsIgnoreCase("GET")) {
        for (Iterator<String[]> iterator = request.getParameterMap().values().iterator(); iterator.hasNext();) {
            String[] parames = iterator.next();
            for (int i = 0; i < parames.length; i++) {
                try {
                    parames[i] = new String(parames[i].getBytes(fromEncoding), toEncoding);
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }/*from  w  w w . j a v a  2  s. c  o  m*/
            }
        }
    }
    filterChain.doFilter(request, response);
}

From source file:org.geowebcache.proxy.ProxyDispatcher.java

protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    String methStr = request.getMethod();
    if (!methStr.equalsIgnoreCase("POST")) {
        throw new ServletException("Illegal method " + methStr + " for this proxy.");
    }/*from ww w.  j  a v a2 s  .c  om*/

    String urlStr = request.getParameter("url");
    if (urlStr == null || urlStr.length() == 0 || !urlStr.startsWith("http://")) {
        throw new ServletException("Expected url parameter.");
    }

    synchronized (this) {
        long time = System.currentTimeMillis();
        if (time - lastRequest < 1000) {
            throw new ServletException("Only one request per second please.");
        } else {
            lastRequest = time;
        }
    }

    log.info("Proxying request for " + request.getRemoteAddr() + " to " + " " + urlStr);

    String charEnc = request.getCharacterEncoding();
    if (charEnc == null) {
        charEnc = "UTF-8";
    }
    String decodedUrl = URLDecoder.decode(urlStr, charEnc);

    URL url = new URL(decodedUrl);
    HttpURLConnection wmsBackendCon = (HttpURLConnection) url.openConnection();

    if (wmsBackendCon.getContentEncoding() != null) {
        response.setCharacterEncoding(wmsBackendCon.getContentEncoding());
    }

    response.setContentType(wmsBackendCon.getContentType());

    int read = 0;
    byte[] data = new byte[1024];
    while (read > -1) {
        read = wmsBackendCon.getInputStream().read(data);
        if (read > -1) {
            response.getOutputStream().write(data, 0, read);
        }
    }

    return null;
}