You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jena.apache.org by "Andy Seaborne (Jira)" <ji...@apache.org> on 2022/01/21 00:06:00 UTC

[jira] [Comment Edited] (JENA-2257) QueryExecHTTP#actualSendMode ignores query length causing HTTP 414

    [ https://issues.apache.org/jira/browse/JENA-2257?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17479599#comment-17479599 ] 

Andy Seaborne edited comment on JENA-2257 at 1/21/22, 12:05 AM:
----------------------------------------------------------------

The code is:
{code:java}
        int thisLengthLimit = urlLimit;
. . .
        // Only QuerySendMode.asGetWithLimitBody and QuerySendMode.asGetWithLimitForm here.
        String requestURL = service;
        // Don't add yet
        //thisParams.addParam(HttpParams.pQuery, queryString);
        String qs = params.httpString();
        // ?query=

        // URL Length, including service (for safety)
        int length = service.length()+1+HttpParams.pQuery.length()+1+qs.length();
        if ( length <= thisLengthLimit )
            return QuerySendMode.asGetAlways;
        return (sendMode==QuerySendMode.asGetWithLimitBody) ? QuerySendMode.asPost : QuerySendMode.asPostForm;
{code}

which I think is testing the query length. Maybe the calculation is wrong.

{{QueryExecHTTPBuilder}} allows the app to set the length.

Intermediaries or the target server (what is it? by the way) may impose lower limits. The code could react to 414 by retrying as POST.

As, in practice, the response to a HTTP GET with query string is not cached, using POST always might be a better default.
-----
Update: Found something : {{params.httpString()}} will not yet to have the query string added.



was (Author: andy.seaborne):
The code is:
{code:java}
        int thisLengthLimit = urlLimit;
. . .
        // Only QuerySendMode.asGetWithLimitBody and QuerySendMode.asGetWithLimitForm here.
        String requestURL = service;
        // Don't add yet
        //thisParams.addParam(HttpParams.pQuery, queryString);
        String qs = params.httpString();
        // ?query=

        // URL Length, including service (for safety)
        int length = service.length()+1+HttpParams.pQuery.length()+1+qs.length();
        if ( length <= thisLengthLimit )
            return QuerySendMode.asGetAlways;
        return (sendMode==QuerySendMode.asGetWithLimitBody) ? QuerySendMode.asPost : QuerySendMode.asPostForm;
{code}

which I think is testing the query length. Maybe the calculation is wrong.

{{QueryExecHTTPBuilder}} allows the app to set the length.

Intermediaries or the target server (what is it? by the way) may impose lower limits. The code could react to 414 by retrying as POST.

As, in practice, the response to a HTTP GET with query string is not cached, using POST always might be a better default.



> QueryExecHTTP#actualSendMode ignores query length causing HTTP 414
> ------------------------------------------------------------------
>
>                 Key: JENA-2257
>                 URL: https://issues.apache.org/jira/browse/JENA-2257
>             Project: Apache Jena
>          Issue Type: Bug
>          Components: ARQ, SPARQL
>    Affects Versions: Jena 4.3.2
>            Reporter: Jan Martin Keil
>            Assignee: Andy Seaborne
>            Priority: Major
>
> {_}QueryExecHTTP#actualSendMode(){_}, called in {_}QueryExecHTTP#query(String reqAcceptHeader){_}, does not consider the length of the query. In case of long queries, this causes _414 Request-URI Too Long_ errors, even if {_}sendMode=={_}{_}QuerySendMode{_}{_}.asGetWithLimitBody{_} (default):
> {quote}HttpException: 414 Request-URI Too Long
>     at org.apache.jena.sparql.engine.http.QueryExceptionHTTP.rewrap(QueryExceptionHTTP.java:49)
>     at org.apache.jena.sparql.exec.http.QueryExecHTTP.executeQuery(QueryExecHTTP.java:493)
>     at org.apache.jena.sparql.exec.http.QueryExecHTTP.query(QueryExecHTTP.java:483)
>     at org.apache.jena.sparql.exec.http.QueryExecHTTP.execRdfWorker(QueryExecHTTP.java:339)
>     at org.apache.jena.sparql.exec.http.QueryExecHTTP.execGraph(QueryExecHTTP.java:287)
>     at org.apache.jena.sparql.exec.http.QueryExecHTTP.construct(QueryExecHTTP.java:244)
>     at org.apache.jena.sparql.exec.QueryExecutionAdapter.execConstruct(QueryExecutionAdapter.java:129)
> {quote}
> Workarounds:
>  * _QuerySendMode.systemDefault = QuerySendMode.asPost;_
>  * _QueryExecution.service(…).sendMode(QuerySendMode.asPost)_



--
This message was sent by Atlassian Jira
(v8.20.1#820001)