Modified: incubator/stanbol/trunk/entityhub/site/linkeddata/src/main/java/org/apache/stanbol/entityhub/site/linkeddata/impl/CoolUriDereferencer.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/site/linkeddata/src/main/java/org/apache/stanbol/entityhub/site/linkeddata/impl/CoolUriDereferencer.java?rev=1364535&r1=1364534&r2=1364535&view=diff ============================================================================== --- incubator/stanbol/trunk/entityhub/site/linkeddata/src/main/java/org/apache/stanbol/entityhub/site/linkeddata/impl/CoolUriDereferencer.java (original) +++ incubator/stanbol/trunk/entityhub/site/linkeddata/src/main/java/org/apache/stanbol/entityhub/site/linkeddata/impl/CoolUriDereferencer.java Mon Jul 23 07:19:09 2012 @@ -73,11 +73,11 @@ public class CoolUriDereferencer extends String format = SupportedFormat.RDF_XML; InputStream in = dereference(uri, format); long queryEnd = System.currentTimeMillis(); - log.info(" > DereferenceTime: "+(queryEnd-start)); + log.debug(" > DereferenceTime: "+(queryEnd-start)); if(in != null){ MGraph rdfData = new IndexedMGraph(parser.parse(in, format,new UriRef(getBaseUri()))); long parseEnd = System.currentTimeMillis(); - log.info(" > ParseTime: "+(parseEnd-queryEnd)); + log.debug(" > ParseTime: "+(parseEnd-queryEnd)); return valueFactory.createRdfRepresentation(new UriRef(uri), rdfData); } else { return null;
Modified: incubator/stanbol/trunk/entityhub/site/linkeddata/src/main/java/org/apache/stanbol/entityhub/site/linkeddata/impl/LarqSearcher.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/site/linkeddata/src/main/java/org/apache/stanbol/entityhub/site/linkeddata/impl/LarqSearcher.java?rev=1364535&r1=1364534&r2=1364535&view=diff ============================================================================== --- incubator/stanbol/trunk/entityhub/site/linkeddata/src/main/java/org/apache/stanbol/entityhub/site/linkeddata/impl/LarqSearcher.java (original) +++ incubator/stanbol/trunk/entityhub/site/linkeddata/src/main/java/org/apache/stanbol/entityhub/site/linkeddata/impl/LarqSearcher.java Mon Jul 23 07:19:09 2012 @@ -65,11 +65,11 @@ public class LarqSearcher extends Abstra query.setEndpointType(EndpointTypeEnum.LARQ); String sparqlQuery = query.toSparqlConstruct(); long initEnd = System.currentTimeMillis(); - log.info(" > InitTime: "+(initEnd-start)); - log.info(" > SPARQL query:\n"+sparqlQuery); + log.debug(" > InitTime: "+(initEnd-start)); + log.debug(" > SPARQL query:\n"+sparqlQuery); InputStream in = SparqlEndpointUtils.sendSparqlRequest(getQueryUri(), sparqlQuery, SparqlSearcher.DEFAULT_RDF_CONTENT_TYPE); long queryEnd = System.currentTimeMillis(); - log.info(" > QueryTime: "+(queryEnd-initEnd)); + log.debug(" > QueryTime: "+(queryEnd-initEnd)); if(in != null){ MGraph graph; TripleCollection rdfData = parser.parse(in, SparqlSearcher.DEFAULT_RDF_CONTENT_TYPE, @@ -80,7 +80,7 @@ public class LarqSearcher extends Abstra graph = new IndexedMGraph(rdfData); } long parseEnd = System.currentTimeMillis(); - log.info(" > ParseTime: "+(parseEnd-queryEnd)); + log.debug(" > ParseTime: "+(parseEnd-queryEnd)); return new RdfQueryResultList(query, graph); } else { return null; Modified: incubator/stanbol/trunk/entityhub/site/linkeddata/src/main/java/org/apache/stanbol/entityhub/site/linkeddata/impl/SparqlDereferencer.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/site/linkeddata/src/main/java/org/apache/stanbol/entityhub/site/linkeddata/impl/SparqlDereferencer.java?rev=1364535&r1=1364534&r2=1364535&view=diff ============================================================================== --- incubator/stanbol/trunk/entityhub/site/linkeddata/src/main/java/org/apache/stanbol/entityhub/site/linkeddata/impl/SparqlDereferencer.java (original) +++ incubator/stanbol/trunk/entityhub/site/linkeddata/src/main/java/org/apache/stanbol/entityhub/site/linkeddata/impl/SparqlDereferencer.java Mon Jul 23 07:19:09 2012 @@ -87,11 +87,11 @@ public class SparqlDereferencer extends String format = SupportedFormat.RDF_XML; InputStream in = dereference(uri, format); long queryEnd = System.currentTimeMillis(); - log.info(" > DereferenceTime: "+(queryEnd-start)); + log.debug(" > DereferenceTime: {}",(queryEnd-start)); if(in != null){ MGraph rdfData = new IndexedMGraph(parser.parse(in, format,new UriRef(getBaseUri()))); long parseEnd = System.currentTimeMillis(); - log.info(" > ParseTime: "+(parseEnd-queryEnd)); + log.debug(" > ParseTime: {}",(parseEnd-queryEnd)); return valueFactory.createRdfRepresentation(new UriRef(uri), rdfData); } else { return null; Modified: incubator/stanbol/trunk/entityhub/site/linkeddata/src/main/java/org/apache/stanbol/entityhub/site/linkeddata/impl/SparqlEndpointUtils.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/site/linkeddata/src/main/java/org/apache/stanbol/entityhub/site/linkeddata/impl/SparqlEndpointUtils.java?rev=1364535&r1=1364534&r2=1364535&view=diff ============================================================================== --- incubator/stanbol/trunk/entityhub/site/linkeddata/src/main/java/org/apache/stanbol/entityhub/site/linkeddata/impl/SparqlEndpointUtils.java (original) +++ incubator/stanbol/trunk/entityhub/site/linkeddata/src/main/java/org/apache/stanbol/entityhub/site/linkeddata/impl/SparqlEndpointUtils.java Mon Jul 23 07:19:09 2012 @@ -26,51 +26,65 @@ import java.net.URLConnection; import javax.ws.rs.core.UriBuilder; import org.apache.commons.io.IOUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public final class SparqlEndpointUtils { - private SparqlEndpointUtils() {/* Do not create instances of utility classes*/} + private SparqlEndpointUtils() {/* + * Do not create instances of utility classes + */ + } + private static final Logger log = LoggerFactory.getLogger(SparqlEndpointUtils.class); public static final String SPARQL_RESULT_JSON = "application/sparql-results+json"; /** - * Sends an SPARQL Request to the accessUri. Please note that based on the - * type of the SPARQL query different content are supported by the Site - * @param accessUri the uri of the SPARQL endpoint - * @param contentType the contentType of the returned RDF graph - * @param query the SPARQL Construct query + * Sends an SPARQL Request to the accessUri. Please note that based on the type of the SPARQL query + * different content are supported by the Site + * + * @param accessUri + * the uri of the SPARQL endpoint + * @param contentType + * the contentType of the returned RDF graph + * @param query + * the SPARQL Construct query * @return the results as input stream * @throws IOException * @throws MalformedURLException */ - public static InputStream sendSparqlRequest(String accessUri, String query, String contentType) throws IOException, MalformedURLException { - final URI dereferenceUri = UriBuilder.fromUri(accessUri) - .queryParam("query", "{query}") - .queryParam("format", "{format}") - .build(query, contentType); + public static InputStream sendSparqlRequest(String accessUri, String query, String contentType) + throws IOException, MalformedURLException { + + + log.trace("Sending SPARQL request [accessUri :: {}][query :: {}][contentType :: {}].", + new Object[]{accessUri, query,contentType}); + + final URI dereferenceUri = UriBuilder.fromUri(accessUri).queryParam("query", "{query}") + .queryParam("format", "{format}").build(query, contentType); final URLConnection con = dereferenceUri.toURL().openConnection(); con.addRequestProperty("Accept", contentType); try { return con.getInputStream(); } catch (IOException e) { - if(con instanceof HttpURLConnection){ - //try to create a better Error Message - InputStream reason = ((HttpURLConnection)con).getErrorStream(); - if(reason != null){ + if (con instanceof HttpURLConnection) { + // try to create a better Error Message + InputStream reason = ((HttpURLConnection) con).getErrorStream(); + if (reason != null) { String errorMessage = null; try { errorMessage = IOUtils.toString(reason); } catch (IOException e1) { - //ignore ... + // ignore ... } IOUtils.closeQuietly(reason); - if(errorMessage != null && !errorMessage.isEmpty()){ - throw new IOException(((HttpURLConnection)con).getRequestMethod()+" with Content: \n"+errorMessage,e); + if (errorMessage != null && !errorMessage.isEmpty()) { + throw new IOException(((HttpURLConnection) con).getRequestMethod() + + " with Content: \n" + errorMessage, e); } } } - //if still here re-throw the original exception + // if still here re-throw the original exception throw e; } } - } Modified: incubator/stanbol/trunk/entityhub/site/linkeddata/src/main/java/org/apache/stanbol/entityhub/site/linkeddata/impl/SparqlSearcher.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/site/linkeddata/src/main/java/org/apache/stanbol/entityhub/site/linkeddata/impl/SparqlSearcher.java?rev=1364535&r1=1364534&r2=1364535&view=diff ============================================================================== --- incubator/stanbol/trunk/entityhub/site/linkeddata/src/main/java/org/apache/stanbol/entityhub/site/linkeddata/impl/SparqlSearcher.java (original) +++ incubator/stanbol/trunk/entityhub/site/linkeddata/src/main/java/org/apache/stanbol/entityhub/site/linkeddata/impl/SparqlSearcher.java Mon Jul 23 07:19:09 2012 @@ -124,11 +124,11 @@ public class SparqlSearcher extends Abst final SparqlFieldQuery query = SparqlFieldQueryFactory.getSparqlFieldQuery(parsedQuery); String sparqlQuery = query.toSparqlConstruct(); long initEnd = System.currentTimeMillis(); - log.info(" > InitTime: "+(initEnd-start)); - log.info(" > SPARQL query:\n"+sparqlQuery); + log.debug(" > InitTime: "+(initEnd-start)); + log.debug(" > SPARQL query:\n"+sparqlQuery); InputStream in = SparqlEndpointUtils.sendSparqlRequest(getQueryUri(), sparqlQuery, DEFAULT_RDF_CONTENT_TYPE); long queryEnd = System.currentTimeMillis(); - log.info(" > QueryTime: "+(queryEnd-initEnd)); + log.debug(" > QueryTime: "+(queryEnd-initEnd)); if(in != null){ MGraph graph; TripleCollection rdfData = parser.parse(in, DEFAULT_RDF_CONTENT_TYPE, @@ -139,7 +139,7 @@ public class SparqlSearcher extends Abst graph = new IndexedMGraph(rdfData); } long parseEnd = System.currentTimeMillis(); - log.info(" > ParseTime: "+(parseEnd-queryEnd)); + log.debug(" > ParseTime: "+(parseEnd-queryEnd)); return new RdfQueryResultList(query, graph); } else { return null; Modified: incubator/stanbol/trunk/entityhub/site/linkeddata/src/main/java/org/apache/stanbol/entityhub/site/linkeddata/impl/VirtuosoSearcher.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/site/linkeddata/src/main/java/org/apache/stanbol/entityhub/site/linkeddata/impl/VirtuosoSearcher.java?rev=1364535&r1=1364534&r2=1364535&view=diff ============================================================================== --- incubator/stanbol/trunk/entityhub/site/linkeddata/src/main/java/org/apache/stanbol/entityhub/site/linkeddata/impl/VirtuosoSearcher.java (original) +++ incubator/stanbol/trunk/entityhub/site/linkeddata/src/main/java/org/apache/stanbol/entityhub/site/linkeddata/impl/VirtuosoSearcher.java Mon Jul 23 07:19:09 2012 @@ -44,14 +44,16 @@ import org.apache.stanbol.entityhub.serv import org.apache.stanbol.entityhub.servicesapi.site.EntitySearcher; import org.slf4j.LoggerFactory; - -@Component( - name="org.apache.stanbol.entityhub.searcher.VirtuosoSearcher", - factory="org.apache.stanbol.entityhub.searcher.VirtuosoSearcherFactory", - policy=ConfigurationPolicy.REQUIRE, //the queryUri and the SPARQL Endpoint are required - specVersion="1.1" - ) -public class VirtuosoSearcher extends AbstractEntitySearcher implements EntitySearcher{ +@Component(name = "org.apache.stanbol.entityhub.searcher.VirtuosoSearcher", factory = "org.apache.stanbol.entityhub.searcher.VirtuosoSearcherFactory", policy = ConfigurationPolicy.REQUIRE, // the +// queryUri +// and +// the +// SPARQL +// Endpoint +// are +// required +specVersion = "1.1") +public class VirtuosoSearcher extends AbstractEntitySearcher implements EntitySearcher { @Reference private Parser parser; @@ -66,22 +68,23 @@ public class VirtuosoSearcher extends Ab query.setEndpointType(EndpointTypeEnum.Virtuoso); String sparqlQuery = query.toSparqlConstruct(); long initEnd = System.currentTimeMillis(); - log.info(" > InitTime: "+(initEnd-start)); - log.info(" > SPARQL query:\n"+sparqlQuery); - InputStream in = SparqlEndpointUtils.sendSparqlRequest(getQueryUri(), sparqlQuery, SparqlSearcher.DEFAULT_RDF_CONTENT_TYPE); + log.info(" > InitTime: " + (initEnd - start)); + log.info(" > SPARQL query:\n" + sparqlQuery); + InputStream in = SparqlEndpointUtils.sendSparqlRequest(getQueryUri(), sparqlQuery, + SparqlSearcher.DEFAULT_RDF_CONTENT_TYPE); long queryEnd = System.currentTimeMillis(); - log.info(" > QueryTime: "+(queryEnd-initEnd)); - if(in != null){ + log.info(" > QueryTime: " + (queryEnd - initEnd)); + if (in != null) { MGraph graph; - TripleCollection rdfData = parser.parse(in, SparqlSearcher.DEFAULT_RDF_CONTENT_TYPE, - new UriRef(getBaseUri())); - if(rdfData instanceof MGraph){ + TripleCollection rdfData = parser.parse(in, SparqlSearcher.DEFAULT_RDF_CONTENT_TYPE, new UriRef( + getBaseUri())); + if (rdfData instanceof MGraph) { graph = (MGraph) rdfData; } else { graph = new IndexedMGraph(rdfData); } long parseEnd = System.currentTimeMillis(); - log.info(" > ParseTime: "+(parseEnd-queryEnd)); + log.info(" > ParseTime: " + (parseEnd - queryEnd)); return new RdfQueryResultList(query, graph); } else { return null; @@ -93,10 +96,12 @@ public class VirtuosoSearcher extends Ab final SparqlFieldQuery query = SparqlFieldQueryFactory.getSparqlFieldQuery(parsedQuery); query.setEndpointType(EndpointTypeEnum.Virtuoso); String sparqlQuery = query.toSparqlSelect(false); - InputStream in = sendSparqlRequest(getQueryUri(), sparqlQuery, SparqlSearcher.DEFAULT_SPARQL_RESULT_CONTENT_TYPE); - //Move to util class! - final List<String> entities = extractEntitiesFromJsonResult(in,query.getRootVariableName()); - return new QueryResultListImpl<String>(query, entities.iterator(),String.class); + log.trace("Sending Sparql request [{}].", sparqlQuery); + InputStream in = sendSparqlRequest(getQueryUri(), sparqlQuery, + SparqlSearcher.DEFAULT_SPARQL_RESULT_CONTENT_TYPE); + // Move to util class! + final List<String> entities = extractEntitiesFromJsonResult(in, query.getRootVariableName()); + return new QueryResultListImpl<String>(query, entities.iterator(), String.class); } }
