Skip to content

Commit

Permalink
Merge pull request #83 from drewwills/bootify-resource-server-webapp1
Browse files Browse the repository at this point in the history
Replace the current resource-server-webapp with a version based on Spring Boot and add support for webjars
  • Loading branch information
bjagg authored Jan 20, 2022
2 parents db165bf + 6b5e1ba commit efa9174
Show file tree
Hide file tree
Showing 13 changed files with 263 additions and 436 deletions.
55 changes: 0 additions & 55 deletions resource-server-webapp/NOTICE

This file was deleted.

163 changes: 87 additions & 76 deletions resource-server-webapp/pom.xml
Original file line number Diff line number Diff line change
@@ -1,83 +1,94 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.jasig.resourceserver</groupId>
<artifactId>resource-server-parent</artifactId>
<version>1.0.49-SNAPSHOT</version>
</parent>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<modelVersion>4.0.0</modelVersion>
<artifactId>resource-server-webapp</artifactId>
<packaging>war</packaging>
<!-- These must also be defined here b/c this module inherits from the Spring Boot parent pom,
not the resource-server parent pom. -->
<groupId>org.jasig.resourceserver</groupId>
<version>1.0.49-SNAPSHOT</version>

<name>Resource Server Webapp</name>
<artifactId>resource-server-webapp</artifactId>
<packaging>war</packaging>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>resource-server-content</artifactId>
<version>${project.version}</version>
<type>war</type>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>resource-server-utils</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<name>Resource Server Webapp</name>
<description>Serves static resources with helpful features like cache control headers, gzip, and webjar support</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>

<dependencies>

<!-- Spring Boot dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>


<!-- Other dependencies -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>resource-server-content</artifactId>
<version>${project.version}</version>
<type>war</type>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>resource-server-utils</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

<build>
<finalName>ResourceServingWebapp</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<overlays>
<overlay>
<groupId>org.jasig.resourceserver</groupId>
<artifactId>resource-server-content</artifactId>
<!-- Prevent the resource-server-content module from adding a web.xml -->
<includes>
<include>rs/**</include>
</includes>
</overlay>
</overlays>
</configuration>
</plugin>
</plugins>
</build>

<build>
<finalName>ResourceServingWebapp</finalName>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.jasig.portal.resourceserver;

import net.sf.ehcache.CacheManager;
import net.sf.ehcache.management.ManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.MethodInvokingFactoryBean;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.jmx.support.MBeanServerFactoryBean;

@SpringBootApplication
@EnableCaching
public class ResourceServerWebappApplication {

@Autowired
private CacheManager cacheManager;

public static void main(String[] args) {
SpringApplication.run(ResourceServerWebappApplication.class, args);
}

@Bean
public MBeanServerFactoryBean mbeanServer() {
final MBeanServerFactoryBean rslt = new MBeanServerFactoryBean();
rslt.setLocateExistingServerIfPossible(true);
return rslt;
}

@Bean
public MethodInvokingFactoryBean ehcacheRegisterMBeans() {
final MethodInvokingFactoryBean rslt = new MethodInvokingFactoryBean();
rslt.setTargetClass(ManagementService.class);
rslt.setTargetMethod("registerMBeans");
rslt.setArguments(cacheManager, mbeanServer().getObject(), true, true, true, true);
return rslt;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.jasig.portal.resourceserver;

import net.sf.ehcache.CacheManager;
import org.jasig.resourceserver.aggr.ResourcesDao;
import org.jasig.resourceserver.aggr.ResourcesDaoImpl;
import org.jasig.resourceserver.utils.aggr.ResourcesElementsProvider;
import org.jasig.resourceserver.utils.aggr.ResourcesElementsProviderImpl;
import org.jasig.resourceserver.utils.cache.ConfigurablePageCachingFilter;
import org.jasig.resourceserver.utils.filter.CacheExpirationFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ServetFilterConfiguration {

private static final String PAGE_CACHE_NAME = "SimplePageCachingFilter";

@Autowired
private CacheManager cacheManager;

@Bean
public ResourcesDao resourcesDao() {
return new ResourcesDaoImpl();
}

@Bean
public ResourcesElementsProvider resourcesElementsProvider() {
final ResourcesElementsProviderImpl rslt = new ResourcesElementsProviderImpl();
rslt.setResourcesDao(resourcesDao());
return rslt;
}

@Bean
public FilterRegistrationBean pageCachingFilter() {
final ConfigurablePageCachingFilter filter = new ConfigurablePageCachingFilter(cacheManager, PAGE_CACHE_NAME);
filter.setResourcesElementsProvider(resourcesElementsProvider());

FilterRegistrationBean rslt = new FilterRegistrationBean();
rslt.setFilter(filter);
rslt.addUrlPatterns("*.js", "*.css");
rslt.addInitParameter("targetFilterLifecycle", "true");
rslt.setName("pageCachingFilter");
return rslt;
}

@Bean
public FilterRegistrationBean cacheExpirationFilter() {
final CacheExpirationFilter filter = new CacheExpirationFilter();

FilterRegistrationBean rslt = new FilterRegistrationBean();
rslt.setFilter(filter);
rslt.addUrlPatterns("/rs/*");
rslt.setName("CacheExpiresFilter");
return rslt;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.jasig.portal.resourceserver;

import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

public class ServletInitializer extends SpringBootServletInitializer {

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(ResourceServerWebappApplication.class);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.jasig.portal.resourceserver;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@EnableWebMvc
public class WebConfiguration implements WebMvcConfigurer {

/**
* Makes static resources within webjars (i.e. JavaScript) available from a browser. Solution
* based on this article: http://www.baeldung.com/maven-webjars.
*/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {

registry
.addResourceHandler("/rs/**")
.addResourceLocations("/rs/");
registry
.addResourceHandler("/webjars/**")
.addResourceLocations("/webjars/");
}

}
Loading

0 comments on commit efa9174

Please sign in to comment.