Skip to content

Commit

Permalink
upgrade Jersey 2.38 to 2.40 and update constructors of StandardClient
Browse files Browse the repository at this point in the history
  • Loading branch information
dunedodo committed Oct 18, 2023
1 parent 7b90576 commit 0c85d41
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 21 deletions.
2 changes: 1 addition & 1 deletion smart-client-core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
description = 'Smart Client core components - This library has minimal dependencies and provides the core generic logic necesary for client-side intelligent load balancing'

dependencies {
implementation 'org.glassfish.jersey.core:jersey-client:2.38'
implementation 'org.glassfish.jersey.core:jersey-client:2.40'
implementation 'org.slf4j:slf4j-api:2.0.6'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.apache.logging.log4j:log4j-core:2.19.0'
Expand Down
4 changes: 2 additions & 2 deletions smart-client-ecs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ description = 'HostListProvider implementation for ECS'
dependencies {
api project(':smart-client-core')
api project(':smart-client-jersey')
implementation 'org.glassfish.jersey.core:jersey-client:2.38'
implementation 'org.glassfish.jersey.connectors:jersey-apache-connector:2.38'
implementation 'org.glassfish.jersey.core:jersey-client:2.40'
implementation 'org.glassfish.jersey.connectors:jersey-apache-connector:2.40'
implementation 'commons-codec:commons-codec:1.15'
// jaxb was removed from Java 11 - jaxb dependencies are provided with Java 8
implementation "javax.xml.bind:jaxb-api:2.3.1"
Expand Down
13 changes: 7 additions & 6 deletions smart-client-jersey/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ description = 'Smart Client for Jersey 2.x - includes a SmartClientFactory'

dependencies {
api project(':smart-client-core')
implementation 'org.glassfish.jersey.core:jersey-client:2.38'
implementation 'org.glassfish.jersey.connectors:jersey-apache-connector:2.38'
implementation 'org.glassfish.jersey.inject:jersey-hk2:2.38'
implementation 'org.glassfish.jersey.core:jersey-client:2.40'
implementation "org.glassfish.jersey.connectors:jersey-apache-connector:2.40"
implementation 'org.glassfish.jersey.connectors:jersey-netty-connector:2.40'
implementation 'org.glassfish.jersey.inject:jersey-hk2:2.40'

implementation 'org.apache.httpcomponents:httpclient:4.5.14'
implementation 'org.glassfish.jersey.media:jersey-media-json-jackson:2.38'
implementation 'org.glassfish.jersey.media:jersey-media-json-processing:2.38'
implementation 'org.glassfish.jersey.media:jersey-media-jaxb:2.38'
implementation 'org.glassfish.jersey.media:jersey-media-json-jackson:2.40'
implementation 'org.glassfish.jersey.media:jersey-media-json-processing:2.40'
implementation 'org.glassfish.jersey.media:jersey-media-jaxb:2.40'
implementation 'com.fasterxml.jackson.jaxrs:jackson-jaxrs-xml-provider:2.14.2'

implementation 'org.slf4j:slf4j-api:2.0.6'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Configuration;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
Expand All @@ -39,8 +40,8 @@
public class OctetStreamXmlProvider implements MessageBodyReader<Object> {
private final MessageBodyReader<Object> delegate;

public OctetStreamXmlProvider(@Context Provider<SAXParserFactory> spf, @Context Providers ps) {
this.delegate = new XmlRootElementJaxbProvider.General(spf, ps);
public OctetStreamXmlProvider(@Context Provider<SAXParserFactory> spf, @Context Providers ps, @Context Configuration config) {
this.delegate = new XmlRootElementJaxbProvider.General(spf, ps, config);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public final class SmartClientFactory {

public static final String IDLE_CONNECTION_MONITOR_PROPERTY_KEY = "com.emc.rest.smart.idleConnectionsExecSvc";

public static final String APACHE_TRANSPORT_CONNECTOR = "APACHE";
public static final String HTTPURLCONNECTION_TRANSPORT_CONNECTOR = "HTTPURLCONNECTION";

public static JerseyClient createSmartClient(SmartConfig smartConfig, JerseyClient client) {

// If you register a second ClientConfig object on the same Client, it will overwrite the first config,
Expand Down Expand Up @@ -83,13 +86,29 @@ public static JerseyClient createSmartClient(SmartConfig smartConfig, JerseyClie
return JerseyClientBuilder.createClient(clientConfig);
}

/**
* This creates a standard apache-based Jersey client, configured with a SmartConfig, but without any load balancing
* or node polling.
*/
public static JerseyClient createStandardClient(SmartConfig smartConfig) {
return createStandardClient(smartConfig, APACHE_TRANSPORT_CONNECTOR);
}

/**
* This creates a standard apache-based Jersey client, configured with a SmartConfig, but without any load balancing
* or node polling.
*/
public static JerseyClient createStandardClient(SmartConfig smartConfig,
JerseyClient clientHandler) {
JerseyClient client = (clientHandler == null ? createApacheClient(smartConfig) : clientHandler);
String clientTransportConnector) {

JerseyClient client = JerseyClientBuilder.createClient();

// register connection provider onto client
if (clientTransportConnector == null || clientTransportConnector.equals(APACHE_TRANSPORT_CONNECTOR))
client = createApacheClient(smartConfig);
else if (clientTransportConnector.equals(HTTPURLCONNECTION_TRANSPORT_CONNECTOR)) {
client = JerseyClientBuilder.createClient();
}

// pass in jersey parameters from calling code (allows customization of client)
for (String propName : smartConfig.getProperties().keySet()) {
Expand Down Expand Up @@ -159,7 +178,7 @@ public static void destroy(JerseyClient client) {
}

static JerseyClient createApacheClient(SmartConfig smartConfig) {
smartConfig.setProperty(CONNECTOR_PROVIDER, "APACHE");
smartConfig.setProperty(CONNECTOR_PROVIDER, APACHE_TRANSPORT_CONNECTOR);

ClientConfig clientConfig = new ClientConfig();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import javax.crypto.spec.SecretKeySpec;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;;
import javax.ws.rs.core.Response;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
Expand Down Expand Up @@ -114,9 +114,10 @@ public void testPutJsonStream() throws Exception {
// (no exception when finding a MessageBodyWriter)
JerseyWebTarget webTarget = client.target(endpoints[0]).path("/rest/namespace/foo");
JerseyInvocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON);
Response response = invocationBuilder.post(Entity.json(data));
try (Response response = invocationBuilder.post(Entity.json(data))) {

Assert.assertTrue(response.getStatus() > 299); // some versions of ECS return 500 instead of 403
Assert.assertTrue(response.getStatus() > 299); // some versions of ECS return 500 instead of 403
}
}

@Test
Expand All @@ -125,7 +126,7 @@ public void testConnTimeout() throws Exception {

SmartConfig smartConfig = new SmartConfig("8.8.4.4:9020");

final JerseyClient client = SmartClientFactory.createStandardClient(smartConfig, null);
final JerseyClient client = SmartClientFactory.createStandardClient(smartConfig);
client.property(ClientProperties.CONNECT_TIMEOUT, CONNECTION_TIMEOUT_MILLIS);

Future<?> future = Executors.newSingleThreadExecutor().submit(() -> {
Expand Down Expand Up @@ -157,11 +158,13 @@ private void getServiceInfo(JerseyClient client, URI serverUri, String uid, Stri
.header("x-emc-signature", signature)
.buildGet();

Response response = invocation.invoke(Response.class);
String responseStr;
try (Response response = invocation.invoke(Response.class)) {

if (response.getStatus() > 299) throw new RuntimeException("error response: " + response.getStatus());
if (response.getStatus() > 299) throw new RuntimeException("error response: " + response.getStatus());

String responseStr = (String)response.getEntity();
responseStr = (String) response.getEntity();
}
if (!responseStr.contains("Atmos")) throw new RuntimeException("unrecognized response string: " + responseStr);
}

Expand Down

0 comments on commit 0c85d41

Please sign in to comment.