Skip to content

Commit

Permalink
Additional 3.0->3.1 merge leftovers
Browse files Browse the repository at this point in the history
Signed-off-by: jansupol <jan.supol@oracle.com>
  • Loading branch information
jansupol committed May 23, 2024
1 parent 0882b15 commit bcfa86b
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 17 deletions.
2 changes: 1 addition & 1 deletion connectors/netty-connector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<profile>
<id>JettyExclude</id>
<activation>
<jdk>1.8</jdk>
<jdk>(1.8,17)</jdk>
</activation>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2024 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 All @@ -20,7 +20,10 @@
import java.util.concurrent.ThreadFactory;

import jakarta.ws.rs.ProcessingException;
import jakarta.ws.rs.core.Configuration;

import org.glassfish.jersey.innate.VirtualThreadUtil;
import org.glassfish.jersey.innate.virtual.LoomishExecutors;
import org.glassfish.jersey.internal.guava.ThreadFactoryBuilder;
import org.glassfish.jersey.jetty.internal.LocalizationMessages;
import org.glassfish.jersey.process.JerseyProcessingUncaughtExceptionHandler;
Expand Down Expand Up @@ -254,7 +257,8 @@ public static Server createServer(final URI uri,
}
final int port = (uri.getPort() == -1) ? defaultPort : uri.getPort();

final Server server = new Server(new JettyConnectorThreadPool());
final Configuration configuration = handler != null ? handler.getConfiguration() : null;
final Server server = new Server(new JettyConnectorThreadPool(configuration));
final HttpConfiguration config = new HttpConfiguration();
if (sslContextFactory != null) {
config.setSecureScheme("https");
Expand Down Expand Up @@ -292,10 +296,20 @@ public static Server createServer(final URI uri,
//
// Keeping this for backwards compatibility for the time being
private static final class JettyConnectorThreadPool extends QueuedThreadPool {
private final ThreadFactory threadFactory = new ThreadFactoryBuilder()
.setNameFormat("jetty-http-server-%d")
.setUncaughtExceptionHandler(new JerseyProcessingUncaughtExceptionHandler())
.build();
private final ThreadFactory threadFactory;

private JettyConnectorThreadPool(Configuration configuration) {
final LoomishExecutors executors = VirtualThreadUtil.withConfig(configuration, false);
if (executors.isVirtual()) {
super.setMaxThreads(Integer.MAX_VALUE - 1);
}

this.threadFactory = new ThreadFactoryBuilder()
.setNameFormat("jetty-http-server-%d")
.setUncaughtExceptionHandler(new JerseyProcessingUncaughtExceptionHandler())
.setThreadFactory(executors.getThreadFactory())
.build();
}

@Override
public Thread newThread(Runnable runnable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ static Optional<SniConfigurator> createWhenHostHeader(URI hostUri, String sniHos
return Optional.empty();
}

final String hostUriString = hostUri.getHost();
if (!whenDiffer && hostUriString.equals(trimmedHeader)) {
return Optional.empty();
if (hostUri != null) {
final String hostUriString = hostUri.getHost();
if (!whenDiffer && hostUriString.equals(trimmedHeader)) {
return Optional.empty();
}
}

return Optional.of(new SniConfigurator(trimmedHeader));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ private ClientResponse _apply(final ClientRequest request) throws IOException {
final HttpURLConnection uc;
final Optional<ClientProxy> proxy = ClientProxy.proxyFromRequest(request);
final SSLParamConfigurator sniConfig = SSLParamConfigurator.builder().request(request)
.setSNIHostName(request.getConfiguration()).build();
.setSNIHostName(request).build();
final URI sniUri;
if (sniConfig.isSNIRequired()) {
sniUri = sniConfig.toIPRequestUri();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2024 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 All @@ -16,6 +16,7 @@

package org.glassfish.jersey.test.jetty;

import java.util.Map;
import jakarta.ws.rs.ProcessingException;
import org.glassfish.jersey.jetty.internal.LocalizationMessages;
import org.glassfish.jersey.test.DeploymentContext;
Expand All @@ -26,6 +27,13 @@

public class JettyTestContainerFactory implements TestContainerFactory {

public JettyTestContainerFactory() {
}

public JettyTestContainerFactory(Map<String, Object> properties) {
}


@Override
public TestContainer create(final URI baseUri, final DeploymentContext context) throws IllegalArgumentException {
throw new ProcessingException(LocalizationMessages.NOT_SUPPORTED());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2024 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 All @@ -17,11 +17,13 @@
package org.glassfish.jersey.test.jetty;

import java.net.URI;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import jakarta.ws.rs.core.UriBuilder;

import org.eclipse.jetty.server.HttpConnectionFactory;
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.jetty.JettyHttpContainerFactory;
import org.glassfish.jersey.test.DeploymentContext;
Expand All @@ -42,16 +44,21 @@
*/
public class JettyTestContainerFactory implements TestContainerFactory {

private final Map<String, Object> propertiesMap;

private static class JettyTestContainer implements TestContainer {

private static final Logger LOGGER = Logger.getLogger(JettyTestContainer.class.getName());

private final Map<String, Object> propertiesMap;

private URI baseUri;
private final Server server;

private JettyTestContainer(final URI baseUri, final DeploymentContext context) {
private JettyTestContainer(final URI baseUri, final DeploymentContext context, final Map<String, Object> propertiesMap) {
final URI base = UriBuilder.fromUri(baseUri).path(context.getContextPath()).build();

this.propertiesMap = propertiesMap;

if (!"/".equals(base.getRawPath())) {
throw new TestContainerException(String.format(
"Cannot deploy on %s. Jetty HTTP container only supports deployment on root path.",
Expand All @@ -68,6 +75,26 @@ private JettyTestContainer(final URI baseUri, final DeploymentContext context) {
this.server = JettyHttpContainerFactory.createServer(this.baseUri, context.getResourceConfig(), false);
}

@Override
public void configureContainer() {

if (propertiesMap == null
|| !propertiesMap.containsKey(JettyTestContainerProperties.HEADER_SIZE)) {
return;
}

for (Connector c : server.getConnectors()) {
c.getConnectionFactory(HttpConnectionFactory.class)
.getHttpConfiguration().setRequestHeaderSize(
(Integer) propertiesMap.get(JettyTestContainerProperties.HEADER_SIZE));
c.getConnectionFactory(HttpConnectionFactory.class)
.getHttpConfiguration().setResponseHeaderSize(
(Integer) propertiesMap.get(JettyTestContainerProperties.HEADER_SIZE));
c.getConnectionFactory(HttpConnectionFactory.class);
}

}

@Override
public ClientConfig getClientConfig() {
return null;
Expand Down Expand Up @@ -123,6 +150,14 @@ public void stop() {

@Override
public TestContainer create(final URI baseUri, final DeploymentContext context) throws IllegalArgumentException {
return new JettyTestContainer(baseUri, context);
return new JettyTestContainer(baseUri, context, propertiesMap);
}

public JettyTestContainerFactory() {
this(null);
}

public JettyTestContainerFactory(Map<String, Object> properties) {
this.propertiesMap = properties;
}
}
}

0 comments on commit bcfa86b

Please sign in to comment.