error message improved on execute query

This commit is contained in:
Lucio Lelii 2020-04-08 18:02:54 +02:00
parent 87c5fcf09e
commit 1fb2e22401
4 changed files with 34 additions and 29 deletions

View File

@ -10,7 +10,7 @@
<groupId>org.gcube.resources.discovery</groupId> <groupId>org.gcube.resources.discovery</groupId>
<artifactId>ic-client</artifactId> <artifactId>ic-client</artifactId>
<version>1.1.0-SNAPSHOT</version> <version>1.0.5-SNAPSHOT</version>
<name>Information Collector Client</name> <name>Information Collector Client</name>
<description>Client API for the Information Collector service</description> <description>Client API for the Information Collector service</description>

View File

@ -1,8 +1,8 @@
package org.gcube.resources.discovery.icclient; package org.gcube.resources.discovery.icclient;
import static org.gcube.common.authorization.client.Constants.authorizationService; import static org.gcube.common.clients.stubs.jaxws.StubFactory.stubFor;
import static org.gcube.common.clients.stubs.jaxws.StubFactory.*; import static org.gcube.resources.discovery.icclient.stubs.CollectorConstants.collector;
import static org.gcube.resources.discovery.icclient.stubs.CollectorConstants.*; import static org.gcube.resources.discovery.icclient.stubs.CollectorConstants.localname;
import java.net.URI; import java.net.URI;
import java.util.ArrayList; import java.util.ArrayList;
@ -12,11 +12,7 @@ import java.util.regex.Pattern;
import javax.xml.ws.soap.SOAPFaultException; import javax.xml.ws.soap.SOAPFaultException;
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
import org.gcube.common.authorization.library.AuthorizationEntry;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.clients.stubs.jaxws.JAXWSUtils; import org.gcube.common.clients.stubs.jaxws.JAXWSUtils;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.api.ServiceMap; import org.gcube.common.scope.api.ServiceMap;
import org.gcube.resources.discovery.client.api.DiscoveryClient; import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.api.DiscoveryException; import org.gcube.resources.discovery.client.api.DiscoveryException;
@ -75,7 +71,7 @@ public class ICClient implements DiscoveryClient<String> {
//helper //helper
private CollectorStub getStub() { private CollectorStub getStub() {
/*
ServiceMap serviceMap = null; ServiceMap serviceMap = null;
if (SecurityTokenProvider.instance.get()!=null) { if (SecurityTokenProvider.instance.get()!=null) {
@ -86,9 +82,9 @@ public class ICClient implements DiscoveryClient<String> {
} catch (Throwable e) { } catch (Throwable e) {
throw new IllegalArgumentException(e); throw new IllegalArgumentException(e);
} }
} }*/
if (serviceMap ==null) serviceMap = ServiceMap.instance; ServiceMap serviceMap = ServiceMap.instance;
String address = serviceMap.endpoint(localname); String address = serviceMap.endpoint(localname);
log.info("connecting to {}",address); log.info("connecting to {}",address);
if (serviceMap.version().equals("2.0.0")) if (serviceMap.version().equals("2.0.0"))

View File

@ -40,9 +40,15 @@ public class CollectorStubRestImpl implements CollectorStub {
HttpURLConnection connection = makeRequest(url, "GET", false); HttpURLConnection connection = makeRequest(url, "GET", false);
connection.setDoInput(true); connection.setDoInput(true);
if (connection.getResponseCode()!=200){ if (connection.getResponseCode()!=200){
log.info("response code is not 200"); try(BufferedReader reader = new BufferedReader(new InputStreamReader((InputStream)connection.getErrorStream()))){
throw new Exception("error executing query"); StringBuilder error = new StringBuilder();
String line;
while((line = reader.readLine()) != null)
error.append(line);
throw new Exception("error executing query: "+error.toString());
} }
} else {
String toReturn; String toReturn;
try(BufferedReader reader = new BufferedReader(new InputStreamReader((InputStream)connection.getContent()))){ try(BufferedReader reader = new BufferedReader(new InputStreamReader((InputStream)connection.getContent()))){
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder();
@ -52,6 +58,7 @@ public class CollectorStubRestImpl implements CollectorStub {
toReturn = result.toString(); toReturn = result.toString();
} }
return toReturn; return toReturn;
}
}catch (Exception e) { }catch (Exception e) {
log.error("error executing query",e); log.error("error executing query",e);
throw new MalformedQueryException(e.getMessage()); throw new MalformedQueryException(e.getMessage());

View File

@ -13,6 +13,7 @@ import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementRef; import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.resources.gcore.GCoreEndpoint; import org.gcube.common.resources.gcore.GCoreEndpoint;
import org.gcube.common.resources.gcore.GenericResource; import org.gcube.common.resources.gcore.GenericResource;
import org.gcube.common.resources.gcore.HostingNode; import org.gcube.common.resources.gcore.HostingNode;
@ -60,7 +61,8 @@ public class APIClient {
@Test @Test
public void testThredds() throws Exception{ public void testThredds() throws Exception{
ScopeProvider.instance.set("/gcube/devNext/NextNext"); //ScopeProvider.instance.set("/gcube/devNext/NextNext");
SecurityTokenProvider.instance.set("52b59669-ccde-46d2-a4da-108b9e941f7c-98187548");
SimpleQuery query = queryFor(GCoreEndpoint.class); SimpleQuery query = queryFor(GCoreEndpoint.class);
query.addCondition("$resource/Profile/ServiceClass/string() eq 'DataAccess' "); query.addCondition("$resource/Profile/ServiceClass/string() eq 'DataAccess' ");
query.setResult("$resource/Profile/ServiceName/text()"); query.setResult("$resource/Profile/ServiceName/text()");