Skip to content

Commit

Permalink
Drop 11 for Jetty11 classnames
Browse files Browse the repository at this point in the history
The customer can change the module, but java code remains the same
Support multipart by Jetty 12 connector

Signed-off-by: jansupol <jan.supol@oracle.com>
  • Loading branch information
jansupol authored and senivam committed Nov 24, 2023
1 parent 485d0b3 commit d8458a6
Show file tree
Hide file tree
Showing 56 changed files with 357 additions and 254 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.net.URI;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -253,10 +254,13 @@ public HttpCookieStore getCookieStore() {
@Override
public ClientResponse apply(final ClientRequest jerseyRequest) throws ProcessingException {
final Request jettyRequest = translateRequest(jerseyRequest);
final Map<String, String> clientHeadersSnapshot = writeOutBoundHeaders(jerseyRequest.getHeaders(), jettyRequest);
final Request.Content entity = getBytesProvider(jerseyRequest);
final Map<String, String> clientHeadersSnapshot = new HashMap<>();
final Request.Content entity =
getBytesProvider(jerseyRequest, jerseyRequest.getHeaders(), clientHeadersSnapshot, jettyRequest);
if (entity != null) {
jettyRequest.body(entity);
} else {
clientHeadersSnapshot.putAll(writeOutBoundHeaders(jerseyRequest.getHeaders(), jettyRequest));
}

try {
Expand Down Expand Up @@ -343,13 +347,16 @@ private Map<String, String> writeOutBoundHeaders(final MultivaluedMap<String, Ob
if (request instanceof HttpRequest) {
final HttpRequest httpRequest = (HttpRequest) request;
for (final Map.Entry<String, String> e : stringHeaders.entrySet()) {
httpRequest.addHeader(new HttpField(e.getKey(), e.getValue()));
httpRequest.headers(httpFields -> httpFields.put(new HttpField(e.getKey(), e.getValue())));
}
}
return stringHeaders;
}

private Request.Content getBytesProvider(final ClientRequest clientRequest) {
private Request.Content getBytesProvider(final ClientRequest clientRequest,
final MultivaluedMap<String, Object> headers,
final Map<String, String> snapshot,
final Request request) {
final Object entity = clientRequest.getEntity();

if (entity == null) {
Expand All @@ -360,6 +367,7 @@ private Request.Content getBytesProvider(final ClientRequest clientRequest) {
clientRequest.setStreamProvider(new OutboundMessageContext.StreamProvider() {
@Override
public OutputStream getOutputStream(final int contentLength) throws IOException {
snapshot.putAll(writeOutBoundHeaders(headers, request));
return outputStream;
}
});
Expand Down
9 changes: 5 additions & 4 deletions connectors/jetty11-connector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@

<dependencyManagement>
<dependencies>
<!-- <dependency>-->
<!-- <groupId>org.eclipse.jetty</groupId>-->
<!-- <artifactId>jetty-server</artifactId>-->
<!-- <version>${jetty11.version}</version>-->
<!-- </dependency>-->
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jetty11.version}</version>
</dependency><dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-client</artifactId>
<version>${jetty11.version}</version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

package org.glassfish.jersey.jetty11.connector;
package org.glassfish.jersey.jetty.connector;

import java.util.Map;

import org.glassfish.jersey.internal.util.PropertiesClass;
import org.glassfish.jersey.internal.util.PropertiesHelper;

/**
* Configuration options specific to the Client API that utilizes {@link Jetty11ConnectorProvider}.
* Configuration options specific to the Client API that utilizes {@link JettyConnectorProvider}.
*
* @author Arul Dhesiaseelan (aruld at acm.org)
*/
@PropertiesClass
public final class Jetty11ClientProperties {
public final class JettyClientProperties {

/**
* Prevents instantiation.
*/
private Jetty11ClientProperties() {
private JettyClientProperties() {
throw new AssertionError("No instances allowed.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

package org.glassfish.jersey.jetty11.connector;
package org.glassfish.jersey.jetty.connector;

import jakarta.ws.rs.ProcessingException;
import jakarta.ws.rs.client.Client;
Expand Down Expand Up @@ -93,10 +93,10 @@
* <li>{@link ClientProperties#PROXY_USERNAME}</li>
* <li>{@link ClientProperties#PROXY_PASSWORD}</li>
* <li>{@link ClientProperties#PROXY_PASSWORD}</li>
* <li>{@link Jetty11ClientProperties#DISABLE_COOKIES}</li>*
* <li>{@link Jetty11ClientProperties#ENABLE_SSL_HOSTNAME_VERIFICATION}</li>
* <li>{@link Jetty11ClientProperties#PREEMPTIVE_BASIC_AUTHENTICATION}</li>
* <li>{@link Jetty11ClientProperties#SYNC_LISTENER_RESPONSE_MAX_SIZE}</li>
* <li>{@link JettyClientProperties#DISABLE_COOKIES}</li>*
* <li>{@link JettyClientProperties#ENABLE_SSL_HOSTNAME_VERIFICATION}</li>
* <li>{@link JettyClientProperties#PREEMPTIVE_BASIC_AUTHENTICATION}</li>
* <li>{@link JettyClientProperties#SYNC_LISTENER_RESPONSE_MAX_SIZE}</li>
* </ul>
* <p/>
* This transport supports both synchronous and asynchronous processing of client requests.
Expand Down Expand Up @@ -129,9 +129,9 @@
* @author Arul Dhesiaseelan (aruld at acm.org)
* @author Marek Potociar
*/
public class Jetty11Connector implements Connector {
public class JettyConnector implements Connector {

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

private final HttpClient client;
private final CookieStore cookieStore;
Expand All @@ -144,7 +144,7 @@ public class Jetty11Connector implements Connector {
* @param jaxrsClient JAX-RS client instance, for which the connector is created.
* @param config client configuration.
*/
protected Jetty11Connector(final Client jaxrsClient, final Configuration config) {
public JettyConnector(final Client jaxrsClient, final Configuration config) {
this.configuration = config;
HttpClient httpClient = getRegisteredHttpClient(config);

Expand All @@ -160,7 +160,7 @@ protected Jetty11Connector(final Client jaxrsClient, final Configuration config)
this.client = httpClient;

Boolean enableHostnameVerification = (Boolean) config.getProperties()
.get(Jetty11ClientProperties.ENABLE_SSL_HOSTNAME_VERIFICATION);
.get(JettyClientProperties.ENABLE_SSL_HOSTNAME_VERIFICATION);
if (enableHostnameVerification != null) {
final String verificationAlgorithm = enableHostnameVerification ? "HTTPS" : null;
client.getSslContextFactory().setEndpointIdentificationAlgorithm(verificationAlgorithm);
Expand All @@ -180,11 +180,11 @@ protected Jetty11Connector(final Client jaxrsClient, final Configuration config)
threadPool.setName(name);
client.setExecutor(threadPool);
}
Boolean disableCookies = (Boolean) config.getProperties().get(Jetty11ClientProperties.DISABLE_COOKIES);
Boolean disableCookies = (Boolean) config.getProperties().get(JettyClientProperties.DISABLE_COOKIES);
disableCookies = (disableCookies != null) ? disableCookies : false;

final AuthenticationStore auth = client.getAuthenticationStore();
final Object basicAuthProvider = config.getProperty(Jetty11ClientProperties.PREEMPTIVE_BASIC_AUTHENTICATION);
final Object basicAuthProvider = config.getProperty(JettyClientProperties.PREEMPTIVE_BASIC_AUTHENTICATION);
if (basicAuthProvider != null && (basicAuthProvider instanceof BasicAuthentication)) {
auth.addAuthentication((BasicAuthentication) basicAuthProvider);
}
Expand All @@ -206,7 +206,7 @@ protected Jetty11Connector(final Client jaxrsClient, final Configuration config)
}

final Object slResponseMaxSize = configuration.getProperties()
.get(Jetty11ClientProperties.SYNC_LISTENER_RESPONSE_MAX_SIZE);
.get(JettyClientProperties.SYNC_LISTENER_RESPONSE_MAX_SIZE);
if (slResponseMaxSize != null && slResponseMaxSize instanceof Integer
&& (Integer) slResponseMaxSize > 0) {
this.syncListenerResponseMaxSize = Optional.of((Integer) slResponseMaxSize);
Expand Down Expand Up @@ -244,11 +244,11 @@ protected HttpClientTransport initClientTransport(ClientConnector clientConnecto
* @since 2.41
*/
protected HttpClient getRegisteredHttpClient(Configuration config) {
if (config.isRegistered(Jetty11HttpClientSupplier.class)) {
if (config.isRegistered(JettyHttpClientSupplier.class)) {
Optional<Object> contract = config.getInstances().stream()
.filter(a-> Jetty11HttpClientSupplier.class.isInstance(a)).findFirst();
.filter(a-> JettyHttpClientSupplier.class.isInstance(a)).findFirst();
if (contract.isPresent()) {
return ((Jetty11HttpClientSupplier) contract.get()).getHttpClient();
return ((JettyHttpClientSupplier) contract.get()).getHttpClient();
}
}
return null;
Expand Down Expand Up @@ -298,7 +298,7 @@ public ClientResponse apply(final ClientRequest jerseyRequest) throws Processing
jettyResponse = listener.get();
}
HeaderUtils.checkHeaderChanges(clientHeadersSnapshot, jerseyRequest.getHeaders(),
Jetty11Connector.this.getClass().getName(), jerseyRequest.getConfiguration());
JettyConnector.this.getClass().getName(), jerseyRequest.getConfiguration());

final jakarta.ws.rs.core.Response.StatusType status = jettyResponse.getReason() == null
? Statuses.from(jettyResponse.getStatus())
Expand Down Expand Up @@ -354,7 +354,7 @@ private Request translateRequest(final ClientRequest clientRequest) {
request.idleTimeout((Integer) readTimeout, TimeUnit.MILLISECONDS);
}

final Object totalTimeout = clientRequest.resolveProperty(Jetty11ClientProperties.TOTAL_TIMEOUT, -1);
final Object totalTimeout = clientRequest.resolveProperty(JettyClientProperties.TOTAL_TIMEOUT, -1);
if (totalTimeout != null && totalTimeout instanceof Integer && (Integer) totalTimeout > 0) {
request.timeout((Integer) totalTimeout, TimeUnit.MILLISECONDS);
}
Expand Down Expand Up @@ -459,7 +459,7 @@ public Future<?> apply(final ClientRequest jerseyRequest, final AsyncConnectorCa
@Override
public void onHeaders(final Response jettyResponse) {
HeaderUtils.checkHeaderChanges(clientHeadersSnapshot, jerseyRequest.getHeaders(),
Jetty11Connector.this.getClass().getName(), jerseyRequest.getConfiguration());
JettyConnector.this.getClass().getName(), jerseyRequest.getConfiguration());

if (responseFuture.isDone()) {
if (!callbackInvoked.compareAndSet(false, true)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

package org.glassfish.jersey.jetty11.connector;
package org.glassfish.jersey.jetty.connector;

import jakarta.ws.rs.ProcessingException;
import jakarta.ws.rs.client.Client;
Expand Down Expand Up @@ -42,10 +42,10 @@
* <li>{@link org.glassfish.jersey.client.ClientProperties#PROXY_USERNAME}</li>
* <li>{@link org.glassfish.jersey.client.ClientProperties#PROXY_PASSWORD}</li>
* <li>{@link org.glassfish.jersey.client.ClientProperties#PROXY_PASSWORD}</li>
* <li>{@link Jetty11ClientProperties#DISABLE_COOKIES}</li>*
* <li>{@link Jetty11ClientProperties#ENABLE_SSL_HOSTNAME_VERIFICATION}</li>
* <li>{@link Jetty11ClientProperties#PREEMPTIVE_BASIC_AUTHENTICATION}</li>
* <li>{@link Jetty11ClientProperties#SYNC_LISTENER_RESPONSE_MAX_SIZE}</li>
* <li>{@link JettyClientProperties#DISABLE_COOKIES}</li>*
* <li>{@link JettyClientProperties#ENABLE_SSL_HOSTNAME_VERIFICATION}</li>
* <li>{@link JettyClientProperties#PREEMPTIVE_BASIC_AUTHENTICATION}</li>
* <li>{@link JettyClientProperties#SYNC_LISTENER_RESPONSE_MAX_SIZE}</li>
* </ul>
* </p>
* <p>
Expand Down Expand Up @@ -82,14 +82,14 @@
* @author Marek Potociar
* @since 2.5
*/
public class Jetty11ConnectorProvider implements ConnectorProvider {
public class JettyConnectorProvider implements ConnectorProvider {

@Override
public Connector getConnector(Client client, Configuration runtimeConfig) {
if (JdkVersion.getJdkVersion().getMajor() < 11) {
throw new ProcessingException(LocalizationMessages.NOT_SUPPORTED());
}
return new Jetty11Connector(client, runtimeConfig);
return new JettyConnector(client, runtimeConfig);
}

/**
Expand Down Expand Up @@ -119,8 +119,8 @@ public static HttpClient getHttpClient(Configurable<?> component) {
connector = initializable.getConfiguration().getConnector();
}

if (connector instanceof Jetty11Connector) {
return ((Jetty11Connector) connector).getHttpClient();
if (connector instanceof JettyConnector) {
return ((JettyConnector) connector).getHttpClient();
}

throw new IllegalArgumentException(LocalizationMessages.EXPECTED_CONNECTOR_PROVIDER_NOT_USED());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

package org.glassfish.jersey.jetty11.connector;
package org.glassfish.jersey.jetty.connector;

import org.eclipse.jetty.client.HttpClient;
import org.glassfish.jersey.spi.Contract;

/**
* A contract that allows for an optional registration of user predefined Jetty {@code HttpClient}
* that is consequently used by {@link Jetty11Connector}
* that is consequently used by {@link JettyConnector}
*/
@Contract
public interface Jetty11HttpClientContract {
public interface JettyHttpClientContract {
/**
* Supply a user predefined HttpClient
* @return a user predefined HttpClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package org.glassfish.jersey.jetty11.connector;
package org.glassfish.jersey.jetty.connector;

import org.eclipse.jetty.client.HttpClient;

/**
* Jetty HttpClient supplier to be registered into Jersey configuration to be used by {@link Jetty11Connector}.
* Jetty HttpClient supplier to be registered into Jersey configuration to be used by {@link JettyConnector}.
* Not every possible configuration option is covered by the Jetty Connector and this supplier offers a way to provide
* an HttpClient that has configured the options not covered by the Jetty Connector.
* <p>
Expand All @@ -35,17 +35,17 @@
* }
* </pre>
* <p>
* The {@code HttpClient} is configured as if it was created by {@link Jetty11Connector} the usual way.
* The {@code HttpClient} is configured as if it was created by {@link JettyConnector} the usual way.
* </p>
*/
public class Jetty11HttpClientSupplier implements Jetty11HttpClientContract {
public class JettyHttpClientSupplier implements JettyHttpClientContract {
private final HttpClient httpClient;

/**
* {@code HttpClient} supplier to be optionally registered to a {@link org.glassfish.jersey.client.ClientConfig}
* @param httpClient a HttpClient to be supplied when {@link Jetty11Connector#getHttpClient()} is called.
* @param httpClient a HttpClient to be supplied when {@link JettyConnector#getHttpClient()} is called.
*/
public Jetty11HttpClientSupplier(HttpClient httpClient) {
public JettyHttpClientSupplier(HttpClient httpClient) {
this.httpClient = httpClient;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
* Jersey client {@link org.glassfish.jersey.client.spi.Connector connector} based on the
* Jetty Client.
*/
package org.glassfish.jersey.jetty11.connector;
package org.glassfish.jersey.jetty.connector;
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

package org.glassfish.jersey.jetty11.connector;
package org.glassfish.jersey.jetty.connector;

import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -149,7 +149,7 @@ protected Application configure() {
protected void configureClient(ClientConfig config) {
// TODO: fails with true on request - should be fixed by resolving JERSEY-2273
config.register(new LoggingFeature(LOGGER, LoggingFeature.Verbosity.HEADERS_ONLY));
config.connectorProvider(new Jetty11ConnectorProvider());
config.connectorProvider(new JettyConnectorProvider());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

package org.glassfish.jersey.jetty11.connector;
package org.glassfish.jersey.jetty.connector;

import java.util.logging.Logger;

Expand Down Expand Up @@ -49,7 +49,7 @@ protected Application configure() {

@Override
protected void configureClient(ClientConfig config) {
config.connectorProvider(new Jetty11ConnectorProvider());
config.connectorProvider(new JettyConnectorProvider());
}

@Test
Expand Down
Loading

0 comments on commit d8458a6

Please sign in to comment.