Skip to content

Commit 0f1a587

Browse files
committed
ProxyResourceBase now supports SPARQL queries over POST
1 parent 1009bbf commit 0f1a587

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

src/main/java/com/atomgraph/linkeddatahub/server/model/impl/ProxyResourceBase.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.atomgraph.client.MediaTypes;
2020
import com.atomgraph.client.util.DataManager;
2121
import com.atomgraph.client.vocabulary.AC;
22+
import com.atomgraph.core.exception.BadGatewayException;
2223
import com.atomgraph.linkeddatahub.apps.model.Dataset;
2324
import com.atomgraph.linkeddatahub.client.LinkedDataClient;
2425
import com.atomgraph.linkeddatahub.client.filter.auth.IDTokenDelegationFilter;
@@ -36,9 +37,11 @@
3637
import jakarta.servlet.http.HttpServletRequest;
3738
import jakarta.ws.rs.NotAllowedException;
3839
import jakarta.ws.rs.Consumes;
40+
import jakarta.ws.rs.NotAcceptableException;
3941
import jakarta.ws.rs.NotFoundException;
4042
import jakarta.ws.rs.POST;
4143
import jakarta.ws.rs.PUT;
44+
import jakarta.ws.rs.ProcessingException;
4245
import jakarta.ws.rs.QueryParam;
4346
import jakarta.ws.rs.client.Entity;
4447
import jakarta.ws.rs.client.Invocation;
@@ -56,6 +59,7 @@
5659
import org.apache.jena.rdf.model.Model;
5760
import org.apache.jena.util.FileManager;
5861
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
62+
import org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException;
5963
import org.slf4j.Logger;
6064
import org.slf4j.LoggerFactory;
6165

@@ -209,6 +213,38 @@ public Response get(WebTarget target, Invocation.Builder builder)
209213
return super.get(target, builder);
210214
}
211215

216+
/**
217+
* Forwards POST request with SPARQL query body and returns response from remote resource.
218+
*
219+
* @param sparqlQuery SPARQL query string
220+
* @return response
221+
*/
222+
@POST
223+
@Consumes(com.atomgraph.core.MediaType.APPLICATION_SPARQL_QUERY)
224+
public Response post(String sparqlQuery)
225+
{
226+
if (getWebTarget() == null) throw new NotFoundException("Resource URI not supplied");
227+
228+
if (log.isDebugEnabled()) log.debug("POSTing SPARQL query to URI: {}", getWebTarget().getUri());
229+
230+
try (Response cr = getWebTarget().request()
231+
.accept(getReadableMediaTypes())
232+
.post(Entity.entity(sparqlQuery, com.atomgraph.core.MediaType.APPLICATION_SPARQL_QUERY_TYPE)))
233+
{
234+
return getResponse(cr);
235+
}
236+
catch (MessageBodyProviderNotFoundException ex)
237+
{
238+
if (log.isWarnEnabled()) log.debug("Dereferenced URI {} returned non-RDF media type", getWebTarget().getUri());
239+
throw new NotAcceptableException(ex);
240+
}
241+
catch (ProcessingException ex)
242+
{
243+
if (log.isWarnEnabled()) log.debug("Could not dereference URI: {}", getWebTarget().getUri());
244+
throw new BadGatewayException(ex);
245+
}
246+
}
247+
212248
/**
213249
* Forwards a multipart <code>POST</code> request returns RDF response from remote resource.
214250
*

0 commit comments

Comments
 (0)