List of usage examples for org.apache.wicket.protocol.ws.api.message ConnectedMessage getSessionId
public String getSessionId()
From source file:com.wicketinaction.charts.ChartUpdater.java
License:Apache License
public static void start(ConnectedMessage message) { Record[] data = generateData();/* ww w .java 2s .c om*/ // create an asynchronous task that will write the data to the client UpdateTask updateTask = new UpdateTask(message.getApplication(), message.getSessionId(), message.getKey(), data); Executors.newScheduledThreadPool(1).schedule(updateTask, 1, TimeUnit.SECONDS); }
From source file:org.apache.openmeetings.web.common.MainPanel.java
License:Apache License
public MainPanel(String id, WebMarkupContainer panel) { super(id);/* ww w. j av a 2 s . co m*/ client = new Client(); add(topControls.setOutputMarkupPlaceholderTag(true).setMarkupId("topControls")); menu = new MenuPanel("menu", getMainMenu()); contents = new WebMarkupContainer("contents"); add(contents.add(panel).setOutputMarkupId(true).setMarkupId("contents")); topControls.add(menu.setVisible(false), topLinks.setVisible(false).setOutputMarkupPlaceholderTag(true).setMarkupId("topLinks")); topLinks.add(new AjaxLink<Void>("messages") { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { updateContents(PROFILE_MESSAGES, target); } }); topLinks.add(new ConfirmableAjaxBorder("logout", getString("310"), getString("634")) { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { getSession().invalidate(); setResponsePage(Application.get().getSignInPageClass()); } }); topLinks.add(new AjaxLink<Void>("profile") { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { updateContents(PROFILE_EDIT, target); } }); final AboutDialog about = new AboutDialog("aboutDialog"); topLinks.add(new AjaxLink<Void>("about") { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { about.open(target); } }); if (getApplication().getDebugSettings().isDevelopmentUtilitiesEnabled()) { add(new DebugBar("dev").setOutputMarkupId(true)); } else { add(new EmptyPanel("dev").setVisible(false)); } add(about, chat = new ChatPanel("chatPanel")); add(newMessage = new MessageDialog("newMessageDialog", new CompoundPropertyModel<PrivateMessage>(new PrivateMessage())) { private static final long serialVersionUID = 1L; @Override public void onClose(IPartialPageRequestHandler handler, DialogButton button) { BasePanel bp = getCurrentPanel(); if (send.equals(button) && bp != null) { bp.onNewMessageClose(handler); } } }); add(userInfo = new UserInfoDialog("userInfoDialog", newMessage)); add(new AbstractDefaultAjaxBehavior() { private static final long serialVersionUID = 1L; @Override protected void respond(AjaxRequestTarget target) { userInfo.open(target, getParam(getComponent(), PARAM_USER_ID).toLong()); } @Override public void renderHead(Component component, IHeaderResponse response) { super.renderHead(component, response); response.render(new PriorityHeaderItem(JavaScriptHeaderItem.forScript( getNamedFunction("showUserInfo", this, explicit(PARAM_USER_ID)), "showUserInfo"))); } }); add(new AbstractDefaultAjaxBehavior() { private static final long serialVersionUID = 1L; @Override protected void respond(AjaxRequestTarget target) { ContactsHelper.addUserToContactList(getParam(getComponent(), PARAM_USER_ID).toLong()); } @Override public void renderHead(Component component, IHeaderResponse response) { super.renderHead(component, response); response.render(new PriorityHeaderItem(JavaScriptHeaderItem .forScript(getNamedFunction("addContact", this, explicit(PARAM_USER_ID)), "addContact"))); } }); add(new AbstractDefaultAjaxBehavior() { private static final long serialVersionUID = 1L; @Override protected void respond(AjaxRequestTarget target) { newMessage.reset(true).open(target, getParam(getComponent(), PARAM_USER_ID).toOptionalLong()); } @Override public void renderHead(Component component, IHeaderResponse response) { super.renderHead(component, response); response.render(new PriorityHeaderItem(JavaScriptHeaderItem.forScript( getNamedFunction("privateMessage", this, explicit(PARAM_USER_ID)), "privateMessage"))); } }); add(new WebSocketBehavior() { private static final long serialVersionUID = 1L; @Override protected void onConnect(ConnectedMessage message) { super.onConnect(message); addOnlineUser(new Client(message.getSessionId(), message.getKey(), getUserId())); log.debug(String.format("WebSocketBehavior::onConnect [session: %s, key: %s]", message.getSessionId(), message.getKey())); } @Override protected void onClose(ClosedMessage message) { Client client = getClientByKeys(getUserId(), WebSession.get().getId()); removeOnlineUser(client); super.onClose(message); log.debug("WebSocketBehavior::onClose"); } }); }
From source file:org.efaps.ui.wicket.pages.main.MainPage.java
License:Apache License
/** * Constructor adding all Components to this Page. * @throws CacheReloadException on error */// w w w. j a va 2 s. co m public MainPage() throws CacheReloadException { super(); // add the debug bar for administration role, in case of an erro only log it Component debug = null; try { // Administration final Role role = Role.get(KernelSettings.USER_ROLE_ADMINISTRATION); if (role != null && Context.getThreadContext().getPerson().isAssigned(role)) { debug = new DebugBar("debug"); } } catch (final CacheReloadException e) { MainPage.LOG.error("Error on retrieving Role assignment.", e); } catch (final EFapsException e) { MainPage.LOG.error("Error on retrieving Role assignment.", e); } finally { if (debug == null) { debug = new WebComponent("debug").setVisible(false); } add(debug); } // call the client info to force the reload script to be executed on the // beginning of a session, // if an ajax call would be done as first an error occurs ((WebClientInfo) Session.get().getClientInfo()).getProperties(); add(new RequireBehavior("dojo/dom", "dojo/_base/window")); add(new PreLoaderPanel("preloader")); add(new OpenWindowOnLoadBehavior()); final WebMarkupContainer borderPanel = new WebMarkupContainer("borderPanel"); this.add(borderPanel); borderPanel.add(new BorderContainerBehavior(Design.HEADLINE, false)); final LazyIframe mainPanel = new LazyIframe("mainPanel", new IFrameProvider() { private static final long serialVersionUID = 1L; @Override public Page getPage() { Page error = null; WebPage page = null; try { page = new DashboardPage(getPageReference()); } catch (final EFapsException e) { error = new ErrorPage(e); } return error == null ? page : error; } }, MainPage.IFRAME_ID); borderPanel.add(mainPanel); mainPanel.add(new ContentPaneBehavior(Region.CENTER, false)); final WebMarkupContainer headerPanel = new WebMarkupContainer("headerPanel"); borderPanel.add(headerPanel); headerPanel.add(new ContentPaneBehavior(Region.TOP, false)); headerPanel.add(new MenuBarPanel("menubar", Model.of(new UIMenuItem(UUID.fromString(Configuration.getAttribute(ConfigAttribute.TOOLBAR)))))); // set the title for the Page add2Page(new Label("pageTitle", DBProperties.getProperty("Logo.Version.Label"))); add(this.modal); add(new ResizeEventBehavior()); try { // only add the search if it is activated in the kernel if (EFapsSystemConfiguration.get().getAttributeValueAsBoolean(KernelSettings.INDEXACTIVATE)) { final SearchPanel search = new SearchPanel("search"); add(search); } else { add(new WebMarkupContainer("search").setVisible(false)); } } catch (final EFapsException e1) { MainPage.LOG.error("Error on retrieving setting for index", e1); } final WebMarkupContainer logo = new WebMarkupContainer("logo"); headerPanel.add(logo); final Label welcome = new Label("welcome", DBProperties.getProperty("Logo.Welcome.Label")); logo.add(welcome); try { final Context context = Context.getThreadContext(); logo.add(new Label("firstname", context.getPerson().getFirstName())); logo.add(new Label("lastname", context.getPerson().getLastName())); final String companyName = context.getCompany() == null ? "" : context.getCompany().getName(); logo.add(new Label("company", companyName)); logo.add(new AttributeModifier("class", new Model<>("eFapsLogo " + companyName.replaceAll("\\W", "")))); final long usrId = context.getPersonId(); // Admin_Common_SystemMessageAlert final LinkItem alert = new LinkItem("useralert", Model.of(new UIMenuItem(SetMessageStatusBehavior.getCmdUUD()))) { private static final long serialVersionUID = 1L; @Override public void onComponentTagBody(final MarkupStream _markupStream, final ComponentTag _openTag) { try { replaceComponentTagBody(_markupStream, _openTag, SetMessageStatusBehavior.getLabel(MessageStatusHolder.getUnReadCount(usrId), MessageStatusHolder.getReadCount(usrId))); } catch (final CacheReloadException e) { MainPage.LOG.error("Cannot replace Component tag"); } } }; add(alert); alert.add(new MessageListenerBehavior()); alert.add(new AttributeModifier("class", new Model<>("eFapsUserMsg"))); if (!MessageStatusHolder.hasReadMsg(usrId)) { alert.add(new AttributeModifier("style", new Model<>("display:none"))); } final WebMarkupContainer socketMsgContainer = new WebMarkupContainer("socketMsgContainer"); add(socketMsgContainer); if (Configuration.getAttributeAsBoolean(ConfigAttribute.WEBSOCKET_ACTVATE)) { socketMsgContainer.setOutputMarkupPlaceholderTag(true); this.socketMsg = new Label("socketMsg", "none yet").setEscapeModelStrings(false); this.socketMsg.setOutputMarkupPlaceholderTag(true); this.socketMsg.add(new WebSocketBehavior() { private static final long serialVersionUID = 1L; @Override protected void onConnect(final ConnectedMessage _message) { RegistryManager.addMsgConnection(_message.getSessionId(), _message.getKey()); } }); socketMsgContainer.add(this.socketMsg); final AjaxLink<Void> close = new AjaxLink<Void>("socketMsgClose") { private static final long serialVersionUID = 1L; @Override public void onClick(final AjaxRequestTarget _target) { final MarkupContainer msgContainer = MainPage.this.socketMsg.getParent(); msgContainer.add(new AttributeModifier("style", new Model<>("display:none"))); _target.add(msgContainer); } }; socketMsgContainer.add(close); } else { socketMsgContainer.setVisible(false); } } catch (final EFapsException e) { throw new RestartResponseException(new ErrorPage(e)); } }