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

Support MP REST Client 4.0 #5831

Merged
merged 2 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2025 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019 Payara Foundation and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -379,6 +379,11 @@ private MultivaluedMap<String, String> resolveCustomHeaders(Object[] args) {
if (!headersContext.isPresent()) {
for (InboundHeadersProvider provider : interfaceModel.context().inboundHeadersProviders()) {
inbound.putAll(provider.inboundHeaders());
if (RestClientBuilderImpl.DefaultInboundHeaderProvider.class.isInstance(provider)) {
MultivaluedMap<String, String> fromFactory =
((ClientHeadersFactory) provider).update(inbound, customHeaders);
customHeaders.putAll(fromFactory);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2024 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2025 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2021 Payara Foundation and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -47,15 +47,19 @@
import jakarta.ws.rs.core.Configuration;
import jakarta.ws.rs.core.Feature;
import jakarta.ws.rs.core.FeatureContext;
import jakarta.ws.rs.core.MultivaluedHashMap;
import jakarta.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.ext.ParamConverterProvider;

import jakarta.ws.rs.ext.RuntimeDelegate;
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;
import org.eclipse.microprofile.rest.client.RestClientBuilder;
import org.eclipse.microprofile.rest.client.RestClientDefinitionException;
import org.eclipse.microprofile.rest.client.annotation.RegisterProvider;
import org.eclipse.microprofile.rest.client.ext.AsyncInvocationInterceptor;
import org.eclipse.microprofile.rest.client.ext.AsyncInvocationInterceptorFactory;
import org.eclipse.microprofile.rest.client.ext.ClientHeadersFactory;
import org.eclipse.microprofile.rest.client.ext.QueryParamStyle;
import org.eclipse.microprofile.rest.client.ext.ResponseExceptionMapper;
import org.eclipse.microprofile.rest.client.spi.RestClientListener;
Expand All @@ -66,10 +70,12 @@
import org.glassfish.jersey.client.spi.ConnectorProvider;
import org.glassfish.jersey.ext.cdi1x.internal.CdiUtil;
import org.glassfish.jersey.innate.VirtualThreadUtil;
import org.glassfish.jersey.internal.RuntimeDelegateDecorator;
import org.glassfish.jersey.internal.ServiceFinder;
import org.glassfish.jersey.internal.inject.InjectionManager;
import org.glassfish.jersey.internal.inject.InjectionManagerSupplier;
import org.glassfish.jersey.internal.util.ReflectionHelper;
import org.glassfish.jersey.message.internal.HeaderUtils;
import org.glassfish.jersey.uri.JerseyQueryParamStyle;

/**
Expand All @@ -92,6 +98,7 @@ class RestClientBuilderImpl implements RestClientBuilder {
private final List<AsyncInvocationInterceptorFactoryPriorityWrapper> asyncInterceptorFactories;
private final Config config;
private final ConfigWrapper configWrapper;
private final DefaultInboundHeaderProvider defaultInboundHeaderProvider;
private URI uri;
private ClientBuilder clientBuilder;
private Supplier<ExecutorService> executorService;
Expand All @@ -112,6 +119,9 @@ class RestClientBuilderImpl implements RestClientBuilder {
config = ConfigProvider.getConfig();
configWrapper = new ConfigWrapper(clientBuilder.getConfiguration());
executorService = () -> VirtualThreadUtil.withConfig(configWrapper).newCachedThreadPool();

defaultInboundHeaderProvider = new DefaultInboundHeaderProvider(clientBuilder.getConfiguration());
inboundHeaderProviders.add(defaultInboundHeaderProvider);
}

@Override
Expand Down Expand Up @@ -491,6 +501,11 @@ public RestClientBuilder queryParamStyle(QueryParamStyle queryParamStyle) {
return this;
}

public RestClientBuilder header(String s, Object o) {
defaultInboundHeaderProvider.header(s, o);
return this;
}

private static class InjectionManagerExposer implements Feature {
InjectionManager injectionManager;

Expand Down Expand Up @@ -529,4 +544,34 @@ Integer getPriority() {
}
}

/* package*/ static class DefaultInboundHeaderProvider implements InboundHeadersProvider, ClientHeadersFactory {
private final RuntimeDelegate delegate;
private final MultivaluedMap<String, String> headers = new MultivaluedHashMap<>();

private DefaultInboundHeaderProvider(Configuration configuration) {
this.delegate = RuntimeDelegateDecorator.configured(configuration);
}

private void header(String key, Object value) {
if (value == null) {
throw new NullPointerException();
}
headers.add(key, HeaderUtils.asString(value, delegate));
}

@Override
public Map<String, List<String>> inboundHeaders() {
return headers;
}

@Override
public MultivaluedMap<String, String> update(MultivaluedMap<String, String> incomingHeaders,
MultivaluedMap<String, String> clientOutgoingHeaders) {
MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
map.putAll(incomingHeaders);
clientOutgoingHeaders.forEach((k, v) -> map.addAll(k, v));
return map;
}
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2025 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 @@ -161,6 +161,13 @@ public Object create(CreationalContext<Object> creationalContext) {

@Override
public void destroy(Object instance, CreationalContext<Object> creationalContext) {
if (AutoCloseable.class.isInstance(instance)) {
try {
((AutoCloseable) instance).close();
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2021, 2025 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,3 +16,4 @@

err.invalid.proxy.uri=Invalid proxy URI: {0}.
err.invalid.proxy.port=Invalid proxy port: {0}.
err.null.header=Header cannot be null.
1 change: 0 additions & 1 deletion media/multipart/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2025 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 @@ -36,7 +36,6 @@
import org.glassfish.jersey.client.HttpUrlConnectorProvider;
import org.glassfish.jersey.client.spi.ConnectorProvider;
import org.glassfish.jersey.grizzly.connector.GrizzlyConnectorProvider;
import org.glassfish.jersey.jetty.connector.JettyConnectorProvider;
import org.glassfish.jersey.media.multipart.MultiPart;
import org.glassfish.jersey.test.TestProperties;
import org.glassfish.jersey.test.spi.TestHelper;
Expand Down
6 changes: 4 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2150,7 +2150,8 @@

<!-- microprofile -->
<microprofile.config.version>3.0.3</microprofile.config.version>
<microprofile.rest.client.version>3.0.1</microprofile.rest.client.version>
<microprofile.rest.client3.version>3.0.1</microprofile.rest.client3.version>
<microprofile.rest.client.version>4.0</microprofile.rest.client.version>
<helidon.config.version>3.2.6</helidon.config.version>
<helidon.connector.version>3.2.8</helidon.connector.version>
<helidon.config.11.version>1.4.14</helidon.config.11.version> <!-- JDK 11- support -->
Expand Down Expand Up @@ -2201,7 +2202,8 @@
<weld3.version>3.1.9.Final</weld3.version>
<validation.impl.version>8.0.1.Final</validation.impl.version>
<!-- END of Jakartified, eligible for CQ -->
<wiremock.version>2.27.2</wiremock.version>
<wiremock.jetty9.version>2.27.2</wiremock.jetty9.version>
<wiremock.jetty11.version>3.10.0</wiremock.jetty11.version>
<xerces.version>2.12.2</xerces.version>

<!-- Graal VM -->
Expand Down
1 change: 1 addition & 0 deletions tests/integration/microprofile/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<module>config</module>
<module>rest-client</module>
<module>rest-client-tck</module>
<module>rest-client-tck3</module>
</modules>

<build>
Expand Down
51 changes: 38 additions & 13 deletions tests/integration/microprofile/rest-client-tck/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@
<artifactId>jersey-mp-rest-client</artifactId>
<version>${project.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.eclipse.microprofile.rest.client</groupId>
<artifactId>microprofile-rest-client-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.microprofile.rest.client</groupId>
<artifactId>microprofile-rest-client-api</artifactId>
<version>${microprofile.rest.client.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.microprofile.rest.client</groupId>
<artifactId>microprofile-rest-client-tck</artifactId>
<version>${microprofile.rest.client.version}</version>
<scope>test</scope>
</dependency>
<!-- Overrides CDI from parent pom -->
<dependency>
Expand All @@ -51,32 +69,25 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>io.smallrye.config</groupId>
<artifactId>smallrye-config</artifactId>
<version>${smallrye.config.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.microprofile.rest.client</groupId>
<artifactId>microprofile-rest-client-tck</artifactId>
<version>${microprofile.rest.client.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng6.version}</version>
<version>${testng.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<groupId>org.wiremock</groupId>
<artifactId>wiremock</artifactId>
<version>${wiremock.version}</version>
<version>${wiremock.jetty11.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
Expand Down Expand Up @@ -170,6 +181,11 @@
<artifactId>jersey-apache-connector</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.ext.cdi</groupId>
<artifactId>jersey-weld2-se</artifactId>
Expand Down Expand Up @@ -239,11 +255,20 @@
</plugins>
</build>
</profile>
<profile>
<id>securityOff</id>
<activation>
<jdk>[24,)</jdk>
</activation>
<properties>
<surefire.security.argline />
</properties>
</profile>
</profiles>

<properties>
<surefire.security.argline>-Djava.security.manager -Djava.security.policy=${project.build.directory}/test-classes/server.policy</surefire.security.argline>
<jetty.version>${jetty9.version}</jetty.version>
<jetty.version>${jetty11.version}</jetty.version>
</properties>


Expand Down
Loading
Loading