From d2b4817993187a34b10cd7a0cfe34ab59d330e71 Mon Sep 17 00:00:00 2001 From: Egon Willighagen Date: Sun, 4 Mar 2018 15:47:59 +0100 Subject: [PATCH] Adds a method to call a remote SPARQL end point, but without having to use Jena. The reason why this is needed is the Jena tries to parse the SPARQL and complains about non-standard extensions, e.g. by Blazegraph. Because the returned content is XML, I opted for returning a byte stream, as passing around Java String sometimes conflicts with XML content. --- .../net.bioclipse.core_feature/feature.xml | 2 + .../META-INF/MANIFEST.MF | 4 +- .../business/BioclipsePlatformManager.java | 61 ++++++++++++++++++- .../business/IBioclipsePlatformManager.java | 12 +++- 4 files changed, 72 insertions(+), 7 deletions(-) diff --git a/features/net.bioclipse.core_feature/feature.xml b/features/net.bioclipse.core_feature/feature.xml index f750d8c1f..5bf303003 100644 --- a/features/net.bioclipse.core_feature/feature.xml +++ b/features/net.bioclipse.core_feature/feature.xml @@ -75,6 +75,8 @@ The Eclipse Public License accompanies this distribution, and is available at ht + + formparams = new ArrayList(); + formparams.add(new BasicNameValuePair("query", sparqlQueryString)); + try { + UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8"); + HttpPost httppost = new HttpPost(serviceURL); + httppost.setEntity(entity); + monitor.worked(20); + HttpResponse response = httpclient.execute(httppost); + StatusLine statusLine = response.getStatusLine(); + int statusCode = statusLine.getStatusCode(); + if (statusCode != 200) throw new BioclipseException( + "Expected HTTP 200, but got a " + statusCode + ": " + statusLine.getReasonPhrase() + ); + monitor.worked(60); + + HttpEntity responseEntity = response.getEntity(); + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + responseEntity.writeTo(buffer); + buffer.flush(); + monitor.worked(20); + return buffer.toByteArray(); + } catch (UnsupportedEncodingException exception) { + throw new BioclipseException( + "Error while creating the SPARQL query: " + exception.getMessage(), exception + ); + } catch (IOException exception) { + throw new BioclipseException( + "Error while processing the SPARQL endpoint feedback: " + exception.getMessage(), exception + ); + } + } + public void openURL(URL url) throws BioclipseException { IWorkbenchBrowserSupport browserSupport = diff --git a/plugins/net.bioclipse.business/src/net/bioclipse/business/IBioclipsePlatformManager.java b/plugins/net.bioclipse.business/src/net/bioclipse/business/IBioclipsePlatformManager.java index b589a8490..441144122 100644 --- a/plugins/net.bioclipse.business/src/net/bioclipse/business/IBioclipsePlatformManager.java +++ b/plugins/net.bioclipse.business/src/net/bioclipse/business/IBioclipsePlatformManager.java @@ -1,5 +1,4 @@ -/* ***************************************************************************** - * Copyright (c) 2009 Egon Willighagen +/* Copyright (c) 2009,2018 Egon Willighagen * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -7,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contact: http://www.bioclipse.net/ - ******************************************************************************/ + */ package net.bioclipse.business; import org.eclipse.core.resources.IFile; @@ -106,4 +105,11 @@ public void requireVersion( String lowerVersionBound, public String fullPath( String file ); public String fullPath( IFile file ); + + @PublishedMethod( + params = "String url, String SPARQL", + methodSummary = "Queries a remote SPARQL end point without parsing the SPARQL first." + ) + public byte[] sparqlRemote(String url, String SPARQL) + throws BioclipseException; }