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.geocent.owf.openlayers.DataRequestProxy.java

/**
 * Gets the data from the provided remote URL.
 * Note that the data will be returned from the method and not automatically
 * populated into the response object.//from   w  ww. jav  a 2  s.  c o m
 * 
 * @param request       ServletRequest object containing the request data.
 * @param response      ServletResponse object for the response information.
 * @param url           URL from which the data will be retrieved.
 * @return              Data from the provided remote URL.
 * @throws IOException 
 */
public String getData(HttpServletRequest request, HttpServletResponse response, String url) throws IOException {

    if (!allowUrl(url)) {
        throw new UnknownHostException("Request to invalid host not allowed.");
    }

    HttpURLConnection connection = (HttpURLConnection) (new URL(url).openConnection());
    connection.setRequestMethod(request.getMethod());

    // Detects a request with a payload inside the message body
    if (request.getContentLength() > 0) {
        connection.setRequestProperty("Content-Type", request.getContentType());
        connection.setDoOutput(true);
        connection.setDoInput(true);
        byte[] requestPayload = IOUtils.toByteArray(request.getInputStream());
        connection.getOutputStream().write(requestPayload);
        connection.getOutputStream().flush();
    }

    // Create handler for the given content type and proxy the extracted information
    Handler contentHandler = HandlerFactory.getHandler(connection.getContentType());
    return contentHandler.handleContent(response, connection.getInputStream());
}

From source file:com.nominanuda.web.http.ServletHelper.java

public HttpRequest copyRequest(HttpServletRequest servletRequest, boolean stripContextPath) throws IOException {
    final InputStream is = getServletRequestBody(servletRequest);
    String method = servletRequest.getMethod();
    String uri = getRequestLineURI(servletRequest, stripContextPath);
    String ct = servletRequest.getContentType();
    @SuppressWarnings("unused")
    String charenc = getCharacterEncoding(servletRequest);
    String cenc = getContentEncoding(servletRequest);
    long contentLength = servletRequest.getContentLength();
    HttpRequest req;//w  w w  .jav a  2 s . c o m
    if (is == null) {
        req = new BasicHttpRequest(method, uri);
    } else {
        req = new BasicHttpEntityEnclosingRequest(method, uri);
        HttpEntity entity = buildEntity(servletRequest, is, contentLength, ct, cenc);
        if (entity != null) {
            ((BasicHttpEntityEnclosingRequest) req).setEntity(entity);
        }
    }
    Enumeration<?> names = servletRequest.getHeaderNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        Enumeration<?> vals = servletRequest.getHeaders(name);
        while (vals.hasMoreElements()) {
            String value = (String) vals.nextElement();
            req.addHeader(name, value);
        }
    }
    return req;
}

From source file:com.khs.sherpa.servlet.SherpaRequest.java

public void loadRequest(HttpServletRequest request, HttpServletResponse response) {

    String urlMethod = ReflectionCache.getUrlMethod(UrlUtil.getPath(request), request.getMethod());
    if (StringUtils.isNotEmpty(urlMethod)) {
        String[] str = StringUtils.split(urlMethod, ".");
        this.setEndpoint(str[0]);
        this.setAction(str[1]);
    } else {//from   w ww . j  a  v a2  s . c  o  m
        this.setEndpoint(request.getParameter("endpoint"));
        this.setAction(request.getParameter("action"));
    }

    this.setServletRequest(request);
    this.setServletResponse(response);
}

From source file:info.magnolia.voting.voters.RequestHasParametersVoter.java

@Override
protected boolean boolVote(Object value) {
    HttpServletRequest request;
    if (value instanceof HttpServletRequest) {
        request = (HttpServletRequest) value;
    } else {//  www. jav  a2s  .  c o  m
        if (MgnlContext.isWebContext()) {
            request = MgnlContext.getWebContext().getRequest();
        } else {
            return false;
        }
    }
    if (StringUtils.equalsIgnoreCase(request.getMethod(), "POST")) {
        return true;
    }

    if (!request.getParameterMap().isEmpty()) {
        return true;
    }

    return false;
}

From source file:it.geosolutions.httpproxy.callback.MethodsChecker.java

public void onRequest(HttpServletRequest request, HttpServletResponse response, URL url) throws IOException {
    Set<String> methods = config.getMethodsWhitelist();

    // ////////////////////////////////
    // Check the whitelist of methods
    // ////////////////////////////////

    if (methods != null && methods.size() > 0) {
        String method = request.getMethod();

        if (!methods.contains(method)) {
            throw new HttpErrorException(403,
                    "HTTP Method " + method + " is not among the ones allowed for this proxy");
        }/*  w  w  w .ja va  2s  .c o  m*/
    }
}

From source file:com.acc.storefront.filters.RequestLoggerFilter.java

protected String buildRequestDetails(final HttpServletRequest request) {
    String queryString = request.getQueryString();
    if (queryString == null) {
        queryString = "";
    }/*from   w  w  w  . j a  v a  2  s  . com*/

    final String requestUri = request.getRequestURI();

    final String securePrefix = request.isSecure() ? "s" : " ";
    final String methodPrefix = request.getMethod().substring(0, 1);

    return securePrefix + methodPrefix + " [" + requestUri + "] [" + queryString + "] ";
}

From source file:cn.guoyukun.spring.web.filter.DebugRequestAndResponseFilter.java

private void debugRequest(HttpServletRequest request) {
    log.debug("=====================request begin==========================");
    String uri = request.getRequestURI();
    String queryString = request.getQueryString();
    if (StringUtils.isNotBlank(queryString)) {
        uri = uri + "?" + queryString;
    }/*from  w w  w.ja  v  a2  s.co m*/
    log.debug("{}:{}", request.getMethod(), uri);
    log.debug("remote ip:{}  sessionId:{}  ", IpUtils.getIpAddr(request), request.getRequestedSessionId());
    log.debug("===header begin============================================");
    Enumeration<String> headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        String name = headerNames.nextElement();
        String value = headersToString(request.getHeaders(name));
        log.debug("{}={}", name, value);
    }
    log.debug("===header   end============================================");
    log.debug("===parameter begin==========================================");
    Enumeration<String> parameterNames = request.getParameterNames();
    while (parameterNames.hasMoreElements()) {
        String name = parameterNames.nextElement();
        String value = StringUtils.join(request.getParameterValues(name), "||");
        log.debug("{}={}", name, value);
    }
    log.debug("===parameter   end==========================================");
    log.debug("=====================request   end==========================");
}

From source file:com.scooterframework.web.controller.ScooterRequestFilter.java

/**
 * Returns the method of the <tt>request</tt>.
 *//*from   www.  ja v  a  2s .  co m*/
protected String getRequestMethod(HttpServletRequest request) {
    String m = request.getParameter(Constants.HTTP_METHOD);
    if (m == null) {
        m = request.getMethod();
    }
    return m.toUpperCase();
}

From source file:com.zimbra.cs.zimlet.ProxyServlet.java

private byte[] copyPostedData(HttpServletRequest req) throws IOException {
    int size = req.getContentLength();
    if (req.getMethod().equalsIgnoreCase("GET") || size <= 0) {
        return null;
    }//from w  w w . j  av  a  2  s  .  c  o m
    InputStream is = req.getInputStream();
    ByteArrayOutputStream baos = null;
    try {
        if (size < 0)
            size = 0;
        baos = new ByteArrayOutputStream(size);
        byte[] buffer = new byte[8192];
        int num;
        while ((num = is.read(buffer)) != -1) {
            baos.write(buffer, 0, num);
        }
        return baos.toByteArray();
    } finally {
        ByteUtil.closeStream(baos);
    }
}

From source file:com.globalsight.everest.webapp.pagehandler.administration.permission.PermissionGroupsHandler.java

/**
 * Remove Permission if there are no dependencies.
 *///from w ww .j  a v  a 2  s  . c o m
private void removePermissionGroup(HttpSession p_session, HttpServletRequest p_request)
        throws RemoteException, NamingException, GeneralException, ServletException {
    String ids = (String) p_request.getParameter("radioBtn");
    if (ids == null || p_request.getMethod().equalsIgnoreCase("get")) {
        return;
    }
    String[] idarr = ids.trim().split(" ");
    for (String id : idarr) {
        if ("on".equals(id))
            continue;
        PermissionGroup permGroup = Permission.getPermissionManager().readPermissionGroup(Long.parseLong(id));
        Permission.getPermissionManager().deletePermissionGroup(permGroup);

    }
}