|
19 | 19 | import com.atomgraph.client.MediaTypes; |
20 | 20 | import com.atomgraph.client.util.DataManager; |
21 | 21 | import com.atomgraph.client.vocabulary.AC; |
| 22 | +import com.atomgraph.core.exception.BadGatewayException; |
22 | 23 | import com.atomgraph.linkeddatahub.apps.model.Dataset; |
23 | 24 | import com.atomgraph.linkeddatahub.client.LinkedDataClient; |
24 | 25 | import com.atomgraph.linkeddatahub.client.filter.auth.IDTokenDelegationFilter; |
|
36 | 37 | import jakarta.servlet.http.HttpServletRequest; |
37 | 38 | import jakarta.ws.rs.NotAllowedException; |
38 | 39 | import jakarta.ws.rs.Consumes; |
| 40 | +import jakarta.ws.rs.NotAcceptableException; |
39 | 41 | import jakarta.ws.rs.NotFoundException; |
40 | 42 | import jakarta.ws.rs.POST; |
41 | 43 | import jakarta.ws.rs.PUT; |
| 44 | +import jakarta.ws.rs.ProcessingException; |
42 | 45 | import jakarta.ws.rs.QueryParam; |
43 | 46 | import jakarta.ws.rs.client.Entity; |
44 | 47 | import jakarta.ws.rs.client.Invocation; |
|
56 | 59 | import org.apache.jena.rdf.model.Model; |
57 | 60 | import org.apache.jena.util.FileManager; |
58 | 61 | import org.glassfish.jersey.media.multipart.FormDataMultiPart; |
| 62 | +import org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException; |
59 | 63 | import org.slf4j.Logger; |
60 | 64 | import org.slf4j.LoggerFactory; |
61 | 65 |
|
@@ -209,6 +213,38 @@ public Response get(WebTarget target, Invocation.Builder builder) |
209 | 213 | return super.get(target, builder); |
210 | 214 | } |
211 | 215 |
|
| 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 | + |
212 | 248 | /** |
213 | 249 | * Forwards a multipart <code>POST</code> request returns RDF response from remote resource. |
214 | 250 | * |
|
0 commit comments