List of usage examples for javax.servlet.http HttpServletRequest getMethod
public String getMethod();
From source file:com.headissue.pigeon.PigeonContainer.java
@Override public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException { long dtStart = System.currentTimeMillis(); HttpServletRequest httpReq = (HttpServletRequest) req; if (log.isTraceEnabled()) { LogUtils.trace(log, "%s '%s'", httpReq.getMethod(), httpReq.getRequestURI()); Enumeration<String> en = httpReq.getHeaderNames(); while (en.hasMoreElements()) { String name = en.nextElement(); String value = httpReq.getHeader(name); LogUtils.trace(log, "request header '%s=%s'", name, value); }/* w w w.j a va 2 s . c o m*/ LogUtils.trace(log, "locale=%s", req.getLocale()); } super.service(req, res); // how long? LogUtils.debug(log, "%s '%s' in msecs %s", httpReq.getMethod(), httpReq.getRequestURI(), System.currentTimeMillis() - dtStart); }
From source file:io.lavagna.web.security.login.DemoLogin.java
@Override public boolean doAction(HttpServletRequest req, HttpServletResponse resp) throws IOException { if (!"POST".equalsIgnoreCase(req.getMethod())) { return false; }//from w ww . j a v a2 s . c o m String username = req.getParameter("username"); String password = req.getParameter("password"); // yes, it's stupid... if (username != null && username.equals(password) && users.userExistsAndEnabled(USER_PROVIDER, username)) { // FIXME refactor out String url = Redirector.cleanupRequestedUrl(req.getParameter("reqUrl"), req); User user = users.findUserByName(USER_PROVIDER, username); sessionHandler.setUser(user.getId(), user.isAnonymous(), req, resp); Redirector.sendRedirect(req, resp, url, Collections.<String, List<String>>emptyMap()); } else { if (sessionHandler.isLocked(req)) { Redirector.sendRedirect(req, resp, req.getContextPath() + "/" + "lockScreen?error-demo", Collections.<String, List<String>>emptyMap()); return true; } Redirector.sendRedirect(req, resp, req.getContextPath() + "/" + removeStart(errorPage, "/"), Collections.<String, List<String>>emptyMap()); } return true; }
From source file:com.brandseye.cors.CorsCompatibleBasicAuthenticationEntryPoint.java
@Override public void commence(final HttpServletRequest request, final HttpServletResponse response, final AuthenticationException authException) throws IOException, ServletException { if (!request.getMethod().equals("OPTIONS")) { super.commence(request, response, authException); }//from www .j a v a 2s . com }
From source file:org.osiam.security.helper.LoginDecisionFilter.java
@Override public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) { if (postOnly && !request.getMethod().equals("POST")) { throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod()); }//from ww w.ja v a 2 s. com UsernamePasswordAuthenticationToken authRequest = null; String username = request.getParameter(getUsernameParameter()); String password = request.getParameter(getPasswordParameter()); if (username == null) { username = ""; } if (password == null) { password = ""; } username = username.trim(); String provider = request.getParameter("provider"); if (!Strings.isNullOrEmpty(provider) && provider.equals("ldap")) { authRequest = new OsiamLdapAuthentication(username, password); } else { authRequest = new InternalAuthentication(username, password, new ArrayList<GrantedAuthority>()); } setDetails(request, authRequest); return this.getAuthenticationManager().authenticate(authRequest); }
From source file:com.k42b3.quantum.handler.MessageHandler.java
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (request.getMethod().equals("GET")) { response.setStatus(HttpServletResponse.SC_OK); response.setContentType("application/json;charset=utf-8"); baseRequest.setHandled(true);//from w ww . ja v a 2 s.c o m try { String modifiedSince = request.getHeader("If-Modified-Since"); Date date = null; if (modifiedSince != null && !modifiedSince.isEmpty()) { date = DateUtils.parseDate(modifiedSince); } response.getWriter() .print(container.getGson().toJson(container.getMessageRepository().getAll(date))); } catch (SQLException e) { this.handleException(response, e); } } else if (request.getMethod().equals("POST")) { Message message = container.getGson().fromJson(readRequestBody(request), Message.class); container.getEventPublisher().publish(null, message); response.setContentType("application/json;charset=utf-8"); response.setStatus(HttpServletResponse.SC_CREATED); response.getWriter().print(container.getGson().toJson(message)); } }
From source file:org.esigate.servlet.MockHttpServletRequestBuilder.java
/** * Build the request as defined in the current builder. * //ww w. j a v a 2 s. co m * @return the request */ public HttpServletRequest build() { HttpServletRequest request = Mockito.mock(HttpServletRequest.class); Mockito.when(request.getMethod()).thenReturn(this.method); Mockito.when(request.getProtocol()).thenReturn(this.protocolVersion); Mockito.when(request.getRequestURI()).thenReturn(this.uriString); Mockito.when(request.getHeaderNames()).thenReturn(Collections.enumeration(headers)); for (Header h : headers) { List<String> hresult = new ArrayList<String>(); hresult.add(h.getValue()); Mockito.when(request.getHeaders(h.getName())).thenReturn(Collections.enumeration(hresult)); Mockito.when(request.getHeader(h.getName())).thenReturn(h.getValue()); } if (session == null) { Mockito.when(request.getSession()).thenReturn(null); } else { HttpSession sessionMock = Mockito.mock(HttpSession.class); Mockito.when(request.getSession()).thenReturn(sessionMock); } return request; }
From source file:edu.umn.msi.tropix.transfer.http.server.HttpTransferControllerImpl.java
public ModelAndView handleRequest(final HttpServletRequest request, final HttpServletResponse response) throws ServletException { final String method = request.getMethod(); if (method.equals("POST")) { doPost(request, response);/* ww w. java 2s . co m*/ } else { doGet(request, response); } return null; }
From source file:uk.org.iay.mdq.server.RequestLogger.java
@Override protected String createMessage(HttpServletRequest request, String prefix, String suffix) { final StringBuilder msg = new StringBuilder(); msg.append(prefix);//from w w w .j av a2 s.c o m msg.append(request.getMethod()); msg.append(" for '").append(request.getRequestURI()).append("'"); if (isIncludeClientInfo()) { final String client = request.getRemoteAddr(); msg.append(" from ").append(client); } msg.append(suffix); return msg.toString(); }
From source file:com.ccc.webapp.http.mappers.MappingJacksonJsonpView.java
/** * Prepares the view given the specified model, merging it with static * attributes and a RequestContext attribute, if necessary. * Delegates to renderMergedOutputModel for the actual rendering. * @see #renderMergedOutputModel/* www. j av a 2 s. c o m*/ */ @Override public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) throws Exception { if ("GET".equals(request.getMethod().toUpperCase())) { @SuppressWarnings("unchecked") Map<String, String[]> params = request.getParameterMap(); if (params.containsKey("callback")) { response.getOutputStream().write(new String(params.get("callback")[0] + "(").getBytes()); super.render(model, request, response); response.getOutputStream().write(new String(");").getBytes()); response.setContentType("application/javascript"); } else { super.render(model, request, response); } } else { super.render(model, request, response); } }
From source file:org.keycloak.adapters.springsecurity.filter.DirectAccessGrantLoginFilter.java
@Override public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException { if (postOnly && !request.getMethod().equals("POST")) { throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod()); }/*from ww w. j a v a 2 s. c o m*/ String username = obtainUsername(request); String password = obtainPassword(request); if (username == null) { username = ""; } if (password == null) { password = ""; } username = username.trim(); DirectAccessGrantToken authRequest = new DirectAccessGrantToken(username, password); // Allow subclasses to set the "details" property setDetails(request, authRequest); return this.getAuthenticationManager().authenticate(authRequest); }