From 9681f6669415a94166c7b45199d7316e009bf512 Mon Sep 17 00:00:00 2001 From: Lucio Lelii Date: Fri, 26 Oct 2018 09:07:23 +0000 Subject: [PATCH] git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/branches/common/common-jaxrs-client/1.0@173839 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../common/calls/jaxrs/TargetFactory.java | 31 +++++++++++++++---- .../common/calls/jaxrs/TargetFactoryDSL.java | 8 ++++- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/gcube/common/calls/jaxrs/TargetFactory.java b/src/main/java/org/gcube/common/calls/jaxrs/TargetFactory.java index 4c99c44..ead81d8 100644 --- a/src/main/java/org/gcube/common/calls/jaxrs/TargetFactory.java +++ b/src/main/java/org/gcube/common/calls/jaxrs/TargetFactory.java @@ -26,14 +26,10 @@ public class TargetFactory implements TargetFactoryDSL.AtClause{ } - public GXWebTargetAdapterRequest at(String address) { + public GXWebTargetAdapterRequest getAsGxRest(String address) { try{ - Client client = ClientBuilder.newClient() - .property(ClientProperties.FOLLOW_REDIRECTS, Boolean.FALSE) - .property(ClientProperties.CHUNKED_ENCODING_SIZE, 1024*1024).property(ClientProperties.OUTBOUND_CONTENT_LENGTH_BUFFER, -1) - .property(ClientProperties.REQUEST_ENTITY_PROCESSING, "CHUNKED"); /* String resourceAddress = address.substring(0, address.indexOf("/service")); @@ -64,8 +60,31 @@ public class TargetFactory implements TargetFactoryDSL.AtClause{ } + public WebTarget at(String address) { + + try{ + + Client client = ClientBuilder.newClient() + .property(ClientProperties.FOLLOW_REDIRECTS, Boolean.FALSE) + .property(ClientProperties.CHUNKED_ENCODING_SIZE, 1024*1024).property(ClientProperties.OUTBOUND_CONTENT_LENGTH_BUFFER, -1) + .property(ClientProperties.REQUEST_ENTITY_PROCESSING, "CHUNKED"); + + + WebTarget webTarget = client.target(address).path(target.path()); + + webTarget.register(new JaxRSRequestFilter(target)); + + return webTarget; + + }catch (Exception e) { + log.error("error building service",e); + throw new RuntimeException("error building service",e); + } + + } + - public GXWebTargetAdapterRequest at(EndpointReference endpoint){ + public WebTarget at(EndpointReference endpoint){ return at(new JaxRSEndpointReference(endpoint).address); } diff --git a/src/main/java/org/gcube/common/calls/jaxrs/TargetFactoryDSL.java b/src/main/java/org/gcube/common/calls/jaxrs/TargetFactoryDSL.java index f64cfd0..3d3f894 100644 --- a/src/main/java/org/gcube/common/calls/jaxrs/TargetFactoryDSL.java +++ b/src/main/java/org/gcube/common/calls/jaxrs/TargetFactoryDSL.java @@ -29,8 +29,14 @@ public interface TargetFactoryDSL { * @param address the address * @return the stub */ - GXWebTargetAdapterRequest at(String address); + GXWebTargetAdapterRequest getAsGxRest(String address); + /** + * Returns a stub for a service endpoint at a given address. + * @param address the address + * @return the stub + */ + WebTarget at(String address); } }