Enable creating an API using Spring Web #5
16
pom.xml
16
pom.xml
@ -91,6 +91,22 @@
|
|||||||
<artifactId>wicket-guice</artifactId>
|
<artifactId>wicket-guice</artifactId>
|
||||||
<version>${wicket.version}</version>
|
<version>${wicket.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.wicket</groupId>
|
||||||
|
<artifactId>wicket-spring</artifactId>
|
||||||
|
<version>${wicket.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-web</artifactId>
|
||||||
|
<version>6.1.4</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-orm</artifactId>
|
||||||
|
<version>6.1.4</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- Servlet API, needed for compilation. -->
|
<!-- Servlet API, needed for compilation. -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
13
view/pom.xml
13
view/pom.xml
@ -46,6 +46,10 @@
|
|||||||
<groupId>org.apache.wicket</groupId>
|
<groupId>org.apache.wicket</groupId>
|
||||||
<artifactId>wicket-guice</artifactId>
|
<artifactId>wicket-guice</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.wicket</groupId>
|
||||||
|
<artifactId>wicket-spring</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.wicket</groupId>
|
<groupId>org.apache.wicket</groupId>
|
||||||
<artifactId>wicket-extensions</artifactId>
|
<artifactId>wicket-extensions</artifactId>
|
||||||
@ -87,6 +91,15 @@
|
|||||||
<version>5.3.2</version>
|
<version>5.3.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-orm</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- Servlet API, needed for compilation. -->
|
<!-- Servlet API, needed for compilation. -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>jakarta.servlet</groupId>
|
<groupId>jakarta.servlet</groupId>
|
||||||
|
@ -1,68 +1,134 @@
|
|||||||
import com.google.inject.AbstractModule;
|
import jakarta.inject.Named;
|
||||||
import com.google.inject.Guice;
|
import jakarta.inject.Provider;
|
||||||
import com.google.inject.Injector;
|
import jakarta.inject.Singleton;
|
||||||
import com.google.inject.Module;
|
import jakarta.persistence.EntityManager;
|
||||||
import com.google.inject.name.Names;
|
import jakarta.persistence.EntityManagerFactory;
|
||||||
import com.google.inject.persist.PersistFilter;
|
import jakarta.persistence.Persistence;
|
||||||
import com.google.inject.servlet.GuiceServletContextListener;
|
|
||||||
import com.google.inject.servlet.ServletModule;
|
|
||||||
import org.apache.wicket.guice.GuiceWebApplicationFactory;
|
|
||||||
import org.apache.wicket.protocol.http.WicketFilter;
|
|
||||||
|
|
||||||
import jakarta.servlet.ServletContext;
|
import jakarta.servlet.ServletContext;
|
||||||
|
import jakarta.servlet.ServletException;
|
||||||
|
import org.apache.wicket.protocol.http.WicketFilter;
|
||||||
|
import org.apache.wicket.spring.injection.annot.SpringComponentInjector;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter;
|
||||||
|
import org.springframework.web.WebApplicationInitializer;
|
||||||
|
import org.springframework.web.context.ContextLoaderListener;
|
||||||
|
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||||
|
import se.su.dsv.scipro.SciProApplication;
|
||||||
|
import se.su.dsv.scipro.gdpr.Reporter;
|
||||||
|
import se.su.dsv.scipro.profiles.CurrentProfile;
|
||||||
|
import se.su.dsv.scipro.system.Lifecycle;
|
||||||
|
import se.su.dsv.scipro.system.ResearchArea;
|
||||||
|
import se.su.dsv.scipro.system.User;
|
||||||
|
import se.su.dsv.scipro.system.UserImportService;
|
||||||
|
import se.su.dsv.scipro.system.UserService;
|
||||||
|
import se.su.dsv.scipro.system.UserServiceImpl;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.net.CookieHandler;
|
import java.net.CookieHandler;
|
||||||
import java.net.CookieManager;
|
import java.net.CookieManager;
|
||||||
import java.time.Clock;
|
import java.nio.file.Path;
|
||||||
import java.util.Enumeration;
|
import java.util.List;
|
||||||
import java.util.HashMap;
|
import java.util.Optional;
|
||||||
import java.util.Map;
|
import java.util.Set;
|
||||||
import java.util.ServiceLoader;
|
|
||||||
|
|
||||||
public class ApplicationBootstrap extends GuiceServletContextListener {
|
public class ApplicationBootstrap implements WebApplicationInitializer {
|
||||||
@Override
|
@Override
|
||||||
protected Injector getInjector() {
|
public void onStartup(ServletContext servletContext)
|
||||||
|
throws ServletException
|
||||||
|
{
|
||||||
// preserve cookies when using Jersey which will use the logged in session cookie from
|
// preserve cookies when using Jersey which will use the logged in session cookie from
|
||||||
// Daisy API thus drastically speeding up the batch jobs
|
// Daisy API thus drastically speeding up the batch jobs
|
||||||
CookieHandler.setDefault(new CookieManager());
|
CookieHandler.setDefault(new CookieManager());
|
||||||
return Guice.createInjector(
|
AnnotationConfigWebApplicationContext webApplicationContext = new AnnotationConfigWebApplicationContext();
|
||||||
new ServletModule() {
|
webApplicationContext.register(SciProApplication.class);
|
||||||
|
webApplicationContext.register(CurrentProfile.class);
|
||||||
|
webApplicationContext.register(Config.class);
|
||||||
|
webApplicationContext.refresh();
|
||||||
|
|
||||||
|
servletContext.addListener(new ContextLoaderListener(webApplicationContext));
|
||||||
|
|
||||||
|
SciProApplication sciProApplication = webApplicationContext.getBean(SciProApplication.class);
|
||||||
|
sciProApplication.getComponentInstantiationListeners()
|
||||||
|
.add(new SpringComponentInjector(sciProApplication, webApplicationContext));
|
||||||
|
|
||||||
|
servletContext.addFilter("osiv", OpenEntityManagerInViewFilter.class)
|
||||||
|
.addMappingForUrlPatterns(null, false, "/*");
|
||||||
|
|
||||||
|
WicketFilter filter = new WicketFilter(sciProApplication);
|
||||||
|
filter.setFilterPath("");
|
||||||
|
|
||||||
|
servletContext.addFilter("wicket-filter", filter)
|
||||||
|
.addMappingForUrlPatterns(null, true, "/*");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public static class Config {
|
||||||
|
@Bean
|
||||||
|
@Named("profile")
|
||||||
|
public String test() {
|
||||||
|
return "DEV";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Lifecycle dummy() {
|
||||||
|
return new Lifecycle() {
|
||||||
@Override
|
@Override
|
||||||
protected void configureServlets() {
|
public void start() {
|
||||||
final ServletContext servletContext = getServletContext();
|
|
||||||
final Enumeration<String> initParameterNames = servletContext.getInitParameterNames();
|
|
||||||
while (initParameterNames.hasMoreElements()) {
|
|
||||||
final String parameterName = initParameterNames.nextElement();
|
|
||||||
final String value = servletContext.getInitParameter(parameterName);
|
|
||||||
bindConstant().annotatedWith(Names.named(parameterName)).to(value);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
|
||||||
new ServletModule() {
|
|
||||||
@Override
|
@Override
|
||||||
protected void configureServlets() {
|
public void stop() {
|
||||||
filter("/*").through(PersistFilter.class);
|
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
new AbstractModule() {
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Reporter reporter() {
|
||||||
|
return user -> null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@Singleton
|
||||||
|
public EntityManagerFactory entityManagerFactory() {
|
||||||
|
System.out.println("Creating EntityManagerFactory");
|
||||||
|
return Persistence.createEntityManagerFactory("defaultPersistenceUnit");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public EntityManager entityManager(EntityManagerFactory entityManagerFactory) {
|
||||||
|
return entityManagerFactory.createEntityManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public UserService userService(Provider<EntityManager> entityManagerProvider) {
|
||||||
|
return new UserServiceImpl(entityManagerProvider);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public UserImportService importService() {
|
||||||
|
return new UserImportService() {
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
public Optional<User> importUser(String userName) {
|
||||||
bind(Clock.class).toInstance(Clock.systemDefaultZone());
|
return Optional.empty();
|
||||||
ServiceLoader<Module> modules = ServiceLoader.load(Module.class);
|
|
||||||
for (Module module : modules) {
|
|
||||||
install(module);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
|
||||||
new ServletModule() {
|
|
||||||
@Override
|
@Override
|
||||||
protected void configureServlets() {
|
public List<ImportableUser> search(String searchTerm) {
|
||||||
Map<String,String> params = new HashMap<>();
|
return List.of();
|
||||||
params.put(WicketFilter.FILTER_MAPPING_PARAM, "/*");
|
|
||||||
params.put(WicketFilter.APP_FACT_PARAM, GuiceWebApplicationFactory.class.getName());
|
|
||||||
params.put("injectorContextAttribute", Injector.class.getName());
|
|
||||||
filter("/*").through(new WicketFilter(), params);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void importUser(ImportableUser importableUser) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<ResearchArea> importResearchAreasForSupervisor(User supervisor) {
|
||||||
|
return Set.of();
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -334,7 +334,7 @@ public class SciProApplication extends LifecycleManagedWebApplication {
|
|||||||
mountPage("admin/users/import", AdminImportUserPage.class);
|
mountPage("admin/users/import", AdminImportUserPage.class);
|
||||||
mountPage("admin/users/roles", AdminRolePage.class);
|
mountPage("admin/users/roles", AdminRolePage.class);
|
||||||
mountPage("admin/users/switch", AdminSwitchUserPage.class);
|
mountPage("admin/users/switch", AdminSwitchUserPage.class);
|
||||||
mountResource("gdpr/report", new GDPRReportResourceReference());
|
//mountResource("gdpr/report", new GDPRReportResourceReference());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void mountNotificationAndSettingsPages() {
|
private void mountNotificationAndSettingsPages() {
|
||||||
|
@ -5,15 +5,6 @@
|
|||||||
|
|
||||||
<display-name>SciPro</display-name>
|
<display-name>SciPro</display-name>
|
||||||
|
|
||||||
<filter>
|
|
||||||
<filter-name>guiceFilter</filter-name>
|
|
||||||
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
|
|
||||||
</filter>
|
|
||||||
<filter-mapping>
|
|
||||||
<filter-name>guiceFilter</filter-name>
|
|
||||||
<url-pattern>/*</url-pattern>
|
|
||||||
</filter-mapping>
|
|
||||||
|
|
||||||
<listener>
|
<listener>
|
||||||
<listener-class>ApplicationBootstrap</listener-class>
|
<listener-class>ApplicationBootstrap</listener-class>
|
||||||
</listener>
|
</listener>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user