Search in sources :

Example 1 with SolutionMetaData

use of com.servoy.j2db.persistence.SolutionMetaData in project servoy-client by Servoy.

the class DebugClientHandler method createDebugHeadlessClient.

public synchronized SessionClient createDebugHeadlessClient(ServletRequest req, String userName, String password, String method, Object[] objects, String preferedSolution) throws Exception {
    if (debugHeadlessClient != null && !debugHeadlessClient.isShutDown()) {
        debugHeadlessClient.shutDown(true);
    }
    SolutionMetaData solutionMetaData = (currentSolution == null) ? null : currentSolution.getSolutionMetaData();
    if (preferedSolution != null && solutionMetaData != null && !preferedSolution.equals(solutionMetaData.getName())) {
        Map<String, Solution> modules = new HashMap<String, Solution>();
        currentSolution.getReferencedModulesRecursive(modules);
        if (modules.containsKey(preferedSolution)) {
            solutionMetaData = (SolutionMetaData) ApplicationServerRegistry.get().getLocalRepository().getRootObjectMetaData(preferedSolution, IRepository.SOLUTIONS);
        }
    }
    debugHeadlessClient = new DebugHeadlessClient(req, userName, password, method, objects, solutionMetaData, designerCallback) {

        @Override
        public void shutDown(boolean force) {
            super.shutDown(force);
            debugHeadlessClient = null;
        }
    };
    testAndStartDebugger();
    return debugHeadlessClient;
}
Also used : HashMap(java.util.HashMap) SolutionMetaData(com.servoy.j2db.persistence.SolutionMetaData) Solution(com.servoy.j2db.persistence.Solution)

Example 2 with SolutionMetaData

use of com.servoy.j2db.persistence.SolutionMetaData in project servoy-client by Servoy.

the class WebClientSession method startSessionClient.

@SuppressWarnings("nls")
public IWebClientApplication startSessionClient(RootObjectMetaData sd, String method, StartupArguments argumentsScope) throws Exception {
    String firstArgument = argumentsScope.getFirstArgument();
    IWebClientApplication webClient = getWebClient();
    if (webClient != null) {
        boolean solutionLoaded = webClient.getSolution() != null;
        if (solutionLoaded && !webClient.closeSolution(false, null)) {
            // not allowed to close solution?
            return webClient;
        }
        if (solutionLoaded && isSignedIn() && !Utils.getAsBoolean(Settings.getInstance().getProperty("servoy.allowSolutionBrowsing", "true")) && !sd.getName().equals(keepCredentialsSolutionName)) {
            webClient.logout(null);
        }
        if (!isSignedIn()) {
            SolutionMetaData smd = (SolutionMetaData) sd;
            IRepository repository = ApplicationServerRegistry.get().getLocalRepository();
            Solution sol = (Solution) repository.getActiveRootObject(smd.getName(), IRepository.SOLUTIONS);
            if (sol.getLoginSolutionName() == null && sol.getLoginFormID() <= 0 && smd.getMustAuthenticate()) {
                // signin first
                throw new RestartResponseAtInterceptPageException(SignIn.class);
            }
        }
        keepCredentialsSolutionName = null;
    }
    if (webClient == null || webClient.isShutDown()) {
        HttpServletRequest req = ((WebRequest) RequestCycle.get().getRequest()).getHttpServletRequest();
        httpSession = req.getSession();
        webClient = createWebClient(req, credentials, method, firstArgument == null ? null : new Object[] { firstArgument, argumentsScope.toJSMap() }, sd.getName());
        webClient.handleArguments(new String[] { sd.getName() }, argumentsScope);
        if (RequestCycle.get() != null) {
            // if this is inside a request cycle set the service provider.
            // will be reset by the detach of the RequestCycle.
            J2DBGlobals.setServiceProvider(webClient);
        }
        setAttribute("servoy_webclient", webClient);
    } else {
        webClient.handleArguments(firstArgument != null ? new String[] { sd.getName(), method, firstArgument } : new String[] { sd.getName(), method }, argumentsScope);
    }
    // fake first load
    webClient.handleClientUserUidChanged(null, "");
    if (webClient.getSolution() != null)
        getSolutionLastModifiedTime(webClient.getSolution());
    else {
        if (webClient.getPreferedSolutionNameToLoadOnInit() != null) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("s", webClient.getPreferedSolutionNameToLoadOnInit());
            map.put("m", webClient.getPreferedSolutionMethodNameToCall());
            if (webClient.getPreferedSolutionMethodArguments() != null && webClient.getPreferedSolutionMethodArguments().length > 0) {
                map.put("a", webClient.getPreferedSolutionMethodArguments()[0]);
            }
            throw new RestartResponseException(SolutionLoader.class, new PageParameters(map));
        }
    }
    return webClient;
}
Also used : HashMap(java.util.HashMap) RestartResponseAtInterceptPageException(org.apache.wicket.RestartResponseAtInterceptPageException) PageParameters(org.apache.wicket.PageParameters) SolutionMetaData(com.servoy.j2db.persistence.SolutionMetaData) HttpServletRequest(javax.servlet.http.HttpServletRequest) WebRequest(org.apache.wicket.protocol.http.WebRequest) RestartResponseException(org.apache.wicket.RestartResponseException) IWebClientApplication(com.servoy.j2db.IWebClientApplication) IRepository(com.servoy.j2db.persistence.IRepository) Solution(com.servoy.j2db.persistence.Solution)

Example 3 with SolutionMetaData

use of com.servoy.j2db.persistence.SolutionMetaData in project servoy-client by Servoy.

the class SharedMediaResource method getResource.

private ResourceState getResource(final String iconId, final String solutionName) {
    return new ResourceState() {

        private String contentType;

        private int length;

        byte[] array = null;

        @Override
        public Time lastModifiedTime() {
            try {
                IRootObject solution = ApplicationServerRegistry.get().getLocalRepository().getActiveRootObject(solutionName, IRepository.SOLUTIONS);
                if (solution != null)
                    return Time.valueOf(solution.getLastModifiedTime());
            } catch (Exception e) {
                Debug.trace(e);
            }
            return time;
        }

        @Override
        public byte[] getData() {
            if (array == null) {
                boolean closeFS = false;
                try {
                    final IRepository repository = ApplicationServerRegistry.get().getLocalRepository();
                    FlattenedSolution fs = null;
                    try {
                        if (Session.exists() && ((WebClientSession) Session.get()).getWebClient() != null) {
                            fs = ((WebClientSession) Session.get()).getWebClient().getFlattenedSolution();
                        }
                        if (fs == null) {
                            SolutionMetaData solutionMetaData = (SolutionMetaData) repository.getRootObjectMetaData(solutionName, IRepository.SOLUTIONS);
                            if (solutionMetaData == null)
                                return new byte[0];
                            closeFS = true;
                            IApplicationServer as = ApplicationServerRegistry.getService(IApplicationServer.class);
                            fs = new FlattenedSolution(solutionMetaData, new AbstractActiveSolutionHandler(as) {

                                @Override
                                public IRepository getRepository() {
                                    return repository;
                                }
                            });
                        }
                        Media m = fs.getMedia(iconId);
                        if (m == null) {
                            try {
                                Integer iIconID = new Integer(iconId);
                                m = fs.getMedia(iIconID.intValue());
                            } catch (NumberFormatException ex) {
                                Debug.error("no media found for: " + iconId);
                            }
                        }
                        if (m != null) {
                            array = m.getMediaData();
                            contentType = m.getMimeType();
                        }
                    } finally {
                        if (closeFS && fs != null) {
                            fs.close(null);
                        }
                    }
                    if (array != null) {
                        if (contentType == null) {
                            contentType = MimeTypes.getContentType(array);
                        }
                        length = array.length;
                    }
                } catch (Exception ex) {
                    Debug.error(ex);
                }
            }
            return array == null ? new byte[0] : array;
        }

        /**
         * @see wicket.markup.html.DynamicWebResource.ResourceState#getLength()
         */
        @Override
        public int getLength() {
            return length;
        }

        @Override
        public String getContentType() {
            return contentType;
        }
    };
}
Also used : Media(com.servoy.j2db.persistence.Media) FlattenedSolution(com.servoy.j2db.FlattenedSolution) IApplicationServer(com.servoy.j2db.server.shared.IApplicationServer) IRootObject(com.servoy.j2db.persistence.IRootObject) StringValueConversionException(org.apache.wicket.util.string.StringValueConversionException) SolutionMetaData(com.servoy.j2db.persistence.SolutionMetaData) AbstractActiveSolutionHandler(com.servoy.j2db.AbstractActiveSolutionHandler) IRepository(com.servoy.j2db.persistence.IRepository)

Example 4 with SolutionMetaData

use of com.servoy.j2db.persistence.SolutionMetaData 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 5 with SolutionMetaData

use of com.servoy.j2db.persistence.SolutionMetaData in project servoy-client by Servoy.

the class NGClient method loadSolution.

public void loadSolution(String solutionName) throws RepositoryException {
    try {
        SolutionMetaData solutionMetaData = getApplicationServer().getSolutionDefinition(solutionName, getSolutionTypeFilter());
        if (solutionMetaData == null) {
            throw new IllegalArgumentException(Messages.getString("servoy.exception.solutionNotFound", new Object[] { solutionName, IApplication.getApplicationTypeAsString(getClientInfo().getApplicationType()), SolutionMetaData.getSolutionNamesByFilter(getSolutionTypeFilter()) }));
        }
        loadSolution(solutionMetaData);
    } catch (RemoteException e) {
        throw new RepositoryException(e);
    }
}
Also used : BaseWebObject(org.sablo.BaseWebObject) JSONObject(org.json.JSONObject) RepositoryException(com.servoy.j2db.persistence.RepositoryException) RemoteException(java.rmi.RemoteException) SolutionMetaData(com.servoy.j2db.persistence.SolutionMetaData)

Aggregations

SolutionMetaData (com.servoy.j2db.persistence.SolutionMetaData)15 RepositoryException (com.servoy.j2db.persistence.RepositoryException)8 AbstractActiveSolutionHandler (com.servoy.j2db.AbstractActiveSolutionHandler)4 FlattenedSolution (com.servoy.j2db.FlattenedSolution)4 Solution (com.servoy.j2db.persistence.Solution)4 IApplicationServer (com.servoy.j2db.server.shared.IApplicationServer)4 RemoteException (java.rmi.RemoteException)4 RootObjectMetaData (com.servoy.j2db.persistence.RootObjectMetaData)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 HttpSession (javax.servlet.http.HttpSession)3 IRepository (com.servoy.j2db.persistence.IRepository)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ServletException (javax.servlet.ServletException)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 JSONObject (org.json.JSONObject)2 IPersistIndex (com.servoy.j2db.IPersistIndex)1 IWebClientApplication (com.servoy.j2db.IWebClientApplication)1 ChangeHandler (com.servoy.j2db.persistence.ChangeHandler)1