Skip to content

Commit

Permalink
Merge branch 'releases/2.0.x' into releases/1.0.x
Browse files Browse the repository at this point in the history
# Conflicts:
#	core/http/server-spring/src/main/java/org/eclipse/rdf4j/http/server/repository/transaction/TransactionController.java
  • Loading branch information
abrokenjester committed Jul 7, 2016
2 parents a32c191 + 28138ef commit 0c81ebe
Show file tree
Hide file tree
Showing 41 changed files with 854 additions and 477 deletions.
5 changes: 5 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@
<artifactId>rdf4j-rio-datatypes</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.rdf4j</groupId>
<artifactId>rdf4j-rio-jsonld</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.rdf4j</groupId>
<artifactId>rdf4j-rio-languages</artifactId>
Expand Down
5 changes: 5 additions & 0 deletions compliance/http/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@
<artifactId>log4j-over-slf4j</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,24 @@
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import org.apache.commons.io.Charsets;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.eclipse.rdf4j.common.io.IOUtil;
import org.eclipse.rdf4j.http.protocol.Protocol;
import org.eclipse.rdf4j.model.ValueFactory;
Expand Down Expand Up @@ -196,6 +202,31 @@ public void testUpdateDirect_POST()
assertEquals(true, statusCode >= 200 && statusCode < 400);
}

/**
* Checks that the server accepts a formencoded POST with an update and a timeout parameter.
*/
@Test
public void testUpdateForm_POST()
throws Exception
{
String update = "delete where { <monkey:pod> ?p ?o . }";
String location = Protocol.getStatementsLocation(TestServer.REPOSITORY_URL);
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPost post = new HttpPost(location);
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair(Protocol.UPDATE_PARAM_NAME, update));
nvps.add(new BasicNameValuePair(Protocol.TIMEOUT_PARAM_NAME, "1"));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(nvps, Charsets.UTF_8);

post.setEntity(entity);

CloseableHttpResponse response = httpclient.execute(post);

System.out.println("Update Form Post Status: " + response.getStatusLine());
int statusCode = response.getStatusLine().getStatusCode();
assertEquals(true, statusCode >= 200 && statusCode < 400);
}

/**
* Checks that the requested content type is returned when accept header explicitly set.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void start()
{
File dataDir = new File(System.getProperty("user.dir") + "/target/datadir");
dataDir.mkdirs();
System.setProperty("info.aduna.platform.appdata.basedir", dataDir.getAbsolutePath());
System.setProperty("org.eclipse.rdf4j.appdata.basedir", dataDir.getAbsolutePath());

jetty.start();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.StringReader;

import org.eclipse.rdf4j.IsolationLevel;
import org.eclipse.rdf4j.RDF4JException;
import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.query.QueryLanguage;
import org.eclipse.rdf4j.query.Update;
import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.RepositoryConnectionTest;
import org.eclipse.rdf4j.repository.http.HTTPRepository;
import org.eclipse.rdf4j.rio.RDFFormat;
import org.junit.AfterClass;
import org.junit.BeforeClass;
Expand Down Expand Up @@ -66,6 +67,20 @@ public void testOrderByQueriesAreInterruptable() {
System.err.println("temporarily disabled testOrderByQueriesAreInterruptable() for HTTPRepository");
}

@Test
public void testContextInTransactionAdd()
throws Exception
{
StringReader stringReader = new StringReader("<urn:1> <urn:1> <urn:1>.");
testCon.begin();
IRI CONTEXT = testCon.getValueFactory().createIRI("urn:context");
testCon.add(stringReader, "urn:baseUri", RDFFormat.NTRIPLES, CONTEXT);
testCon.commit();

IRI iri = testCon.getValueFactory().createIRI("urn:1");
assertTrue(testCon.hasStatement(iri, iri, iri, false, CONTEXT));
}

@Test
public void testUpdateExecution()
throws Exception
Expand Down
10 changes: 9 additions & 1 deletion core/http/server-spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
Expand Down Expand Up @@ -75,6 +75,14 @@
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,33 @@ public static <FF extends FileFormat, S> S getAcceptableService(HttpServletReque
}
}

/**
* Reads the {@link Protocol#TIMEOUT_PARAM_NAME} parameter from the request and (if present) parses it
* into an integer value.
*
* @param request
* the {@link HttpServletRequest} to read the parameter from
* @return the value of the timeout parameter as an integer (representing the timeout time in seconds), or
* 0 if no timeout parameter is specified in the request.
* @throws ClientHTTPException
* if the value of the timeout parameter is not a valid integer.
*/
public static int parseTimeoutParam(HttpServletRequest request)
throws ClientHTTPException
{
final String timeoutParam = request.getParameter(Protocol.TIMEOUT_PARAM_NAME);
int maxExecutionTime = 0;
if (timeoutParam != null) {
try {
maxExecutionTime = Integer.parseInt(timeoutParam);
}
catch (NumberFormatException e) {
throw new ClientHTTPException(SC_BAD_REQUEST, "Invalid timeout value: " + timeoutParam);
}
}
return maxExecutionTime;
}

public static void logAcceptableFormats(HttpServletRequest request) {
Logger logger = LoggerFactory.getLogger(ProtocolUtil.class);
if (logger.isDebugEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,16 +275,7 @@ private Query getQuery(Repository repository, RepositoryConnection repositoryCon
// determine if inferred triples should be included in query evaluation
boolean includeInferred = ProtocolUtil.parseBooleanParam(request, INCLUDE_INFERRED_PARAM_NAME, true);

String timeout = request.getParameter(Protocol.TIMEOUT_PARAM_NAME);
int maxQueryTime = 0;
if (timeout != null) {
try {
maxQueryTime = Integer.parseInt(timeout);
}
catch (NumberFormatException e) {
throw new ClientHTTPException(SC_BAD_REQUEST, "Invalid timeout value: " + timeout);
}
}
final int maxQueryTime = ProtocolUtil.parseTimeoutParam(request);

// build a dataset, if specified
String[] defaultGraphURIs = request.getParameterValues(DEFAULT_GRAPH_PARAM_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package org.eclipse.rdf4j.http.server.repository.statements;

import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
import static javax.servlet.http.HttpServletResponse.SC_SERVICE_UNAVAILABLE;
import static javax.servlet.http.HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE;
import static org.eclipse.rdf4j.http.protocol.Protocol.BASEURI_PARAM_NAME;
import static org.eclipse.rdf4j.http.protocol.Protocol.BINDING_PREFIX;
Expand Down Expand Up @@ -49,6 +50,7 @@
import org.eclipse.rdf4j.model.Value;
import org.eclipse.rdf4j.model.ValueFactory;
import org.eclipse.rdf4j.query.MalformedQueryException;
import org.eclipse.rdf4j.query.QueryInterruptedException;
import org.eclipse.rdf4j.query.QueryLanguage;
import org.eclipse.rdf4j.query.Update;
import org.eclipse.rdf4j.query.UpdateExecutionException;
Expand Down Expand Up @@ -246,13 +248,14 @@ private ModelAndView getSparqlUpdateResult(Repository repository, HttpServletReq
}
}

final int maxQueryTime = ProtocolUtil.parseTimeoutParam(request);
try {

RepositoryConnection repositoryCon = RepositoryInterceptor.getRepositoryConnection(request);
synchronized (repositoryCon) {
Update update = repositoryCon.prepareUpdate(queryLn, sparqlUpdateString, baseURI);

update.setIncludeInferred(includeInferred);
update.setMaxExecutionTime(maxQueryTime);

if (dataset != null) {
update.setDataset(dataset);
Expand Down Expand Up @@ -281,6 +284,9 @@ private ModelAndView getSparqlUpdateResult(Repository repository, HttpServletReq

return new ModelAndView(EmptySuccessView.getInstance());
}
catch (QueryInterruptedException e) {
throw new ServerHTTPException(SC_SERVICE_UNAVAILABLE, "update execution took too long");
}
catch (UpdateExecutionException e) {
if (e.getCause() != null && e.getCause() instanceof HTTPException) {
// custom signal from the backend, throw as HTTPException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
import org.eclipse.rdf4j.repository.RepositoryConnection;
import org.eclipse.rdf4j.repository.RepositoryException;
import org.eclipse.rdf4j.rio.RDFFormat;
import org.eclipse.rdf4j.repository.util.RDFInserter;
import org.eclipse.rdf4j.rio.RDFFormat;
import org.eclipse.rdf4j.rio.RDFHandlerException;
import org.eclipse.rdf4j.rio.RDFParser;
import org.eclipse.rdf4j.rio.RDFWriterFactory;
Expand Down Expand Up @@ -247,6 +249,12 @@ private ModelAndView processModificationOperation(RepositoryConnection conn, Act
baseURI = "";
}

final Resource[] contexts = ProtocolUtil.parseContextParam(request, CONTEXT_PARAM_NAME,
conn.getValueFactory());

final boolean preserveNodeIds = ProtocolUtil.parseBooleanParam(request,
Protocol.PRESERVE_BNODE_ID_PARAM_NAME, false);

try {
RDFFormat parserFormat = Rio.getParserFormatForMIMEType(request.getContentType());

Expand All @@ -255,7 +263,22 @@ private ModelAndView processModificationOperation(RepositoryConnection conn, Act
if (parserFormat == null) {
throw Rio.unsupportedFormat(request.getContentType());
}
conn.add(request.getInputStream(), baseURI, parserFormat);
if (preserveNodeIds) {
// create a reconfigured parser + inserter instead of relying on standard
// repositoryconn add method.
RDFParser parser = Rio.createParser(parserFormat);
parser.getParserConfig().set(BasicParserSettings.PRESERVE_BNODE_IDS, true);
RDFInserter inserter = new RDFInserter(conn);
inserter.setPreserveBNodeIDs(true);
if (contexts.length > 0) {
inserter.enforceContext(contexts);
}
parser.setRDFHandler(inserter);
parser.parse(request.getInputStream(), baseURI);
}
else {
conn.add(request.getInputStream(), baseURI, parserFormat, contexts);
}
break;
case DELETE:
if (parserFormat == null) {
Expand Down Expand Up @@ -754,8 +777,9 @@ public void handleStatement(Statement st)
Resource subject = SESAME.WILDCARD.equals(st.getSubject()) ? null : st.getSubject();
IRI predicate = SESAME.WILDCARD.equals(st.getPredicate()) ? null : st.getPredicate();
Value object = SESAME.WILDCARD.equals(st.getObject()) ? null : st.getObject();
Resource context = st.getContext();

try {
Resource context = st.getContext();
if (context != null) {
conn.remove(subject, predicate, object, st.getContext());
}
Expand Down
Loading

0 comments on commit 0c81ebe

Please sign in to comment.