Example usage for org.apache.wicket.guice GuiceComponentInjector GuiceComponentInjector

List of usage examples for org.apache.wicket.guice GuiceComponentInjector GuiceComponentInjector

Introduction

In this page you can find the example usage for org.apache.wicket.guice GuiceComponentInjector GuiceComponentInjector.

Prototype

public GuiceComponentInjector(final Application app, final Injector injector) 

Source Link

Document

Constructor

Usage

From source file:biz.turnonline.ecosystem.origin.frontend.FrontendApplication.java

License:Apache License

@Override
protected void init() {
    super.init();

    // add guice component injector
    Injector injector = getInjector();/*from  w w w  .  j  a v a2  s .  c  om*/
    getComponentInstantiationListeners().add(new GuiceComponentInjector(this, injector));

    // set custom resource locator
    IResourceSettings resourceSettings = getResourceSettings();
    List<IResourceFinder> finders = resourceSettings.getResourceFinders();
    Cache memcache = injector.getInstance(Cache.class);
    resourceSettings.setResourceStreamLocator(new MemcacheResourceLocator(finders, memcache));

    // set custom properties factory
    resourceSettings.setPropertiesFactory(new MemcachePropertiesFactory(resourceSettings, memcache, include));

    mountPage(LOGIN, Login.class);
    mountPage(SIGNUP, Signup.class);
    mountPage(MY_ACCOUNT, MyAccount.class);

    // init wicket bootstrap
    BootstrapSettings bootstrapSettings = new BootstrapSettings();
    bootstrapSettings.setThemeProvider(new SingleThemeProvider(new MaterialDesignTheme()));
    bootstrapSettings.useCdnResources(true);
    Bootstrap.install(this, bootstrapSettings);
}

From source file:com.effectivemaven.centrepoint.web.CentrepointApplication.java

License:Apache License

@Override
protected void init() {
    super.init();

    ServletContext servletContext = getWicketFilter().getFilterConfig().getServletContext();

    final String dataLocation = servletContext.getInitParameter("dataLocation");

    final String localRepository = servletContext.getInitParameter("localRepository");

    final String remoteRepository = servletContext.getInitParameter("remoteRepository");

    Injector injector = this.injector;
    if (injector == null) {
        injector = Guice.createInjector(new AbstractModule() {
            @Override/*from  www. jav  a 2 s .c o  m*/
            protected void configure() {
                if (dataLocation != null) {
                    logger.info("Using custom data location: " + dataLocation);
                    bindConstant().annotatedWith(DataLocation.class).to(dataLocation);
                }

                if (remoteRepository != null) {
                    logger.info("Using custom remote repository: " + remoteRepository);
                    bindConstant().annotatedWith(RemoteRepositoryUrl.class).to(remoteRepository);
                }

                if (localRepository != null) {
                    logger.info("Using custom local repository: " + localRepository);
                    bindConstant().annotatedWith(LocalRepository.class).to(localRepository);
                }

                bind(ProjectStore.class).to(PropertiesProjectStore.class).in(Scopes.SINGLETON);
                bind(PluginManager.class).to(PluginManagerImpl.class).in(Scopes.SINGLETON);
                ClassLoader loader = getClass().getClassLoader();
                bind(ClassLoader.class).annotatedWith(Names.named("Plugin ClassLoader")).toInstance(loader);
            }
        });
    }

    // Use Guice to inject components
    addComponentInstantiationListener(new GuiceComponentInjector(this, injector));

    // Configure project viewing under the /project/NUMBER path
    mount(new MixedParamUrlCodingStrategy("/project", ViewProjectPage.class, new String[] { "id" }));
    mount(new MixedParamUrlCodingStrategy("/edit-panel", EditPanelConfigurationPage.class,
            new String[] { "id", "panel" }));
    // Configure a "friendly" URL for adding projects from Maven POMs under the /project/add-maven path
    mountBookmarkablePage("/project/add-maven", null, AddProjectFromMavenPage.class);
}

From source file:com.example.justaddwater.web.app.WicketApplication.java

License:Apache License

@Override
public void init() {
    super.init();

    BeanManager manager = (BeanManager) getServletContext().getAttribute(Listener.BEAN_MANAGER_ATTRIBUTE_NAME);
    new CdiConfiguration(manager).configure(this);

    // for Google App Engine
    getResourceSettings().setResourcePollFrequency(null);

    mountPage("/signup", SignupPage.class);
    mountPage("/forgot", ForgotPasswordPage.class);
    mountPage("/login", LoginPage.class);
    mountPage("/loginhandler", LoginFormHandlerPage.class);
    mountPage("/contact", ContactPage.class);
    mountPage("/about", AboutPage.class);
    mountPage("/change", ChangePasswordPage.class);
    mountPage("/404", Error404Page.class);
    mountPage("/500", Error500Page.class);
    mountPage("/account", AccountPage.class);
    mountPage("/fbauth", FacebookOAuthPage.class);

    final DeployConfiguration dConf = DeployConfiguration.valueOf(getInitParameter("deployconfiguration"));
    log.info("DeployConfiguration: " + dConf);
    switch (dConf) {
    case localhost:
        setRootRequestMapper(new HttpsMapper(getRootRequestMapper(), new HttpsConfig(HTTP_PORT, HTTPS_PORT)));
        break;/*from w w w. j a  va 2  s.com*/
    case appspot:
        setRootRequestMapper(
                new HttpsMapper(getRootRequestMapper(), new HttpsConfig(HTTP_PORT_GAE, HTTPS_PORT_GAE)));
        break;
    default:
        break;
    }
    getSecuritySettings().setAuthorizationStrategy(new AuthorizationStrategy());

    IApplicationSettings settings = getApplicationSettings();
    settings.setInternalErrorPage(Error500Page.class);

    // https://cwiki.apache.org/WICKET/error-pages-and-feedback-messages.html
    getExceptionSettings().setUnexpectedExceptionDisplay(IExceptionSettings.SHOW_INTERNAL_ERROR_PAGE);

    // Enable Guice for field injection on Wicket pages. Unfortunately,
    // constructor injection into
    // pages is not supported. Supplying ServletModule is optional; it
    // enables usage of @RequestScoped and
    // @SessionScoped, which may not be useful for Wicket applications
    // because the WebPage instances are
    // already stored in session, with their dependencies injected once per
    // session.
    getComponentInstantiationListeners().add(new GuiceComponentInjector(this, guiceModule));
    // addComponentInstantiationListener(new GuiceComponentInjector(this,
    // new ServletModule(), new GuiceModule()));

    ISerializer serializer = new GaeObjectSerializer(getApplicationKey());
    getFrameworkSettings().setSerializer(serializer);

    // disable file cleaning because it starts a new thread
    getResourceSettings().setFileCleaner(null);

    setPageManagerProvider(new DefaultPageManagerProvider(WicketApplication.this) {
        protected IDataStore newDataStore() {
            //return new HttpSessionDataStore(getPageManagerContext(), new PageNumberEvictionStrategy(20));
            IDataStore store = new BigTableGAEPageStore(getApplicationKey());
            Guice.createInjector(guiceModule).injectMembers(store);
            return store;
        }
    });
}

From source file:com.pennychecker.wicketexample.WicketApplication.java

License:Apache License

@Override
protected void init() {
    addComponentInstantiationListener(new GuiceComponentInjector(this, injector));
}

From source file:com.ttdev.wicketpagetest.sample.guice.MyApp.java

License:Open Source License

@Override
protected void init() {
    super.init();
    // Starting with wpt 2.0, you don't need and must NOT install
    // the Guice component injector.
    MockableGuiceBeanInjector.installInjector(this, new GuiceComponentInjector(this, new MyModule()));
}

From source file:com.visural.stereotyped.ui.StereotypedApp.java

License:Mozilla Public License

@Override
protected void init() {
    i = GuiceBootstrapper.getInjector(this.getServletContext());
    ServiceProvider.init(i);//from ww w  .  j av  a  2 s .c o  m
    try {
        AtAnnotation.mount(this, "com.visural");
    } catch (ClassNotFoundException ex) {
        throw new IllegalStateException(ex);
    }

    getSecuritySettings().setAuthorizationStrategy(new AuthorizationStrategy(new IClientProvider() {
        private final UserService userService = i.getInstance(UserService.class);
        private final Provider<SessionBean> sessionBean = i.getProvider(SessionBean.class);

        public IClient getCurrentClient() {
            return (IClient) (userService.isAuthenticated()
                    ? userService.getUser(sessionBean.get().getLoggedInUsername())
                    : null);
        }
    }));

    addComponentInstantiationListener(new GuiceComponentInjector(this, i));

    addRenderHeadListener(JavascriptPackageResource.getHeaderContribution(new JQueryResourceReference()));
    addRenderHeadListener(JavascriptPackageResource.getHeaderContribution(new HoverIntentRef()));
    addRenderHeadListener(CSSPackageResource.getHeaderContribution(BasePage.class, "reset-fonts-grids.css"));
    addRenderHeadListener(CSSPackageResource.getHeaderContribution(BasePage.class, "style-2.css"));

    getMarkupSettings().setCompressWhitespace(true);
    getMarkupSettings().setStripWicketTags(true);
    getMarkupSettings().setStripComments(true);
    getRequestCycleSettings().setUnexpectedExceptionDisplay(IExceptionSettings.SHOW_EXCEPTION_PAGE);

    ResourceReference favicon = new FaviconRef();
    favicon.bind(this);
    mountSharedResource("/favicon.ico", favicon.getSharedResourceKey());
}

From source file:de.codepitbull.guice.TestHomePage.java

License:Apache License

@Before
public void setUp() {
    WicketApplication wicketApplication = new WicketApplication();
    tester = new WicketTester(wicketApplication);
    wicketApplication.getComponentInstantiationListeners()
            .add(new GuiceComponentInjector(wicketApplication, new WebApplicationModule()));

}

From source file:de.jetwick.ese.ui.ExampleApp.java

License:Apache License

protected GuiceComponentInjector getGuiceInjector() {
    return new GuiceComponentInjector(this, injector);
}

From source file:de.jetwick.ui.WicketPagesTestClass.java

License:Apache License

protected JetwickApp createJetwickApp() {
    DefaultModule module = new DefaultModule() {

        @Override//  w  w  w. j  a  va2s.co  m
        public void installTwitterModule() {
            bind(TwitterSearch.class).toInstance(createTestTwitterSearch());
        }

        //            @Override
        //            public void installDbModule() {                
        //                WorkManager db = mock(WorkManager.class);
        //                bind(WorkManager.class).toInstance(db);
        //                TagDao tagDao = mock(TagDao.class);
        //                bind(TagDao.class).toInstance(tagDao);
        //                UserDao userDao = mock(UserDao.class);
        //                bind(UserDao.class).toInstance(userDao);
        //            }
        @Override
        public void installSearchModule() {
            ElasticUserSearch userSearch = mock(ElasticUserSearch.class);
            bind(ElasticUserSearch.class).toInstance(mockUserSearch(userSearch));

            ElasticTagSearch tagSearch = mock(ElasticTagSearch.class);
            bind(ElasticTagSearch.class).toInstance(tagSearch);

            ElasticTweetSearch twSearch = mock(ElasticTweetSearch.class);

            // mock this hit/result too!
            //new InternalSearchHit(1, "1", "tweet", source, fields);
            InternalSearchResponse iRsp2 = new InternalSearchResponse(
                    new InternalSearchHits(new InternalSearchHit[0], 0, 0), new InternalFacets(new ArrayList()),
                    true);
            when(twSearch.query((Collection<JUser>) any(), (TweetQuery) any()))
                    .thenReturn(new SearchResponse(iRsp2, "", 4, 4, 1L, new ShardSearchFailure[0]));

            bind(ElasticTweetSearch.class).toInstance(twSearch);
        }

        @Override
        public void installRMIModule() {
            bind(RMIClient.class).toInstance(createRMIClient());
        }
    };
    injector = Guice.createInjector(module);
    return new JetwickApp(injector) {

        @Override
        public String getConfigurationType() {
            return Application.DEVELOPMENT;
        }

        @Override
        protected GuiceComponentInjector getGuiceInjector() {
            return new GuiceComponentInjector(this, injector);
        }

        @Override
        public Session newSession(Request request, Response response) {
            Session sess = super.newSession(request, response);
            return changeSession((MySession) sess, request);
        }
    };
}

From source file:net.fatlenny.datacitation.webapp.WicketApplication.java

License:Apache License

/**
 * @see org.apache.wicket.Application#init()
 *//*  w ww .  ja  v  a 2 s  .c o m*/
@Override
public void init() {
    super.init();

    getComponentInstantiationListeners().add(new GuiceComponentInjector(this, new BindingModule()));

    mountPage("/home", HomePage.class);
    mountPage("/query", QueryPage.class);
    mountPage("/datasetcreation", DatasetCreationPage.class);
}