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;
}
}
};
}
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);
}
}
}
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);
}
}
}
}
}
}
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;
}
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;
}
}
Aggregations