Skip to content

Commit e06f669

Browse files
author
James Leigh
committed
Merge branch 'master' of github.com:eclipse/rdf4j into develop
2 parents f42cee6 + cb28bc5 commit e06f669

32 files changed

Lines changed: 307 additions & 171 deletions

File tree

compliance/store/src/test/java/org/eclipse/rdf4j/repository/sparql/SPARQLServiceEvaluationTest.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,21 @@
2626
import org.eclipse.rdf4j.query.QueryLanguage;
2727
import org.eclipse.rdf4j.query.TupleQuery;
2828
import org.eclipse.rdf4j.query.TupleQueryResult;
29+
import org.eclipse.rdf4j.query.algebra.evaluation.EvaluationStrategy;
30+
import org.eclipse.rdf4j.query.algebra.evaluation.federation.FederatedServiceResolverImpl;
31+
import org.eclipse.rdf4j.query.algebra.evaluation.impl.StrictEvaluationStrategyFactory;
2932
import org.eclipse.rdf4j.repository.Repository;
3033
import org.eclipse.rdf4j.repository.RepositoryConnection;
3134
import org.eclipse.rdf4j.repository.RepositoryException;
3235
import org.eclipse.rdf4j.repository.http.HTTPMemServer;
3336
import org.eclipse.rdf4j.repository.http.HTTPRepository;
3437
import org.eclipse.rdf4j.repository.sail.SailRepository;
35-
import org.eclipse.rdf4j.rio.RDFFormat;
3638
import org.eclipse.rdf4j.rio.RDFParseException;
3739
import org.eclipse.rdf4j.rio.Rio;
40+
import org.eclipse.rdf4j.sail.Sail;
3841
import org.eclipse.rdf4j.sail.memory.MemoryStore;
42+
import org.eclipse.rdf4j.sail.memory.config.MemoryStoreConfig;
43+
import org.eclipse.rdf4j.sail.memory.config.MemoryStoreFactory;
3944
import org.junit.After;
4045
import org.junit.AfterClass;
4146
import org.junit.Before;
@@ -100,6 +105,12 @@ public void setUp()
100105
localRepository = new SailRepository(new MemoryStore());
101106
localRepository.initialize();
102107

108+
prepareLocalRepository();
109+
}
110+
111+
private void prepareLocalRepository()
112+
throws IOException
113+
{
103114
loadDataSet(localRepository, "/testdata-query/defaultgraph.ttl");
104115

105116
f = localRepository.getValueFactory();
@@ -199,4 +210,23 @@ else if (alice.equals(x)) {
199210
conn.close();
200211
}
201212
}
213+
214+
/**
215+
* The provided FederatedServiceResolver should finds it way to the {@link EvaluationStrategy}
216+
*/
217+
@Test
218+
public void testRepositoryConfigurationSetup()
219+
throws Exception
220+
{
221+
tearDown();
222+
MemoryStoreFactory factory = new MemoryStoreFactory();
223+
MemoryStoreConfig config = new MemoryStoreConfig();
224+
config.setEvaluationStrategyFactoryClassName(StrictEvaluationStrategyFactory.class.getName());
225+
Sail sail = factory.getSail(config);
226+
localRepository = new SailRepository(sail);
227+
localRepository.setFederatedServiceResolver(new FederatedServiceResolverImpl());
228+
localRepository.initialize();
229+
prepareLocalRepository();
230+
testSimpleServiceQuery();
231+
}
202232
}

core/http/client/src/main/java/org/eclipse/rdf4j/http/client/SPARQLProtocolSession.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,12 @@
3131
import org.apache.http.auth.AuthScope;
3232
import org.apache.http.auth.UsernamePasswordCredentials;
3333
import org.apache.http.client.AuthCache;
34-
import org.apache.http.client.CookieStore;
3534
import org.apache.http.client.CredentialsProvider;
3635
import org.apache.http.client.HttpClient;
3736
import org.apache.http.client.entity.UrlEncodedFormEntity;
3837
import org.apache.http.client.methods.HttpGet;
3938
import org.apache.http.client.methods.HttpPost;
4039
import org.apache.http.client.methods.HttpUriRequest;
41-
import org.apache.http.client.params.ClientPNames;
42-
import org.apache.http.client.params.CookiePolicy;
43-
import org.apache.http.client.protocol.ClientContext;
4440
import org.apache.http.client.protocol.HttpClientContext;
4541
import org.apache.http.client.utils.URIBuilder;
4642
import org.apache.http.entity.ContentType;
@@ -176,7 +172,7 @@ public class SPARQLProtocolSession implements HttpClientDependent {
176172

177173
private final HttpClientContext httpContext;
178174

179-
private final HttpParams params = new BasicHttpParams();
175+
private HttpParams params;
180176

181177
private ParserConfig parserConfig = new ParserConfig();
182178

@@ -197,10 +193,7 @@ public SPARQLProtocolSession(HttpClient client, ExecutorService executor) {
197193
this.httpContext = new HttpClientContext();
198194
this.executor = executor;
199195
valueFactory = SimpleValueFactory.getInstance();
200-
params.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, true);
201-
CookieStore cookieStore = new BasicCookieStore();
202-
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
203-
params.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.RFC_2109);
196+
httpContext.setCookieStore(new BasicCookieStore());
204197

205198
// parser used for processing server response data should be lenient
206199
parserConfig.addNonFatalError(BasicParserSettings.VERIFY_DATATYPE_VALUES);
@@ -1114,7 +1107,9 @@ protected HttpResponse execute(HttpUriRequest method)
11141107
throws IOException, RDF4JException
11151108
{
11161109
boolean consume = true;
1117-
method.setParams(params);
1110+
if (params != null) {
1111+
method.setParams(params);
1112+
}
11181113
HttpResponse response = httpClient.execute(method, httpContext);
11191114

11201115
try {
@@ -1144,9 +1139,12 @@ else if (errInfo.getErrorType() == ErrorType.MALFORMED_QUERY) {
11441139
else if (errInfo.getErrorType() == ErrorType.UNSUPPORTED_QUERY_LANGUAGE) {
11451140
throw new UnsupportedQueryLanguageException(errInfo.getErrorMessage());
11461141
}
1147-
else {
1142+
else if (errInfo.toString().length() > 0){
11481143
throw new RepositoryException(errInfo.toString());
11491144
}
1145+
else {
1146+
throw new RepositoryException(response.getStatusLine().getReasonPhrase());
1147+
}
11501148
}
11511149
}
11521150
}
@@ -1225,6 +1223,9 @@ public ParserConfig getParserConfig() {
12251223
* Gets the http connection read timeout in milliseconds.
12261224
*/
12271225
public long getConnectionTimeout() {
1226+
if (params == null) {
1227+
return 0;
1228+
}
12281229
return (long)params.getIntParameter(CoreConnectionPNames.SO_TIMEOUT, 0);
12291230
}
12301231

@@ -1235,6 +1236,9 @@ public long getConnectionTimeout() {
12351236
* timeout in milliseconds. Zero sets to infinity.
12361237
*/
12371238
public void setConnectionTimeout(long timeout) {
1239+
if (params == null) {
1240+
params = new BasicHttpParams();
1241+
}
12381242
params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, (int)timeout);
12391243
}
12401244
}

core/http/client/src/main/java/org/eclipse/rdf4j/http/client/SharedHttpClientSessionManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private CloseableHttpClient createHttpClient() {
106106
if (nextHttpClientBuilder != null) {
107107
return nextHttpClientBuilder.build();
108108
}
109-
return HttpClients.createSystem();
109+
return HttpClientBuilder.create().useSystemProperties().disableAutomaticRetries().build();
110110
}
111111

112112
@Override

core/http/workbench/src/main/java/org/eclipse/rdf4j/workbench/base/AbstractServlet.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,14 @@ public abstract class AbstractServlet implements Servlet {
3838

3939
protected final Logger log = LoggerFactory.getLogger(this.getClass());
4040

41+
@Deprecated
4142
protected static final String SERVER_USER = "server-user";
4243

44+
@Deprecated
4345
protected static final String SERVER_PASSWORD = "server-password";
4446

47+
protected static final String SERVER_USER_PASSWORD = "server-user-password";
48+
4549
protected static final String ACCEPT = "Accept";
4650

4751
/**

core/http/workbench/src/main/java/org/eclipse/rdf4j/workbench/proxy/WorkbenchGateway.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,8 @@ private void changeServer(final HttpServletRequest req, final HttpServletRespons
178178
// Valid server was submitted by form. Set cookie and redirect to
179179
// repository selection page.
180180
this.cookies.addNewCookie(req, resp, SERVER_COOKIE, server);
181-
final String user = getOptionalParameter(req, SERVER_USER);
182-
this.cookies.addNewCookie(req, resp, SERVER_USER, user);
183-
final String password = getOptionalParameter(req, SERVER_PASSWORD);
184-
this.cookies.addNewCookie(req, resp, SERVER_PASSWORD, password);
181+
final String user_password = getOptionalParameter(req, SERVER_USER_PASSWORD);
182+
this.cookies.addNewCookie(req, resp, SERVER_USER_PASSWORD, user_password);
185183
final StringBuilder uri = new StringBuilder(req.getRequestURI());
186184
uri.setLength(uri.length() - req.getPathInfo().length());
187185
resetCache();

core/http/workbench/src/main/java/org/eclipse/rdf4j/workbench/proxy/WorkbenchServlet.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.net.MalformedURLException;
1414
import java.net.URL;
1515
import java.net.URLDecoder;
16+
import java.util.Base64;
1617
import java.util.concurrent.ConcurrentHashMap;
1718
import java.util.concurrent.ConcurrentMap;
1819

@@ -217,6 +218,7 @@ private void service(final String repoID, final HttpServletRequest req, final Ht
217218
if (repository == null) {
218219
final String noId = config.getInitParameter(NO_REPOSITORY);
219220
if (noId == null || !noId.equals(repoID)) {
221+
resp.setHeader("Cache-Control", "no-cache, no-store");
220222
throw new BadRequestException("No such repository: " + repoID);
221223
}
222224
}
@@ -254,10 +256,21 @@ private void setCredentials(final HttpServletRequest req, final HttpServletRespo
254256
final RemoteRepositoryManager rrm = (RemoteRepositoryManager)manager;
255257
LOGGER.info("RemoteRepositoryManager URL: {}", rrm.getLocation());
256258
final CookieHandler cookies = new CookieHandler(config);
257-
final String user = cookies.getCookieNullIfEmpty(req, resp, WorkbenchGateway.SERVER_USER);
258-
final String password = cookies.getCookieNullIfEmpty(req, resp, WorkbenchGateway.SERVER_PASSWORD);
259-
LOGGER.info("Setting user '{}' and password '{}'.", user, password);
260-
rrm.setUsernameAndPassword(user, password);
259+
final String user_password = cookies.getCookieNullIfEmpty(req, resp, WorkbenchGateway.SERVER_USER_PASSWORD);
260+
if (user_password == null) {
261+
rrm.setUsernameAndPassword(null, null);
262+
} else {
263+
String decoded;
264+
try {
265+
decoded = new String(Base64.getDecoder().decode(user_password));
266+
} catch(IllegalArgumentException e) {
267+
decoded = user_password; // older browsers
268+
}
269+
final String user = decoded.substring(0, decoded.indexOf(':'));
270+
final String password = decoded.substring(decoded.indexOf(':')+1);
271+
LOGGER.info("Setting user '{}' and their password.", user);
272+
rrm.setUsernameAndPassword(user, password);
273+
}
261274
// initialize() required to push credentials to internal HTTP
262275
// client.
263276
rrm.initialize();

core/http/workbench/src/main/java/org/eclipse/rdf4j/workbench/util/PagedQuery.java

Lines changed: 28 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,11 @@ public class PagedQuery {
2525

2626
private static final Pattern LIMIT_OR_OFFSET = Pattern.compile("((limit)|(offset))\\s+\\d+", FLAGS);
2727

28-
private static final Pattern SPLITTER = Pattern.compile("\\s");
29-
30-
private static final Pattern OFFSET_PATTERN = Pattern.compile("\\boffset\\s+\\d+\\b", FLAGS);
31-
32-
private static final Pattern LIMIT_PATTERN = Pattern.compile("\\blimit\\s+\\d+\\b", FLAGS);
33-
3428
private static final Pattern SERQL_NAMESPACE = Pattern.compile("\\busing namespace\\b", FLAGS);
3529

3630
private final String modifiedQuery;
3731

38-
private final boolean hasLimitAndOffset;
32+
private final boolean inlineLimitAndOffset;
3933

4034
private int limitSubstitute, offsetSubstitute;
4135

@@ -68,49 +62,27 @@ public PagedQuery(final String query, final QueryLanguage language, final int re
6862

6963
String rval = query;
7064

65+
/*
66+
* the matcher on the pattern will have a group for "limit l#" as well as a group for l#, similarly
67+
* for "offset o#" and o#. If either exists, disable paging.
68+
*/
69+
final Matcher matcher = LIMIT_OR_OFFSET.matcher(query);
7170
// requestLimit <= 0 actually means don't limit display
72-
hasLimitAndOffset = requestLimit > 0;
73-
if (hasLimitAndOffset) {
74-
/*
75-
* the matcher on the pattern will have a group for "limit l#" as well as a group for l#,
76-
* similarly for "offset o#" and o#. If either doesn't exist, it can be appended at the end.
77-
*/
78-
int queryLimit = -1;
79-
int queryOffset = -1;
80-
final Matcher matcher = LIMIT_OR_OFFSET.matcher(query);
81-
while (matcher.find()) {
82-
final String clause = matcher.group().toLowerCase();
83-
final int value = Integer.parseInt(SPLITTER.split(clause)[1]);
84-
if (clause.startsWith("limit")) {
85-
if (query.indexOf('}', matcher.end()) < 0) {
86-
queryLimit = value;
87-
}
88-
}
89-
else {
90-
queryOffset = value;
91-
}
92-
}
93-
94-
final boolean queryLimitExists = (queryLimit >= 0);
95-
final boolean queryOffsetExists = (queryOffset >= 0);
96-
final int maxQueryCount = getMaxQueryResultCount(queryLimit, queryOffset, queryLimitExists,
97-
queryOffsetExists);
98-
// gracefully handle malicious value
99-
final int offset = (requestOffset < 0) ? 0 : requestOffset;
100-
final int maxRequestCount = requestLimit + offset;
101-
limitSubstitute = (maxRequestCount < maxQueryCount) ? requestLimit : queryLimit - offset;
102-
offsetSubstitute = queryOffsetExists ? queryOffset + offset : offset;
103-
rval = modifyLimit(language, rval, queryLimit, queryLimitExists, queryOffsetExists,
104-
limitSubstitute);
105-
rval = modifyOffset(language, offset, rval, queryOffsetExists);
71+
inlineLimitAndOffset = requestLimit > 0 && !matcher.find();
72+
// gracefully handle malicious value
73+
offsetSubstitute = (requestOffset < 0) ? 0 : requestOffset;
74+
limitSubstitute = requestLimit;
75+
if (inlineLimitAndOffset) {
76+
rval = modifyLimit(language, rval, limitSubstitute);
77+
rval = modifyOffset(language, offsetSubstitute, rval);
10678
LOGGER.debug("Modified Query: {}", rval);
10779
}
10880

10981
this.modifiedQuery = rval;
11082
}
11183

11284
public boolean isPaged() {
113-
return this.hasLimitAndOffset;
85+
return this.inlineLimitAndOffset;
11486
}
11587

11688
public int getLimit() {
@@ -126,42 +98,19 @@ public String toString() {
12698
return this.modifiedQuery;
12799
}
128100

129-
private static int getMaxQueryResultCount(final int queryLimit, final int queryOffset,
130-
final boolean queryLimitExists, final boolean queryOffsetExists)
131-
{
132-
final int maxQueryCount = queryLimitExists ? (queryLimit + (queryOffsetExists ? queryOffset : 0))
133-
: Integer.MAX_VALUE;
134-
return maxQueryCount;
135-
}
136-
137-
private String modifyOffset(final QueryLanguage language, final int offset, final String query,
138-
final boolean queryOffsetExists)
139-
{
101+
private String modifyOffset(final QueryLanguage language, final int offset, final String query) {
140102
String rval = query;
141-
if (queryOffsetExists) {
142-
if (offsetSubstitute != offset) {
143-
// do a clause replacement
144-
final Matcher offsetMatcher = OFFSET_PATTERN.matcher(rval);
145-
final StringBuffer buffer = new StringBuffer();
146-
offsetMatcher.find();
147-
offsetMatcher.appendReplacement(buffer, "offset " + offsetSubstitute);
148-
offsetMatcher.appendTail(buffer);
149-
rval = buffer.toString();
103+
final String newOffsetClause = "offset " + offset;
104+
if (QueryLanguage.SPARQL == language) {
105+
if (offset > 0) {
106+
rval = ensureNewlineAndAppend(rval, newOffsetClause);
150107
}
151108
}
152109
else {
153-
final String newOffsetClause = "offset " + offset;
154-
if (QueryLanguage.SPARQL == language) {
155-
if (offset > 0) {
156-
rval = ensureNewlineAndAppend(rval, newOffsetClause);
157-
}
158-
}
159-
else {
160-
/*
161-
* SeRQL, add the clause before before the namespace section
162-
*/
163-
rval = insertAtMatchOnOwnLine(SERQL_NAMESPACE, rval, newOffsetClause);
164-
}
110+
/*
111+
* SeRQL, add the clause before before the namespace section
112+
*/
113+
rval = insertAtMatchOnOwnLine(SERQL_NAMESPACE, rval, newOffsetClause);
165114
}
166115
return rval;
167116
}
@@ -176,8 +125,8 @@ private static String ensureNewlineAndAppend(final String original, final String
176125
return buffer.append(append).toString();
177126
}
178127

179-
private static String modifyLimit(final QueryLanguage language, final String query, final int queryLimit,
180-
final boolean queryLimitExists, final boolean queryOffsetExists, final int limitSubstitute)
128+
private static String modifyLimit(final QueryLanguage language, final String query,
129+
final int limitSubstitute)
181130
{
182131
String rval = query;
183132

@@ -187,29 +136,11 @@ private static String modifyLimit(final QueryLanguage language, final String que
187136
* and LIMIT must precede OFFSET. This code makes no attempt to correct if the user places them out of
188137
* order in the query.
189138
*/
190-
if (queryLimitExists) {
191-
if (limitSubstitute != queryLimit) {
192-
// do a clause replacement
193-
final Matcher limitMatcher = LIMIT_PATTERN.matcher(rval);
194-
final StringBuffer buffer = new StringBuffer();
195-
limitMatcher.find();
196-
limitMatcher.appendReplacement(buffer, "limit " + limitSubstitute);
197-
limitMatcher.appendTail(buffer);
198-
rval = buffer.toString();
199-
}
139+
if (QueryLanguage.SPARQL == language) {
140+
rval = ensureNewlineAndAppend(rval, "limit " + limitSubstitute);
200141
}
201142
else {
202-
final String newLimitClause = "limit " + limitSubstitute;
203-
if (QueryLanguage.SPARQL == language) {
204-
rval = ensureNewlineAndAppend(rval, newLimitClause);
205-
}
206-
else {
207-
/*
208-
* SeRQL, add the clause before any offset clause or the namespace section
209-
*/
210-
final Pattern pattern = queryOffsetExists ? OFFSET_PATTERN : SERQL_NAMESPACE;
211-
rval = insertAtMatchOnOwnLine(pattern, rval, newLimitClause);
212-
}
143+
rval = insertAtMatchOnOwnLine(SERQL_NAMESPACE, rval, "limit " + limitSubstitute);
213144
}
214145
return rval;
215146
}

0 commit comments

Comments
 (0)