diff --git a/smart-client-core/build.gradle b/smart-client-core/build.gradle index fe23237..dd65e5b 100644 --- a/smart-client-core/build.gradle +++ b/smart-client-core/build.gradle @@ -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' diff --git a/smart-client-ecs/build.gradle b/smart-client-ecs/build.gradle index 310860b..7cd3354 100644 --- a/smart-client-ecs/build.gradle +++ b/smart-client-ecs/build.gradle @@ -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" diff --git a/smart-client-jersey/build.gradle b/smart-client-jersey/build.gradle index d1484e3..5a71309 100644 --- a/smart-client-jersey/build.gradle +++ b/smart-client-jersey/build.gradle @@ -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' diff --git a/smart-client-jersey/src/main/java/com/emc/rest/smart/jersey/OctetStreamXmlProvider.java b/smart-client-jersey/src/main/java/com/emc/rest/smart/jersey/OctetStreamXmlProvider.java index 7b5f91e..e0afed5 100644 --- a/smart-client-jersey/src/main/java/com/emc/rest/smart/jersey/OctetStreamXmlProvider.java +++ b/smart-client-jersey/src/main/java/com/emc/rest/smart/jersey/OctetStreamXmlProvider.java @@ -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; @@ -39,8 +40,8 @@ public class OctetStreamXmlProvider implements MessageBodyReader { private final MessageBodyReader delegate; - public OctetStreamXmlProvider(@Context Provider spf, @Context Providers ps) { - this.delegate = new XmlRootElementJaxbProvider.General(spf, ps); + public OctetStreamXmlProvider(@Context Provider spf, @Context Providers ps, @Context Configuration config) { + this.delegate = new XmlRootElementJaxbProvider.General(spf, ps, config); } @Override diff --git a/smart-client-jersey/src/main/java/com/emc/rest/smart/jersey/SmartClientFactory.java b/smart-client-jersey/src/main/java/com/emc/rest/smart/jersey/SmartClientFactory.java index 212a564..d6f2512 100644 --- a/smart-client-jersey/src/main/java/com/emc/rest/smart/jersey/SmartClientFactory.java +++ b/smart-client-jersey/src/main/java/com/emc/rest/smart/jersey/SmartClientFactory.java @@ -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, @@ -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()) { @@ -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(); diff --git a/smart-client-jersey/src/test/java/com/emc/rest/smart/SmartClientTest.java b/smart-client-jersey/src/test/java/com/emc/rest/smart/SmartClientTest.java index 2ac4aac..bbb1e09 100644 --- a/smart-client-jersey/src/test/java/com/emc/rest/smart/SmartClientTest.java +++ b/smart-client-jersey/src/test/java/com/emc/rest/smart/SmartClientTest.java @@ -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; @@ -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 @@ -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(() -> { @@ -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); }