Search in sources :

Example 1 with UrlCompressingWebRequestProcessor

use of org.apache.wicket.protocol.http.request.urlcompressing.UrlCompressingWebRequestProcessor 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)

Aggregations

IFieldComponent (com.servoy.j2db.ui.IFieldComponent)1 Settings (com.servoy.j2db.util.Settings)1 IOException (java.io.IOException)1 AbstractRestartResponseException (org.apache.wicket.AbstractRestartResponseException)1 Component (org.apache.wicket.Component)1 IRequestTarget (org.apache.wicket.IRequestTarget)1 Page (org.apache.wicket.Page)1 Request (org.apache.wicket.Request)1 RequestCycle (org.apache.wicket.RequestCycle)1 RestartResponseException (org.apache.wicket.RestartResponseException)1 Session (org.apache.wicket.Session)1 PageExpiredException (org.apache.wicket.protocol.http.PageExpiredException)1 WebRequest (org.apache.wicket.protocol.http.WebRequest)1 UrlCompressingWebCodingStrategy (org.apache.wicket.protocol.http.request.urlcompressing.UrlCompressingWebCodingStrategy)1 UrlCompressingWebRequestProcessor (org.apache.wicket.protocol.http.request.urlcompressing.UrlCompressingWebRequestProcessor)1 RequestParameters (org.apache.wicket.request.RequestParameters)1 BehaviorRequestTarget (org.apache.wicket.request.target.component.listener.BehaviorRequestTarget)1 IRequestCycleSettings (org.apache.wicket.settings.IRequestCycleSettings)1 IWiQuerySettings (org.odlabs.wiquery.core.commons.IWiQuerySettings)1 WiQuerySettings (org.odlabs.wiquery.core.commons.WiQuerySettings)1