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.gamewin.weixin.web.api.ApiListController.java

@RequestMapping(method = { RequestMethod.GET, RequestMethod.POST })
public void list(HttpServletRequest request, HttpServletResponse response) {
    System.out.println("chat");
    boolean isGet = request.getMethod().toLowerCase().equals("get");
    if (isGet) {/* w  w  w. j  a  va 2  s  .c om*/
        String signature = request.getParameter("signature");
        String timestamp = request.getParameter("timestamp");
        String nonce = request.getParameter("nonce");
        String echostr = request.getParameter("echostr");
        System.out.println(signature);
        System.out.println(timestamp);
        System.out.println(nonce);
        System.out.println(echostr);
        if (!StringUtils.isEmpty(signature) && !StringUtils.isEmpty(timestamp) && !StringUtils.isEmpty(nonce)
                && !StringUtils.isEmpty(echostr))
            access(request, response);
    } else {
        // POST??
        System.out.println("enter post");
        try {
            // ??
            acceptMessage(request, response);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}

From source file:com.db.comserv.main.utilities.HttpCaller.java

private int getQueryCost(HttpServletRequest request) {
    int multiplier = 1;
    if (request != null) {
        String reqAction = request.getMethod();
        final String url = request.getRequestURI().toString();
        String doubleReadTimeout = properties.getValue("doubleReadTimeout");
        String tripleReadTimeout = properties.getValue("tripleReadTimeout");

        if ("GET".equals(reqAction.toUpperCase()) && (url.contains("/metrics") || url.contains("/tops"))) {
            Long startTime = Utility.formatDate(request.getParameter("startTime"));
            Long endTime = Utility.formatDate(request.getParameter("endTime"));
            Long diff = (endTime - startTime) / (3600000 * 24); // diff in days
            if (diff >= 1 && diff < 7)
                multiplier = 2;//from  w  w  w .  j a v  a  2s  .com
            else if (diff >= 7)
                multiplier = 3;
        } else {
            if (matchPattern(url, doubleReadTimeout, reqAction))
                multiplier = 2;
            else if (matchPattern(url, tripleReadTimeout, reqAction))
                multiplier = 3;
        }
    }

    return multiplier;
}

From source file:com.primeleaf.krystal.web.action.cpanel.EditClassIndexesAction.java

public WebView execute(HttpServletRequest request, HttpServletResponse response) throws Exception {
    HttpSession session = request.getSession();
    User loggedInUser = (User) session.getAttribute(HTTPConstants.SESSION_KRYSTAL);

    if (request.getMethod().equalsIgnoreCase("POST")) {
        try {/*from  w w w  . j ava  2  s. c o  m*/
            String indexName = "";
            String indexDisplayName = "";
            String mandatory = "";
            String indexSequence = "";
            String defaultValue = "";
            short sequence = 0;

            int documentClassId = 0;
            try {
                documentClassId = Integer.parseInt(
                        request.getParameter("classid") != null ? request.getParameter("classid") : "0");
            } catch (Exception e) {
                request.setAttribute(HTTPConstants.REQUEST_ERROR, "Invalid input");
                return (new ManageDocumentClassesAction().execute(request, response));
            }
            DocumentClass documentClass = DocumentClassDAO.getInstance().readDocumentClassById(documentClassId);
            if (documentClass == null) {
                request.setAttribute(HTTPConstants.REQUEST_ERROR, "Invalid document class");
                return (new ManageDocumentClassesAction().execute(request, response));
            }

            int documentClassIndexCount = documentClass.getIndexCount();

            if (documentClassIndexCount > 0) {
                for (IndexDefinition indexDefinition : documentClass.getIndexDefinitions()) {
                    indexName = indexDefinition.getIndexColumnName();
                    indexDisplayName = request.getParameter(
                            "txtIndexDescription" + indexDefinition.getIndexColumnName() + "") != null
                                    ? request.getParameter(
                                            "txtIndexDescription" + indexDefinition.getIndexColumnName() + "")
                                    : "";
                    mandatory = request
                            .getParameter("" + indexDefinition.getIndexColumnName() + "radMandatory") != null
                                    ? request.getParameter(
                                            "" + indexDefinition.getIndexColumnName() + "radMandatory")
                                    : "";
                    indexSequence = request
                            .getParameter("" + indexDefinition.getIndexColumnName() + "sequence") != null
                                    ? request.getParameter(
                                            "" + indexDefinition.getIndexColumnName() + "sequence")
                                    : "";
                    defaultValue = request
                            .getParameter("txtDefaultValue" + indexDefinition.getIndexColumnName()) != null
                                    ? request.getParameter(
                                            "txtDefaultValue" + indexDefinition.getIndexColumnName())
                                    : "";

                    if (!GenericValidator.maxLength(indexDisplayName, 50)) {
                        request.setAttribute(HTTPConstants.REQUEST_ERROR, "Value too large for Index");
                        return (new ClassIndexesAction().execute(request, response));
                    }
                    if (!GenericValidator.maxLength(defaultValue, 255)) {
                        request.setAttribute(HTTPConstants.REQUEST_ERROR, "Value too large for default value");
                        return (new ClassIndexesAction().execute(request, response));
                    }

                    try {
                        sequence = Short.parseShort(indexSequence);
                    } catch (Exception e) {
                        request.setAttribute(HTTPConstants.REQUEST_ERROR, "Invalid input");
                        return (new ClassIndexesAction().execute(request, response));
                    }
                    if (sequence > documentClassIndexCount) {
                        request.setAttribute(HTTPConstants.REQUEST_ERROR, "Invalid input for Index Order");
                        return (new ClassIndexesAction().execute(request, response));
                    }

                    IndexDefinition newIndexDefinition = IndexDefinitionDAO.getInstance()
                            .readIndexDefinition(documentClass.getIndexId(), indexName);
                    newIndexDefinition.setMandatory("Y".equalsIgnoreCase(mandatory));
                    newIndexDefinition.setSequence(sequence);
                    newIndexDefinition.setIndexDisplayName(indexDisplayName);
                    newIndexDefinition.setDefaultValue(defaultValue);
                    IndexDefinitionDAO.getInstance().updateIndexDefinition(newIndexDefinition);
                }
                AuditLogManager.log(new AuditLogRecord(documentClass.getClassId(),
                        AuditLogRecord.OBJECT_DOCUMENTCLASS, AuditLogRecord.ACTION_EDITED,
                        loggedInUser.getUserName(), request.getRemoteAddr(), AuditLogRecord.LEVEL_INFO,
                        "Name : " + documentClass.getClassName(), "Indexes Updated"));
                request.setAttribute(HTTPConstants.REQUEST_MESSAGE,
                        "Document class indexes updated successfully");
                return (new ClassIndexesAction().execute(request, response));
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    return (new ClassIndexesAction().execute(request, response));
}

From source file:com.thoughtworks.go.server.GoServerContextHandlersTest.java

@Test
public void shouldNotRedirectNonCruiseRequestsToGoPage() throws IOException, ServletException {
    GoServer goServer = new GoServer(new SystemEnvironment(), new GoCipherSuite(sslSocketFactory),
            mock(GoWebXmlConfiguration.class));
    Handler legacyRequestHandler = goServer.legacyRequestHandler();
    HttpServletResponse response = mock(HttpServletResponse.class);

    when(response.getWriter()).thenReturn(new PrintWriter(new ByteArrayOutputStream()));

    HttpServletRequest req = mock(HttpServletRequest.class);
    when(req.getMethod()).thenReturn(HttpMethods.GET);
    legacyRequestHandler.handle("/cruise_but_not_quite", req, response, Handler.REQUEST);
    verifyNoMoreInteractions(response);/*from www .  j ava  2 s  .  c  o m*/
    legacyRequestHandler.handle("/something_totally_different", req, response, Handler.REQUEST);
    verifyNoMoreInteractions(response);
}

From source file:cat.calidos.morfeu.webapp.GenericHttpServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    String path = req.getPathInfo();
    log.trace("GenericMorfeuServlet::doGet {}", path);

    Map<String, String> params = normaliseParams(req.getParameterMap());
    params.put(METHOD, req.getMethod());
    params = processParams(params);/* w  ww  . j a va 2  s. c o m*/

    ControlComponent controlComponent = getControl(path, params);

    handleResponse(resp, controlComponent);

}

From source file:com.microsoft.applicationinsights.web.extensibility.modules.WebRequestTrackingTelemetryModuleTests.java

private ServletRequest createServletRequest(String queryString, String pathVariable) {
    HttpServletRequest request = mock(HttpServletRequest.class);

    String uri = DEFAULT_REQUEST_URI;
    if (pathVariable != null) {
        uri = uri.concat(pathVariable);//ww w  . j a v a2 s  .  c o m
    }

    when(request.getRequestURI()).thenReturn(uri);
    when(request.getMethod()).thenReturn(HttpMethods.GET);
    when(request.getScheme()).thenReturn("http");
    when(request.getHeader("Host")).thenReturn("localhost:1234");
    when(request.getQueryString()).thenReturn(queryString);

    return request;
}

From source file:cat.calidos.morfeu.webapp.GenericHttpServlet.java

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    String path = req.getPathInfo();
    log.trace("GenericMorfeuServlet::doPost {}", path);

    Map<String, String> params = normaliseParams(req.getParameterMap());
    params.put(METHOD, req.getMethod());
    String content = IOUtils.toString(req.getInputStream(), Config.DEFAULT_CHARSET);
    params.put(POST_VALUE, content);//ww  w  . j a va 2s .  c om
    params = processParams(params);

    ControlComponent controlComponent = putControl(path, params);
    handleResponse(resp, controlComponent);

}

From source file:com.globalsight.everest.webapp.pagehandler.administration.config.fileextension.FileExtensionMainHandler.java

private void removeFileExtension(HttpServletRequest p_request) {
    String ids = p_request.getParameter("checkboxBtn");
    try {/*  w  w w.j  a  v a 2s.  co  m*/
        if (ids == null || p_request.getMethod().equals("get")) {
            return;
        }
        String[] idarr = ids.trim().split(" ");
        for (String id : idarr) {
            FileExtensionImpl fileExtension = ServerProxy.getFileProfilePersistenceManager()
                    .getFileExtension(Long.valueOf(id));
            String deps = checkDependencies(fileExtension, p_request.getSession());
            if (deps == null) {
                ServerProxy.getFileProfilePersistenceManager().deleteFileExtension(fileExtension);
            } else {
                SessionManager sessionMgr = (SessionManager) p_request.getSession()
                        .getAttribute(WebAppConstants.SESSION_MANAGER);
                sessionMgr.setAttribute("dependencies", deps);
            }
        }
    } catch (Exception e) {
        throw new EnvoyServletException(e);
    }
}

From source file:com.talis.platform.testsupport.VerifyableHandler.java

@Override
public void handle(final String target, final HttpServletRequest req, final HttpServletResponse resp,
        final int dispatch) throws IOException, ServletException {
    try {/*w  w  w .  ja  v a 2s . co  m*/
        StubCallDefn defn = getExpectedCallDefn(target, req);
        if (defn == null) {
            assertionLog.append(String.format("Unexpected call: %s %s\n", req.getMethod(), target));
            fail("fail test, no more handlers");
        }

        assertEquals(defn.getExpectedPath(), target);
        assertEquals(defn.getExpectedMethod(), req.getMethod());

        BufferedReader reader = req.getReader();

        String entity = IOUtils.toString(reader);
        assertEquals(defn.getExpectedEntity(), entity);

        for (String key : defn.getHeaders().keySet()) {
            String expected = defn.getHeaders().get(key);
            String value = req.getHeader(key);
            assertEquals("Headers don't match for header " + key, expected, value);
        }

        resp.setStatus(defn.getExpectedReturnStatus());
        resp.setHeader("Content-Type", defn.getExpectedReturnType());
        Map<String, String> returnHeaders = defn.getReturnHeaders();
        if (null != returnHeaders) {
            for (Entry<String, String> header : returnHeaders.entrySet()) {
                resp.setHeader(header.getKey(), header.getValue());
            }
        }

        byte[] expectedReturnEntity = defn.getExpectedReturnEntity();
        if (expectedReturnEntity != null) {
            resp.getOutputStream().write(expectedReturnEntity);
        }
        resp.flushBuffer();
    } catch (RuntimeException t) {
        isOk.set(false);
        assertionLog.append(t.getStackTrace());
        assertionLog.append('\n');
        throw t;
    } catch (Error t) {
        isOk.set(false);
        assertionLog.append(t.getMessage());
        assertionLog.append('\n');
        throw t;
    }
}