Skip to content

Commit

Permalink
Fixes issue with the encoding of the query used for SPARQL RDF export
Browse files Browse the repository at this point in the history
- Changed the mechanism of encoding of the content for the HTTP entity
used for payload of the request for the RDF export.
- Added logging of the SPARQL which will be executed for the RDF export.
- Prepared the library for the ``minor`` release.
  • Loading branch information
tonyKunchev committed Apr 7, 2022
1 parent 8a15390 commit ad09196
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
9 changes: 4 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# Ontotext OntoRefine Client Library

## Version 1.7

### New

### Changes
## Version 1.6.1

### Bug fixes

- Changed the mechanism of encoding for the content of the entity, which represents the SPARQL conversion query. Apparently there are characters that are not handled
correctly by the ``java.net.URLEncoder``. Now we are going to just use ``UrlEncodedFormEntity``, which handles the encoding in correct way.


## Version 1.6

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ complete given operation.
<dependency>
<groupId>com.ontotext</groupId>
<artifactId>ontorefine-client</artifactId>
<version>1.6.0</version>
<version>1.6.1</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>com.ontotext</groupId>
<artifactId>ontorefine-client</artifactId>
<version>1.7.0-SNAPSHOT</version>
<version>1.6.1</version>

<name>${project.groupId}:${project.artifactId}</name>
<description>An OntoRefine Client Library</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static com.ontotext.refine.client.util.HttpParser.HTTP_PARSER;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Collections.singletonList;
import static org.apache.commons.lang3.Validate.notBlank;
import static org.apache.commons.lang3.Validate.notNull;
import static org.apache.http.HttpHeaders.ACCEPT;
Expand All @@ -13,16 +14,19 @@
import com.ontotext.refine.client.command.RefineCommand;
import com.ontotext.refine.client.exceptions.RefineException;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.entity.BasicHttpEntity;
import org.apache.http.entity.BufferedHttpEntity;
import org.apache.http.message.BasicNameValuePair;
import org.eclipse.rdf4j.rio.RDFFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* A command that exports the data of specific project in RDF format using a SPARQL Construct query.
Expand All @@ -36,6 +40,8 @@
*/
public class SparqlBasedExportRdfCommand implements RefineCommand<ExportRdfResponse> {

private static final Logger LOGGER = LoggerFactory.getLogger(SparqlBasedExportRdfCommand.class);

private final String project;
private final String projectPlaceholder;
private final String query;
Expand Down Expand Up @@ -87,9 +93,7 @@ public ExportRdfResponse execute(RefineClient client) throws RefineException {
* repeatable so that it can be retried.
*/
private HttpEntity buildEntity() throws IOException {
BasicHttpEntity entity = new BasicHttpEntity();
entity.setContent(IOUtils.toInputStream(buildRequestContent(), UTF_8));
return new BufferedHttpEntity(entity);
return new BufferedHttpEntity(new UrlEncodedFormEntity(buildRequestContent(), UTF_8));
}

/**
Expand All @@ -105,10 +109,10 @@ private HttpEntity buildEntity() throws IOException {
* </pre>
* And prepends the expected field for the request.
*/
private String buildRequestContent() {
private List<NameValuePair> buildRequestContent() {
String fixedQuery = query.replaceFirst(projectPlaceholder, project);
String encodedQuery = URLEncoder.encode(fixedQuery, UTF_8);
return StringUtils.prependIfMissing(encodedQuery, "query=");
LOGGER.debug("The query that will be used for RDF export is: {}", fixedQuery);
return singletonList(new BasicNameValuePair("query", fixedQuery));
}

@Override
Expand Down

0 comments on commit ad09196

Please sign in to comment.