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

[JENKINS-73137] Adapt Jira plugin for jetty 12 EE8 #613

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
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],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're not dropping JDK11 until there is an LTS release that is no longer supporting Java11.

[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>
Copy link
Contributor

@rantoniuk rantoniuk Aug 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are supporting only LTS line, so let's make this PR a draft until there is an LTS released >=2.472
https://www.jenkins.io/changelog-stable/

<!-- 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>
BorisYaoA marked this conversation as resolved.
Show resolved Hide resolved
<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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes looks good.
But I wonder if it would be better to simply use Servlet API filter to have some implementation of this not depending on Jetty core API (which may change soon again for 12.1.x)

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