Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrating from javax servlet to jakarta servlet #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 32 additions & 20 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<groupId>com.thetransactioncompany</groupId>
<artifactId>cors-filter</artifactId>
<version>2.2.2-SNAPSHOT</version>
<version>3.0.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>CORS Filter</name>
Expand All @@ -22,7 +22,12 @@
participating servers.
</description>
<inceptionYear>2010</inceptionYear>
<url>http://software.dzhuvinov.com/cors-filter.html</url>
<properties>
<java.version>11</java.version>

<junit-jupiter.version>5.10.0</junit-jupiter.version>
</properties>
<url>https://software.dzhuvinov.com/cors-filter.html</url>

<organization>
<name>The Transaction Company</name>
Expand Down Expand Up @@ -65,75 +70,80 @@
<dependency>
<groupId>com.thetransactioncompany</groupId>
<artifactId>java-property-utils</artifactId>
<version>1.9.1</version>
<version>1.17</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>6.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>


<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<version>3.11.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<version>3.1.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<version>3.3.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<version>3.4.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
<version>3.3.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8</version>
<version>3.6.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
<version>3.1.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.3.2</version>
<version>3.0.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.1</version>
<version>3.1.0</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.1</version>
<version>3.2.0</version>
</plugin>
</plugins>
</pluginManagement>
Expand All @@ -144,6 +154,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgument>-Xlint</compilerArgument>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import java.util.Enumeration;
import java.util.Properties;

import javax.servlet.FilterConfig;

import com.thetransactioncompany.cors.environment.Environment;
import com.thetransactioncompany.cors.environment.SystemProperties;
import jakarta.servlet.FilterConfig;


/**
Expand Down
13 changes: 4 additions & 9 deletions src/main/java/com/thetransactioncompany/cors/CORSFilter.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
package com.thetransactioncompany.cors;


import jakarta.servlet.*;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
* Cross-Origin Resource Sharing (CORS) servlet filter.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.thetransactioncompany.cors;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

/**
* Handles incoming cross-origin (CORS) requests according to the configured
Expand Down Expand Up @@ -86,7 +85,7 @@ public CORSRequestHandler(final CORSConfiguration config) {
* is not supported by the CORS
* policy.
*/
public void handleActualRequest(final HttpServletRequest request,
public void handleActualRequest(final HttpServletRequest request,
final HttpServletResponse response)
throws InvalidCORSRequestException,
CORSOriginDeniedException,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.thetransactioncompany.cors;


import javax.servlet.http.HttpServletRequest;

import jakarta.servlet.http.HttpServletRequest;

/**
* Enumeration of the CORS request types.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.thetransactioncompany.cors;


import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletResponseWrapper;

import java.util.*;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;


/**
* HTTP response wrapper that preserves the CORS response headers on
* {@link javax.servlet.ServletResponse#reset()}. Some web applications and
* {@link jakarta.servlet.ServletResponse#reset()}. Some web applications and
* frameworks (e.g. RestEasy) reset the servlet response when a HTTP 4xx error
* is produced; this wrapper ensures previously set CORS headers survive such a
* reset.
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/thetransactioncompany/cors/Origin.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@ public Origin(final String value) {

this.value = value;
}


/**
* Returns a validated instance of this origin.
*
*
* @throws OriginException If the value doesn't represent a valid and
* supported origin string.
* @return a validated instance of this origin
*/
public ValidatedOrigin validate()
throws OriginException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.thetransactioncompany.cors;


import javax.servlet.http.HttpServletRequest;

import jakarta.servlet.http.HttpServletRequest;

/**
* Request tagger. Tags HTTP servlet requests to provide CORS information to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ public int getPort() {
* <p>Example:
*
* <pre>
* http://example.com => example.com
* http://example.com:8080 => example.com:8080
* http://example.com = example.com
* http://example.com:8080 = example.com:8080
* </pre>
*
* @return The suffix.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.thetransactioncompany.cors.demo;


import java.io.*;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@


import com.thetransactioncompany.cors.environment.MockEnvironment;
import junit.framework.TestCase;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;




/**
Expand All @@ -11,9 +15,10 @@
* @author David Bellem
* @author Vladimir Dzhuvinov
*/
public class CORSConfigurationLoaderTest extends TestCase {

public class CORSConfigurationLoaderTest {


@Test
public void testEnvVarBasedConfig() {

CORSConfigurationLoader configLoader = new CORSConfigurationLoader(new MockFilterConfig());
Expand Down Expand Up @@ -55,7 +60,7 @@ public void testEnvVarBasedConfig() {
assertTrue(c.isSupportedHeader("Accept"));
assertFalse(c.isSupportedHeader("X-Forwarded-Proto"));

assertTrue(c.exposedHeaders.size() == 0);
assertEquals(0, c.exposedHeaders.size());

assertTrue(c.supportsCredentials);

Expand Down
Loading