Search in sources :

Example 1 with IWebClientApplication

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

Aggregations

IWebClientApplication (com.servoy.j2db.IWebClientApplication)1 IRepository (com.servoy.j2db.persistence.IRepository)1 Solution (com.servoy.j2db.persistence.Solution)1 SolutionMetaData (com.servoy.j2db.persistence.SolutionMetaData)1 HashMap (java.util.HashMap)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 PageParameters (org.apache.wicket.PageParameters)1 RestartResponseAtInterceptPageException (org.apache.wicket.RestartResponseAtInterceptPageException)1 RestartResponseException (org.apache.wicket.RestartResponseException)1 WebRequest (org.apache.wicket.protocol.http.WebRequest)1