Added exception marshalling/umarshalling via json using jackson

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry-client@144210 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2017-02-23 16:08:04 +00:00
parent ff0462ccac
commit e0c6542f9e
2 changed files with 36 additions and 7 deletions

View File

@ -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();

View File

@ -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<TypeDefinition> typeDefinitions = resourceRegistryClient.getSchema(Aux.class, true);
logger.trace("{}", typeDefinitions);
}
}