Search in sources :

Example 1 with NGClientWebsocketSessionWindows

use of com.servoy.j2db.server.ngclient.eventthread.NGClientWebsocketSessionWindows in project servoy-client by Servoy.

the class ServoyDebugger method getFrame.

/**
 * @see org.eclipse.dltk.rhino.dbgp.DBGPDebugger#getFrame(org.mozilla.javascript.Context, org.mozilla.javascript.debug.DebuggableScript)
 */
@Override
public DebugFrame getFrame(Context cx, DebuggableScript fnOrScript) {
    final IServiceProvider client = J2DBGlobals.getServiceProvider();
    if (profilelisteners.size() > 0) {
        ProfileInfo info = profileInfo.get();
        return new ServoyDebugFrame(cx, fnOrScript, this, info != null ? info.peek() : null);
    }
    return new DBGPDebugFrame(cx, fnOrScript, this) {

        @Override
        public Object eval(String value) {
            if (client != null && J2DBGlobals.getServiceProvider() == null) {
                J2DBGlobals.setServiceProvider(client);
            }
            boolean reset = false;
            try {
                if (client instanceof NGClient && !CurrentWindow.exists()) {
                    // make sure that for an NGClient the current window is set.
                    CurrentWindow.set(new NGClientWebsocketSessionWindows(((NGClient) client).getWebsocketSession()));
                    reset = true;
                }
                return super.eval(value);
            } finally {
                if (reset)
                    CurrentWindow.set(null);
            }
        }
    };
}
Also used : IServiceProvider(com.servoy.j2db.IServiceProvider) NGClientWebsocketSessionWindows(com.servoy.j2db.server.ngclient.eventthread.NGClientWebsocketSessionWindows) NGClient(com.servoy.j2db.server.ngclient.NGClient) DBGPDebugFrame(org.eclipse.dltk.rhino.dbgp.DBGPDebugFrame)

Example 2 with NGClientWebsocketSessionWindows

use of com.servoy.j2db.server.ngclient.eventthread.NGClientWebsocketSessionWindows in project servoy-client by Servoy.

the class AbstractSolutionTest method buildSolution.

@Before
public void buildSolution() throws Exception {
    TestNGClient.initSettings();
    Types.getTypesInstance().registerTypes();
    final File f = new File(NGClient.class.getProtectionDomain().getCodeSource().getLocation().getPath());
    IPackageReader[] servicesReaders = null;
    IPackageReader[] componentsReaders = null;
    InMemPackageReader inMemPackageReader = getTestComponents();
    if (f.isFile() && f.getName().startsWith("servoy_ngclient") && f.getName().endsWith(".jar")) {
        // it is running from bundles/jars
        ZipFile zipFile = new ZipFile(f);
        componentsReaders = inMemPackageReader != null ? new IPackageReader[] { new ZipPackageReader(zipFile, "war/servoycore/"), new ZipPackageReader(zipFile, "war/servoydefault/"), inMemPackageReader } : new IPackageReader[] { new ZipPackageReader(zipFile, "war/servoycore/"), new ZipPackageReader(zipFile, "war/servoydefault/") };
        servicesReaders = new IPackageReader[] { new ZipPackageReader(zipFile, "war/servoyservices/") };
    } else {
        // it is running from sources/projects
        File ngClientProjDir = f;
        if (!new File(ngClientProjDir, "/war/servoycore/").exists()) {
            ngClientProjDir = ngClientProjDir.getParentFile();
        }
        componentsReaders = getReaders(new File[] { new File(ngClientProjDir.getAbsoluteFile() + "/war/servoycore/"), new File(ngClientProjDir.getAbsoluteFile() + "/war/servoydefault/") }, // in eclipse we .. out of bin, in jenkins we .. out of @dot
        inMemPackageReader);
        servicesReaders = getReaders(new File[] { new File(ngClientProjDir.getAbsoluteFile(), "/war/servoyservices/") }, null);
    }
    WebComponentSpecProvider.init(componentsReaders, DefaultComponentPropertiesProvider.instance);
    WebServiceSpecProvider.init(servicesReaders);
    final TestRepository tr = new TestRepository();
    try {
        ApplicationServerRegistry.setApplicationServerSingleton(new TestApplicationServer(tr));
        UUID uuid = UUID.randomUUID();
        final RootObjectMetaData metadata = tr.createRootObjectMetaData(tr.getElementIdForUUID(uuid), uuid, "Test", IRepository.SOLUTIONS, 1, 1);
        solution = (Solution) tr.createRootObject(metadata);
        tr.cacheRootObject(solution);
        solution.setChangeHandler(new ChangeHandler(tr));
        fillTestSolution();
        HttpSession testHttpsession = new TestHttpsession();
        endpoint = new NGClientEndpoint() {

            // for testing onstart of the NGClientEndpoint should not run
            @Override
            public void onStart() {
            }

            @Override
            protected HttpSession getHttpSession(Session session) {
                return testHttpsession;
            }
        };
        NGClientWebsocketSession session = new NGClientWebsocketSession(new WebsocketSessionKey(testHttpsession.getId(), 1)) {

            @Override
            public void init(Map<String, List<String>> requestParams) throws Exception {
            // override default init, shouldnt make another client.
            }

            @Override
            protected IEventDispatcher createEventDispatcher() {
                return new TestNGEventDispatcher(endpoint);
            }
        };
        WebsocketSessionManager.addSession(session);
        NGClientWebsocketSessionWindows windows = new NGClientWebsocketSessionWindows(session);
        CurrentWindow.set(windows);
        client = new TestNGClient(tr, session) {

            @Override
            public boolean loadSolutionsAndModules(SolutionMetaData solutionMetaData) {
                boolean b = super.loadSolutionsAndModules(solutionMetaData);
                IPersistIndex index = PersistIndexCache.getCachedIndex(solution);
                solution.getChangeHandler().addIPersistListener((IItemChangeListener<IPersist>) index);
                try {
                    setupData();
                } catch (ServoyException e) {
                    e.printStackTrace();
                }
                return b;
            }
        };
        J2DBGlobals.setServiceProvider(client);
        client.setUseLoginSolution(false);
        endpoint.start(new TestSession(), String.valueOf(session.getSessionKey().getClientnr()), "null", "42");
        CurrentWindow.set(session.getWindows().iterator().next());
    } catch (RepositoryException e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}
Also used : RootObjectMetaData(com.servoy.j2db.persistence.RootObjectMetaData) IPackageReader(org.sablo.specification.Package.IPackageReader) ServoyException(com.servoy.j2db.util.ServoyException) ChangeHandler(com.servoy.j2db.persistence.ChangeHandler) InMemPackageReader(org.sablo.InMemPackageReader) UUID(com.servoy.j2db.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) HttpSession(javax.servlet.http.HttpSession) NGClientWebsocketSessionWindows(com.servoy.j2db.server.ngclient.eventthread.NGClientWebsocketSessionWindows) RepositoryException(com.servoy.j2db.persistence.RepositoryException) SolutionMetaData(com.servoy.j2db.persistence.SolutionMetaData) NGClientEndpoint(com.servoy.j2db.server.ngclient.endpoint.NGClientEndpoint) ZipFile(java.util.zip.ZipFile) WebsocketSessionKey(org.sablo.websocket.WebsocketSessionKey) NGClientWebsocketSession(com.servoy.j2db.server.ngclient.NGClientWebsocketSession) IPersistIndex(com.servoy.j2db.IPersistIndex) ZipFile(java.util.zip.ZipFile) File(java.io.File) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) HttpSession(javax.servlet.http.HttpSession) Session(javax.websocket.Session) NGClientWebsocketSession(com.servoy.j2db.server.ngclient.NGClientWebsocketSession) IItemChangeListener(com.servoy.j2db.persistence.IItemChangeListener) Before(org.junit.Before)

Example 3 with NGClientWebsocketSessionWindows

use of com.servoy.j2db.server.ngclient.eventthread.NGClientWebsocketSessionWindows in project servoy-client by Servoy.

the class NGClient method changesWillBeSend.

@Override
public void changesWillBeSend() {
    reloadClientFunctionsSend = false;
    if (toRecreate.size() > 0) {
        NGClientWebsocketSessionWindows allWindowsProxy = new NGClientWebsocketSessionWindows(getWebsocketSession());
        for (Pair<Form, String> pair : toRecreate) {
            IFormHTMLAndJSGenerator generator = getWebsocketSession().getFormHTMLAndJSGenerator(pair.getLeft(), pair.getRight());
            allWindowsProxy.updateForm(pair.getLeft(), pair.getRight(), generator);
        }
        toRecreate.clear();
    }
    if (showUrl != null) {
        this.getWebsocketSession().getClientService(NGClient.APPLICATION_SERVICE).executeAsyncServiceCall("showUrl", new Object[] { showUrl.url, showUrl.target, showUrl.target_options, Integer.valueOf(showUrl.timeout) });
        showUrl = null;
    }
}
Also used : Form(com.servoy.j2db.persistence.Form) NGClientWebsocketSessionWindows(com.servoy.j2db.server.ngclient.eventthread.NGClientWebsocketSessionWindows) IFormHTMLAndJSGenerator(com.servoy.j2db.server.ngclient.INGClientWindow.IFormHTMLAndJSGenerator)

Example 4 with NGClientWebsocketSessionWindows

use of com.servoy.j2db.server.ngclient.eventthread.NGClientWebsocketSessionWindows in project servoy-client by Servoy.

the class NGClientWebsocketSession method sendRedirect.

public void sendRedirect(final String redirectUrl) {
    IWindow curr = CurrentWindow.safeGet();
    CurrentWindow.runForWindow(curr != null && redirectUrl != null ? curr : new NGClientWebsocketSessionWindows(client.getWebsocketSession()), new Runnable() {

        @Override
        public void run() {
            Map<String, Object> detail = new HashMap<>();
            String htmlfilePath = Settings.getInstance().getProperty("servoy.webclient.pageexpired.page");
            if (htmlfilePath != null)
                detail.put("viewUrl", htmlfilePath);
            if (redirectUrl != null)
                detail.put("redirectUrl", redirectUrl);
            getClientService("$sessionService").executeAsyncServiceCall("expireSession", new Object[] { detail });
        }
    });
}
Also used : NGClientWebsocketSessionWindows(com.servoy.j2db.server.ngclient.eventthread.NGClientWebsocketSessionWindows) JSONObject(org.json.JSONObject) Map(java.util.Map) HashMap(java.util.HashMap) IWindow(org.sablo.websocket.IWindow)

Example 5 with NGClientWebsocketSessionWindows

use of com.servoy.j2db.server.ngclient.eventthread.NGClientWebsocketSessionWindows in project servoy-client by Servoy.

the class NGFormManager method propertyChange.

@Override
public void propertyChange(PropertyChangeEvent evt) {
    String name = evt.getPropertyName();
    if (// $NON-NLS-1$
    "solution".equals(name)) {
        final Solution s = (Solution) evt.getNewValue();
        Runnable run = new Runnable() {

            @Override
            public void run() {
                boolean isReload = s != null;
                // must run on same thread
                destroySolutionSettings(isReload);
                if (isReload) {
                    makeSolutionSettings(s);
                }
            }
        };
        if (CurrentWindow.exists())
            run.run();
        else
            CurrentWindow.runForWindow(new NGClientWebsocketSessionWindows(getApplication().getWebsocketSession()), run);
    } else if (// $NON-NLS-1$
    "mode".equals(name)) {
        int oldmode = ((Integer) evt.getOldValue()).intValue();
        int newmode = ((Integer) evt.getNewValue()).intValue();
        IFormController fp = getCurrentMainShowingFormController();
        if (oldmode == IModeManager.FIND_MODE || newmode == IModeManager.FIND_MODE) {
            fp.setMode(newmode);
        }
    }
}
Also used : NGClientWebsocketSessionWindows(com.servoy.j2db.server.ngclient.eventthread.NGClientWebsocketSessionWindows) IFormController(com.servoy.j2db.IFormController) Solution(com.servoy.j2db.persistence.Solution)

Aggregations

NGClientWebsocketSessionWindows (com.servoy.j2db.server.ngclient.eventthread.NGClientWebsocketSessionWindows)10 ServoyException (com.servoy.j2db.util.ServoyException)3 JSONObject (org.json.JSONObject)3 IFormController (com.servoy.j2db.IFormController)2 Form (com.servoy.j2db.persistence.Form)2 NGClient (com.servoy.j2db.server.ngclient.NGClient)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 WebsocketSessionWindows (org.sablo.eventthread.WebsocketSessionWindows)2 ApplicationException (com.servoy.j2db.ApplicationException)1 IPersistIndex (com.servoy.j2db.IPersistIndex)1 IServiceProvider (com.servoy.j2db.IServiceProvider)1 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)1 ChangeHandler (com.servoy.j2db.persistence.ChangeHandler)1 IItemChangeListener (com.servoy.j2db.persistence.IItemChangeListener)1 RepositoryException (com.servoy.j2db.persistence.RepositoryException)1 RootObjectMetaData (com.servoy.j2db.persistence.RootObjectMetaData)1 Solution (com.servoy.j2db.persistence.Solution)1 SolutionMetaData (com.servoy.j2db.persistence.SolutionMetaData)1