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:com.sun.socialsite.web.rest.core.RestrictedMakeRequestHandler.java

/**
 * TODO: enable this (once token access issues are addressed).
 *///from  ww w.  j a  va  2  s. co  m
public void __fetch(HttpServletRequest request, HttpServletResponse response)
        throws GadgetException, IOException {
    log.debug("Entered");
    Permission requiredPermission = new HttpPermission(request.getParameter(URL_PARAM), request.getMethod());
    try {
        SecurityToken token = new AuthInfo(request).getSecurityToken();
        log.debug("token=" + token);
        Factory.getSocialSite().getPermissionManager().checkPermission(requiredPermission, token);
        super.fetch(request, response);
    } catch (SecurityException e) {
        log.debug("Permission Denied", e);
        throw new GadgetException(GadgetException.Code.INTERNAL_SERVER_ERROR, e);
    } catch (Exception e) {
        log.error("Unexpected Exception", e);
        throw new GadgetException(GadgetException.Code.INTERNAL_SERVER_ERROR, e);
    }
}

From source file:com.scf.module.security.matcher.AntPathRequestMatcher.java

/**
 * Returns true if the configured pattern (and HTTP-Method) match those of the supplied request.
 *
 * @param request the request to match against. The ant pattern will be matched against the
 *    {@code servletPath} + {@code pathInfo} of the request.
 *///from  w w  w  .  j  a  v  a2 s.  co m
public boolean matches(HttpServletRequest request) {
    if (httpMethod != null && request.getMethod() != null && httpMethod != valueOf(request.getMethod())) {
        if (logger.isDebugEnabled()) {
            logger.debug("Request '" + request.getMethod() + " " + getRequestPath(request) + "'"
                    + " doesn't match '" + httpMethod + " " + pattern);
        }

        return false;
    }

    if (pattern.equals(MATCH_ALL)) {
        if (logger.isDebugEnabled()) {
            logger.debug("Request '" + getRequestPath(request) + "' matched by universal pattern '/**'");
        }

        return true;
    }

    String url = getRequestPath(request);

    if (logger.isDebugEnabled()) {
        logger.debug("Checking match of request : '" + url + "'; against '" + pattern + "'");
    }

    return matcher.matches(url);
}

From source file:org.impalaframework.extension.mvc.annotation.handler.AnnotationHandlerMethodResolver.java

public Method resolveHandlerMethod(HttpServletRequest request) throws ServletException {

    String lookupPath = urlPathHelper.getLookupPathForRequest(request);
    String methodLookupPath = lookupPath + "." + request.getMethod();

    Method methodToReturn = pathMethodCache.get(methodLookupPath);

    if (methodToReturn == null) {
        methodToReturn = getHandlerMethod(lookupPath, methodLookupPath, request);
    }/*ww  w  .ja  v a2 s. co m*/

    return methodToReturn;
}

From source file:org.cloudfoundry.identity.api.web.CorsFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {
    response.addHeader("Access-Control-Allow-Origin", "*");
    if (request.getHeader("Access-Control-Request-Method") != null && "OPTIONS".equals(request.getMethod()))
        ;/*from   w w w  .  j a  v a2s .c  om*/
    {
        // CORS "pre-flight" request
        response.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
        response.addHeader("Access-Control-Allow-Headers", "Authorization");
        response.addHeader("Access-Control-Max-Age", "1728000");
    }
    filterChain.doFilter(request, response);
}

From source file:com.app.framework.web.mvc.ActionMap.java

public static ActionMap Init(ServletRequest request, ServletResponse response) throws IOException {
    ActionMap actMap = null;//ww  w  . j  a v  a 2s.com
    HttpServletRequest req = ((HttpServletRequest) request);
    String s1 = req.getContextPath();
    String s2 = req.getRequestURI();
    String s3 = req.getRequestURL().toString();
    String fullUrl = getFullURL(req).toLowerCase();
    if (fullUrl.contains(".css") || fullUrl.contains(".js") || fullUrl.contains(".html")
            || fullUrl.contains(".jpg") || fullUrl.contains(".png") || fullUrl.contains(".gif")
            || fullUrl.contains(".icon")) {
        return null;
    }
    Gson g = new Gson();
    String requestedResource = s2.replace(s1 + "/", "");
    String[] urlParts = requestedResource.split("/");
    if (urlParts != null && urlParts.length >= 2) {
        String controller = urlParts[0];
        String action = urlParts[1];

        String jsonFilePath = req.getServletContext().getRealPath("/WEB-INF/action-map.json");

        String json = FileUtils.readFileToString(new File(jsonFilePath), "utf-8");

        Type listType = new TypeToken<Map<String, ControllerInfo>>() {
        }.getType();
        Map<String, ControllerInfo> map = g.fromJson(json, listType);

        String method = req.getMethod();
        if (map.containsKey(controller)) {
            actMap = new ActionMap();
            ControllerInfo cInfo = map.get(controller);
            ActionInfo mInfo = cInfo.getActions().get(action).get(method);
            actMap.setController(cInfo.getControllerClassName());
            actMap.setAction(mInfo.getMethodName());
            actMap.setModel(mInfo.getModelClassName());
        }
    }
    return actMap;
}

From source file:org.zalando.zmon.actuator.metrics.MetricsWrapper.java

public void recordClientRequestMetrics(final HttpServletRequest request, final String path, final int status,
        final long time) {
    String suffix = getFinalStatus(request);
    submitToTimer(getKey("zmon.response." + status + "." + request.getMethod().toUpperCase() + suffix), time);
}

From source file:com.pearson.developer.xapi.proxy.AuthFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws java.io.IOException, ServletException {

    HttpServletRequest req = (HttpServletRequest) request;

    // AJAX will preflight xAPI request with OPTIONS request without Authorization header
    if ("OPTIONS".equals(req.getMethod())) {
        chain.doFilter(request, response);
        return;/*from   w  w w.  j  a v a  2  s .  c om*/
    }

    boolean authorized = false;
    try { // decode and verify the basic auth credentials
        String authHeader = req.getHeader("Authorization");
        authHeader = authHeader.substring("Basic ".length());
        String decodedAuthHeader = new String(Base64.decodeBase64(authHeader), "UTF-8");
        String[] credentials = decodedAuthHeader.split(":");
        if (credentials.length == 2) {
            String username = credentials[0];
            String password = credentials[1];
            authorized = SessionDatabase.verify(username, password);
        }
    } catch (Exception e) {
        // do nothing
    }

    // proceed to xAPI if session was authorized
    if (authorized) {
        final String targetBasicAuth = config.getInitParameter("targetBasicAuth");

        // need to give the LRS it's expected Authorization value
        HttpServletRequestWrapper requestWrapper = new HttpServletRequestWrapper(req) {
            @Override
            public String getHeader(String name) {
                if ("Authorization".equalsIgnoreCase(name)) {
                    return targetBasicAuth;
                }
                return super.getHeader(name);
            }

            @Override
            public Enumeration<String> getHeaders(String name) {
                if ("Authorization".equalsIgnoreCase(name)) {
                    List<String> values = new ArrayList<String>();
                    values.add(targetBasicAuth);
                    return Collections.enumeration(values);
                }
                return super.getHeaders(name);
            }
        };
        chain.doFilter(requestWrapper, response);
        return;
    }

    // respond with a 401 if missing auth
    HttpServletResponse resp = (HttpServletResponse) response;
    resp.reset();
    resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    resp.getWriter().println("401 - Unauthorized");
}

From source file:csiro.pidsvc.servlet.info.java

/**
 * Echoes HTTP headers./*w  ww.j  av a 2 s  . c  o  m*/
 *
 * @param request
 * @param response
 * @throws IOException
 * @throws URISyntaxException
 */
protected void echo(HttpServletRequest request, HttpServletResponse response)
        throws IOException, URISyntaxException {
    String ret = "HTTP " + request.getMethod() + " " + request.getRequestURL() + "?" + request.getQueryString()
            + "\n\n";

    // Retrieve HTTP headers.
    for (@SuppressWarnings("unchecked")
    Enumeration<String> header = request.getHeaderNames(); header.hasMoreElements();) {
        String headerName = (String) header.nextElement();
        ret += headerName + ": " + request.getHeader(headerName) + "\n";
    }

    response.setContentType("text/plain");
    response.getWriter().write(ret);
}

From source file:com.indoqa.httpproxy.HttpClientProxy.java

private HttpUriRequest createProxyRequest(HttpServletRequest request) throws IOException {
    String url = this.createProxyUrl(request);
    String method = request.getMethod();

    HttpUriRequest proxyRequest = this.createProxyRequest(method, url);

    this.copyRequestHeaders(request, proxyRequest);
    this.copyRequestBody(request, proxyRequest);

    return proxyRequest;
}