Skip to content

Commit

Permalink
Upgrade to Jetty 12
Browse files Browse the repository at this point in the history
Signed-off-by: Steffen Nießing <zuniquex@protonmail.com>
  • Loading branch information
zUniQueX committed Jun 18, 2023
1 parent eeb0ade commit f0a887e
Show file tree
Hide file tree
Showing 16 changed files with 213 additions and 234 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@
</dependency> -->

<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-ee10-servlet</artifactId>
<version>\${jetty.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-ee10-webapp</artifactId>
<version>\${jetty.version}</version>
<scope>provided</scope>
</dependency>
Expand Down Expand Up @@ -89,8 +89,8 @@
</executions>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-ee10-maven-plugin</artifactId>
<version>\${jetty.version}</version>
<configuration>
<contextPath>/</contextPath>
Expand All @@ -112,7 +112,7 @@

<properties>
<jersey.version>${project.version}</jersey.version>
<jetty.version>11.0.15</jetty.version>
<jetty.version>12.0.0.beta1</jetty.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<surefire.mvn.plugin.version>3.0.0-M7</surefire.mvn.plugin.version>
</properties>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ${package}.heroku;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.ee10.webapp.WebAppContext;

/**
* This class launches the web application in an embedded Jetty container. This is the entry point to your application. The Java
Expand Down Expand Up @@ -30,7 +30,7 @@ public static void main(String[] args) throws Exception{

final String webappDirLocation = "src/main/webapp/";
root.setDescriptor(webappDirLocation + "/WEB-INF/web.xml");
root.setResourceBase(webappDirLocation);
root.setBaseResourceAsString(webappDirLocation);

server.setHandler(root);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,24 @@
import jakarta.ws.rs.ProcessingException;
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.core.Configuration;
import jakarta.ws.rs.core.HttpHeaders;
import jakarta.ws.rs.core.MultivaluedMap;

import javax.net.ssl.SSLContext;

import jakarta.ws.rs.ext.RuntimeDelegate;
import org.eclipse.jetty.client.AuthenticationStore;
import org.eclipse.jetty.client.BasicAuthentication;
import org.eclipse.jetty.client.ByteBufferRequestContent;
import org.eclipse.jetty.client.ContentResponse;
import org.eclipse.jetty.client.FutureResponseListener;
import org.eclipse.jetty.client.HttpClientTransport;
import org.eclipse.jetty.client.HttpRequest;
import org.eclipse.jetty.client.http.HttpClientTransportOverHTTP;
import org.eclipse.jetty.client.OutputStreamRequestContent;
import org.eclipse.jetty.client.Request;
import org.eclipse.jetty.client.Response;
import org.eclipse.jetty.client.Result;
import org.eclipse.jetty.client.transport.HttpClientTransportOverHTTP;
import org.eclipse.jetty.client.transport.HttpRequest;
import org.eclipse.jetty.http.HttpCookieStore;
import org.eclipse.jetty.io.ClientConnector;
import org.eclipse.jetty.client.util.BasicAuthentication;
import org.eclipse.jetty.client.util.BytesContentProvider;
import org.eclipse.jetty.client.util.FutureResponseListener;
import org.eclipse.jetty.client.util.OutputStreamContentProvider;
import org.glassfish.jersey.client.ClientProperties;
import org.glassfish.jersey.client.ClientRequest;
import org.glassfish.jersey.client.ClientResponse;
Expand All @@ -70,16 +74,9 @@
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.HttpProxy;
import org.eclipse.jetty.client.ProxyConfiguration;
import org.eclipse.jetty.client.api.AuthenticationStore;
import org.eclipse.jetty.client.api.ContentProvider;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.client.api.Response;
import org.eclipse.jetty.client.api.Result;
import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.util.HttpCookieStore;
import org.eclipse.jetty.util.Jetty;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
Expand Down Expand Up @@ -138,7 +135,7 @@ class JettyConnector implements Connector {
private static final Logger LOGGER = Logger.getLogger(JettyConnector.class.getName());

private final HttpClient client;
private final CookieStore cookieStore;
private final HttpCookieStore cookieStore;
private final Configuration configuration;
private final Optional<Integer> syncListenerResponseMaxSize;

Expand Down Expand Up @@ -203,7 +200,7 @@ class JettyConnector implements Connector {
proxy.ifPresent(clientProxy -> {
final ProxyConfiguration proxyConfig = client.getProxyConfiguration();
final URI u = clientProxy.uri();
proxyConfig.getProxies().add(new HttpProxy(u.getHost(), u.getPort()));
proxyConfig.addProxy(new HttpProxy(u.getHost(), u.getPort()));

if (clientProxy.userName() != null) {
auth.addAuthentication(new BasicAuthentication(u, "<<ANY_REALM>>",
Expand All @@ -212,7 +209,7 @@ class JettyConnector implements Connector {
});

if (disableCookies) {
client.setCookieStore(new HttpCookieStore.Empty());
client.setHttpCookieStore(new HttpCookieStore.Empty());
}

final Object slResponseMaxSize = configuration.getProperties()
Expand All @@ -230,7 +227,7 @@ class JettyConnector implements Connector {
} catch (final Exception e) {
throw new ProcessingException("Failed to start the client.", e);
}
this.cookieStore = client.getCookieStore();
this.cookieStore = client.getHttpCookieStore();
}

/**
Expand All @@ -249,17 +246,17 @@ public HttpClient getHttpClient() {
* @return the {@link CookieStore} instance or null when
* JettyClientProperties.DISABLE_COOKIES set to true.
*/
public CookieStore getCookieStore() {
public HttpCookieStore getCookieStore() {
return cookieStore;
}

@Override
public ClientResponse apply(final ClientRequest jerseyRequest) throws ProcessingException {
final Request jettyRequest = translateRequest(jerseyRequest);
final Map<String, String> clientHeadersSnapshot = writeOutBoundHeaders(jerseyRequest.getHeaders(), jettyRequest);
final ContentProvider entity = getBytesProvider(jerseyRequest);
final Request.Content entity = getBytesProvider(jerseyRequest);
if (entity != null) {
jettyRequest.content(entity);
jettyRequest.body(entity);
}

try {
Expand Down Expand Up @@ -352,7 +349,7 @@ private Map<String, String> writeOutBoundHeaders(final MultivaluedMap<String, Ob
return stringHeaders;
}

private ContentProvider getBytesProvider(final ClientRequest clientRequest) {
private Request.Content getBytesProvider(final ClientRequest clientRequest) {
final Object entity = clientRequest.getEntity();

if (entity == null) {
Expand All @@ -372,17 +369,22 @@ public OutputStream getOutputStream(final int contentLength) throws IOException
} catch (final IOException e) {
throw new ProcessingException("Failed to write request entity.", e);
}
return new BytesContentProvider(outputStream.toByteArray());
return new ByteBufferRequestContent(ByteBuffer.wrap(outputStream.toByteArray()));
}

private ContentProvider getStreamProvider(final ClientRequest clientRequest) {
private Request.Content getStreamProvider(final ClientRequest clientRequest) {
final Object entity = clientRequest.getEntity();

if (entity == null) {
return null;
}

final OutputStreamContentProvider streamContentProvider = new OutputStreamContentProvider();
String contentTypeHeader = clientRequest.getRequestHeaders()
.getFirst(HttpHeader.CONTENT_TYPE.asString());

String contentType = contentTypeHeader != null ? contentTypeHeader : "application/octet-stream";

final OutputStreamRequestContent streamContentProvider = new OutputStreamRequestContent(contentType);
clientRequest.setStreamProvider(new OutboundMessageContext.StreamProvider() {
@Override
public OutputStream getOutputStream(final int contentLength) throws IOException {
Expand All @@ -392,12 +394,12 @@ public OutputStream getOutputStream(final int contentLength) throws IOException
return streamContentProvider;
}

private void processContent(final ClientRequest clientRequest, final ContentProvider entity) throws IOException {
private void processContent(final ClientRequest clientRequest, final Request.Content entity) throws IOException {
if (entity == null) {
return;
}

final OutputStreamContentProvider streamContentProvider = (OutputStreamContentProvider) entity;
final OutputStreamRequestContent streamContentProvider = (OutputStreamRequestContent) entity;
try (final OutputStream output = streamContentProvider.getOutputStream()) {
clientRequest.writeEntity();
}
Expand All @@ -407,9 +409,9 @@ private void processContent(final ClientRequest clientRequest, final ContentProv
public Future<?> apply(final ClientRequest jerseyRequest, final AsyncConnectorCallback callback) {
final Request jettyRequest = translateRequest(jerseyRequest);
final Map<String, String> clientHeadersSnapshot = writeOutBoundHeaders(jerseyRequest.getHeaders(), jettyRequest);
final ContentProvider entity = getStreamProvider(jerseyRequest);
final Request.Content entity = getStreamProvider(jerseyRequest);
if (entity != null) {
jettyRequest.content(entity);
jettyRequest.body(entity);
}
final AtomicBoolean callbackInvoked = new AtomicBoolean(false);
final Throwable failure;
Expand All @@ -426,7 +428,7 @@ public Future<?> apply(final ClientRequest jerseyRequest, final AsyncConnectorCa

final AtomicReference<ClientResponse> jerseyResponse = new AtomicReference<>();
final ByteBufferInputStream entityStream = new ByteBufferInputStream();
jettyRequest.send(new Response.Listener.Adapter() {
jettyRequest.send(new Response.Listener() {

@Override
public void onHeaders(final Response jettyResponse) {
Expand Down Expand Up @@ -500,7 +502,7 @@ public void onFailure(final Response response, final Throwable t) {
}

private static ClientResponse translateResponse(final ClientRequest jerseyRequest,
final org.eclipse.jetty.client.api.Response jettyResponse,
final org.eclipse.jetty.client.Response jettyResponse,
final NonBlockingInputStream entityStream) {
final ClientResponse jerseyResponse = new ClientResponse(Statuses.from(jettyResponse.getStatus()), jerseyRequest);
processResponseHeaders(jettyResponse.getHeaders(), jerseyResponse);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -33,12 +33,12 @@

import jakarta.inject.Singleton;

import org.eclipse.jetty.client.BasicAuthentication;
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.logging.LoggingFeature;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;

import org.eclipse.jetty.client.util.BasicAuthentication;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -95,7 +95,7 @@ public void testDisabledCookies() {

final JettyConnector connector = (JettyConnector) client.getConfiguration().getConnector();
if (connector.getCookieStore() != null) {
assertTrue(connector.getCookieStore().getCookies().isEmpty());
assertTrue(connector.getCookieStore().all().isEmpty());
} else {
assertNull(connector.getCookieStore());
}
Expand All @@ -113,9 +113,9 @@ public void testCookies() {
assertEquals("value", r.request().get(String.class));

final JettyConnector connector = (JettyConnector) client.getConfiguration().getConnector();
assertNotNull(connector.getCookieStore().getCookies());
assertEquals(1, connector.getCookieStore().getCookies().size());
assertEquals("value", connector.getCookieStore().getCookies().get(0).getValue());
assertNotNull(connector.getCookieStore().all());
assertEquals(1, connector.getCookieStore().all().size());
assertEquals("value", connector.getCookieStore().all().get(0).getValue());
client.close();
}
}
2 changes: 1 addition & 1 deletion containers/grizzly2-http/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
</dependency>
<dependency>
<groupId>org.eclipse.jetty.http2</groupId>
<artifactId>http2-http-client-transport</artifactId>
<artifactId>jetty-http2-client-transport</artifactId>
<version>${jetty.version}</version>
<scope>test</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021 Payara Foundation and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -20,12 +20,12 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;

import org.eclipse.jetty.client.ContentResponse;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.HttpClientTransport;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.http.HttpClientTransportOverHTTP;
import org.eclipse.jetty.client.transport.HttpClientTransportOverHTTP;
import org.eclipse.jetty.http2.client.HTTP2Client;
import org.eclipse.jetty.http2.client.http.HttpClientTransportOverHTTP2;
import org.eclipse.jetty.http2.client.transport.HttpClientTransportOverHTTP2;
import org.eclipse.jetty.io.ClientConnector;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down
13 changes: 9 additions & 4 deletions containers/jetty-http/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,18 @@
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<scope>provided</scope>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
<artifactId>jetty-security</artifactId>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
Expand Down
Loading

0 comments on commit f0a887e

Please sign in to comment.