error message improved on execute query
This commit is contained in:
parent
87c5fcf09e
commit
1fb2e22401
2
pom.xml
2
pom.xml
|
@ -10,7 +10,7 @@
|
|||
|
||||
<groupId>org.gcube.resources.discovery</groupId>
|
||||
<artifactId>ic-client</artifactId>
|
||||
<version>1.1.0-SNAPSHOT</version>
|
||||
<version>1.0.5-SNAPSHOT</version>
|
||||
<name>Information Collector Client</name>
|
||||
<description>Client API for the Information Collector service</description>
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package org.gcube.resources.discovery.icclient;
|
||||
|
||||
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
||||
import static org.gcube.common.clients.stubs.jaxws.StubFactory.*;
|
||||
import static org.gcube.resources.discovery.icclient.stubs.CollectorConstants.*;
|
||||
import static org.gcube.common.clients.stubs.jaxws.StubFactory.stubFor;
|
||||
import static org.gcube.resources.discovery.icclient.stubs.CollectorConstants.collector;
|
||||
import static org.gcube.resources.discovery.icclient.stubs.CollectorConstants.localname;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
|
@ -12,11 +12,7 @@ import java.util.regex.Pattern;
|
|||
|
||||
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.scope.api.ScopeProvider;
|
||||
import org.gcube.common.scope.api.ServiceMap;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryException;
|
||||
|
@ -75,7 +71,7 @@ public class ICClient implements DiscoveryClient<String> {
|
|||
|
||||
//helper
|
||||
private CollectorStub getStub() {
|
||||
|
||||
/*
|
||||
ServiceMap serviceMap = null;
|
||||
|
||||
if (SecurityTokenProvider.instance.get()!=null) {
|
||||
|
@ -86,9 +82,9 @@ public class ICClient implements DiscoveryClient<String> {
|
|||
} catch (Throwable e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
if (serviceMap ==null) serviceMap = ServiceMap.instance;
|
||||
ServiceMap serviceMap = ServiceMap.instance;
|
||||
String address = serviceMap.endpoint(localname);
|
||||
log.info("connecting to {}",address);
|
||||
if (serviceMap.version().equals("2.0.0"))
|
||||
|
|
|
@ -40,18 +40,25 @@ public class CollectorStubRestImpl implements CollectorStub {
|
|||
HttpURLConnection connection = makeRequest(url, "GET", false);
|
||||
connection.setDoInput(true);
|
||||
if (connection.getResponseCode()!=200){
|
||||
log.info("response code is not 200");
|
||||
throw new Exception("error executing query");
|
||||
try(BufferedReader reader = new BufferedReader(new InputStreamReader((InputStream)connection.getErrorStream()))){
|
||||
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;
|
||||
try(BufferedReader reader = new BufferedReader(new InputStreamReader((InputStream)connection.getContent()))){
|
||||
StringBuilder result = new StringBuilder();
|
||||
String line;
|
||||
while((line = reader.readLine()) != null)
|
||||
result.append(line);
|
||||
toReturn = result.toString();
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
String toReturn;
|
||||
try(BufferedReader reader = new BufferedReader(new InputStreamReader((InputStream)connection.getContent()))){
|
||||
StringBuilder result = new StringBuilder();
|
||||
String line;
|
||||
while((line = reader.readLine()) != null)
|
||||
result.append(line);
|
||||
toReturn = result.toString();
|
||||
}
|
||||
return toReturn;
|
||||
}catch (Exception e) {
|
||||
log.error("error executing query",e);
|
||||
throw new MalformedQueryException(e.getMessage());
|
||||
|
|
|
@ -13,6 +13,7 @@ import javax.xml.bind.annotation.XmlElement;
|
|||
import javax.xml.bind.annotation.XmlElementRef;
|
||||
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.GenericResource;
|
||||
import org.gcube.common.resources.gcore.HostingNode;
|
||||
|
@ -60,7 +61,8 @@ public class APIClient {
|
|||
|
||||
@Test
|
||||
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);
|
||||
query.addCondition("$resource/Profile/ServiceClass/string() eq 'DataAccess' ");
|
||||
query.setResult("$resource/Profile/ServiceName/text()");
|
||||
|
|
Loading…
Reference in New Issue