@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; }
public boolean match(ScriptSession session) { return !user.getUserId().equals(session.getAttribute("userId")) && currentSession.getPage().equals(session.getPage()) && host.equals(session.getAttribute("host")); } },
/** * Utility to add the given script to all known browsers. * @param script The Javascript to send to the browsers */ public void addScript(ScriptBuffer script) { for (ScriptSession scriptSession : scriptSessions) { scriptSession.addScript(script); } }
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; }
ConverterManager converterManager = webContext.getContainer().getBean(ConverterManager.class); Map<String, Class<T>> typeMap = (Map<String, Class<T>>) session.getAttribute(KEY_TYPE); Class<T> type = typeMap.remove(key); session.removeAttribute(KEY_TYPE); session.setAttribute(KEY_TYPE, typeMap); Object callbackData = converterManager.convertInbound(type, iv, property); Map<String, Callback<T>> callbackMap = (Map<String, Callback<T>>) session.getAttribute(KEY_TYPE); Callback<T> callback = callbackMap.remove(key); session.removeAttribute(KEY_TYPE); session.setAttribute(KEY_CALLBACK, callbackMap);
@Override public void put(ScriptSession scriptSession, String name, Object value) { scriptSession.setAttribute(name, value); } };
@Override public Object get(ScriptSession scriptSession, String name) { return scriptSession.getAttribute(name); }
public boolean match(ScriptSession session) { return session.getPage().equals(page); }
@Override public String toString() { return "browser[" + session.getId() + "].functions[" + id + "](...)"; }
/** * Removes the object bound with the specified name from this session. * If the session does not have an object bound with the specified name, * this method does nothing. * <p>After this method executes, and if the object implements * {@link ScriptSessionBindingListener}, the container calls * {@link ScriptSessionBindingListener#valueUnbound}. * @param name the name of the object to remove from this session * @throws IllegalStateException if the page has been invalidated */ public static void removeAttribute(String name) { Collection<ScriptSession> sessions = Browser.getTargetSessions(); for (ScriptSession scriptSession : sessions) { scriptSession.removeAttribute(name); } }
/** * Call {@link ScriptSession#invalidate()} on the {@link ScriptSession} * that called this method. * Used by the page unloader. */ public void pageUnloaded() { WebContext wctx = WebContextFactory.get(); ScriptSession scriptSession = wctx.getScriptSession(); log.debug("pageUnloaded is invalidating scriptSession: " + scriptSession); scriptSession.invalidate(); }
/** * 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); } }
/** * Stop notifications of against a subscription id * @param subscriptionId The ID to pass back to link to client side data * @return true iff someone was unsubscribed */ @SuppressWarnings("unchecked") public boolean unsubscribe(String subscriptionId) { WebContext webContext = WebContextFactory.get(); Hub hub = HubFactory.get(); ScriptSession session = webContext.getScriptSession(); Map<String, BrowserMessageListener> subscriptions = (Map<String, BrowserMessageListener>) session.getAttribute(ATTRIBUTE_SUBSCRIPTIONS); BrowserMessageListener subscription = subscriptions.get(subscriptionId); return hub.unsubscribe(subscription.topic, subscription); }
@Override public String toString() { return "browser[" + session.getId() + "].object[" + id + "](...)"; }
/** * 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; }
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()); }
public void close() { ScriptBuffer script = EnginePrivate.getRemoteCloseFunctionScript(id); session.addScript(script); }
public boolean match(ScriptSession session) { return session.getId().equals(id); }
/** * 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 void execute(String methodName, Object... params) { ScriptBuffer script = EnginePrivate.getRemoteExecuteObjectScript(id, methodName, params); session.addScript(script); }