Skip to content

Commit

Permalink
Adapt plugin for jetty 12 ee8
Browse files Browse the repository at this point in the history
  • Loading branch information
BorisYaoA committed Aug 20, 2024
1 parent 273cfb4 commit 5db534d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 37 deletions.
3 changes: 1 addition & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Builds a module using https://github.com/jenkins-infra/pipeline-library
buildPlugin(useContainerAgent: true, configurations: [
[platform: 'linux', jdk: 11],
[platform: 'windows', jdk: 11],
[platform: 'windows', jdk: 17],
[platform: 'linux', jdk: 17],
[platform: 'linux', jdk: 21]
])
11 changes: 8 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,22 @@
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
<jira-rest-client.version>5.2.7</jira-rest-client.version>
<fugue.version>4.7.2</fugue.version>
<!-- TODO: replace when 2.472 is in LTS -->
<!-- <jenkins.version>${jenkins.baseline}.3</jenkins.version> -->
<jenkins.baseline>2.462</jenkins.baseline>
<!-- jenkins -->
<jenkins.version>2.440.3</jenkins.version>
<jenkins.version>2.472</jenkins.version>
<!-- TODO JENKINS-73339 until in parent POM -->
<jenkins-test-harness.version>2254.vcff7a_d4969e5</jenkins-test-harness.version>
<spotless.check.skip>false</spotless.check.skip>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.440.x</artifactId>
<version>3234.v5ca_5154341ef</version>
<artifactId>bom-${jenkins.baseline}.x</artifactId>
<version>3271.vf18ea_cb_9edfb_</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@
import hudson.ProxyConfiguration;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.Base64;
import java.util.Date;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jenkins.model.Jenkins;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.io.Content;
import org.eclipse.jetty.server.ConnectionFactory;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.util.Callback;
import org.junit.After;
import org.junit.Assert;
import org.junit.Rule;
Expand Down Expand Up @@ -151,7 +151,7 @@ public void simple_post_with_proxy() throws Exception {
Assert.assertEquals("FOO", testHandler.postReceived);
}

public class ProxyTestHandler extends AbstractHandler {
public static class ProxyTestHandler extends Handler.Abstract {

String postReceived;

Expand All @@ -164,55 +164,52 @@ public class ProxyTestHandler extends AbstractHandler {
final String realm = "test_realm";

@Override
public void handle(
String target,
org.eclipse.jetty.server.Request jettyRequest,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
public boolean handle(
org.eclipse.jetty.server.Request request,
org.eclipse.jetty.server.Response response,
Callback callback)
throws IOException {

final String credentials = Base64.getEncoder().encodeToString((user + ":" + password).getBytes("UTF-8"));
final String credentials = Base64.getEncoder().encodeToString((user + ":" + password).getBytes(StandardCharsets.UTF_8));

jettyRequest.setHandled(true);

String authorization = request.getHeader(HttpHeader.PROXY_AUTHORIZATION.asString());
String authorization = request.getHeaders().get(HttpHeader.PROXY_AUTHORIZATION);
if (authorization == null) {
response.setStatus(HttpStatus.PROXY_AUTHENTICATION_REQUIRED_407);
response.setHeader(HttpHeader.PROXY_AUTHENTICATE.asString(), "Basic realm=\"" + realm + "\"");
return;
response.getHeaders().add(HttpHeader.PROXY_AUTHENTICATE, "Basic realm=\"" + realm + "\"");
return true;
} else {
String prefix = "Basic ";
if (authorization.startsWith(prefix)) {
String attempt = authorization.substring(prefix.length());
if (!credentials.equals(attempt)) {
return;
return true;
}
}
}

if (StringUtils.equalsIgnoreCase("post", request.getMethod())) {
postReceived = IOUtils.toString(request.getReader());
postReceived = Content.Source.asString(request, StandardCharsets.UTF_8);
}
response.getWriter().write(CONTENT_RESPONSE);
Content.Sink.write(response, true, CONTENT_RESPONSE, callback);
return true;
}
}

public class TestHandler extends AbstractHandler {
public static class TestHandler extends Handler.Abstract {

String postReceived;

@Override
public void handle(
String target,
org.eclipse.jetty.server.Request jettyRequest,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
jettyRequest.setHandled(true);
public boolean handle(
org.eclipse.jetty.server.Request request,
org.eclipse.jetty.server.Response response,
Callback callback)
throws IOException {
if (StringUtils.equalsIgnoreCase("post", request.getMethod())) {
postReceived = IOUtils.toString(request.getReader());
postReceived = Content.Source.asString(request, StandardCharsets.UTF_8);
}
response.getWriter().write(CONTENT_RESPONSE);
Content.Sink.write(response, true, CONTENT_RESPONSE, callback);
return true;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
import net.sf.json.JSONObject;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.servlet.DefaultServlet;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.ee8.servlet.DefaultServlet;
import org.eclipse.jetty.ee8.servlet.ServletContextHandler;
import org.eclipse.jetty.ee8.servlet.ServletHolder;
import org.htmlunit.HttpMethod;
import org.htmlunit.Page;
import org.htmlunit.WebRequest;
Expand Down

0 comments on commit 5db534d

Please sign in to comment.