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

Make the helidon-jersey-connector module discoverable by Jersey if available #2008

Merged
merged 7 commits into from
Jun 17, 2020
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
10 changes: 10 additions & 0 deletions jersey/client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2020 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.helidon.jersey.client;

import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.ServiceLoader;

import org.glassfish.jersey.client.spi.ConnectorProvider;
import org.junit.jupiter.api.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

public class ConnectorProviderTest {

/**
* There should be no {@link org.glassfish.jersey.client.spi.ConnectorProvider}'s in
* path when running this test. This test will fail if the {@code io.helidon.jersey.connector}
* module is available.
*
* @throws NoSuchElementException If not found.
*/
@Test
public void testConnectorProvider() throws NoSuchElementException {
ServiceLoader<ConnectorProvider> loader = ServiceLoader.load(ConnectorProvider.class);
assertThat(loader.findFirst(), is(Optional.empty()));
}
}
24 changes: 20 additions & 4 deletions jersey/connector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,21 @@

<dependencies>
<dependency>
<groupId>io.helidon.jersey</groupId>
<artifactId>helidon-jersey-client</artifactId>
<!-- for use with plain Jersey -->
<scope>provided</scope>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
</dependency>
<dependency>
<!-- this module is required by Jakarta JAX-RS (requires transitive in module-info.java) -->
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.webclient</groupId>
Expand All @@ -59,6 +70,11 @@
<artifactId>commons-lang3</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
3 changes: 3 additions & 0 deletions jersey/connector/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

import io.helidon.jersey.connector.HelidonConnectorProvider;

/**
* A {@link org.glassfish.jersey.client.spi.Connector} that utilizes the Helidon HTTP Client to send and receive
* * HTTP request and responses.
Expand All @@ -29,4 +31,5 @@
requires io.netty.codec.http;

exports io.helidon.jersey.connector;
provides org.glassfish.jersey.client.spi.ConnectorProvider with HelidonConnectorProvider;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
# Copyright (c) 2020 Oracle and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

io.helidon.jersey.connector.HelidonConnectorProvider
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2020 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.helidon.jersey.connector;

import javax.ws.rs.client.ClientBuilder;
import java.util.NoSuchElementException;
import java.util.ServiceLoader;

import org.glassfish.jersey.client.JerseyClient;
import org.junit.jupiter.api.Test;
import org.glassfish.jersey.client.spi.ConnectorProvider;

import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;

public class ConnectorProviderTest {

/**
* Test how Jersey will load the Helidon connector provider.
*
* @throws NoSuchElementException If not found.
*/
@Test
public void testConnectorProvider() throws NoSuchElementException {
ServiceLoader<ConnectorProvider> loader = ServiceLoader.load(ConnectorProvider.class);
ConnectorProvider provider = loader.findFirst().orElseThrow();
assertThat(provider, instanceOf(HelidonConnectorProvider.class));
}

/**
* Check that Jersey has found the Helidon connector provider.
*/
@Test
public void testConnectorLoaded() {
JerseyClient jerseyClient = (JerseyClient) ClientBuilder.newClient();
ConnectorProvider provider = jerseyClient.getConfiguration().getConnectorProvider();
assertThat(provider, instanceOf(HelidonConnectorProvider.class));
}
}
4 changes: 4 additions & 0 deletions tests/functional/jax-rs-subresource/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
<groupId>io.helidon.microprofile</groupId>
<artifactId>helidon-microprofile-security</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.jersey</groupId>
<artifactId>helidon-jersey-connector</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,6 +27,13 @@
import javax.ws.rs.core.Response;

import io.helidon.microprofile.server.Server;
import io.helidon.jersey.connector.HelidonConnectorProvider;

import org.glassfish.jersey.client.JerseyClient;
import org.glassfish.jersey.client.spi.ConnectorProvider;

import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
Expand All @@ -39,6 +46,7 @@
* Unit test for {@link MpSubResource}.
*/
class MpSubResourceTest {
private static Client client;
private static Server server;
private static WebTarget baseTarget;

Expand All @@ -47,7 +55,7 @@ static void initClass() throws IOException {
LogManager.getLogManager().readConfiguration(MpSubResourceTest.class.getResourceAsStream("/logging.properties"));
Main.main(new String[0]);
server = Main.server();
Client client = ClientBuilder.newClient();
client = ClientBuilder.newClient();
baseTarget = client.target("http://localhost:" + server.port());
}

Expand Down Expand Up @@ -155,6 +163,17 @@ void testSubParentSecurity() {
assertOk(secureRequest(target, "jill"), okMessage);
}

/**
* Verifies that the {@code HelidonConnectorProvider} is being used
* by Jersey.
*/
@Test
public void testConnectorLoaded() {
JerseyClient jerseyClient = (JerseyClient) client;
ConnectorProvider provider = jerseyClient.getConfiguration().getConnectorProvider();
assertThat(provider, instanceOf(HelidonConnectorProvider.class));
}

private void assertOk(Response response, String expectedMessage) {
assertThat(response.getStatus(), is(200));
assertThat(response.readEntity(String.class), is(expectedMessage));
Expand Down