Search in sources :

Example 1 with IApplicationServerSingleton

use of com.servoy.j2db.server.shared.IApplicationServerSingleton in project servoy-client by Servoy.

the class FormCssResource method getResourceStream.

/**
 * @see org.apache.wicket.Resource#getResourceStream()
 */
@Override
public IResourceStream getResourceStream() {
    String css = "";
    ValueMap params = getParameters();
    Long time = null;
    if (params.size() == 1) {
        Iterator iterator = params.entrySet().iterator();
        if (iterator.hasNext()) {
            Map.Entry entry = (Entry) iterator.next();
            String solutionName = (String) entry.getKey();
            Pair<String, Long> filterTime = filterTime((String) entry.getValue());
            String formInstanceName = filterTime.getLeft();
            time = filterTime.getRight();
            // $NON-NLS-1$
            String solutionAndForm = solutionName + "/" + formInstanceName;
            // $NON-NLS-1$
            String templateDir = "default";
            IServiceProvider sp = null;
            Solution solution = null;
            Form form = null;
            if (Session.exists()) {
                sp = WebClientSession.get().getWebClient();
                if (sp != null) {
                    IForm fc = ((WebClient) sp).getFormManager().getForm(formInstanceName);
                    if (fc instanceof FormController) {
                        FlattenedSolution clientSolution = sp.getFlattenedSolution();
                        form = clientSolution.getForm(((FormController) fc).getForm().getName());
                    }
                }
                templateDir = WebClientSession.get().getTemplateDirectoryName();
            }
            final String fullpath = "/servoy-webclient/templates/" + templateDir + "/" + solutionAndForm + ".css";
            try {
                URL url = context.getResource(fullpath);
                if (url != null) {
                    return new NullUrlResourceStream(url);
                }
            } catch (Exception e) {
                Debug.error(e);
            }
            try {
                IApplicationServerSingleton as = ApplicationServerRegistry.get();
                RootObjectMetaData sd = as.getLocalRepository().getRootObjectMetaData(solutionName, IRepository.SOLUTIONS);
                if (sd != null) {
                    solution = (Solution) as.getLocalRepository().getActiveRootObject(sd.getRootObjectId());
                    if (form == null) {
                        form = solution.getForm(formInstanceName);
                    }
                }
                if (form != null) {
                    Pair<String, String> formHTMLAndCSS = TemplateGenerator.getFormHTMLAndCSS(solution, form, sp, formInstanceName);
                    css = formHTMLAndCSS.getRight();
                }
            } catch (Exception e) {
                Debug.error(e);
            }
        }
    }
    // $NON-NLS-1$
    StringResourceStream stream = new StringResourceStream(css, "text/css");
    stream.setLastModified(time != null ? Time.valueOf(time.longValue()) : null);
    return stream;
}
Also used : Entry(java.util.Map.Entry) FormController(com.servoy.j2db.FormController) RootObjectMetaData(com.servoy.j2db.persistence.RootObjectMetaData) IApplicationServerSingleton(com.servoy.j2db.server.shared.IApplicationServerSingleton) IForm(com.servoy.j2db.IForm) Form(com.servoy.j2db.persistence.Form) ValueMap(org.apache.wicket.util.value.ValueMap) FlattenedSolution(com.servoy.j2db.FlattenedSolution) IForm(com.servoy.j2db.IForm) URL(java.net.URL) Entry(java.util.Map.Entry) IServiceProvider(com.servoy.j2db.IServiceProvider) Iterator(java.util.Iterator) StringResourceStream(org.apache.wicket.util.resource.StringResourceStream) Map(java.util.Map) ValueMap(org.apache.wicket.util.value.ValueMap) FlattenedSolution(com.servoy.j2db.FlattenedSolution) Solution(com.servoy.j2db.persistence.Solution)

Example 2 with IApplicationServerSingleton

use of com.servoy.j2db.server.shared.IApplicationServerSingleton in project servoy-client by Servoy.

the class NGClientWebsocketSession method updateLastAccessed.

@Override
public void updateLastAccessed(IWindow window) {
    super.updateLastAccessed(window);
    // see that the app server is still running
    IApplicationServerSingleton as = ApplicationServerRegistry.get();
    ScheduledExecutorService ee = (as != null ? as.getExecutor() : null);
    // check for window activity each time a window is closed, after the timeout period
    if (ee != null)
        ee.schedule(new Runnable() {

            @Override
            public void run() {
                WebsocketSessionManager.closeInactiveSessions();
            }
        }, getWindowTimeout() * 1000 + 10, TimeUnit.MILLISECONDS);
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) IApplicationServerSingleton(com.servoy.j2db.server.shared.IApplicationServerSingleton)

Example 3 with IApplicationServerSingleton

use of com.servoy.j2db.server.shared.IApplicationServerSingleton in project servoy-client by Servoy.

the class SecuritySupport method initSSLKeyStoreAndPassphrase.

@SuppressWarnings("nls")
private static void initSSLKeyStoreAndPassphrase(Properties settings) throws Exception {
    if (sslKeyStore == null) {
        InputStream is = null;
        try {
            passphrase = "passphrase".toCharArray();
            String filename = settings.getProperty("SocketFactory.SSLKeystorePath", "");
            if (// $NON-NLS-1$
            !"".equals(filename)) {
                try {
                    File file = new File(filename);
                    if (!file.exists()) {
                        IApplicationServerSingleton appServer = ApplicationServerRegistry.exists() ? ApplicationServerRegistry.get() : null;
                        if (appServer != null && appServer.getServoyApplicationServerDirectory() != null) {
                            String applicationServerDirectory = appServer.getServoyApplicationServerDirectory();
                            file = new File(applicationServerDirectory, filename);
                        }
                        if (!file.exists()) {
                            Debug.error("couldn't resolve the ssl keystore file " + file.getAbsolutePath() + ", maybe the user dir (" + System.getProperty("user.dir") + ") of the application server is incorrect, please specify the system property: servoy.application_server.dir to point to the right directory [servoy_install]/application_server");
                        }
                    }
                    is = new FileInputStream(file);
                    passphrase = settings.getProperty("SocketFactory.SSLKeystorePassphrase", "").toCharArray();
                } catch (Exception e) {
                    Debug.error("SSLKeystorePath not found: " + filename + " fallback to default one", e);
                }
            }
            if (is == null) {
                is = SecuritySupport.class.getResourceAsStream("background2.gif");
            }
            sslKeyStore = KeyStore.getInstance("JKS");
            sslKeyStore.load(is, passphrase);
        } finally {
            Utils.closeInputStream(is);
        }
    }
}
Also used : IApplicationServerSingleton(com.servoy.j2db.server.shared.IApplicationServerSingleton) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 4 with IApplicationServerSingleton

use of com.servoy.j2db.server.shared.IApplicationServerSingleton in project servoy-client by Servoy.

the class HeadlessClientFactoryInternal method createSessionBean.

public static ISessionClient createSessionBean(final ServletRequest req, final String solutionname, final String username, final String password, final Object[] solutionOpenMethodArgs) throws Exception {
    final ISessionClient[] sc = { null };
    final Exception[] exception = { null };
    Runnable createSessionBeanRunner = new Runnable() {

        public void run() {
            try {
                IApplicationServerSingleton as = ApplicationServerRegistry.get();
                boolean nodebug = false;
                Object[] openArgs = solutionOpenMethodArgs;
                if (solutionOpenMethodArgs != null && solutionOpenMethodArgs.length != 0 && "nodebug".equals(solutionOpenMethodArgs[solutionOpenMethodArgs.length - 1])) {
                    nodebug = true;
                    openArgs = Utils.arraySub(solutionOpenMethodArgs, 0, solutionOpenMethodArgs.length - 1);
                }
                // When last entry in solutionOpenMethodArgs in "nodebug" a non-debugging client is created.
                if (as.isDeveloperStartup() && !nodebug) {
                    sc[0] = as.getDebugClientHandler().createDebugHeadlessClient(req, username, password, null, openArgs, solutionname);
                } else {
                    sc[0] = new HeadlessClient(req, username, password, null, openArgs, solutionname);
                }
                sc[0].setUseLoginSolution(false);
                sc[0].loadSolution(solutionname);
            } catch (Exception e) {
                exception[0] = e;
                if (sc[0] != null) {
                    try {
                        sc[0].shutDown(true);
                    } catch (Exception ex) {
                        Debug.error(ex);
                    }
                }
            }
        }
    };
    if (Context.getCurrentContext() == null) {
        createSessionBeanRunner.run();
    } else {
        // we are running from a javascript thread, probably developer or webclient, create the bean in a
        // separate thread so that a new context will be created
        // $NON-NLS-1$
        Thread createSessionBeanThread = new Thread(createSessionBeanRunner, "createSessionBean");
        createSessionBeanThread.start();
        createSessionBeanThread.join();
    }
    if (exception[0] != null) {
        throw exception[0];
    }
    return sc[0];
}
Also used : IApplicationServerSingleton(com.servoy.j2db.server.shared.IApplicationServerSingleton) ISessionClient(com.servoy.j2db.ISessionClient) JavaScriptException(org.mozilla.javascript.JavaScriptException) RemoteException(java.rmi.RemoteException) RepositoryException(com.servoy.j2db.persistence.RepositoryException)

Example 5 with IApplicationServerSingleton

use of com.servoy.j2db.server.shared.IApplicationServerSingleton in project servoy-client by Servoy.

the class SelectNGSolutionFilter method doFilter.

public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
    if (Utils.getAsBoolean(Settings.getInstance().getProperty("servoy.allowSolutionBrowsing", "true"))) {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        String uri = request.getServletPath();
        if (uri != null) {
            if (uri.equals("/servoy-ngclient")) {
                // html contents
                ((HttpServletResponse) servletResponse).setContentType("text/html");
                PrintWriter w = servletResponse.getWriter();
                addNeededJSAndCSS(getClass().getResource("solution_list.html"), w);
                w.flush();
                return;
            } else if (uri.equals("/servoy-ngclient/solutions.js")) {
                HTTPUtils.setNoCacheHeaders((HttpServletResponse) servletResponse);
                IApplicationServerSingleton as = ApplicationServerRegistry.get();
                // js contents giving the actual solutions list
                List<Solution> ngCompatibleSolutions = new ArrayList<Solution>();
                if (as.isDeveloperStartup()) {
                    Solution active = as.getDebugClientHandler().getDebugSmartClient().getCurrent();
                    if ((((SolutionMetaData) active.getMetaData()).getSolutionType() & (SolutionMetaData.SOLUTION | SolutionMetaData.NG_CLIENT_ONLY)) != 0)
                        ngCompatibleSolutions.add(active);
                } else {
                    try {
                        RootObjectMetaData[] smds = as.getLocalRepository().getRootObjectMetaDatasForType(IRepository.SOLUTIONS);
                        int solutionType;
                        for (RootObjectMetaData element : smds) {
                            solutionType = ((SolutionMetaData) element).getSolutionType();
                            if ((solutionType & (SolutionMetaData.SOLUTION | SolutionMetaData.NG_CLIENT_ONLY)) > 0) {
                                Solution solution = (Solution) as.getLocalRepository().getActiveRootObject(element.getRootObjectId());
                                if (solution != null) {
                                    ngCompatibleSolutions.add(solution);
                                }
                            }
                        }
                    } catch (RepositoryException e) {
                        Debug.error(e);
                    }
                }
                // now generate the js containing these solutions
                ((HttpServletResponse) servletResponse).setContentType("text/javascript");
                PrintWriter w = servletResponse.getWriter();
                w.println("angular.module('solutionsListModule', []).value('$solutionsList', {");
                w.println("    ngSolutions: [");
                boolean putComma = false;
                for (Solution s : ngCompatibleSolutions) {
                    if (putComma)
                        w.println(",");
                    else
                        putComma = true;
                    String titleText = (s.getTitleText() != null ? "'" + s.getTitleText() + "'" : null);
                    // it wouldn't look nice in the list of solutions to pick + client can't convert those
                    if (titleText != null && (titleText.contains("#") || titleText.startsWith("i18n:")))
                        titleText = null;
                    w.print("        { name : '" + s.getName() + "', titleText : " + titleText + ", requiresAuth : " + s.requireAuthentication() + " }");
                }
                if (putComma)
                    w.println("");
                w.println("    ]");
                w.println("});");
                w.flush();
                return;
            }
        }
    }
    filterChain.doFilter(servletRequest, servletResponse);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) RootObjectMetaData(com.servoy.j2db.persistence.RootObjectMetaData) IApplicationServerSingleton(com.servoy.j2db.server.shared.IApplicationServerSingleton) HttpServletResponse(javax.servlet.http.HttpServletResponse) ArrayList(java.util.ArrayList) List(java.util.List) RepositoryException(com.servoy.j2db.persistence.RepositoryException) Solution(com.servoy.j2db.persistence.Solution) SolutionMetaData(com.servoy.j2db.persistence.SolutionMetaData) PrintWriter(java.io.PrintWriter)

Aggregations

IApplicationServerSingleton (com.servoy.j2db.server.shared.IApplicationServerSingleton)5 RepositoryException (com.servoy.j2db.persistence.RepositoryException)2 RootObjectMetaData (com.servoy.j2db.persistence.RootObjectMetaData)2 Solution (com.servoy.j2db.persistence.Solution)2 FlattenedSolution (com.servoy.j2db.FlattenedSolution)1 FormController (com.servoy.j2db.FormController)1 IForm (com.servoy.j2db.IForm)1 IServiceProvider (com.servoy.j2db.IServiceProvider)1 ISessionClient (com.servoy.j2db.ISessionClient)1 Form (com.servoy.j2db.persistence.Form)1 SolutionMetaData (com.servoy.j2db.persistence.SolutionMetaData)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 PrintWriter (java.io.PrintWriter)1 URL (java.net.URL)1 RemoteException (java.rmi.RemoteException)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1