List of usage examples for javax.servlet.http HttpServletRequest getAttribute
public Object getAttribute(String name);
Object
, or null
if no attribute of the given name exists. From source file:net.prasenjit.auth.config.CsrfCookieGeneratorFilter.java
/** * {@inheritDoc}/*w w w. ja v a 2 s . c om*/ */ @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { // Spring put the CSRF token in session attribute "_csrf" CsrfToken csrfToken = (CsrfToken) request.getAttribute("_csrf"); // Send the cookie only if the token has changed String actualToken = request.getHeader("X-XSRF-TOKEN"); if (actualToken == null || !actualToken.equals(csrfToken.getToken())) { // Session cookie that will be used by AngularJS String pCookieName = "XSRF-TOKEN"; Cookie cookie = new Cookie(pCookieName, csrfToken.getToken()); cookie.setMaxAge(-1); cookie.setHttpOnly(false); cookie.setPath("/"); response.addCookie(cookie); } filterChain.doFilter(request, response); }
From source file:org.dspace.webmvc.controller.ResourceController.java
protected LookupResult lookup(HttpServletRequest req) { LookupResult r = (LookupResult) req.getAttribute("lookupResult"); if (r == null) { r = lookupNoCache(req);/*from w w w .j a v a 2s . c om*/ req.setAttribute("lookupResult", r); } return r; }
From source file:sample.UserAccountsFilter.java
@SuppressWarnings("unchecked") public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; // tag::HttpSessionManager[] HttpSessionManager sessionManager = (HttpSessionManager) httpRequest .getAttribute(HttpSessionManager.class.getName()); // end::HttpSessionManager[] SessionRepository<Session> repo = (SessionRepository<Session>) httpRequest .getAttribute(SessionRepository.class.getName()); String currentSessionAlias = sessionManager.getCurrentSessionAlias(httpRequest); Map<String, String> sessionIds = sessionManager.getSessionIds(httpRequest); String unauthenticatedAlias = null; String contextPath = httpRequest.getContextPath(); List<Account> accounts = new ArrayList<Account>(); Account currentAccount = null;//from w ww. j ava2 s .co m for (Map.Entry<String, String> entry : sessionIds.entrySet()) { String alias = entry.getKey(); String sessionId = entry.getValue(); Session session = repo.getSession(sessionId); if (session == null) { continue; } String username = session.getAttribute("username"); if (username == null) { unauthenticatedAlias = alias; continue; } String logoutUrl = sessionManager.encodeURL("./logout", alias); String switchAccountUrl = sessionManager.encodeURL("./", alias); Account account = new Account(username, logoutUrl, switchAccountUrl); if (currentSessionAlias.equals(alias)) { currentAccount = account; } else { accounts.add(account); } } // tag::addAccountUrl[] String addAlias = unauthenticatedAlias == null ? // <1> sessionManager.getNewSessionAlias(httpRequest) : // <2> unauthenticatedAlias; // <3> String addAccountUrl = sessionManager.encodeURL(contextPath, addAlias); // <4> // end::addAccountUrl[] httpRequest.setAttribute("currentAccount", currentAccount); httpRequest.setAttribute("addAccountUrl", addAccountUrl); httpRequest.setAttribute("accounts", accounts); chain.doFilter(request, response); }
From source file:com.osafe.events.CheckOutEvents.java
public static String setShipOptions(HttpServletRequest request, HttpServletResponse response) { LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher"); Delegator delegator = (Delegator) request.getAttribute("delegator"); Locale locale = UtilHttp.getLocale(request); ShoppingCart cart = ShoppingCartEvents.getCartObject(request); try {//from w w w . j a v a 2 s .co m for (int i = 0; i < cart.getShipInfoSize(); i++) { CartShipInfo shipInfo = cart.getShipInfo(i); String shippingMethod = request.getParameter("shipping_method_" + i); if (UtilValidate.isNotEmpty(shippingMethod) && shippingMethod.indexOf("@") != -1) { String shipmentMethodTypeId = shippingMethod.substring(0, shippingMethod.indexOf("@")); String carrierPartyId = shippingMethod.substring(shippingMethod.indexOf("@") + 1); cart.setShipmentMethodTypeId(i, shipmentMethodTypeId); cart.setCarrierPartyId(i, carrierPartyId); } } if (cart.getShipInfoSize() > 1) { cart.setOrderAttribute("DELIVERY_OPTION", "SHIP_TO_MULTI"); } else { cart.setOrderAttribute("DELIVERY_OPTION", "SHIP_TO"); } } catch (Exception e) { Debug.logError(e, "Error: Setting Multi Ship Groups", module); } return "success"; }
From source file:com.app.controller.interceptor.AuthenticationInterceptor.java
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { Subject currentUser = SecurityUtils.getSubject(); if (!currentUser.isAuthenticated()) { String originalUrl = (String) request .getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE); WebUtils.setSessionAttribute(request, "redirect", originalUrl); response.sendRedirect("log_in"); return false; }// w w w. j a v a 2 s. co m return true; }
From source file:de.innovationgate.wgpublisher.WGPRequestPath.java
public static URL buildCompleteURL(HttpServletRequest request) throws MalformedURLException, URIException { StringBuffer url = new StringBuffer(); url.append((String) request.getAttribute(WGAFilter.REQATTRIB_ORIGINAL_URL)); String qs = request.getQueryString(); if (qs != null) { url.append("?").append(qs); }//from w ww .j a v a 2s .co m return new URL(url.toString()); }
From source file:info.magnolia.cms.servlets.ResourceDispatcher.java
/** * Get the requested resource and copy it to the ServletOutputStream, bit by bit. * * @param req HttpServletRequest as given by the servlet container * @param res HttpServletResponse as given by the servlet container * @throws IOException standard servlet exception *///from www . j a va 2s . com private void handleResourceRequest(HttpServletRequest req, HttpServletResponse res) throws IOException { String resourceHandle = (String) req.getAttribute(Aggregator.HANDLE); if (log.isDebugEnabled()) { log.debug("handleResourceRequest, resourceHandle=\"" + resourceHandle + "\""); //$NON-NLS-1$ //$NON-NLS-2$ } if (StringUtils.isNotEmpty(resourceHandle)) { HierarchyManager hm = (HierarchyManager) req.getAttribute(Aggregator.HIERARCHY_MANAGER); InputStream is = null; try { is = getNodedataAstream(resourceHandle, hm, res); if (null != is) { // todo find better way to discover if resource could be compressed, implement as in "cache" // browsers will always send header saying either it can decompress or not, but // resources like jpeg which is already compressed should be not be written on // zipped stream otherwise some browsers takes a long time to render sendUnCompressed(is, res); IOUtils.closeQuietly(is); return; } } catch (IOException e) { // don't log at error level since tomcat tipically throws a // org.apache.catalina.connector.ClientAbortException if the user stops loading the page if (log.isDebugEnabled()) log.debug("Exception while dispatching resource " + e.getClass().getName() + ": " //$NON-NLS-1$//$NON-NLS-2$ + e.getMessage(), e); } catch (Exception e) { log.error("Exception while dispatching resource " + e.getClass().getName() + ": " + e.getMessage(), //$NON-NLS-1$//$NON-NLS-2$ e); } finally { IOUtils.closeQuietly(is); } } if (log.isDebugEnabled()) { log.debug("Resource not found, redirecting request for [" + req.getRequestURI() + "] to 404 URI"); //$NON-NLS-1$ } if (!res.isCommitted()) { res.sendError(HttpServletResponse.SC_NOT_FOUND); } else { log.info("Unable to redirect to 404 page, response is already committed"); //$NON-NLS-1$ } }
From source file:com.orange.ngsi.client.NgsiClient.java
private boolean isJsonContentType(HttpServletRequest request) { boolean result = false; if (request != null && request.getAttribute("Content-Type") != null && request.getAttribute("Content-Type").equals("application/json")) { result = true;//from w w w . j a v a 2s .c o m } return result; }
From source file:com.pkrete.locationservice.admin.controller.rest.v1.SubjectMattersRestController.java
@RequestMapping(method = RequestMethod.GET, produces = "application/json; charset=utf-8") @ResponseBody/* w w w. j av a 2 s.com*/ public List index(HttpServletRequest request) { // Get Owner object related to the user Owner owner = (Owner) request.getAttribute("owner"); // Get list of subject matters related to the Owner List subjects = this.subjectMattersService.getSubjectMattersWithLanguage(owner); // Return the list return this.mapConverter.convert(subjects); }
From source file:com.adito.setup.actions.SessionInformationAction.java
/** * @param mapping//from w w w . j av a 2s. c o m * @param form * @param request * @param response * @return ActionForward * @throws Exception */ public ActionForward sessionInformation(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { SessionInformationForm informationForm = (SessionInformationForm) form; SessionInfo session = (SessionInfo) request.getAttribute(Constants.REQ_ATTR_INFO_RESOURCE); informationForm.initialise(session); return mapping.findForward("display"); }