-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow for setting connector provider via properties (#5345)
* Allow for setting connector provider via properties Signed-off-by: jansupol <[email protected]>
- Loading branch information
Showing
17 changed files
with
561 additions
and
84 deletions.
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
...n-connector/src/test/java/org/glassfish/jersey/helidon/connector/MetaInfOverrideTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright (c) 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 | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
|
||
package org.glassfish.jersey.helidon.connector; | ||
|
||
import org.glassfish.jersey.client.ClientConfig; | ||
import org.glassfish.jersey.client.ClientProperties; | ||
import org.glassfish.jersey.client.HttpUrlConnectorProvider; | ||
import org.glassfish.jersey.server.ResourceConfig; | ||
import org.glassfish.jersey.test.JerseyTest; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.client.ClientBuilder; | ||
import javax.ws.rs.client.ClientRequestContext; | ||
import javax.ws.rs.client.ClientRequestFilter; | ||
import javax.ws.rs.core.Application; | ||
import javax.ws.rs.core.Context; | ||
import javax.ws.rs.core.HttpHeaders; | ||
import javax.ws.rs.core.Response; | ||
import java.io.IOException; | ||
|
||
// The Helidon jar has META-INF set | ||
// Test of override | ||
class MetaInfOverrideTest extends JerseyTest { | ||
|
||
@Path("/origin") | ||
public static class UserAgentServer { | ||
@GET | ||
public String get(@Context HttpHeaders headers) { | ||
return headers.getHeaderString(HttpHeaders.USER_AGENT); | ||
} | ||
} | ||
|
||
@Override | ||
protected Application configure() { | ||
return new ResourceConfig(UserAgentServer.class); | ||
} | ||
|
||
@Test | ||
void defaultMetaInfTest() { | ||
try (Response r = target("origin").request().get()) { | ||
Assertions.assertEquals(200, r.getStatus()); | ||
Assertions.assertTrue(r.readEntity(String.class).contains("Helidon")); | ||
} | ||
} | ||
|
||
@Test | ||
void overrideMetaInfTest() { | ||
ClientConfig config = new ClientConfig(); | ||
config.connectorProvider(new HttpUrlConnectorProvider()); | ||
try (Response r = ClientBuilder.newClient(config).target(target("origin").getUri()).request().get()) { | ||
Assertions.assertEquals(200, r.getStatus()); | ||
r.bufferEntity(); | ||
System.out.println(r.readEntity(String.class)); | ||
Assertions.assertTrue(r.readEntity(String.class).contains("HttpUrlConnection")); | ||
} | ||
} | ||
|
||
@Test | ||
void overrideMetaInfByOtherConfigPropertyTest() { | ||
ClientConfig config = new ClientConfig(); | ||
config.property(ClientProperties.CONNECTOR_PROVIDER, "org.glassfish.jersey.client.HttpUrlConnectorProvider"); | ||
try (Response r = ClientBuilder.newClient(config).target(target("origin").getUri()).request().get()) { | ||
Assertions.assertEquals(200, r.getStatus()); | ||
r.bufferEntity(); | ||
System.out.println(r.readEntity(String.class)); | ||
Assertions.assertTrue(r.readEntity(String.class).contains("HttpUrlConnection")); | ||
} | ||
} | ||
|
||
@Test | ||
void overrideMetaInfByThePropertyTest() { | ||
try (Response r = ClientBuilder.newBuilder() | ||
.property(ClientProperties.CONNECTOR_PROVIDER, "org.glassfish.jersey.client.HttpUrlConnectorProvider") | ||
.build() | ||
.target(target("origin").getUri()).request().get()) { | ||
Assertions.assertEquals(200, r.getStatus()); | ||
r.bufferEntity(); | ||
System.out.println(r.readEntity(String.class)); | ||
Assertions.assertTrue(r.readEntity(String.class).contains("HttpUrlConnection")); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 0 additions & 35 deletions
35
...rc/main/java/org/glassfish/jersey/internal/config/ExternalPropertiesAutoDiscoverable.java
This file was deleted.
Oops, something went wrong.
29 changes: 0 additions & 29 deletions
29
...ain/java/org/glassfish/jersey/internal/config/ExternalPropertiesConfigurationFeature.java
This file was deleted.
Oops, something went wrong.
3 changes: 1 addition & 2 deletions
3
...n/src/main/resources/META-INF/services/org.glassfish.jersey.internal.spi.AutoDiscoverable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
org.glassfish.jersey.logging.LoggingFeatureAutoDiscoverable | ||
org.glassfish.jersey.internal.config.ExternalPropertiesAutoDiscoverable | ||
org.glassfish.jersey.logging.LoggingFeatureAutoDiscoverable |
Oops, something went wrong.