Skip to content

Commit

Permalink
Merge pull request #208 from bjagg/chore/upgrade-spring-boot
Browse files Browse the repository at this point in the history
chore(deps): update POMs and code for Spring Boot 2.6.1
  • Loading branch information
bjagg authored Dec 21, 2021
2 parents 676b897 + 3a4442d commit fb0290d
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 51 deletions.
25 changes: 14 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<project.build.targetVersion>1.8</project.build.targetVersion>

<jaxb2basicsVersion>0.12.0</jaxb2basicsVersion>
<springVersion>5.3.14</springVersion>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -78,8 +79,9 @@
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2</version>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
Expand All @@ -88,8 +90,9 @@
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down Expand Up @@ -149,7 +152,7 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>3.2.18.RELEASE</version>
<version>${springVersion}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
Expand All @@ -160,7 +163,7 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.2.18.RELEASE</version>
<version>${springVersion}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
Expand All @@ -171,7 +174,7 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>3.2.18.RELEASE</version>
<version>${springVersion}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
Expand All @@ -182,7 +185,7 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.2.18.RELEASE</version>
<version>${springVersion}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
Expand All @@ -193,7 +196,7 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>3.2.18.RELEASE</version>
<version>${springVersion}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
Expand All @@ -204,7 +207,7 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.2.18.RELEASE</version>
<version>${springVersion}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
Expand All @@ -215,7 +218,7 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.2.18.RELEASE</version>
<version>${springVersion}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
Expand Down
4 changes: 2 additions & 2 deletions resource-server-utils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<artifactId>javax.servlet.jsp-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.jasig.resourceserver.utils.filter;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

import javax.servlet.FilterChain;
import javax.servlet.ServletContext;
Expand All @@ -36,22 +37,22 @@
import org.springframework.web.filter.GenericFilterBean;

/**
* CacheExpirationFilter sets a far-future expiration timeout on the HTTP
* CacheExpirationFilter sets a far-future expiration timeout on the HTTP
* response of the filtered resource. This filter is intended for resources
* which will not be changed, such as versioned javascript and css files. Any
* resources protected by this filter should be renamed upon update.
*
*
* init-params:<br/>
* cacheMaxAge - Sets the max age in seconds to be used in the cache headers for cached resources,
* defaults to 1 year (31536000).<br/>
*
*
* regenerateHeadersInterval - The interval in milliseconds to regenerate the cache headers,
* defaults to 1 second (1000).
*
*
* @author Jen Bourey
*/
public class CacheExpirationFilter extends GenericFilterBean {
private static final long YEAR_OF_MILLISECONDS = 365l * 24l * 60l * 60l * 1000l;
private static final long YEAR_OF_MILLISECONDS = TimeUnit.DAYS.toMillis(365);

protected final Logger logger = LoggerFactory.getLogger(this.getClass());

Expand Down Expand Up @@ -95,12 +96,12 @@ protected void initFilterBean() throws ServletException {
final ServletContext servletContext = this.getServletContext();
this.resourcesElementsProvider = ResourcesElementsProviderUtils.getOrCreateResourcesElementsProvider(servletContext);
}

this.updateHeaders();
}

/**
*
*
*/
private void updateHeaders() {
//Generate cache control value
Expand All @@ -120,7 +121,7 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
final Included includedType = this.resourcesElementsProvider.getIncludedType(httpServletRequest);
if (includedType == Included.AGGREGATED) {
final HttpServletResponse httpResponse = (HttpServletResponse) response;

httpResponse.setDateHeader("Expires", this.cacheMaxAge + System.currentTimeMillis());
httpResponse.setHeader("Cache-Control", this.cachedControlString);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,29 @@
public class CacheExpirationFilterTest extends TestCase {
private final FilterConfig filterConfig = Mockito.mock(FilterConfig.class);
private final ServletContext servletContext = Mockito.mock(ServletContext.class);

private CacheExpirationFilter cacheExpirationFilter;


/* (non-Javadoc)
* @see junit.framework.TestCase#setUp()
*/
@Override
protected void setUp() throws Exception {
Mockito.when(filterConfig.getInitParameterNames()).thenReturn(new Enumeration<Object>() {
Mockito.when(filterConfig.getInitParameterNames()).thenReturn(new Enumeration<String>() {
@Override
public boolean hasMoreElements() {
return false;
}
@Override
public Object nextElement() {
public String nextElement() {
return null;
}
});
Mockito.when(filterConfig.getServletContext()).thenReturn(servletContext);
Mockito.when(filterConfig.getFilterName()).thenReturn("CacheExpirationFilter");
Mockito.when(servletContext.getContextPath()).thenReturn("/ResourceServingWebapp");

this.cacheExpirationFilter = new CacheExpirationFilter();
this.cacheExpirationFilter.init(filterConfig);
}
Expand All @@ -78,12 +78,12 @@ public void testTimezoneFormat() throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockHttpServletResponse response = new MockHttpServletResponse();
final MockFilterChain chain = new MockFilterChain();

this.cacheExpirationFilter.doFilter(request, response, chain);
final Long expires = (Long)response.getHeaderValue("Expires");

final long expires = response.getDateHeader("Expires");
final String cacheControl = response.getHeader("Cache-Control");

assertTrue(expires > System.currentTimeMillis());
assertEquals("public, max-age=31536000", cacheControl);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,68 +43,69 @@
public class PathBasedCacheExpirationFilterTest {
private final FilterConfig filterConfig = Mockito.mock(FilterConfig.class);
private final ServletContext servletContext = Mockito.mock(ServletContext.class);





private PathBasedCacheExpirationFilter pathBasedCacheExpirationFilter;

@Before
public void setUp() throws Exception {
Mockito.when(filterConfig.getInitParameterNames()).thenReturn(new Enumeration<Object>() {
Mockito.when(filterConfig.getInitParameterNames()).thenReturn(new Enumeration<String>() {
@Override
public boolean hasMoreElements() {
return false;
}
@Override
public Object nextElement() {
public String nextElement() {
return null;
}
});
Mockito.when(filterConfig.getServletContext()).thenReturn(servletContext);
Mockito.when(filterConfig.getFilterName()).thenReturn("CacheExpirationFilter");
Mockito.when(servletContext.getContextPath()).thenReturn("/ResourceServingWebapp");

this.pathBasedCacheExpirationFilter = new PathBasedCacheExpirationFilter();
this.pathBasedCacheExpirationFilter.init(filterConfig);
}

@After
public void tearDown() throws Exception {
this.pathBasedCacheExpirationFilter.destroy();
}

@Test
public void testPathBasedCacheExpirationFilterHit() throws Exception {
final long expectedExpires = System.currentTimeMillis() + TimeUnit.DAYS.toMillis(365);

// Subtract 10 seconds to allow for slow test runs
final long expectedExpires = System.currentTimeMillis() + TimeUnit.DAYS.toMillis(365) - 10000;

final MockHttpServletRequest request = new MockHttpServletRequest();
final MockHttpServletResponse response = new MockHttpServletResponse();
final MockFilterChain chain = new MockFilterChain();

request.setServletPath("/rs/jqueryui/1.8/jquery-ui-1.8.js");

this.pathBasedCacheExpirationFilter.doFilter(request, response, chain);
final Long expires = (Long)response.getHeaderValue("Expires");

final long expires = response.getDateHeader("Expires");
final String cacheControl = response.getHeader("Cache-Control");

assertTrue(expires > expectedExpires);
assertEquals("public, max-age=31536000", cacheControl);
}

@Test
public void testPathBasedCacheExpirationFilterMiss() throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockHttpServletResponse response = new MockHttpServletResponse();
final MockFilterChain chain = new MockFilterChain();

request.setServletPath("/index.html");

this.pathBasedCacheExpirationFilter.doFilter(request, response, chain);

final Long expires = (Long)response.getHeaderValue("Expires");
final String cacheControl = response.getHeader("Cache-Control");

assertNull(expires);
assertNull(cacheControl);
}
Expand Down
8 changes: 6 additions & 2 deletions resource-server-webapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
<version>2.6.1</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>

Expand Down Expand Up @@ -78,7 +78,11 @@
<artifactId>webjars-locator</artifactId>
<version>0.42</version>
</dependency>
</dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>

<build>
<finalName>ResourceServingWebapp</finalName>
Expand Down

0 comments on commit fb0290d

Please sign in to comment.