@Override public void put(ScriptSession scriptSession, String name, Object value) { scriptSession.setAttribute(name, value); } };
/** * Binds an object to this session, using the name specified. * If an object of the same name is already bound to the session, the * object is replaced. * <p>After this method executes, and if the new object implements * {@link ScriptSessionBindingListener}, the container calls * {@link ScriptSessionBindingListener#valueBound}. * <p>If an object was already bound to this session of this name that * implements {@link ScriptSessionBindingListener}, its * {@link ScriptSessionBindingListener#valueUnbound} method is called. * <p>If the value passed in is null, this has the same effect as calling * {@link #removeAttribute}. * @param name the name to which the object is bound; cannot be null * @param value the object to be bound * @throws IllegalStateException if the page has been invalidated */ public static void setAttribute(String name, Object value) { Collection<ScriptSession> sessions = Browser.getTargetSessions(); for (ScriptSession scriptSession : sessions) { scriptSession.setAttribute(name, value); } }
@SuppressWarnings("unchecked") public <T> String saveCallback(Callback<T> callback, Class<T> type) { String key = createUniqueId(); for (ScriptSession session : callback.getScriptSessions()) { // Save the callback itself Map<String, Callback<T>> callbackMap = (Map<String, Callback<T>>) session.getAttribute(KEY_CALLBACK); callbackMap.put(key, callback); session.setAttribute(KEY_CALLBACK, callbackMap); // And save the type of the callback Map<String, Class<T>> typeMap = (Map<String, Class<T>>) session.getAttribute(KEY_TYPE); typeMap.put(key, type); session.setAttribute(KEY_TYPE, typeMap); } return key; }
private void initScriptSession() { WebContext webContext = WebContextFactory.get(); HttpServletRequest request = webContext.getHttpServletRequest(); ScriptSession currentSession = webContext.getScriptSession(); String host = request.getServerName(); RiotUser user = AccessController.getCurrentUser(); currentSession.setAttribute("host", host); currentSession.setAttribute("userId", user.getUserId()); }
/** * Internal method to find or create a StoreProvider for a given user. */ @Override protected StoreProvider<T> getStoreProvider() { ScriptSession session = WebContextFactory.get().getScriptSession(); @SuppressWarnings("unchecked") StoreProvider<T> storeProvider = (StoreProvider<T>) session.getAttribute(attributeName); if (storeProvider == null) { storeProvider = factory.create(session); session.setAttribute(attributeName, storeProvider); } return storeProvider; }
webcx.getScriptSession().setAttribute(name, object);
/** * Ensure that the clients know about server publishes * @param topic The topic being subscribed to * @param subscriptionId The ID to pass back to link to client side data */ @SuppressWarnings("unchecked") public void subscribe(String topic, String subscriptionId) { WebContext webContext = WebContextFactory.get(); Hub hub = HubFactory.get(); final ScriptSession session = webContext.getScriptSession(); // Create a subscription block BrowserMessageListener subscription = new BrowserMessageListener(session, topic, subscriptionId); Map<String, BrowserMessageListener> subscriptions = (Map<String, BrowserMessageListener>) session.getAttribute(ATTRIBUTE_SUBSCRIPTIONS); if (subscriptions == null) { subscriptions = new HashMap<String, BrowserMessageListener>(); } subscriptions.put(subscriptionId, subscription); session.setAttribute(ATTRIBUTE_SUBSCRIPTIONS, subscriptions); hub.subscribe(subscription.topic, subscription); }
public Object doFilter(Object obj, Method method, Object[] params, AjaxFilterChain chain) throws Exception { ScriptSession session = WebContextFactory.get().getScriptSession(); Long lastAccess = (Long) session.getAttribute(ATTRIBUTE_LAST_ACTION); // Free pass in if you've not done anything so far. if (lastAccess != null) { long now = System.currentTimeMillis(); if (now > lastAccess + actionTimeoutMillis) { session.addScript(new ScriptBuffer(onTimeout)); session.invalidate(); throw new DwrConvertedException("Your session has timed out"); } } Object reply = chain.doFilter(obj, method, params); session.setAttribute(ATTRIBUTE_LAST_ACTION, System.currentTimeMillis()); return reply; }
Class<T> type = typeMap.remove(key); session.removeAttribute(KEY_TYPE); session.setAttribute(KEY_TYPE, typeMap); Callback<T> callback = callbackMap.remove(key); session.removeAttribute(KEY_TYPE); session.setAttribute(KEY_CALLBACK, callbackMap);