List of usage examples for javax.servlet ServletRequest getAttribute
public Object getAttribute(String name);
Object
, or null
if no attribute of the given name exists. From source file:org.opencms.jsp.util.CmsJspStandardContextBean.java
/** * Creates a new standard JSP context bean. * /*from ww w . j ava 2s .c o m*/ * @param req the current servlet request */ private CmsJspStandardContextBean(ServletRequest req) { CmsFlexController controller = CmsFlexController.getController(req); CmsObject cms; if (controller != null) { cms = controller.getCmsObject(); } else { cms = (CmsObject) req.getAttribute(ATTRIBUTE_CMS_OBJECT); } if (cms == null) { // cms object unavailable - this request was not initialized properly throw new CmsRuntimeException( Messages.get().container(Messages.ERR_MISSING_CMS_CONTROLLER_1, CmsJspBean.class.getName())); } updateCmsObject(cms); m_detailContentResource = CmsDetailPageResourceHandler.getDetailResource(req); }
From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo.java
/** * The editKey can be a HTTP query parameter or it can be a request attribute. *///from w w w. j a v a 2 s . co m public static String getEditKeyFromRequest(ServletRequest request) { String key = null; if (request instanceof VitroRequest) { return request.getParameter("editKey"); } else if (request instanceof HttpServletRequest) { HttpServletRequest hsreq = (HttpServletRequest) request; boolean isMultipart = ServletFileUpload.isMultipartContent(hsreq); if (isMultipart) { //multipart parsing will consume all request parameters so //the editKey needs to be stashed in the request attributes. key = (String) request.getAttribute("editKey"); if (key == null) { // handle the cancel button where nothing is really uploaded key = request.getParameter("editKey"); } } else { key = (String) request.getAttribute("editKey"); if (key != null) { return key; } else { key = request.getParameter("editKey"); } } } if (key != null && key.trim().length() > 0) { return key; } else { log.debug("cannnot find editKey in request query parameters or from request"); return null; } }
From source file:com.jaspersoft.jasperserver.war.tags.BaseTagSupport.java
protected Map setRequestAttributes(Map attributes) { ServletRequest request = pageContext.getRequest(); Set attributeNames = new HashSet(); for (Enumeration it = request.getAttributeNames(); it.hasMoreElements();) { String attribute = (String) it.nextElement(); attributeNames.add(attribute);//from w w w. j a v a2s . c o m } Map restoreMap = new HashMap(); for (Iterator it = attributes.entrySet().iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry) it.next(); String attribute = (String) entry.getKey(); Object value = entry.getValue(); Object restoreValue; if (attributeNames.contains(attribute)) { restoreValue = request.getAttribute(attribute); } else { restoreValue = NO_ATTRIBUTE; } restoreMap.put(attribute, restoreValue); request.setAttribute(attribute, value); } return restoreMap; }
From source file:com.hp.autonomy.frontend.find.hod.web.SsoController.java
@RequestMapping(value = SSO_LOGOUT_PAGE, method = RequestMethod.GET) public ModelAndView ssoLogoutPage(final ServletRequest request) throws JsonProcessingException { final HodFindConfig hodFindConfig = configService.getConfig(); final Map<String, Object> ssoConfig = new HashMap<>(); ssoConfig.put(SsoMvcConstants.LOGOUT_ENDPOINT.value(), logoutEndpoint); ssoConfig.put(SsoMvcConstants.LOGOUT_REDIRECT_URL.value(), hodFindConfig.getHsod().getExternalUrl() + FindController.APP_PATH); final Map<String, Object> attributes = new HashMap<>(); attributes.put(MvcConstants.GIT_COMMIT.value(), gitCommit); attributes.put(MvcConstants.CONFIG.value(), controllerUtils.convertToJson(ssoConfig)); attributes.put(ControllerUtils.SPRING_CSRF_ATTRIBUTE, request.getAttribute(ControllerUtils.SPRING_CSRF_ATTRIBUTE)); return new ModelAndView(ViewNames.SSO_LOGOUT.viewName(), attributes); }
From source file:org.acmsl.commons.utils.http.HttpServletUtils.java
/** * Retrieves an object from the repository. * @param key the key./*from www.j a v a 2s . c o m*/ * @param request the request. * @param session the session. * @param context the context. * @return the object if it's found. */ @Nullable public Object retrieve(@NotNull final String key, @Nullable final ServletRequest request, @Nullable final HttpSession session, @Nullable final ServletContext context) { @Nullable Object result = null; // Thanks Sun for had missed an interface for // all classes that export setAttribute(). if (request != null) { result = request.getAttribute(key); } if ((result == null) && (session != null)) { result = session.getAttribute(key); } if ((result == null) && (context != null)) { result = context.getAttribute(key); } return result; }
From source file:filters.ActionValidationFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpServletRequest = (HttpServletRequest) request; String requPath = httpServletRequest.getServletPath(); /*//from w w w. j a v a 2s . co m * ignore resource files (CSS, JPEG/PNG, JavaScript) ... */ if (requPath.startsWith(STATIC_RESOURCES) || requPath.startsWith(API)) { chain.doFilter(request, response); return; } /* * This filter makes only sense, if user is logged in. */ User user = AuthenticationUtils.getUser(); if (user != null && user.getName() != null) { /* * get sessions credential storage variable */ String storedCredential = (String) request.getAttribute(REQUEST_ATTRIB_CREDENTIAL); /* * if null, create new one */ if (storedCredential == null) { storedCredential = getNewCredential(user, httpServletRequest.getSession()); request.setAttribute(REQUEST_ATTRIB_CREDENTIAL, storedCredential); } log.debug("credential for " + user.getName() + " = " + storedCredential); /* * get credential from request parameter * * FIXME: This does not work with multipart-requests! Thus, on such * requests we must otherwise send the ckey. */ String requestCredential = request.getParameter(REQUEST_PARAM_CREDENTIAL); /* * check and propagate correctness */ request.setAttribute(REQUEST_ATTRIB_VALID_CREDENTIAL, storedCredential.equals(requestCredential)); } // Pass control on to the next filter chain.doFilter(request, response); }
From source file:org.apache.vysper.xmpp.extension.xep0124.BoshBackedSessionContext.java
protected void handleAsyncEventError(AsyncEvent event) { final ServletRequest suppliedRequest = event.getSuppliedRequest(); final ServletResponse suppliedResponse = event.getSuppliedResponse(); BoshRequest boshRequest = (BoshRequest) suppliedRequest.getAttribute(BOSH_REQUEST_ATTRIBUTE); BoshResponse boshResponse = (BoshResponse) suppliedRequest.getAttribute(BOSH_RESPONSE_ATTRIBUTE); // works at least for jetty: final Exception exceptionObject = (Exception) suppliedRequest.getAttribute("javax.servlet.error.exception"); final Throwable throwable = event.getThrowable() != null ? event.getThrowable() : exceptionObject; final Long rid = boshRequest == null ? null : boshRequest.getRid(); LOGGER.warn("SID = " + getSessionId() + " - JID = " + getInitiatingEntity() + " - RID = " + rid + " - async error on event ", event.getClass(), throwable); }
From source file:com.adito.vfs.webdav.DAVServlet.java
public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException { HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse res = (HttpServletResponse) response; debugRequest(req);/* ww w . j a va 2s . c om*/ DAVTransaction transaction = null; try { transaction = new DAVTransaction(req, res); DAVProcessor processor = null; try { processor = DAVServlet.getDAVProcessor(req); } catch (CoreException e) { ActionMessages mesgs = (ActionMessages) request.getAttribute(Globals.ERROR_KEY); if (mesgs == null) { mesgs = new ActionMessages(); request.setAttribute(Globals.ERROR_KEY, mesgs); } mesgs.add(Globals.MESSAGE_KEY, e.getBundleActionMessage()); return; } catch (Exception e1) { throw new IOException(e1.getMessage()); } /** * LDP - JB I have removed the authentication code here and instead * placed in DAVTransaction. This allows the transaction to * correctly obtain sessionInfo through WEBDav. */ /* Mark our presence */ res.setHeader("Server", this.context.getServerInfo() + " WebDAV"); res.setHeader("MS-Author-Via", "DAV"); res.setHeader("DAV", "1"); /* * Get the current SessionInfo if possible, but do not request * authentication yet This is because the VFSResource that we want * is in a mount that does not require Adito authentication * (required for some ActiveX and Applet extensions). * * SessionInfo will be null if session can yet be determined */ if (!transaction.attemptToAuthorize()) { return; } SessionInfo sessionInfo = transaction.getSessionInfo(); // Timeout block is not needed if we have no session int timeoutId = sessionInfo == null ? -1 : LogonControllerFactory.getInstance().addSessionTimeoutBlock( transaction.getSessionInfo().getHttpSession(), "DAV Transaction"); ; try { processor.process(transaction); } catch (DAVAuthenticationRequiredException dare) { /* * If the session is temporary, then we are probably dealing * with a client that doesn't support cookies. This means that * secondary authentication that may be required for some mounts * won't work as we cannot have two different sets of * credentials without session tracking */ if (sessionInfo != null && sessionInfo.isTemporary()) { throw new IOException("Mount requires further authentication. This cannot work " + "on WebDAV clients that do not support cookies."); } else { throw dare; } } finally { if (timeoutId != -1) LogonControllerFactory.getInstance() .removeSessionTimeoutBlock(transaction.getSessionInfo().getHttpSession(), timeoutId); } } catch (DAVRedirection redir) { String redirPath = "/fs" + redir.getLocation().getFullPath(); req.getRequestDispatcher(redirPath).forward(req, res); } catch (DAVAuthenticationRequiredException e) { // We need to be able to authenticate the Adito session was // well // sendAuthorizationError(req, res, e.getMount().getMountString()); sendAuthorizationError(req, res, e.getHttpRealm()); } catch (DAVBundleActionMessageException ex) { log.error("Network Places Request Failed: " + req.getPathInfo(), ex); BundleActionMessage bam = ex.getBundleActionMessage(); MessageResources mr = CoreUtil.getMessageResources(req.getSession(), bam.getBundle()); // TODO locale String val = mr == null ? null : mr.getMessage(bam.getKey()); res.sendError(DAVStatus.SC_INTERNAL_SERVER_ERROR, val == null ? (ex.getMessage() == null ? "No message supplied." : ex.getMessage()) : val); } catch (DAVException ex) { res.setStatus(ex.getStatus()); } catch (LockedException ex) { res.sendError(DAVStatus.SC_LOCKED, ex.getMessage()); } catch (Throwable t) { log.error("Network Places Request Failed: " + req.getPathInfo(), t); res.sendError(DAVStatus.SC_INTERNAL_SERVER_ERROR, t.getMessage() == null ? "<null>" : t.getMessage()); } finally { if (transaction != null && transaction.getSessionInfo() != null && transaction.getSessionInfo().isTemporary()) { transaction.getSessionInfo().getHttpSession().invalidate(); } } }
From source file:com.sslexplorer.vfs.webdav.DAVServlet.java
public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException { HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse res = (HttpServletResponse) response; debugRequest(req);/* w w w. j a va 2 s .c o m*/ DAVTransaction transaction = null; try { transaction = new DAVTransaction(req, res); DAVProcessor processor = null; try { processor = DAVServlet.getDAVProcessor(req); } catch (CoreException e) { ActionMessages mesgs = (ActionMessages) request.getAttribute(Globals.ERROR_KEY); if (mesgs == null) { mesgs = new ActionMessages(); request.setAttribute(Globals.ERROR_KEY, mesgs); } mesgs.add(Globals.MESSAGE_KEY, e.getBundleActionMessage()); return; } catch (Exception e1) { throw new IOException(e1.getMessage()); } /** * LDP - JB I have removed the authentication code here and instead * placed in DAVTransaction. This allows the transaction to * correctly obtain sessionInfo through WEBDav. */ /* Mark our presence */ res.setHeader("Server", this.context.getServerInfo() + " WebDAV"); res.setHeader("MS-Author-Via", "DAV"); res.setHeader("DAV", "1"); /* * Get the current SessionInfo if possible, but do not request * authentication yet This is because the VFSResource that we want * is in a mount that does not require SSL-Explorer authentication * (required for some ActiveX and Applet extensions). * * SessionInfo will be null if session can yet be determined */ if (!transaction.attemptToAuthorize()) { return; } SessionInfo sessionInfo = transaction.getSessionInfo(); // Timeout block is not needed if we have no session int timeoutId = sessionInfo == null ? -1 : LogonControllerFactory.getInstance().addSessionTimeoutBlock( transaction.getSessionInfo().getHttpSession(), "DAV Transaction"); ; try { processor.process(transaction); } catch (DAVAuthenticationRequiredException dare) { /* * If the session is temporary, then we are probably dealing * with a client that doesn't support cookies. This means that * secondary authentication that may be required for some mounts * won't work as we cannot have two different sets of * credentials without session tracking */ if (sessionInfo != null && sessionInfo.isTemporary()) { throw new IOException("Mount requires further authentication. This cannot work " + "on WebDAV clients that do not support cookies."); } else { throw dare; } } finally { if (timeoutId != -1) LogonControllerFactory.getInstance() .removeSessionTimeoutBlock(transaction.getSessionInfo().getHttpSession(), timeoutId); } } catch (DAVRedirection redir) { String redirPath = "/fs" + redir.getLocation().getFullPath(); req.getRequestDispatcher(redirPath).forward(req, res); } catch (DAVAuthenticationRequiredException e) { // We need to be able to authenticate the SSL-Explorer session was // well // sendAuthorizationError(req, res, e.getMount().getMountString()); sendAuthorizationError(req, res, e.getHttpRealm()); } catch (DAVBundleActionMessageException ex) { log.error("Network Places Request Failed: " + req.getPathInfo(), ex); BundleActionMessage bam = ex.getBundleActionMessage(); MessageResources mr = CoreUtil.getMessageResources(req.getSession(), bam.getBundle()); // TODO locale String val = mr == null ? null : mr.getMessage(bam.getKey()); res.sendError(DAVStatus.SC_INTERNAL_SERVER_ERROR, val == null ? (ex.getMessage() == null ? "No message supplied." : ex.getMessage()) : val); } catch (DAVException ex) { res.setStatus(ex.getStatus()); } catch (LockedException ex) { res.sendError(DAVStatus.SC_LOCKED, ex.getMessage()); } catch (Throwable t) { log.error("Network Places Request Failed: " + req.getPathInfo(), t); res.sendError(DAVStatus.SC_INTERNAL_SERVER_ERROR, t.getMessage() == null ? "<null>" : t.getMessage()); } finally { if (transaction != null && transaction.getSessionInfo() != null && transaction.getSessionInfo().isTemporary()) { transaction.getSessionInfo().getHttpSession().invalidate(); } } }
From source file:org.apache.catalina.core.ApplicationDispatcher.java
/** * Prepare the request based on the filter configuration. * @param request The servlet request we are processing * @param response The servlet response we are creating * * @exception IOException if an input/output error occurs * @exception ServletException if a servlet error occurs *//*ww w .ja va 2 s .c o m*/ private void processRequest(ServletRequest request, ServletResponse response) throws IOException, ServletException { Integer disInt = (Integer) request.getAttribute(ApplicationFilterFactory.DISPATCHER_TYPE_ATTR); if (disInt != null) { if (disInt.intValue() != ApplicationFilterFactory.ERROR) { outerRequest.setAttribute(ApplicationFilterFactory.DISPATCHER_REQUEST_PATH_ATTR, origServletPath); outerRequest.setAttribute(ApplicationFilterFactory.DISPATCHER_TYPE_ATTR, new Integer(ApplicationFilterFactory.FORWARD)); invoke(outerRequest, response); } else { invoke(outerRequest, response); } } }