Search in sources :

Example 1 with RequestCycle

use of org.apache.wicket.RequestCycle in project servoy-client by Servoy.

the class WebClientsApplication method newRequestCycleProcessor.

@Override
protected IRequestCycleProcessor newRequestCycleProcessor() {
    return new UrlCompressingWebRequestProcessor() {

        @Override
        public void respond(RequestCycle requestCycle) {
            // execute events from WebClient.invokeLater() before the respond (render) is started
            Session session = Session.get();
            if (session instanceof WebClientSession && ((WebClientSession) session).getWebClient() != null) {
                ((WebClientSession) session).getWebClient().executeEvents();
            }
            super.respond(requestCycle);
        }

        /**
         * @see wicket.protocol.http.WebRequestCycleProcessor#newRequestCodingStrategy()
         */
        @Override
        protected IRequestCodingStrategy newRequestCodingStrategy() {
            Settings settings = Settings.getInstance();
            if (// $NON-NLS-1$ //$NON-NLS-2$
            Utils.getAsBoolean(settings.getProperty("servoy.webclient.crypt-urls", "true"))) {
                return new ServoyCryptedUrlWebRequestCodingStrategy(new UrlCompressingWebCodingStrategy());
            } else {
                return new UrlCompressingWebCodingStrategy();
            }
        }

        @Override
        protected IRequestTarget resolveListenerInterfaceTarget(RequestCycle requestCycle, Page page, String componentPath, String interfaceName, RequestParameters requestParameters) {
            try {
                IRequestTarget requestTarget = super.resolveListenerInterfaceTarget(requestCycle, page, componentPath, interfaceName, requestParameters);
                if (requestTarget instanceof BehaviorRequestTarget) {
                    Component target = ((BehaviorRequestTarget) requestTarget).getTarget();
                    if (!(target instanceof Page)) {
                        boolean invalidPage = false;
                        Page page2 = null;
                        try {
                            // test if it has a page.
                            page2 = target.findParent(Page.class);
                        } catch (Exception e) {
                            Debug.trace(e);
                            invalidPage = true;
                        }
                        if (page2 == null || !page2.getId().equals(page.getId())) {
                            invalidPage = true;
                        }
                        if (invalidPage) {
                            // $NON-NLS-1$
                            Debug.log("Couldn't resolve the page of the component, component already gone from page? returning empty");
                            return EmptyRequestTarget.getInstance();
                        }
                    }
                }
                return requestTarget;
            } catch (Exception e) {
                // $NON-NLS-1$
                Debug.log("couldnt resolve interface, component page already gone from page? returning empty");
            }
            return EmptyRequestTarget.getInstance();
        }

        @Override
        public IRequestTarget resolve(final RequestCycle requestCycle, final RequestParameters requestParameters) {
            try {
                return super.resolve(requestCycle, requestParameters);
            } catch (PageExpiredException e) {
                // if there is a page expired exception
                // then ignore it if there is a current form.
                // $NON-NLS-1$
                Debug.trace("Page expired, checking for a current form");
                Request request = requestCycle.getRequest();
                if (request instanceof WebRequest && ((WebRequest) request).isAjax() && requestParameters.isOnlyProcessIfPathActive()) {
                    // $NON-NLS-1$
                    Debug.trace("Page expired, it is an ajan/process only if active request");
                    Session session = Session.get();
                    if (session instanceof WebClientSession && ((WebClientSession) session).getWebClient() != null) {
                        WebClient webClient = ((WebClientSession) session).getWebClient();
                        if (webClient.getFormManager().getCurrentForm() != null) {
                            // $NON-NLS-1$
                            Debug.trace("Page expired, there is a current form, ignore this ajax request");
                            return EmptyAjaxRequestTarget.getInstance();
                        }
                    }
                }
                throw e;
            }
        }
    };
}
Also used : RequestCycle(org.apache.wicket.RequestCycle) PageExpiredException(org.apache.wicket.protocol.http.PageExpiredException) WebRequest(org.apache.wicket.protocol.http.WebRequest) Request(org.apache.wicket.Request) Page(org.apache.wicket.Page) RestartResponseException(org.apache.wicket.RestartResponseException) AbstractRestartResponseException(org.apache.wicket.AbstractRestartResponseException) IOException(java.io.IOException) PageExpiredException(org.apache.wicket.protocol.http.PageExpiredException) RequestParameters(org.apache.wicket.request.RequestParameters) UrlCompressingWebCodingStrategy(org.apache.wicket.protocol.http.request.urlcompressing.UrlCompressingWebCodingStrategy) BehaviorRequestTarget(org.apache.wicket.request.target.component.listener.BehaviorRequestTarget) WebRequest(org.apache.wicket.protocol.http.WebRequest) IRequestTarget(org.apache.wicket.IRequestTarget) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) Component(org.apache.wicket.Component) Settings(com.servoy.j2db.util.Settings) IWiQuerySettings(org.odlabs.wiquery.core.commons.IWiQuerySettings) IRequestCycleSettings(org.apache.wicket.settings.IRequestCycleSettings) WiQuerySettings(org.odlabs.wiquery.core.commons.WiQuerySettings) UrlCompressingWebRequestProcessor(org.apache.wicket.protocol.http.request.urlcompressing.UrlCompressingWebRequestProcessor) Session(org.apache.wicket.Session)

Example 2 with RequestCycle

use of org.apache.wicket.RequestCycle in project servoy-client by Servoy.

the class DebugClientHandler method executeMethod.

/**
 * @param persist
 * @param elementName
 */
public void executeMethod(final ISupportChilds persist, final String scopeName, final String methodname) {
    final IApplication serviceProvider = getDebugReadyClient();
    if (serviceProvider != null) {
        final Runnable run = new Runnable() {

            public void run() {
                if (persist instanceof Solution) {
                    try {
                        serviceProvider.getScriptEngine().getScopesScope().executeGlobalFunction(scopeName, methodname, null, false, false);
                    } catch (Exception e) {
                        Debug.log(e);
                    }
                } else if (persist instanceof Form) {
                    try {
                        IFormController fp = serviceProvider.getFormManager().leaseFormPanel(((Form) persist).getName());
                        if (fp != null) {
                            fp.initForJSUsage();
                            fp.setView(fp.getView());
                            fp.executeOnLoadMethod();
                            fp.executeFunction(methodname, null, false, null, false, null);
                        }
                    } catch (Exception e) {
                        Debug.log(e);
                    }
                }
            }
        };
        if (serviceProvider == getDebugHeadlessClient() || serviceProvider == getDebugAuthenticator()) {
            ApplicationServerRegistry.get().getExecutor().execute(new Runnable() {

                public void run() {
                    serviceProvider.invokeLater(run);
                }
            });
        } else if (serviceProvider == getDebugWebClient()) {
            ApplicationServerRegistry.get().getExecutor().execute(new Runnable() {

                public void run() {
                    RequestCycle rc = null;
                    try {
                        // fake a request as much as possible
                        WebClientsApplication fakeApplication = ((WebClient) serviceProvider).getFakeApplication();
                        Application.set(fakeApplication);
                        rc = new WebRequestCycle(fakeApplication, new EmptyRequest(), new WebResponse());
                        serviceProvider.invokeAndWait(run);
                    } finally {
                        Application.unset();
                        rc.detach();
                    }
                }
            });
        } else {
            serviceProvider.invokeLater(run);
        }
    }
}
Also used : WebRequestCycle(org.apache.wicket.protocol.http.WebRequestCycle) IApplication(com.servoy.j2db.IApplication) WebResponse(org.apache.wicket.protocol.http.WebResponse) Form(com.servoy.j2db.persistence.Form) WebRequestCycle(org.apache.wicket.protocol.http.WebRequestCycle) RequestCycle(org.apache.wicket.RequestCycle) EmptyRequest(com.servoy.j2db.server.headlessclient.EmptyRequest) IFormController(com.servoy.j2db.IFormController) WebClientsApplication(com.servoy.j2db.server.headlessclient.WebClientsApplication) WebClient(com.servoy.j2db.server.headlessclient.WebClient) IDebugWebClient(com.servoy.j2db.IDebugWebClient) Solution(com.servoy.j2db.persistence.Solution) CoreException(org.eclipse.core.runtime.CoreException)

Example 3 with RequestCycle

use of org.apache.wicket.RequestCycle in project servoy-client by Servoy.

the class MainPage method configureResponse.

/**
 * @see wicket.Page#configureResponse()
 */
@SuppressWarnings("nls")
@Override
protected void configureResponse() {
    super.configureResponse();
    if (getWebRequestCycle().getResponse() instanceof WebResponse) {
        final WebResponse response = getWebRequestCycle().getWebResponse();
        HTTPUtils.setNoCacheHeaders(response.getHttpServletResponse(), "no-store");
    }
    final RequestCycle cycle = getRequestCycle();
    final Response response = cycle.getResponse();
    if (main != null) {
        final MarkupStream markupStream = main.getAssociatedMarkupStream(false);
        if (markupStream != null) {
            // markupStream.setCurrentIndex(0); // this doesn't seem to be needed
            MarkupElement m = markupStream.get();
            if (m != null) {
                String docType = m.toString().trim();
                if (docType.toUpperCase().startsWith("<!DOCTYPE")) {
                    int index = docType.indexOf('>');
                    if (index != -1) {
                        // delegate form doctype to be the mainpage doctype
                        response.write(docType.substring(0, index + 1));
                    } else {
                        // delegate form doctype to be the mainpage doctype
                        response.write(docType);
                    }
                }
            }
        }
    }
}
Also used : IHeaderResponse(org.apache.wicket.markup.html.IHeaderResponse) Response(org.apache.wicket.Response) WebResponse(org.apache.wicket.protocol.http.WebResponse) WebResponse(org.apache.wicket.protocol.http.WebResponse) RequestCycle(org.apache.wicket.RequestCycle) MarkupStream(org.apache.wicket.markup.MarkupStream) MarkupElement(org.apache.wicket.markup.MarkupElement) Point(java.awt.Point)

Example 4 with RequestCycle

use of org.apache.wicket.RequestCycle in project servoy-client by Servoy.

the class MainPage method getRequestMainPage.

public static MainPage getRequestMainPage() {
    RequestCycle rc = RequestCycle.get();
    // can't find the page that generated this request
    if (rc == null)
        return null;
    Page tmp = rc.getResponsePage();
    // can't find the page that generated this request
    if (!(tmp instanceof MainPage))
        return null;
    return (MainPage) tmp;
}
Also used : RequestCycle(org.apache.wicket.RequestCycle) WebPage(org.apache.wicket.markup.html.WebPage) Page(org.apache.wicket.Page)

Example 5 with RequestCycle

use of org.apache.wicket.RequestCycle in project servoy-client by Servoy.

the class WebClient method closeSolution.

@SuppressWarnings("nls")
@Override
public boolean closeSolution(boolean force, Object[] args) {
    if (getSolution() == null || closing)
        return true;
    try {
        RequestCycle rc = RequestCycle.get();
        closing = true;
        MainPage mp = MainPage.getRequestMainPage();
        if (mp == null) {
            mp = getMainPage();
        }
        // generate requests on all other reachable browser tabs/browser windows that are open in this client;
        // so that they can show the "page expired" page (even if AJAX timer is not enabled)
        List<String> triggerReqScripts = getTriggerReqOnOtherPagesJS(rc, mp);
        MainPage.ShowUrlInfo showUrlInfo = mp.getShowUrlInfo();
        // if this page is showing in a div dialog (or is about to be closed as it was in one), the page redirect needs to happen inside root page, not in iframe
        boolean shownInDialog = mp.isShowingInDialog() || mp.isClosingAsDivPopup();
        boolean retval = super.closeSolution(force, args);
        if (retval) {
            // reset path to templates such as servoy_webclient_default.css in case session/client are reused for another solution
            if (rc != null)
                putClientProperty(WEBCONSTANTS.WEBCLIENT_TEMPLATES_DIR, null);
            else {
                // for example when being closed from admin page
                invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        putClientProperty(WEBCONSTANTS.WEBCLIENT_TEMPLATES_DIR, null);
                    }
                });
            }
            if (rc != null && rc.getRequestTarget() instanceof AjaxRequestTarget) {
                // the idea of this line is to block all possible showurl calls generated by any RedirectAjaxRequestTargets arriving (after the solution is closed) on the page,
                // page that might want to actually show some (possibly external and slow) other page instead of page expired
                ((AjaxRequestTarget) rc.getRequestTarget()).appendJavascript("getRootServoyFrame().Servoy.redirectingOnSolutionClose = true;");
                if (triggerReqScripts != null) {
                    for (String js : triggerReqScripts) {
                        ((AjaxRequestTarget) rc.getRequestTarget()).appendJavascript(js);
                    }
                }
            }
            // close all windows
            getRuntimeWindowManager().closeFormInWindow(null, true);
            Collection<Style> userStyles = getFlattenedSolution().flushUserStyles();
            if (userStyles != null) {
                for (Style style : userStyles) {
                    ComponentFactory.flushStyle(this, style);
                }
            }
            getRuntimeProperties().put(IServiceProvider.RT_VALUELIST_CACHE, null);
            getRuntimeProperties().put(IServiceProvider.RT_OVERRIDESTYLE_CACHE, null);
            // what page should be shown next in browser?
            if (rc != null) {
                boolean showDefault = true;
                boolean urlShown = false;
                if (showUrlInfo != null) {
                    showDefault = !"_self".equals(showUrlInfo.getTarget()) && !"_top".equals(showUrlInfo.getTarget());
                    String url = "/";
                    if (showUrlInfo.getUrl() != null) {
                        url = showUrlInfo.getUrl();
                    }
                    if (rc.getRequestTarget() instanceof AjaxRequestTarget) {
                        showUrlInfo.setOnRootFrame(true);
                        showUrlInfo.setUseIFrame(false);
                        String show = MainPage.getShowUrlScript(showUrlInfo, getSettings());
                        if (show != null) {
                            urlShown = true;
                            ((AjaxRequestTarget) rc.getRequestTarget()).appendJavascript(show);
                            // extra call to make sure that it is removed for the next time.
                            mp.getShowUrlScript();
                        }
                    } else {
                        rc.setRequestTarget(new RedirectRequestTarget(url));
                    }
                }
                if (showDefault) {
                    if (Session.exists() && RequestCycle.get() != null) {
                        if (getPreferedSolutionNameToLoadOnInit() == null) {
                            if ((urlShown || shownInDialog) && rc.getRequestTarget() instanceof AjaxRequestTarget) {
                                // if this page is shown in a dialog then try to get the parent so that the page map is not included in the url
                                MainPage page = mp;
                                while ((page.isShowingInDialog() || page.isClosingAsDivPopup()) && page.getCallingContainer() != null) {
                                    page = page.getCallingContainer();
                                }
                                CharSequence urlFor = page.urlFor(SelectSolution.class, null);
                                ((AjaxRequestTarget) rc.getRequestTarget()).appendJavascript(MainPage.getShowUrlScript(new ShowUrlInfo(urlFor.toString(), "_self", null, 0, true, false), getSettings()));
                            } else {
                                mp.setResponsePage(SelectSolution.class);
                            }
                        } else {
                            // if solution browsing is false, make sure that the credentials are kept
                            if (!Utils.getAsBoolean(Settings.getInstance().getProperty("servoy.allowSolutionBrowsing", "true"))) {
                                WebClientSession.get().keepCredentials(getPreferedSolutionNameToLoadOnInit());
                            }
                            Map<String, Object> map = new HashMap<String, Object>();
                            map.put("s", getPreferedSolutionNameToLoadOnInit());
                            map.put("m", getPreferedSolutionMethodNameToCall());
                            if (getPreferedSolutionMethodArguments() != null && getPreferedSolutionMethodArguments().length > 0) {
                                map.put("a", getPreferedSolutionMethodArguments()[0]);
                            }
                            if ((urlShown || shownInDialog) && rc.getRequestTarget() instanceof AjaxRequestTarget) {
                                CharSequence urlFor = mp.urlFor(SolutionLoader.class, new PageParameters(map));
                                ((AjaxRequestTarget) rc.getRequestTarget()).appendJavascript(MainPage.getShowUrlScript(new ShowUrlInfo(urlFor.toString(), "_self", null, 0, true, false), getSettings()));
                            } else {
                                rc.setResponsePage(SolutionLoader.class, new PageParameters(map), null);
                            }
                        }
                    }
                }
            }
        }
        return retval;
    } finally {
        closing = false;
    }
}
Also used : ShowUrlInfo(com.servoy.j2db.server.headlessclient.MainPage.ShowUrlInfo) HashMap(java.util.HashMap) WebRequestCycle(org.apache.wicket.protocol.http.WebRequestCycle) RequestCycle(org.apache.wicket.RequestCycle) PageParameters(org.apache.wicket.PageParameters) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) RedirectRequestTarget(org.apache.wicket.request.target.basic.RedirectRequestTarget) Style(com.servoy.j2db.persistence.Style) ShowUrlInfo(com.servoy.j2db.server.headlessclient.MainPage.ShowUrlInfo)

Aggregations

RequestCycle (org.apache.wicket.RequestCycle)7 Page (org.apache.wicket.Page)2 WebRequestCycle (org.apache.wicket.protocol.http.WebRequestCycle)2 WebResponse (org.apache.wicket.protocol.http.WebResponse)2 IApplication (com.servoy.j2db.IApplication)1 IDebugWebClient (com.servoy.j2db.IDebugWebClient)1 IFormController (com.servoy.j2db.IFormController)1 Form (com.servoy.j2db.persistence.Form)1 Solution (com.servoy.j2db.persistence.Solution)1 Style (com.servoy.j2db.persistence.Style)1 EmptyRequest (com.servoy.j2db.server.headlessclient.EmptyRequest)1 ShowUrlInfo (com.servoy.j2db.server.headlessclient.MainPage.ShowUrlInfo)1 WebClient (com.servoy.j2db.server.headlessclient.WebClient)1 WebClientsApplication (com.servoy.j2db.server.headlessclient.WebClientsApplication)1 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)1 Settings (com.servoy.j2db.util.Settings)1 Point (java.awt.Point)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 AbstractRestartResponseException (org.apache.wicket.AbstractRestartResponseException)1