Skip to content

Migrate to jakarta namespace #238

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

Merged
merged 3 commits into from
Jun 20, 2023
Merged
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
16 changes: 0 additions & 16 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,12 @@ jobs:
strategy:
matrix:
include:
- HTTPCLIENT_VERSION: 4.3.6
HTTPCLIENT_TEST_VERSION: 4.3.6
JDOC: ""
- HTTPCLIENT_VERSION: 4.4.1
HTTPCLIENT_TEST_VERSION: 4.3.6
JDOC: ""
- HTTPCLIENT_VERSION: 4.5.13
HTTPCLIENT_TEST_VERSION: 4.3.6
JDOC: "site"

steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Build with Maven
env:
HTTPCLIENT_VERSION: ${{ matrix.HTTPCLIENT_VERSION }}
HTTPCLIENT_TEST_VERSION: ${{ matrix.HTTPCLIENT_TEST_VERSION }}
JDOC: ${{ matrix.JDOC }}
run: mvn -B -Dhttpclient.version=$HTTPCLIENT_VERSION -Dhttpclient.test.version=$HTTPCLIENT_TEST_VERSION verify $JDOC
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
Expand Down
4 changes: 3 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Version 1.13 (unreleased)
# Version 2.0 (unreleased)

\#231: Added support of preserveCookiePath configuration parameter. It allows to keep cookie path unchanged in Set-Cookie server response header.

\#237: Switched to the `jakarta servlet-api`. However, legacy `javax servlet-api` support is still available via the `javax` classifier.

# Version 1.12.1 released on 2021-12-28

\#215: '[' and ']' should be encoded as they are unsafe characters. https://www.ietf.org/rfc/rfc1738.txt
Expand Down
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,20 @@ In the meantime, you'll have to add the jar files for this and its dependencies:
| +- commons-logging:commons-logging:jar:1.2:compile
| \- commons-codec:commons-codec:jar:1.11:compile

This proxy supports HttpClient 4.3, and newer version too.
If you need to support _older_ HttpClient versions, namely 4.1 and 4.2, then use the 1.8 version of this proxy.
This proxy supports HttpClient 4.5, and newer version too.
If you need to support _older_ HttpClient versions:
* use 1.8 version of this proxy for HttpClient versions 4.1 and 4.2
* use 1.12 version of this proxy for HttpClient versions 4.3 and 4.4

As of version 2.0 of the proxy, the proxy switched to the `jakarta servlet-api`, while nonetheless retaining support for the `javax servlet-api` version for those that need it. To use that, specify the `javax` classifier on the dependency declaration as follows:
```xml
<dependency>
<groupId>org.mitre.dsmiley.httpproxy</groupId>
<artifactId>smiley-http-proxy-servlet</artifactId>
<version>${smiley-http-proxy-servlet.version}</version>
<classifier>javax</classifier>
</dependency>
```

As of version 1.5 of the proxy, there is the ability to parameterize your proxy URL, allowing you to use
the same web.xml servlet specification for multiple target servers. It follows the
Expand Down
54 changes: 44 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.mitre.dsmiley.httpproxy</groupId>
<artifactId>smiley-http-proxy-servlet</artifactId>
<version>1.13-SNAPSHOT</version>
<version>2.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Smiley's HTTP Proxy Servlet</name>
Expand Down Expand Up @@ -54,11 +54,10 @@

<dependencies>

<!-- Probably works with 3.0 as well -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>5.0.0</version>
<scope>provided</scope>
</dependency>

Expand All @@ -84,9 +83,9 @@
</dependency>

<dependency>
<groupId>httpunit</groupId>
<groupId>com.github.hazendaz.httpunit</groupId>
<artifactId>httpunit</artifactId>
<version>1.7</version>
<version>2.0.0</version>
<scope>test</scope>
</dependency>

Expand All @@ -106,7 +105,7 @@
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>9.4.30.v20200611</version>
<version>11.0.13</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down Expand Up @@ -147,8 +146,8 @@
org.apache.http.util; version="0",
org.apache.http.client.utils;version="0",
org.apache.http.client.methods;version="0",
javax.servlet;version="0",
javax.servlet.http;version="0",
jakarta.servlet;version="0",
jakarta.servlet.http;version="0",
javax.net.ssl;version="0", org.apache.http.client.config;version="0"</Import-Package>
</manifestEntries>
</archive>
Expand Down Expand Up @@ -191,6 +190,41 @@
<version>3.9.1</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.2</version>
<executions>
<execution>
<id>javax</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedClassifierName>javax</shadedClassifierName>
<shadedArtifactAttached>true</shadedArtifactAttached>
<createDependencyReducedPom>false</createDependencyReducedPom>
<artifactSet>
<includes>
<include>${project.groupId}:${project.artifactId}</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>jakarta.servlet</pattern>
<shadedPattern>javax.servlet</shadedPattern>
</relocation>
<relocation>
<pattern>jakarta.annotation</pattern>
<shadedPattern>javax.annotation</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>

</plugins>
</build>

Expand Down
19 changes: 8 additions & 11 deletions src/main/java/org/mitre/dsmiley/httpproxy/ProxyServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
import org.apache.http.message.HeaderGroup;
import org.apache.http.util.EntityUtils;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -272,7 +272,7 @@ protected void initTarget() throws ServletException {
}

/**
* Called from {@link #init(javax.servlet.ServletConfig)}.
* Called from {@link #init(jakarta.servlet.ServletConfig)}.
* HttpClient offers many opportunities for customization.
* In any case, it should be thread-safe.
*/
Expand Down Expand Up @@ -374,11 +374,8 @@ protected void service(HttpServletRequest servletRequest, HttpServletResponse se

// Process the response:

// Pass the response code. This method with the "reason phrase" is deprecated but it's the
// only way to pass the reason along too.
int statusCode = proxyResponse.getStatusLine().getStatusCode();
//noinspection deprecation
servletResponse.setStatus(statusCode, proxyResponse.getStatusLine().getReasonPhrase());
servletResponse.setStatus(statusCode);

// Copying response headers to make sure SESSIONID or other Cookie which comes from the remote
// server will be saved in client when the proxied url was redirected to another one.
Expand Down Expand Up @@ -751,7 +748,7 @@ protected String rewriteQueryStringFromRequest(HttpServletRequest servletRequest
}

/**
* Allow overrides of {@link javax.servlet.http.HttpServletRequest#getPathInfo()}.
* Allow overrides of {@link jakarta.servlet.http.HttpServletRequest#getPathInfo()}.
* Useful when url-pattern of servlet-mapping (web.xml) requires manipulation.
*/
protected String rewritePathInfoFromRequest(HttpServletRequest servletRequest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import org.apache.http.client.utils.URIUtils;
import org.apache.http.client.utils.URLEncodedUtils;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@
*/
package org.mitre.dsmiley.httpproxy;

import static org.junit.Assert.assertEquals;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.HashSet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
Expand All @@ -34,7 +36,6 @@
import org.eclipse.jetty.servlet.ServletHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.junit.After;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.http.MalformedChunkCodingException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import org.apache.http.protocol.HttpContext;
import org.junit.Test;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;

import static org.junit.Assert.assertEquals;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
Expand Down