Package org.eclipse.rdf4j.workbench.commands

## Class QueryServlet

- java.lang.Object
- - org.eclipse.rdf4j.workbench.base.AbstractServlet
  - - org.eclipse.rdf4j.workbench.base.AbstractRepositoryServlet
    - - org.eclipse.rdf4j.workbench.base.TransformationServlet
      - - org.eclipse.rdf4j.workbench.commands.QueryServlet

- All Implemented Interfaces:
    `javax.servlet.Servlet`, `RepositoryServlet`

      public class QueryServlet
      extends TransformationServlet

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `protected static String` | `LIMIT` |
    `protected static String` | `QUERY` |
    `protected static String` | `REF` |
    `protected boolean` | `writeQueryCookie` |

    - ### Fields inherited from class org.eclipse.rdf4j.workbench.base.TransformationServlet

      `CONTEXT, cookies, INFO, NON_VERIFYING_PARSER_CONFIG`

    - ### Fields inherited from class org.eclipse.rdf4j.workbench.base.AbstractRepositoryServlet

      `info, manager, MANAGER_PARAM, repository, REPOSITORY_PARAM, vf`

    - ### Fields inherited from class org.eclipse.rdf4j.workbench.base.AbstractServlet

      `appConfig, APPLICATION_JAVASCRIPT, APPLICATION_SPARQL_RESULTS_XML, APPLICATION_XML, config, DEFAULT_JSONP_CALLBACK_PARAMETER, JSONP_CALLBACK_PARAMETER, JSONP_ENABLED, JSONP_VALIDATOR, log, MOZILLA, MSIE, SERVER_PASSWORD, SERVER_USER, SERVER_USER_PASSWORD, TEXT_HTML, TEXT_PLAIN, USER_AGENT`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `QueryServlet()` |

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `destroy()` |
    `protected void` | `doPost​(WorkbenchRequest req, javax.servlet.http.HttpServletResponse resp, String xslPath)` |
    `String[]` | `getCookieNames()` |
    `protected String` | `getQueryText​(WorkbenchRequest req)` |
    `void` | `init​(javax.servlet.ServletConfig config)` | Initialize this instance of the servlet.
    `void` | `service​(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)` | Long query strings could blow past the Tomcat default 8k HTTP header limit if stuffed into a cookie.
    `protected void` | `service​(WorkbenchRequest req, javax.servlet.http.HttpServletResponse resp, String xslPath)` |
    `protected boolean` | `shouldWriteQueryCookie​(String queryText)` | Determines if the servlet should write out the query text into a cookie as received, or write it's hash instead.
    `protected static void` | `substituteQueryCache​(Map<String,​String> testQueryCache)` | For testing purposes only.
    `protected void` | `substituteQueryStorage​(QueryStorage storage)` |

    - ### Methods inherited from class org.eclipse.rdf4j.workbench.base.TransformationServlet

      `service`

    - ### Methods inherited from class org.eclipse.rdf4j.workbench.base.AbstractRepositoryServlet

      `setRepository, setRepositoryInfo, setRepositoryManager`

    - ### Methods inherited from class org.eclipse.rdf4j.workbench.base.AbstractServlet

      `checkJSONP, getBooleanResultFormat, getJSONPResultFormat, getResultWriter, getServletConfig, getServletInfo, getTupleResultBuilder, getTupleResultFormat, service`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface javax.servlet.Servlet

      `getServletConfig, getServletInfo, service`

- - ### Field Detail

    - #### REF

          protected static final String REF

      See Also:
        Constant Field Values

    - #### LIMIT

          protected static final String LIMIT

      See Also:
        Constant Field Values

    - #### QUERY

          protected static final String QUERY

      See Also:
        Constant Field Values

    - #### writeQueryCookie

          protected boolean writeQueryCookie

  - ### Constructor Detail

    - #### QueryServlet

          public QueryServlet()

  - ### Method Detail

    - #### substituteQueryCache

          protected static void substituteQueryCache​(Map<String,​String> testQueryCache)

      For testing purposes only.
      Parameters:
        `testQueryCache` - cache to use instead of the production cache instance

    - #### substituteQueryStorage

          protected void substituteQueryStorage​(QueryStorage storage)

    - #### getCookieNames

          public String[] getCookieNames()

      Overrides:
        `getCookieNames` in class `TransformationServlet`
      Returns:
        the names of the cookies that will be retrieved from the request, and returned in the response

    - #### init

          public void init​(javax.servlet.ServletConfig config)
                    throws javax.servlet.ServletException

      Initialize this instance of the servlet.
      Specified by:
        `init` in interface `javax.servlet.Servlet`
      Overrides:
        `init` in class `TransformationServlet`
      Parameters:
        `config` - configuration passed in by the application container
      Throws:
        `javax.servlet.ServletException`

    - #### destroy

          public void destroy()

      Specified by:
        `destroy` in interface `javax.servlet.Servlet`
      Overrides:
        `destroy` in class `AbstractServlet`

    - #### service

          public final void service​(javax.servlet.http.HttpServletRequest req,
                                    javax.servlet.http.HttpServletResponse resp)
                             throws javax.servlet.ServletException,
                                    IOException

      Long query strings could blow past the Tomcat default 8k HTTP header limit if stuffed into a cookie. In this case, we need to set a flag to avoid this happening before `TransformationServlet.service(HttpServletRequest, HttpServletResponse)` is called. A much lower limit on the size of the query text is used to stay well below the Tomcat limitation.
      Overrides:
        `service` in class `TransformationServlet`
      Throws:
        `javax.servlet.ServletException`
        `IOException`

    - #### shouldWriteQueryCookie

          protected boolean shouldWriteQueryCookie​(String queryText)

      Determines if the servlet should write out the query text into a cookie as received, or write it's hash instead.

      Note: This is a separate method for testing purposes.

      Parameters:
        `queryText` - the text received as the value for the parameter 'query'

    - #### service

          protected void service​(WorkbenchRequest req,
                                 javax.servlet.http.HttpServletResponse resp,
                                 String xslPath)
                          throws IOException,
                                 RDF4JException,
                                 BadRequestException

      Overrides:
        `service` in class `TransformationServlet`
      Throws:
        `IOException`
        `RDF4JException`
        `BadRequestException`

    - #### doPost

          protected void doPost​(WorkbenchRequest req,
                                javax.servlet.http.HttpServletResponse resp,
                                String xslPath)
                         throws IOException,
                                BadRequestException,
                                RDF4JException

      Overrides:
        `doPost` in class `TransformationServlet`
      Throws:
        `IOException`
        `BadRequestException`
        `RDF4JException`

    - #### getQueryText

          protected String getQueryText​(WorkbenchRequest req)
                                 throws BadRequestException,
                                        RDF4JException

      Parameters:
        `req` - for looking at the request parameters
      Returns:
        the query text, if it can somehow be retrieved from request parameters, otherwise an empty string
      Throws:
        `BadRequestException` - if a problem occurs grabbing the request from storage
        `RDF4JException` - if a problem occurs grabbing the request from storage