|
24 | 24 | import com.atomgraph.linkeddatahub.server.util.OntologyRepository; |
25 | 25 | import org.apache.jena.riot.RDFParser; |
26 | 26 | import com.atomgraph.linkeddatahub.server.mapper.HttpHostConnectExceptionMapper; |
| 27 | +import com.atomgraph.linkeddatahub.server.mapper.ResponseContentTooLargeExceptionMapper; |
27 | 28 | import com.atomgraph.linkeddatahub.server.mapper.InternalURLExceptionMapper; |
28 | 29 | import com.atomgraph.linkeddatahub.server.mapper.MessagingExceptionMapper; |
29 | 30 | import com.atomgraph.linkeddatahub.server.mapper.auth.webid.WebIDLoadingExceptionMapper; |
@@ -270,6 +271,8 @@ public class Application extends ResourceConfig |
270 | 271 | public static final String CLIENT_SEF_PATH = "/static/com/atomgraph/linkeddatahub/xsl/client.xsl.sef.json"; |
271 | 272 | /** Milliseconds a request waits for a connection from the client pool when nothing configures it; the image sets the same through CONNECTION_REQUEST_TIMEOUT */ |
272 | 273 | public static final int DEFAULT_CONNECTION_REQUEST_TIMEOUT = 30000; |
| 274 | + /** Bytes of a SPARQL endpoint query result when nothing configures it; the image sets the same through MAX_QUERY_RESPONSE_LENGTH */ |
| 275 | + public static final int DEFAULT_MAX_QUERY_RESPONSE_LENGTH = 5242880; |
273 | 276 | /** ORCID's production environment, used when no issuer is configured; a client registered on the sandbox sets <code>https://sandbox.orcid.org</code> */ |
274 | 277 | public static final String ORCID_ISSUER = "https://orcid.org"; |
275 | 278 | /** Path of the client stylesheet source in the webapp, composed with package stylesheets per import set */ |
@@ -302,6 +305,7 @@ public class Application extends ResourceConfig |
302 | 305 | private final boolean allowInternalUrls; |
303 | 306 | private final URLValidator urlValidator; |
304 | 307 | private final Integer maxContentLength; |
| 308 | + private final int maxQueryResponseLength; |
305 | 309 | private final Address notificationAddress; |
306 | 310 | private final Authenticator authenticator; |
307 | 311 | private final Properties emailProperties = new Properties(); |
@@ -378,6 +382,8 @@ public Application(@Context ServletConfig servletConfig) throws URISyntaxExcepti |
378 | 382 | System.getProperty("com.atomgraph.linkeddatahub.allowInternalUrls") != null ? Boolean.parseBoolean(System.getProperty("com.atomgraph.linkeddatahub.allowInternalUrls")) : |
379 | 383 | servletConfig.getServletContext().getInitParameter(LDHC.allowInternalUrls.getURI()) != null ? Boolean.parseBoolean(servletConfig.getServletContext().getInitParameter(LDHC.allowInternalUrls.getURI())) : false, |
380 | 384 | servletConfig.getServletContext().getInitParameter(LDHC.maxContentLength.getURI()) != null ? Integer.valueOf(servletConfig.getServletContext().getInitParameter(LDHC.maxContentLength.getURI())) : null, |
| 385 | + servletConfig.getServletContext().getInitParameter(LDHC.maxQueryResponseLength.getURI()) != null ? Integer.parseInt(servletConfig.getServletContext().getInitParameter(LDHC.maxQueryResponseLength.getURI())) : |
| 386 | + DEFAULT_MAX_QUERY_RESPONSE_LENGTH, // unset means the endpoint buffers, and a page renders, a result of any length |
381 | 387 | System.getProperty("com.atomgraph.linkeddatahub.maxConnPerRoute") != null ? Integer.valueOf(System.getProperty("com.atomgraph.linkeddatahub.maxConnPerRoute")) : |
382 | 388 | servletConfig.getServletContext().getInitParameter(LDHC.maxConnPerRoute.getURI()) != null ? Integer.valueOf(servletConfig.getServletContext().getInitParameter(LDHC.maxConnPerRoute.getURI())) : null, |
383 | 389 | System.getProperty("com.atomgraph.linkeddatahub.maxTotalConn") != null ? Integer.valueOf(System.getProperty("com.atomgraph.linkeddatahub.maxTotalConn")) : |
@@ -449,6 +455,7 @@ public Application(@Context ServletConfig servletConfig) throws URISyntaxExcepti |
449 | 455 | * @param enableAssistant true if the assistant's plan service is deployed beside this instance |
450 | 456 | * @param allowInternalUrls true if internal/private network URLs are allowed (disables SSRF protection) |
451 | 457 | * @param maxContentLength maximum size of request entity |
| 458 | + * @param maxQueryResponseLength maximum length of a SPARQL endpoint query result in bytes |
452 | 459 | * @param maxConnPerRoute maximum client connections per rout |
453 | 460 | * @param maxTotalConn maximum total client connections |
454 | 461 | * @param maxRequestRetries maximum number of times that the HTTP client will retry a request |
@@ -480,7 +487,7 @@ public Application(final ServletConfig servletConfig, final MediaTypes mediaType |
480 | 487 | final String webIDQueryString, final String agentQueryString, final String userAccountQueryString, final String ontologyQueryString, |
481 | 488 | final String baseURIString, final String proxyScheme, final String proxyHostname, final Integer proxyPort, |
482 | 489 | final String uploadRootString, final String sefRootString, final String sefCompilerString, final String clientStylesheetString, final boolean invalidateCache, |
483 | | - final Integer cookieMaxAge, final boolean enableLinkedDataProxy, final boolean enableAssistant, final boolean allowInternalUrls, final Integer maxContentLength, |
| 490 | + final Integer cookieMaxAge, final boolean enableLinkedDataProxy, final boolean enableAssistant, final boolean allowInternalUrls, final Integer maxContentLength, final int maxQueryResponseLength, |
484 | 491 | final Integer maxConnPerRoute, final Integer maxTotalConn, final Integer maxRequestRetries, final Integer connectionRequestTimeout, |
485 | 492 | final Integer socketTimeout, final Integer connectTimeout, final Integer selfRequestTimeout, final Long connectionTimeToLive, final Integer validateAfterInactivity, final Integer maxImportThreads, |
486 | 493 | final String notificationAddressString, final boolean enableWebIDSignUp, final String oidcRefreshTokensPropertiesPath, |
@@ -622,6 +629,7 @@ public Application(final ServletConfig servletConfig, final MediaTypes mediaType |
622 | 629 | this.urlValidator = new URLValidator(allowInternalUrls); |
623 | 630 | configureServiceExecution(allowInternalUrls); |
624 | 631 | this.maxContentLength = maxContentLength; |
| 632 | + this.maxQueryResponseLength = maxQueryResponseLength; |
625 | 633 | this.invalidateCache = invalidateCache; |
626 | 634 | this.enableWebIDSignUp = enableWebIDSignUp; |
627 | 635 | this.oidcRefreshTokensPropertiesPath = oidcRefreshTokensPropertiesPath; |
@@ -1288,6 +1296,7 @@ protected void registerExceptionMappers() |
1288 | 1296 | register(NotAcceptableExceptionMapper.class); |
1289 | 1297 | register(ClientErrorExceptionMapper.class); |
1290 | 1298 | register(HttpHostConnectExceptionMapper.class); |
| 1299 | + register(ResponseContentTooLargeExceptionMapper.class); |
1291 | 1300 | register(InternalURLExceptionMapper.class); |
1292 | 1301 | register(BadGatewayExceptionMapper.class); |
1293 | 1302 | register(OntClassNotFoundExceptionMapper.class); |
@@ -2514,6 +2523,16 @@ public Integer getMaxContentLength() |
2514 | 2523 | return maxContentLength; |
2515 | 2524 | } |
2516 | 2525 |
|
| 2526 | + /** |
| 2527 | + * Maximum length of the result the SPARQL endpoint answers a query with. |
| 2528 | + * |
| 2529 | + * @return length in bytes |
| 2530 | + */ |
| 2531 | + public int getMaxQueryResponseLength() |
| 2532 | + { |
| 2533 | + return maxQueryResponseLength; |
| 2534 | + } |
| 2535 | + |
2517 | 2536 | /** |
2518 | 2537 | * Keystore of the HTTP client. |
2519 | 2538 | * |
|
0 commit comments