diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/client/proxy/ResourceRegistryClientImpl.java b/src/main/java/org/gcube/informationsystem/resourceregistry/client/proxy/ResourceRegistryClientImpl.java index 90a1ca9..798a87c 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/client/proxy/ResourceRegistryClientImpl.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/client/proxy/ResourceRegistryClientImpl.java @@ -31,6 +31,7 @@ import org.gcube.informationsystem.model.ER; import org.gcube.informationsystem.model.ISManageable; import org.gcube.informationsystem.model.entity.Entity; import org.gcube.informationsystem.model.entity.Resource; +import org.gcube.informationsystem.resourceregistry.api.exceptions.ExceptionMapper; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.er.ERException; import org.gcube.informationsystem.resourceregistry.api.exceptions.er.ERNotFoundException; @@ -239,13 +240,28 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { URL url = new URL(callUrl.toString()); HttpURLConnection connection = getConnection(url, httpInputs.method); - logger.debug("Response code for {} is {} : {}", - connection.getURL(), connection.getResponseCode(), - connection.getResponseMessage()); - - if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) { - throw new Exception( - "Error Contacting Resource Registry Service"); + String responseMessage = connection.getResponseMessage(); + int responseCode = connection.getResponseCode(); + + if (responseCode != HttpURLConnection.HTTP_OK) { + + logger.error("Response code for {} is {} : {}", + connection.getURL(), responseCode, + responseMessage); + + ResourceRegistryException rre = null; + try { + rre = ExceptionMapper.unmarshal(ResourceRegistryException.class, responseMessage); + }catch (Exception e) { + rre = new ResourceRegistryException(responseMessage); + } + + throw rre; + + }else{ + logger.debug("Response code for {} is {} : {}", + connection.getURL(), responseCode, + responseMessage); } StringBuilder result = new StringBuilder(); diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/client/proxy/ResourceRegistryClientTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/client/proxy/ResourceRegistryClientTest.java index 8bbb4d2..2bcc70b 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/client/proxy/ResourceRegistryClientTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/client/proxy/ResourceRegistryClientTest.java @@ -7,6 +7,7 @@ import java.util.List; import org.gcube.informationsystem.model.entity.facet.ContactFacet; import org.gcube.informationsystem.model.entity.resource.HostingNode; +import org.gcube.informationsystem.model.entity.resource.Service; import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException; import org.gcube.informationsystem.types.TypeBinder.TypeDefinition; @@ -48,4 +49,16 @@ public class ResourceRegistryClientTest extends ScopedTest { logger.trace("{}", typeDefinitions); } + interface Aux extends Service { + + + } + + @Test + public void testException() throws SchemaNotFoundException { + List typeDefinitions = resourceRegistryClient.getSchema(Aux.class, true); + logger.trace("{}", typeDefinitions); + } + + }