List of usage examples for org.apache.wicket Page getId
@Override public final String getId()
From source file:com.servoy.j2db.server.headlessclient.SolutionLoader.java
License:Open Source License
public SolutionLoader(PageParameters pp) { SolutionMetaData theReq = null;// w w w . j a v a2 s . c o m try { if (ApplicationServerRegistry.get().getDataServer().isInGlobalMaintenanceMode() || ApplicationServerRegistry.get().getDataServer().isInServerMaintenanceMode()) { // do this before redirect & register client - where it is usually detected, because when clustered // this should result in a valid switch to another server in the cluster by the load balancer; if we wait until // after redirect, a page expired will happen on the other server // throw new AbortWithHttpStatusException(HttpServletResponse.SC_SERVICE_UNAVAILABLE, false); this works, but doesn't show maintenance error page for non-clustered case Session.get().invalidate(); RequestCycle.get().setRedirect(false); throw new RestartResponseException(new ServoyServerInMaintenanceMode()); } } catch (RemoteException e) { // will not happen throw new RuntimeException(e); } FeedbackPanel feedback = new FeedbackPanel("feedback"); add(feedback); StartupArguments argumentsScope = new StartupArguments(pp); String solutionName = argumentsScope.getSolutionName(); String method = argumentsScope.getMethodName(); String firstArgument = argumentsScope.getFirstArgument(); try { IRepository repository = ApplicationServerRegistry.get().getLocalRepository(); SolutionMetaData smd = (SolutionMetaData) repository.getRootObjectMetaData(solutionName, IRepository.SOLUTIONS); if (smd == null || smd.getSolutionType() == SolutionMetaData.SOLUTION || smd.getSolutionType() == SolutionMetaData.WEB_CLIENT_ONLY || ((smd.getSolutionType() == SolutionMetaData.MOBILE || smd.getSolutionType() == SolutionMetaData.MODULE) && ApplicationServerRegistry.get().isDeveloperStartup())) { theReq = smd; } else { Debug.log("Not loading solution " + smd.getName() + ", it is not configured for webclient usage"); theReq = null; } if (theReq != null) { Solution sol = (Solution) repository.getActiveRootObject(solutionName, IRepository.SOLUTIONS); if (sol.getLoginSolutionName() == null && sol.getLoginFormID() <= 0 && theReq.getMustAuthenticate() && !((WebClientSession) getSession()).isSignedIn()) { String authType = pp.getString("sv_auth_type"); //$NON-NLS-1$ boolean authorized = false; if ((authType != null && authType.equals("basic")) || //$NON-NLS-1$ (authType == null && Utils.getAsBoolean(Settings.getInstance() .getProperty("servoy.webclient.basic.authentication", "false")))) //$NON-NLS-1$ //$NON-NLS-2$ { String authorizationHeader = ((WebRequest) RequestCycle.get().getRequest()) .getHttpServletRequest().getHeader("Authorization"); //$NON-NLS-1$ if (authorizationHeader != null) { String authorization = authorizationHeader.substring(6); // TODO: which encoding to use? see http://tools.ietf.org/id/draft-reschke-basicauth-enc-05.xml authorization = new String(Utils.decodeBASE64(authorization)); int index = authorization.indexOf(':'); if (index > 0) { String username = authorization.substring(0, index); String password = authorization.substring(index + 1); authorized = ((WebClientSession) getSession()).authenticate(username, password); } } if (!authorized) { ((WebResponse) RequestCycle.get().getResponse()).getHttpServletResponse() .setHeader("WWW-Authenticate", "Basic realm=\"webclient\""); //$NON-NLS-1$ //$NON-NLS-2$ throw new AbortWithWebErrorCodeException(401); } } if (!authorized) { //signin first throw new RestartResponseAtInterceptPageException(SignIn.class); } } WebClientSession session; HttpSession httpSession; synchronized (sol) { // create the http session httpSession = ((WebRequest) RequestCycle.get().getRequest()).getHttpServletRequest() .getSession(); Session.unset(); session = (WebClientSession) getSession(); session.bind(); session.getClientInfo(); } synchronized (httpSession) { IWebClientApplication sc = session.getWebClient(); if (sc != null && sc.getSolution() != null && sc.getFlattenedSolution().getMainSolutionMetaData().getName().equals(solutionName)) { // make sure it is registered as a start of a request. session.getWebClient().onBeginRequest(session); FormManager formManager = ((FormManager) sc.getFormManager()); String currentPageMapName = getPageMap().getName(); if (currentPageMapName != null && !Utils .equalObjects(sc.getMainPage().getPageMap().getName(), currentPageMapName)) { IMainContainer newContainer = formManager.getOrCreateMainContainer(currentPageMapName); formManager.setCurrentContainer(newContainer, currentPageMapName); } // remove the method/argument from the page parameters, they shouldn't be used to generate a redirect url. pp.remove("method"); //$NON-NLS-1$ pp.remove("m"); //$NON-NLS-1$ pp.remove("argument"); //$NON-NLS-1$ pp.remove("a"); //$NON-NLS-1$ // also remove client method arguments to avoid stackoverflow for deeplinked authenticate solutions (js_login called inside deeplinked method) sc.handleArguments(null); if (method != null) { try { sc.getScriptEngine().getScopesScope().executeGlobalFunction(null, method, (firstArgument == null ? null : new Object[] { firstArgument, argumentsScope.toJSMap() }), false, false); } catch (Exception e1) { sc.reportError( Messages.getString("servoy.formManager.error.ExecutingOpenSolutionMethod", //$NON-NLS-1$ new Object[] { method }), e1); } } if (formManager.getCurrentContainer().getController() == null) { Iterator<Form> e = sc.getFlattenedSolution().getForms(true); // add all forms first, they may be referred to in the login form Form first = sc.getFlattenedSolution().getForm(sc.getSolution().getFirstFormID()); boolean formCanBeInstantiated = sc.getFlattenedSolution().formCanBeInstantiated(first); while (!formCanBeInstantiated && e.hasNext()) { Form form = e.next(); formCanBeInstantiated = sc.getFlattenedSolution().formCanBeInstantiated(form); if (formCanBeInstantiated) first = form; } if (first != null) { formManager.showFormInCurrentContainer(first.getName()); } } } else { sc = session.startSessionClient(theReq, method, argumentsScope); } if (sc.isValid()) { Page page = sc.getMainPage(); // do get it from the real wicket session so that a lock is set on this page. (or waited for the lock) Page p = session.getPage(page.getPageMapName(), page.getId(), page.getCurrentVersionNumber()); if (p instanceof MainPage) { page = p; ShowUrlInfo urlScript = ((MainPage) p).getShowUrlInfo(); if (urlScript != null && "_self".equals(urlScript.getTarget())) { // a redirect was found to it self, just redirect directly to that one. // clear the current main pages show url script first. ((MainPage) p).getShowUrlScript(); RequestCycle.get().setRequestTarget(new RedirectRequestTarget(urlScript.getUrl())); return; } } HybridUrlCodingStrategy.setInitialPageParameters(page, pp); setResponsePage(page); setRedirect(true); //setRedirect(Utils.getAsBoolean(sc.getSettings().getProperty("servoy.webclient.nice.urls", "false"))); } } } } catch (RestartResponseAtInterceptPageException restart) { setRedirect(false); throw restart; } catch (AbortException abort) { setRedirect(true); throw abort; } catch (Exception e) { Debug.error(e); error(e.toString()); } }
From source file:com.servoy.j2db.server.headlessclient.WebClientsApplication.java
License:Open Source License
@Override protected IRequestCycleProcessor newRequestCycleProcessor() { return new UrlCompressingWebRequestProcessor() { @Override//w w w . j a v a 2 s.co m 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 (Utils.getAsBoolean(settings.getProperty("servoy.webclient.crypt-urls", "true"))) //$NON-NLS-1$ //$NON-NLS-2$ { 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 { page2 = target.findParent(Page.class); // test if it has a page. } catch (Exception e) { Debug.trace(e); invalidPage = true; } if (page2 == null || !page2.getId().equals(page.getId())) { invalidPage = true; } if (invalidPage) { Debug.log( "Couldn't resolve the page of the component, component already gone from page? returning empty"); //$NON-NLS-1$ return EmptyRequestTarget.getInstance(); } } } return requestTarget; } catch (Exception e) { Debug.log("couldnt resolve interface, component page already gone from page? returning empty"); //$NON-NLS-1$ } 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. Debug.trace("Page expired, checking for a current form"); //$NON-NLS-1$ Request request = requestCycle.getRequest(); if (request instanceof WebRequest && ((WebRequest) request).isAjax() && requestParameters.isOnlyProcessIfPathActive()) { Debug.trace("Page expired, it is an ajan/process only if active request"); //$NON-NLS-1$ Session session = Session.get(); if (session instanceof WebClientSession && ((WebClientSession) session).getWebClient() != null) { WebClient webClient = ((WebClientSession) session).getWebClient(); if (webClient.getFormManager().getCurrentForm() != null) { Debug.trace("Page expired, there is a current form, ignore this ajax request"); //$NON-NLS-1$ return EmptyAjaxRequestTarget.getInstance(); } } } throw e; } } }; }