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.kamhon.ieagle.security.AuthenticationUtil.java

public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response,
        String username, String password) throws AuthenticationException {
    if (postOnly && !request.getMethod().equals("POST")) {
        throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod());
    }/*from   w w  w.  j av  a 2s  .  c  om*/

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

    if (username == null) {
        username = "";
    }

    if (password == null) {
        password = "";
    }

    username = username.trim();

    UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username,
            password);

    // Place the last username attempted into HttpSession for views
    HttpSession session = request.getSession(false);

    if (session != null || getAllowSessionCreation()) {
        request.getSession().setAttribute(SPRING_SECURITY_LAST_USERNAME_KEY,
                TextEscapeUtils.escapeEntities(username));
    }

    // Allow subclasses to set the "details" property
    setDetails(request, authRequest);

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

From source file:com.concursive.connect.web.webdav.WebdavManager.java

public static int validateUser(Connection db, HttpServletRequest req) throws Exception {
    String argHeader = req.getHeader("Authorization");
    HashMap params = getAuthenticationParams(argHeader);
    String username = (String) params.get("username");

    if (md5Helper == null) {
        md5Helper = MessageDigest.getInstance("MD5");
    }//from  ww  w  .  ja  va  2  s. com

    int userId = -1;
    String password = null;
    PreparedStatement pst = db.prepareStatement(
            "SELECT user_id, webdav_password " + "FROM users " + "WHERE username = ? " + "AND enabled = ? ");
    pst.setString(1, username);
    pst.setBoolean(2, true);
    ResultSet rs = pst.executeQuery();
    if (rs.next()) {
        userId = rs.getInt("user_id");
        password = rs.getString("webdav_password");
    }
    rs.close();
    pst.close();
    if (userId == -1) {
        return userId;
    }
    String method = req.getMethod();
    String uri = (String) params.get("uri");
    String a2 = MD5Encoder.encode(md5Helper.digest((method + ":" + uri).getBytes()));
    String digest = MD5Encoder
            .encode(md5Helper.digest((password + ":" + params.get("nonce") + ":" + a2).getBytes()));
    if (!digest.equals(params.get("response"))) {
        userId = -1;
    }
    return userId;
}

From source file:org.energyos.espi.common.utils.StringToLongFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
        throws IOException, ServletException {

    if (logger.isDebugEnabled()) {

        logger.debug("StringToLongFilter processing");

        HttpServletRequest httpRequest = (HttpServletRequest) request;
        HttpServletResponse httpResponse = (HttpServletResponse) response;

        logger.debug("Request is " + httpRequest.getClass());
        logger.debug("Request URL: " + httpRequest.getRequestURL());
        logger.debug("Request Method is '" + httpRequest.getMethod() + "'");
        logger.debug("Response is " + httpResponse.getClass());

    }// w  ww  . ja  va  2s  . c om

    // TODO: Add Long to String conversion logic

    filterChain.doFilter(request, response);
}

From source file:com.thinkgem.jeesite.modules.sys.interceptor.GlobalInterceptor.java

@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler,
        Exception ex) throws Exception {
    String uri = request.getRequestURI();
    String uriPrefix = request.getContextPath() + Global.ADMIN_PATH;
    // ??POST/*from   w  w  w  .  j  ava  2 s  .c o  m*/
    if ("POST".equals(request.getMethod()) && uri.length() > uriPrefix.length()) {
        User user = UserUtils.getUser();
        if (user != null) {
            StringBuilder sb = new StringBuilder();
            sb.append("url: (" + request.getMethod() + ") " + uri);
            int index = 0;
            for (Object param : request.getParameterMap().keySet()) {
                sb.append((index++ == 0 ? "?" : "&") + param + "=");
                sb.append(StringUtils.abbreviate(request.getParameter((String) param), 100));
            }
            sb.append("; userId: " + user.getId());
            sb.append("; userName: " + user.getName());
            sb.append("; loginName: " + user.getLoginName());
            sb.append("; ipAddr: " + request.getLocalAddr());
            sb.append("; datetime: " + DateUtils.getDateTime());
            sb.append("; handler: " + handler.toString());
            logger.info(sb.toString());
        }
    }
}

From source file:net.proest.librepilot.web.handler.ObjectHandler.java

public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    response.setCharacterEncoding("utf-8");
    response.setStatus(HttpServletResponse.SC_OK);

    if (request.getMethod().equals("POST")) {
        handlePost(target, baseRequest, request, response);
    } else if (request.getMethod().equals("GET")) {
        handleGet(target, baseRequest, request, response);
    }/*from  w w  w . j  av  a  2s  .  c om*/
    baseRequest.setHandled(true);
}

From source file:com.fujitsu.dc.engine.rs.StatusResource.java

/**
 * Service./*  w  ww . j  a va  2s.c o m*/
 * @param path ??
 * @param req Request
 * @param res Response
 * @param is 
 * @return Response
 */
public final Response run(final String path, final HttpServletRequest req, final HttpServletResponse res,
        final InputStream is) {
    StringBuilder msg = new StringBuilder();
    msg.append(">>> Request Started ");
    msg.append(" method:");
    msg.append(req.getMethod());
    msg.append(" method:");
    msg.append(req.getRequestURL());
    msg.append(" url:");
    log.info(msg);

    // ? ????
    Enumeration<String> multiheaders = req.getHeaderNames();
    for (String headerName : Collections.list(multiheaders)) {
        Enumeration<String> headers = req.getHeaders(headerName);
        for (String header : Collections.list(headers)) {
            log.debug("RequestHeader['" + headerName + "'] = " + header);
        }
    }
    try {
        DcEngineConfig.reload();
    } catch (Exception e) {
        log.warn(" unknown Exception(" + e.getMessage() + ")");
        return errorResponse(new DcEngineException("500 Internal Server Error (Unknown Error)",
                DcEngineException.STATUSCODE_SERVER_ERROR));
    }
    return Response.status(HttpStatus.SC_NO_CONTENT).build();
}

From source file:io.personium.engine.rs.StatusResource.java

/**
 * Service./*from w w  w  . ja  v  a  2  s .co m*/
 * @param path ??
 * @param req Request
 * @param res Response
 * @param is 
 * @return Response
 */
public final Response run(final String path, final HttpServletRequest req, final HttpServletResponse res,
        final InputStream is) {
    StringBuilder msg = new StringBuilder();
    msg.append(">>> Request Started ");
    msg.append(" method:");
    msg.append(req.getMethod());
    msg.append(" method:");
    msg.append(req.getRequestURL());
    msg.append(" url:");
    log.info(msg);

    // ? ????
    Enumeration<String> multiheaders = req.getHeaderNames();
    for (String headerName : Collections.list(multiheaders)) {
        Enumeration<String> headers = req.getHeaders(headerName);
        for (String header : Collections.list(headers)) {
            log.debug("RequestHeader['" + headerName + "'] = " + header);
        }
    }
    try {
        PersoniumEngineConfig.reload();
    } catch (Exception e) {
        log.warn(" unknown Exception(" + e.getMessage() + ")");
        return errorResponse(new PersoniumEngineException("500 Internal Server Error (Unknown Error)",
                PersoniumEngineException.STATUSCODE_SERVER_ERROR));
    }
    return Response.status(HttpStatus.SC_NO_CONTENT).build();
}

From source file:es.logongas.ix3.web.util.ControllerHelper.java

public EndPoint getEndPoint(HttpServletRequest httpServletRequest) {
    String path = (String) httpServletRequest
            .getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
    String method = httpServletRequest.getMethod();
    EndPoint endPoint = EndPoint.getBestEndPoint(
            EndPoint.getMatchEndPoint(endPointsFactory.getEndPoints(), path, method), path, method);

    return endPoint;
}

From source file:com.alibaba.intl.bcds.goldroom.web.ShelveFormController.java

@Override
protected Map<String, Object> referenceData(HttpServletRequest request, Object command, Errors errors)
        throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();
    String isbn = (String) request.getParameter("isbn");
    if (!validateIsbn(isbn) && !request.getMethod().equals("POST")) {
        map.put("isbnError", true);
        map.put("isbn", isbn);
        return map;
    }//from w  ww.j a  v a 2s . co m
    BookInfo bookInfo = bookInfoService.getBookInfoFromDbAndNetWork(isbn);
    map.put("bookInfo", bookInfo);
    Shelve shelve = (Shelve) command;
    if (bookInfo == null) {
        shelve.setNewBookInfo(true);
        shelve.getBookInfo().setIsbn(isbn);
        map.put("isbn", isbn);
    } else if (bookInfo != null) {
        shelve.setBookInfo(bookInfo);
        if (bookInfo.getCategoryId() == null)
            shelve.setUpdateCategory(true);
    }
    map.put("showForm", true);
    map.put("isbnError", false);
    return map;
}

From source file:com.redhat.rhn.frontend.servlets.DumpFilter.java

/** {@inheritDoc} */
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
        throws IOException, ServletException {

    if (log.isDebugEnabled()) {
        // handle request
        HttpServletRequest request = (HttpServletRequest) req;
        log.debug("Entered doFilter() ===================================");
        log.debug("AuthType: " + request.getAuthType());
        log.debug("Method: " + request.getMethod());
        log.debug("PathInfo: " + request.getPathInfo());
        log.debug("Translated path: " + request.getPathTranslated());
        log.debug("ContextPath: " + request.getContextPath());
        log.debug("Query String: " + request.getQueryString());
        log.debug("Remote User: " + request.getRemoteUser());
        log.debug("Remote Host: " + request.getRemoteHost());
        log.debug("Remote Addr: " + request.getRemoteAddr());
        log.debug("SessionId: " + request.getRequestedSessionId());
        log.debug("uri: " + request.getRequestURI());
        log.debug("url: " + request.getRequestURL().toString());
        log.debug("Servlet path: " + request.getServletPath());
        log.debug("Server Name: " + request.getServerName());
        log.debug("Server Port: " + request.getServerPort());
        log.debug("RESPONSE encoding: " + resp.getCharacterEncoding());
        log.debug("REQUEST encoding: " + request.getCharacterEncoding());
        log.debug("JVM encoding: " + System.getProperty("file.encoding"));
        logSession(request.getSession());
        logHeaders(request);/*from ww  w . j a v  a2  s . com*/
        logCookies(request.getCookies());
        logParameters(request);
        logAttributes(request);
        log.debug("Calling chain.doFilter() -----------------------------");
    }

    chain.doFilter(req, resp);

    if (log.isDebugEnabled()) {
        log.debug("Returned from chain.doFilter() -----------------------");
        log.debug("Handle Response, not much to print");
        log.debug("Response: " + resp.toString());
        log.debug("Leaving doFilter() ===================================");
    }
}