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.ihandy.rbquote.controller.RbController.java

/**
 * ??//from w w  w  . ja va2 s  . c o  m
 *
 * @param LicenseNo
 * @param CityCode
 * @param CustKey
 * @param SecCode
 * @return
 */
@RequestMapping("/getRenewalInfo")
@Transactional
public void getRenewalInfo(HttpServletRequest request, HttpServletResponse response, String LicenseNo,
        int CityCode, String CustKey, String SecCode, String IsPublic) {
    if (request.getMethod().equals("GET")) {
        try {
            if (StringUtils.isNotBlank(LicenseNo)) {
                LicenseNo = new String(LicenseNo.getBytes("iso8859-1"), "GBK");
            }
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
    JSONObject renewalInfoJson = new JSONObject();
    try {
        renewalInfoJson = rbService.getRenewalInfo(LicenseNo, CityCode, CustKey, IsPublic);
        logger.info("? API?????LicenseNo" + LicenseNo);
    } catch (Exception e) {
        logger.info("? API????LicenseNo" + LicenseNo + ""
                + e.getMessage());
    }
    SpringMVCUtils.renderJson(response, renewalInfoJson);
}

From source file:com.silverpeas.web.UserPriviledgeValidation.java

/**
 * Validates the authorization of the specified user to access the specified attachment.
 *
 * @param request the HTTP request from which the authentication of the caller can be done.
 * @param user the user for whom the authorization has to be validated.
 * @param doc the document accessed./*from   w  w w. j  a v  a2  s  .c om*/
 * @throws WebApplicationException exception if the validation failed.
 */
public void validateUserAuthorizationOnAttachment(final HttpServletRequest request, final UserDetail user,
        SimpleDocument doc) throws WebApplicationException {
    AccessControlContext context = AccessControlContext.init();
    if (HttpMethod.PUT.equals(request.getMethod())) {
        context.onOperationsOf(AccessControlOperation.creation);
    } else if (HttpMethod.POST.equals(request.getMethod())) {
        context.onOperationsOf(AccessControlOperation.modification);
    } else if (HttpMethod.DELETE.equals(request.getMethod())) {
        context.onOperationsOf(AccessControlOperation.deletion);
    }
    if (!documentAccessController.isUserAuthorized(user.getId(), doc, context)) {
        throw new WebApplicationException(Response.Status.FORBIDDEN);
    }
}

From source file:com.honnix.yaacs.adapter.http.ACRequestHandler.java

public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch)
        throws IOException, ServletException {
    if (!ACHttpConstant.SUPPORTED_METHOD.equals(request.getMethod())) {
        createHeaderAndStatusResponse(response,
                new ACException(ACHttpError.WRONG_METHOD_MSG, ACHttpError.WRONG_METHOD));
        endOfResponse(response);/*  w  ww .  j a  va 2  s  . co m*/
    } else if (ACHttpPropertiesConstant.HTTP_SESSION_CONTROL_URL.equals(target)) {
        handleSession(request, response);
    } else if (ACHttpPropertiesConstant.HTTP_AC_REQUEST_URL.equals(target)) {
        handleAC(request, response);
    } else {
        createHeaderAndStatusResponse(response,
                new ACException(ACHttpError.WRONG_ULR_MSG, ACHttpError.WRONG_URL));
        endOfResponse(response);
    }

    ((Request) request).setHandled(true);
}

From source file:org.apache.hadoop.gateway.AuditLoggingTest.java

@Test
/**/*from   w w w. j a v a 2 s .c  om*/
 * One NoOp filter in chain. Single audit event with same with specified request URI is expected:
 * 
 * action=access request_type=uri outcome=unavailable
 */
public void testNoopFilter() throws ServletException, IOException, URISyntaxException {

    FilterConfig config = EasyMock.createNiceMock(FilterConfig.class);
    EasyMock.replay(config);

    HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class);
    ServletContext context = EasyMock.createNiceMock(ServletContext.class);
    GatewayConfig gatewayConfig = EasyMock.createNiceMock(GatewayConfig.class);
    EasyMock.expect(request.getMethod()).andReturn(METHOD).anyTimes();
    EasyMock.expect(request.getPathInfo()).andReturn(PATH).anyTimes();
    EasyMock.expect(request.getContextPath()).andReturn(CONTEXT_PATH).anyTimes();
    EasyMock.expect(request.getRemoteAddr()).andReturn(ADDRESS).anyTimes();
    EasyMock.expect(request.getRemoteHost()).andReturn(HOST).anyTimes();
    EasyMock.expect(request.getServletContext()).andReturn(context).anyTimes();
    EasyMock.expect(context.getAttribute(GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE)).andReturn(gatewayConfig)
            .anyTimes();
    EasyMock.expect(gatewayConfig.getHeaderNameForRemoteAddress()).andReturn("Custom-Forwarded-For").anyTimes();
    EasyMock.replay(request);
    EasyMock.replay(context);
    EasyMock.replay(gatewayConfig);

    HttpServletResponse response = EasyMock.createNiceMock(HttpServletResponse.class);
    EasyMock.replay(response);

    FilterChain chain = EasyMock.createNiceMock(FilterChain.class);
    EasyMock.replay(chain);

    Filter filter = EasyMock.createNiceMock(Filter.class);
    EasyMock.replay(filter);

    GatewayFilter gateway = new GatewayFilter();
    gateway.addFilter("path", "filter", filter, null, null);
    gateway.init(config);
    gateway.doFilter(request, response, chain);
    gateway.destroy();

    assertThat(CollectAppender.queue.size(), is(1));
    Iterator<LoggingEvent> iterator = CollectAppender.queue.iterator();
    LoggingEvent accessEvent = iterator.next();
    verifyAuditEvent(accessEvent, CONTEXT_PATH + PATH, ResourceType.URI, Action.ACCESS,
            ActionOutcome.UNAVAILABLE, null, "Request method: GET");

}

From source file:com.conwet.silbops.connectors.comet.CometAPIHandler.java

@Override
public void onRequest(AtmosphereResource<HttpServletRequest, HttpServletResponse> event) throws IOException {

    HttpServletRequest req = event.getRequest();
    HttpServletResponse res = event.getResponse();

    res.addHeader("Cache-Control", "max-age=0, no-cache, must-revalidate");
    res.addHeader("Expires", "Sat, 26 Jul 1997 05:00:00 GMT");

    String method = req.getMethod();

    if (method.equals("GET")) {
        onRequestGet(event);// w  w w .  j  a  v  a 2s  .c  o  m
    } else if (method.equals("POST")) {
        onRequestPost(event);
    } else if (method.equals("OPTIONS")) {
        onRequestOption(event);
    }
}

From source file:com.streamsets.pipeline.stage.origin.httpserver.PushHttpReceiver.java

protected Map<String, String> getCustomHeaderAttributes(HttpServletRequest req) {
    Map<String, String> customHeaderAttributes = new HashMap<>();
    customHeaderAttributes.put(PATH_HEADER, StringUtils.stripToEmpty(req.getServletPath()));
    customHeaderAttributes.put(QUERY_STRING_HEADER, StringUtils.stripToEmpty(req.getQueryString()));
    customHeaderAttributes.put(METHOD_HEADER, StringUtils.stripToEmpty(req.getMethod()));
    customHeaderAttributes.put(REMOTE_HOST, StringUtils.stripToEmpty(req.getRemoteHost()));
    Enumeration<String> headerNames = req.getHeaderNames();
    if (headerNames != null) {
        while (headerNames.hasMoreElements()) {
            String headerName = headerNames.nextElement();
            customHeaderAttributes.put(headerName, req.getHeader(headerName));
        }//from   w w  w  .j a  v  a2  s .  c o m
    }

    return customHeaderAttributes;
}

From source file:grails.web.servlet.mvc.GrailsParameterMap.java

/**
 * Creates a GrailsParameterMap populating from the given request object
 * @param request The request object// ww  w.  j av a  2s.  c om
 */
public GrailsParameterMap(HttpServletRequest request) {
    this.request = request;
    final Map requestMap = new LinkedHashMap(request.getParameterMap());
    if (requestMap.isEmpty() && ("PUT".equals(request.getMethod()) || "PATCH".equals(request.getMethod()))
            && request.getAttribute(REQUEST_BODY_PARSED) == null) {
        // attempt manual parse of request body. This is here because some containers don't parse the request body automatically for PUT request
        String contentType = request.getContentType();
        if ("application/x-www-form-urlencoded".equals(contentType)) {
            try {
                Reader reader = request.getReader();
                if (reader != null) {
                    String contents = IOUtils.toString(reader);
                    request.setAttribute(REQUEST_BODY_PARSED, true);
                    requestMap.putAll(WebUtils.fromQueryString(contents));
                }
            } catch (Exception e) {
                LOG.error("Error processing form encoded " + request.getMethod() + " request", e);
            }
        }
    }

    if (request instanceof MultipartHttpServletRequest) {
        Map<String, MultipartFile> fileMap = ((MultipartHttpServletRequest) request).getFileMap();
        for (Map.Entry<String, MultipartFile> entry : fileMap.entrySet()) {
            requestMap.put(entry.getKey(), entry.getValue());
        }
    }

    updateNestedKeys(requestMap);
}

From source file:org.bessle.neo4j.proxy.HttpRequestLoggingFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {

    HttpServletRequestWrapper wrappedRequest = new HttpServletRequestWrapper(request);
    Map<String, Object> trace = getTrace(wrappedRequest);
    if (this.logger.isTraceEnabled()) {
        this.logger.trace("Processing request " + request.getMethod() + " " + request.getRequestURI());
        if (this.dumpRequests) {
            @SuppressWarnings("unchecked")
            Map<String, Object> headers = (Map<String, Object>) trace.get("headers");
            this.logger.trace("Headers: " + headers);
            Object body = trace.get("body");
            this.logger.trace("Body: " + body.toString());
        }//from   w w  w  .j  a  v  a2s.com
    }

    try {
        filterChain.doFilter(wrappedRequest, response);
    } finally {
        enhanceTrace(trace, response);
    }
}

From source file:org.realityforge.proxy_servlet.AbstractProxyServlet.java

private HttpRequest newProxyRequest(final HttpServletRequest servletRequest, final String proxyRequestUri)
        throws IOException {
    final String method = servletRequest.getMethod();
    if (null != servletRequest.getHeader(HttpHeaders.CONTENT_LENGTH)
            || null != servletRequest.getHeader(HttpHeaders.TRANSFER_ENCODING)) {
        //spec: RFC 2616, sec 4.3: either of these two headers signal that there is a message body.
        final HttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest(method, proxyRequestUri);
        r.setEntity(new InputStreamEntity(servletRequest.getInputStream(), servletRequest.getContentLength()));
        return r;
    } else {//w  w w .jav a  2 s.  c o m
        return new BasicHttpRequest(method, proxyRequestUri);
    }
}

From source file:com.kolich.spring.interceptors.RequestPathInterceptor.java

@Override
public boolean preHandle(final HttpServletRequest request, final HttpServletResponse response,
        final Object handler) throws Exception {
    final String url = request.getRequestURL().toString();
    boolean found = false;
    for (final PathMapping pm : mappings_) {
        // Does the incoming request match the request of this mapping?
        if (pm.isWildcardMethod() || pm.getMethod().equalsIgnoreCase(request.getMethod())) {
            if (pm.getMatcher(url).find()) {
                found = true;//from w w w . j a  v a  2  s  . c om
                break;
            }
        }
    }
    // If we got here, and found is false, that means that the incoming
    // request path does not match any of our expected mappings.
    if (!found) {
        logger__.debug("No path mapping was found that matched " + "to URL: " + url);
        throw new InvalidResourceException("No path mapping was found " + "that matched to URL: " + url);
    }
    // Always return true.
    return true;
}