Search in sources :

Example 11 with SolutionMetaData

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

the class DebugWebClient method checkForChanges.

public synchronized boolean checkForChanges() {
    if (getClientInfo() == null)
        return false;
    boolean changed = false;
    SolutionMetaData mainSolutionMetaData = getFlattenedSolution().getMainSolutionMetaData();
    if ((mainSolutionMetaData == null && solution != null) || (mainSolutionMetaData != null && !mainSolutionMetaData.getName().equals(solution.getName()))) {
        try {
            loadSolution(solution);
            changed = true;
        } catch (Exception e) {
            Debug.error(e);
        }
    }
    if (!changed) {
        changed = performRefresh();
    }
    if (getSolution() != null && form != null) {
        getFormManager().showFormInMainPanel(form.getName());
        form = null;
        changed = true;
    }
    return changed;
}
Also used : SolutionMetaData(com.servoy.j2db.persistence.SolutionMetaData) RepositoryException(com.servoy.j2db.persistence.RepositoryException)

Example 12 with SolutionMetaData

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

the class NGClientEntryFilter method doFilter.

@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
    try {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        if ("GET".equalsIgnoreCase(request.getMethod())) {
            if (request.getCharacterEncoding() == null)
                request.setCharacterEncoding("UTF8");
            String uri = request.getRequestURI();
            if (handleShortSolutionRequest(request, response)) {
                return;
            }
            if (handleDeeplink(request, response)) {
                return;
            }
            if (handleRecording(request, response)) {
                return;
            }
            if (uri != null && (uri.endsWith(".html") || uri.endsWith(".js"))) {
                String solutionName = getSolutionNameFromURI(uri);
                if (solutionName != null) {
                    String clientnr = AngularIndexPageWriter.getClientNr(uri, request);
                    INGClientWebsocketSession wsSession = null;
                    HttpSession httpSession = request.getSession(false);
                    if (clientnr != null && httpSession != null) {
                        wsSession = (INGClientWebsocketSession) WebsocketSessionManager.getSession(CLIENT_ENDPOINT, httpSession, Integer.parseInt(clientnr));
                    }
                    FlattenedSolution fs = null;
                    boolean closeFS = false;
                    if (wsSession != null) {
                        fs = wsSession.getClient().getFlattenedSolution();
                    }
                    if (fs == null) {
                        try {
                            closeFS = true;
                            IApplicationServer as = ApplicationServerRegistry.getService(IApplicationServer.class);
                            if (AngularIndexPageWriter.applicationServerUnavailable(response, as)) {
                                return;
                            }
                            SolutionMetaData solutionMetaData = (SolutionMetaData) ApplicationServerRegistry.get().getLocalRepository().getRootObjectMetaData(solutionName, SOLUTIONS);
                            if (AngularIndexPageWriter.solutionMissing(response, solutionName, solutionMetaData)) {
                                return;
                            }
                            fs = new FlattenedSolution(solutionMetaData, new AbstractActiveSolutionHandler(as) {

                                @Override
                                public IRepository getRepository() {
                                    return ApplicationServerRegistry.get().getLocalRepository();
                                }
                            });
                        } catch (Exception e) {
                            Debug.error("error loading solution: " + solutionName + " for clientnr: " + clientnr, e);
                        }
                    }
                    if (fs != null) {
                        try {
                            if (handleMainJs(request, response, fs)) {
                                return;
                            }
                            if (handleForm(request, response, wsSession, fs)) {
                                return;
                            }
                            if (AngularIndexPageWriter.handleMaintenanceMode(request, response, wsSession)) {
                                return;
                            }
                            // prepare for possible index.html lookup
                            Map<String, Object> variableSubstitution = getSubstitutions(request, solutionName, clientnr, fs);
                            List<String> extraMeta = new ArrayList<String>();
                            addManifest(fs, extraMeta);
                            addHeadIndexContributions(fs, extraMeta);
                            ContentSecurityPolicyConfig contentSecurityPolicyConfig = addcontentSecurityPolicyHeader(request, response, true);
                            super.doFilter(servletRequest, servletResponse, filterChain, asList(SERVOY_CSS), new ArrayList<String>(getFormScriptReferences(fs)), extraMeta, variableSubstitution, contentSecurityPolicyConfig == null ? null : contentSecurityPolicyConfig.getNonce());
                            return;
                        } finally {
                            if (closeFS) {
                                fs.close(null);
                            }
                        }
                    }
                }
            }
            if (!uri.contains(ModifiablePropertiesGenerator.PUSH_TO_SERVER_BINDINGS_LIST))
                Debug.log("No solution found for this request, calling the default filter: " + uri);
        }
        super.doFilter(servletRequest, servletResponse, filterChain, null, null, null, null, null);
    } catch (RuntimeException | Error e) {
        Debug.error(e);
        throw e;
    }
}
Also used : HttpSession(javax.servlet.http.HttpSession) ArrayList(java.util.ArrayList) HttpServletResponse(javax.servlet.http.HttpServletResponse) FlattenedSolution(com.servoy.j2db.FlattenedSolution) IApplicationServer(com.servoy.j2db.server.shared.IApplicationServer) SolutionMetaData(com.servoy.j2db.persistence.SolutionMetaData) ServletException(javax.servlet.ServletException) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ContentSecurityPolicyConfig(org.sablo.security.ContentSecurityPolicyConfig) HttpServletRequest(javax.servlet.http.HttpServletRequest) AbstractActiveSolutionHandler(com.servoy.j2db.AbstractActiveSolutionHandler) JSONObject(org.json.JSONObject)

Example 13 with SolutionMetaData

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

the class AngularIndexPageWriter method getFlattenedSolution.

private static Pair<FlattenedSolution, Boolean> getFlattenedSolution(String solutionName, String clientnr, HttpServletRequest request, HttpServletResponse response) {
    INGClientWebsocketSession wsSession = null;
    HttpSession httpSession = request.getSession(false);
    if (clientnr != null && httpSession != null) {
        wsSession = (INGClientWebsocketSession) WebsocketSessionManager.getSession(CLIENT_ENDPOINT, httpSession, Integer.parseInt(clientnr));
    }
    FlattenedSolution fs = null;
    boolean closeFS = false;
    if (wsSession != null) {
        fs = wsSession.getClient().getFlattenedSolution();
    }
    if (fs == null) {
        try {
            closeFS = true;
            IApplicationServer as = ApplicationServerRegistry.getService(IApplicationServer.class);
            if (applicationServerUnavailable(response, as)) {
                return new Pair<FlattenedSolution, Boolean>(null, Boolean.FALSE);
            }
            SolutionMetaData solutionMetaData = (SolutionMetaData) ApplicationServerRegistry.get().getLocalRepository().getRootObjectMetaData(solutionName, SOLUTIONS);
            if (solutionMissing(response, solutionName, solutionMetaData)) {
                return new Pair<FlattenedSolution, Boolean>(null, Boolean.FALSE);
            }
            fs = new FlattenedSolution(solutionMetaData, new AbstractActiveSolutionHandler(as) {

                @Override
                public IRepository getRepository() {
                    return ApplicationServerRegistry.get().getLocalRepository();
                }
            });
        } catch (Exception e) {
            Debug.error("error loading solution: " + solutionName + " for clientnr: " + clientnr, e);
        }
    }
    return new Pair<FlattenedSolution, Boolean>(fs, Boolean.valueOf(closeFS));
}
Also used : AbstractActiveSolutionHandler(com.servoy.j2db.AbstractActiveSolutionHandler) HttpSession(javax.servlet.http.HttpSession) FlattenedSolution(com.servoy.j2db.FlattenedSolution) IApplicationServer(com.servoy.j2db.server.shared.IApplicationServer) SolutionMetaData(com.servoy.j2db.persistence.SolutionMetaData) ServletException(javax.servlet.ServletException) JSONException(org.json.JSONException) IOException(java.io.IOException) Pair(com.servoy.j2db.util.Pair)

Example 14 with SolutionMetaData

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

Example 15 with SolutionMetaData

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

the class MediaResourcesServlet method sendFlattenedSolutionBasedMedia.

private boolean sendFlattenedSolutionBasedMedia(HttpServletRequest request, HttpServletResponse response, String rootSolutionName, String mediaName) throws IOException {
    FlattenedSolution fs = null;
    try {
        IApplicationServer as = ApplicationServerRegistry.getService(IApplicationServer.class);
        SolutionMetaData solutionMetaData = (SolutionMetaData) ApplicationServerRegistry.get().getLocalRepository().getRootObjectMetaData(rootSolutionName, IRepository.SOLUTIONS);
        if (solutionMetaData == null) {
            Debug.error("Solution '" + rootSolutionName + "' was not found when sending media data for '" + mediaName + "'.");
            return false;
        }
        fs = new FlattenedSolution(solutionMetaData, new AbstractActiveSolutionHandler(as) {

            @Override
            public IRepository getRepository() {
                return ApplicationServerRegistry.get().getLocalRepository();
            }
        });
    } catch (RepositoryException e) {
        Debug.error(e);
    }
    try {
        return findAndSendMediaData(request, response, mediaName, fs);
    } finally {
        fs.close(null);
    }
}
Also used : AbstractActiveSolutionHandler(com.servoy.j2db.AbstractActiveSolutionHandler) FlattenedSolution(com.servoy.j2db.FlattenedSolution) IApplicationServer(com.servoy.j2db.server.shared.IApplicationServer) RepositoryException(com.servoy.j2db.persistence.RepositoryException) 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