Class LanguageToolHttpHandler

  • All Implemented Interfaces:
    com.sun.net.httpserver.HttpHandler

    class LanguageToolHttpHandler
    extends java.lang.Object
    implements com.sun.net.httpserver.HttpHandler
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private java.util.Map<java.lang.String,​java.lang.String> getParameterMap​(java.lang.String query, com.sun.net.httpserver.HttpExchange httpExchange)  
      private @Nullable java.lang.String getRealRemoteAddressOrNull​(com.sun.net.httpserver.HttpExchange httpExchange)
      A (reverse) proxy can set the 'X-forwarded-for' header so we can see a user's original IP.
      private java.util.Map<java.lang.String,​java.lang.String> getRequestQuery​(com.sun.net.httpserver.HttpExchange httpExchange, java.net.URI requestedUri)  
      private @NotNull java.lang.String getTextOrDataSizeMessage​(java.util.Map<java.lang.String,​java.lang.String> parameters)  
      void handle​(com.sun.net.httpserver.HttpExchange httpExchange)  
      private boolean hasCause​(java.lang.Exception e, java.lang.Class<AuthException> clazz)  
      private void logError​(java.lang.String errorMessage, int code, java.util.Map<java.lang.String,​java.lang.String> params, com.sun.net.httpserver.HttpExchange httpExchange)  
      private void logError​(java.lang.String errorMessage, int code, java.util.Map<java.lang.String,​java.lang.String> params, com.sun.net.httpserver.HttpExchange httpExchange, boolean logToDb)  
      private void logError​(java.lang.String remoteAddress, java.lang.Exception e, int errorCode, com.sun.net.httpserver.HttpExchange httpExchange, java.util.Map<java.lang.String,​java.lang.String> params, boolean textLoggingAllowed, boolean logStacktrace, long runtimeMillis)  
      private void logToDatabase​(java.util.Map<java.lang.String,​java.lang.String> params, java.lang.String message)  
      private java.util.Map<java.lang.String,​java.lang.String> parseQuery​(java.lang.String query, com.sun.net.httpserver.HttpExchange httpExchange)  
      private java.lang.String readerToString​(java.io.Reader reader, int maxTextLength)  
      private void sendError​(com.sun.net.httpserver.HttpExchange httpExchange, int httpReturnCode, java.lang.String response)  
      (package private) void shutdown()  
      private boolean siteMatches​(java.lang.String referrer, java.lang.String blockedRef)  
      private boolean workQueueFull​(com.sun.net.httpserver.HttpExchange httpExchange, java.util.Map<java.lang.String,​java.lang.String> parameters, java.lang.String response)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • logger

        private static final org.slf4j.Logger logger
      • allowedIps

        private final java.util.Set<java.lang.String> allowedIps
      • workQueue

        private final java.util.concurrent.LinkedBlockingQueue<java.lang.Runnable> workQueue
      • textCheckerV2

        private final TextChecker textCheckerV2
    • Constructor Detail

      • LanguageToolHttpHandler

        LanguageToolHttpHandler​(HTTPServerConfig config,
                                java.util.Set<java.lang.String> allowedIps,
                                boolean internal,
                                RequestLimiter requestLimiter,
                                ErrorRequestLimiter errorLimiter,
                                java.util.concurrent.LinkedBlockingQueue<java.lang.Runnable> workQueue)
    • Method Detail

      • shutdown

        void shutdown()
        Since:
        2.6
      • handle

        public void handle​(com.sun.net.httpserver.HttpExchange httpExchange)
                    throws java.io.IOException
        Specified by:
        handle in interface com.sun.net.httpserver.HttpHandler
        Throws:
        java.io.IOException
      • hasCause

        private boolean hasCause​(java.lang.Exception e,
                                 java.lang.Class<AuthException> clazz)
      • siteMatches

        private boolean siteMatches​(java.lang.String referrer,
                                    java.lang.String blockedRef)
      • workQueueFull

        private boolean workQueueFull​(com.sun.net.httpserver.HttpExchange httpExchange,
                                      java.util.Map<java.lang.String,​java.lang.String> parameters,
                                      java.lang.String response)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • getTextOrDataSizeMessage

        @NotNull
        private @NotNull java.lang.String getTextOrDataSizeMessage​(java.util.Map<java.lang.String,​java.lang.String> parameters)
      • logError

        private void logError​(java.lang.String errorMessage,
                              int code,
                              java.util.Map<java.lang.String,​java.lang.String> params,
                              com.sun.net.httpserver.HttpExchange httpExchange)
      • logError

        private void logError​(java.lang.String errorMessage,
                              int code,
                              java.util.Map<java.lang.String,​java.lang.String> params,
                              com.sun.net.httpserver.HttpExchange httpExchange,
                              boolean logToDb)
      • logError

        private void logError​(java.lang.String remoteAddress,
                              java.lang.Exception e,
                              int errorCode,
                              com.sun.net.httpserver.HttpExchange httpExchange,
                              java.util.Map<java.lang.String,​java.lang.String> params,
                              boolean textLoggingAllowed,
                              boolean logStacktrace,
                              long runtimeMillis)
      • logToDatabase

        private void logToDatabase​(java.util.Map<java.lang.String,​java.lang.String> params,
                                   java.lang.String message)
      • getRealRemoteAddressOrNull

        @Nullable
        private @Nullable java.lang.String getRealRemoteAddressOrNull​(com.sun.net.httpserver.HttpExchange httpExchange)
        A (reverse) proxy can set the 'X-forwarded-for' header so we can see a user's original IP. But that's just a common header than can also be set by the client. So we restrict access to this server to the load balancer, which should add the header originally with the user's own IP.
      • sendError

        private void sendError​(com.sun.net.httpserver.HttpExchange httpExchange,
                               int httpReturnCode,
                               java.lang.String response)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • getRequestQuery

        private java.util.Map<java.lang.String,​java.lang.String> getRequestQuery​(com.sun.net.httpserver.HttpExchange httpExchange,
                                                                                       java.net.URI requestedUri)
                                                                                throws java.io.IOException
        Throws:
        java.io.IOException
      • readerToString

        private java.lang.String readerToString​(java.io.Reader reader,
                                                int maxTextLength)
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • parseQuery

        private java.util.Map<java.lang.String,​java.lang.String> parseQuery​(java.lang.String query,
                                                                                  com.sun.net.httpserver.HttpExchange httpExchange)
                                                                           throws java.io.UnsupportedEncodingException
        Throws:
        java.io.UnsupportedEncodingException
      • getParameterMap

        private java.util.Map<java.lang.String,​java.lang.String> getParameterMap​(java.lang.String query,
                                                                                       com.sun.net.httpserver.HttpExchange httpExchange)
                                                                                throws java.io.UnsupportedEncodingException
        Throws:
        java.io.UnsupportedEncodingException