Example usage for org.apache.wicket.protocol.http WebSession WebSession

List of usage examples for org.apache.wicket.protocol.http WebSession WebSession

Introduction

In this page you can find the example usage for org.apache.wicket.protocol.http WebSession WebSession.

Prototype

public WebSession(Request request) 

Source Link

Document

Constructor.

Usage

From source file:org.jabylon.rest.ui.wicket.JabylonApplication.java

License:Open Source License

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override//from w w  w  . j  a  va 2s . c  o  m
protected void init() {
    super.init();
    mount(new ResouceAwareMountedMapper("/", StartupPage.class)); //$NON-NLS-1$
    getRequestCycleSettings().setResponseRequestEncoding("UTF-8");
    getMarkupSettings().setDefaultMarkupEncoding("UTF-8");
    OSGiInjector injector = new OSGiInjector(this);
    getBehaviorInstantiationListeners().add(injector);
    getResourceSettings().getStringResourceLoaders().add(new OSGiAwareBundleStringResourceLoader());
    getApplicationSettings().setInternalErrorPage(CustomInternalErrorPage.class);
    getComponentInstantiationListeners().add(injector);
    getSecuritySettings().setAuthorizationStrategy(new PermissionBasedAuthorizationStrategy());
    getAjaxRequestTargetListeners().add(new AjaxFeedbackListener());
    final BundleContext bundleContext = Activator.getDefault().getContext();

    pageTracker = new ServiceTracker(bundleContext, PageProvider.class, new ServiceTrackerCustomizer() {

        @Override
        public Object addingService(ServiceReference ref) {

            PageProvider service = (PageProvider) bundleContext.getService(ref);
            Object pathObject = ref.getProperty(PageProvider.MOUNT_PATH_PROPERTY);
            if (pathObject instanceof String) {
                String path = (String) pathObject;
                Class pageClass = service.getPageClass();

                if (pageClass == ResourcePage.class) {
                    //workaround so wicket doesn't choke because the thread context isn't filled (wrong thread)
                    ThreadContext.setApplication(JabylonApplication.this);
                    ThreadContext.setSession(new WebSession(createFakeRequest(null)));
                    //if the main page is ready, we can mount the rest of the pages
                    initMainPages();
                }

                logger.info("Mounting new page {} at {}", pageClass, path); //$NON-NLS-1$
                mount(new ResouceAwareMountedMapper(path, pageClass));

            } else {
                logger.warn("Ignored Page {} because it was registered with invalid path property '{}'", //$NON-NLS-1$
                        service, pathObject);
            }
            return service;
        }

        @Override
        public void modifiedService(ServiceReference arg0, Object arg1) {
            // TODO Auto-generated method stub

        }

        @Override
        public void removedService(ServiceReference ref, Object service) {
            Object pathObject = ref.getProperty(PageProvider.MOUNT_PATH_PROPERTY);
            if (pathObject instanceof String) {
                String path = (String) pathObject;
                internalUmount(path);
            }
        }

    });
    pageTracker.open();
}

From source file:org.jabylon.rest.ui.wicket.JabylonApplication.java

License:Open Source License

private void internalUmount(String path) {
    //workaround so wicket doesn't choke because the thread context isn't filled (wrong thread)
    Application application = ThreadContext.getApplication();
    if (application == null)
        ThreadContext.setApplication(JabylonApplication.this);
    if (ThreadContext.getSession() == null)
        ThreadContext.setSession(new WebSession(createFakeRequest(null)));
    //        unmount(path);
    /*//from   w  w w  .  jav a  2s .  co m
     * umount seems to be greedy, e.g. a prefix match is enough.
     * That's troublesome because umount /settings/log will also umount /settings
     */
    ICompoundRequestMapper rootRequestMapperAsCompound = getRootRequestMapperAsCompound();
    if (rootRequestMapperAsCompound instanceof CompoundRequestMapper) {
        CompoundRequestMapper compound = (CompoundRequestMapper) rootRequestMapperAsCompound;
        Iterator<IRequestMapper> it = compound.iterator();
        while (it.hasNext()) {
            IRequestMapper iRequestMapper = it.next();
            if (iRequestMapper instanceof ResouceAwareMountedMapper) {
                ResouceAwareMountedMapper mapper = (ResouceAwareMountedMapper) iRequestMapper;
                if (path.equals(mapper.getMountPath())) {
                    logger.info("Unmounting  {}", path);
                    getRootRequestMapperAsCompound().remove(mapper);
                }
            }
        }
    }
}

From source file:org.lbogdanov.poker.web.PokerWebApplication.java

License:Apache License

/**
 * {@inheritDoc}//from  w w  w.j ava2s  .  com
 */
@Override
public Session newSession(Request request, Response response) {
    return new WebSession(request) {

        @Override
        public void replaceSession() {
            SecurityUtils.getSubject().getSession().stop();
            super.replaceSession();
        }

    };
}

From source file:org.ops4j.pax.wicket.internal.PageMounterTracker.java

License:Apache License

@Override
public final void removedService(ServiceReference reference, Object mounter) {
    PageMounter pageMounter = (PageMounter) mounter;
    List<MountPointInfo> infos = pageMounter.getMountPoints();
    for (MountPointInfo info : infos) {
        LOGGER.trace("Trying to mount {} with {}", info.getPath(), info.getPage().getName());
        Application oldApp = ThreadContext.getApplication();
        ThreadContext.setApplication(application);
        if (!Session.exists()) {
            Request request = new MockWebRequest(Url.parse(info.getPath()));
            ThreadContext.setSession(new WebSession(request));
        }//w  w  w.j a  v  a  2 s. co  m
        application.unmount(info.getPath());
        ThreadContext.setApplication(oldApp);
        LOGGER.info("Unmounted {} with {}", info.getPath(), info.getPage().getName());
    }

    super.removedService(reference, pageMounter);
}

From source file:org.wicketTutorial.eventinfra.WicketApplication.java

License:Apache License

@Override
public Session newSession(Request request, Response response) {
    return new WebSession(request) {
        @Override//from w  w  w.  j av a 2s.c o  m
        public void onEvent(IEvent<?> event) {
            Session.get().info("I'm the session and I received an event.");
        }
    };
}