Class ApiV2


  • class ApiV2
    extends java.lang.Object
    Handle requests to /v2/ of the HTTP API.
    Since:
    3.4
    • Constructor Summary

      Constructors 
      Constructor Description
      ApiV2​(TextChecker textChecker, java.lang.String allowOriginUrl)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void ensureGetMethod​(com.sun.net.httpserver.HttpExchange httpExchange, java.lang.String url)  
      private void ensurePostMethod​(com.sun.net.httpserver.HttpExchange httpExchange, java.lang.String url)  
      private org.languagetool.markup.AnnotatedText getAnnotatedTextFromJson​(com.fasterxml.jackson.databind.JsonNode data)  
      private org.languagetool.markup.AnnotatedText getAnnotatedTextFromString​(com.fasterxml.jackson.databind.JsonNode data, java.lang.String text)  
      (package private) java.lang.String getConfigurationInfo​(org.languagetool.Language lang, HTTPServerConfig config)  
      (package private) java.lang.String getLanguages()  
      private @NotNull UserLimits getUserLimits​(java.util.Map<java.lang.String,​java.lang.String> parameters, HTTPServerConfig config)  
      private void handleCheckRequest​(com.sun.net.httpserver.HttpExchange httpExchange, java.util.Map<java.lang.String,​java.lang.String> parameters, ErrorRequestLimiter errorRequestLimiter, java.lang.String remoteAddress)  
      private void handleGetConfigurationInfoRequest​(com.sun.net.httpserver.HttpExchange httpExchange, java.util.Map<java.lang.String,​java.lang.String> parameters, HTTPServerConfig config)  
      private void handleLanguagesRequest​(com.sun.net.httpserver.HttpExchange httpExchange)  
      private void handleLogRequest​(com.sun.net.httpserver.HttpExchange httpExchange, java.util.Map<java.lang.String,​java.lang.String> parameters)  
      private void handleMaxTextLengthRequest​(com.sun.net.httpserver.HttpExchange httpExchange, HTTPServerConfig config)  
      (package private) void handleRequest​(java.lang.String path, com.sun.net.httpserver.HttpExchange httpExchange, java.util.Map<java.lang.String,​java.lang.String> parameters, ErrorRequestLimiter errorRequestLimiter, java.lang.String remoteAddress, HTTPServerConfig config)  
      private void handleRuleExamplesRequest​(com.sun.net.httpserver.HttpExchange httpExchange, java.util.Map<java.lang.String,​java.lang.String> params)  
      private void handleWordAddRequest​(com.sun.net.httpserver.HttpExchange httpExchange, java.util.Map<java.lang.String,​java.lang.String> parameters, HTTPServerConfig config)  
      private void handleWordDeleteRequest​(com.sun.net.httpserver.HttpExchange httpExchange, java.util.Map<java.lang.String,​java.lang.String> parameters, HTTPServerConfig config)  
      private void handleWordsRequest​(com.sun.net.httpserver.HttpExchange httpExchange, java.util.Map<java.lang.String,​java.lang.String> params, HTTPServerConfig config)  
      private void sendJson​(com.sun.net.httpserver.HttpExchange httpExchange, java.io.StringWriter sw)  
      private void writeListResponse​(java.lang.String fieldName, java.util.List<UserDictEntry> words, com.sun.net.httpserver.HttpExchange httpExchange)  
      private void writeResponse​(java.lang.String fieldName, boolean added, com.sun.net.httpserver.HttpExchange httpExchange)  
      • Methods inherited from class java.lang.Object

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

      • JSON_CONTENT_TYPE

        private static final java.lang.String JSON_CONTENT_TYPE
        See Also:
        Constant Field Values
      • TEXT_CONTENT_TYPE

        private static final java.lang.String TEXT_CONTENT_TYPE
        See Also:
        Constant Field Values
      • allowOriginUrl

        private final java.lang.String allowOriginUrl
      • factory

        private final com.fasterxml.jackson.core.JsonFactory factory
    • Constructor Detail

      • ApiV2

        ApiV2​(TextChecker textChecker,
              java.lang.String allowOriginUrl)
    • Method Detail

      • handleRequest

        void handleRequest​(java.lang.String path,
                           com.sun.net.httpserver.HttpExchange httpExchange,
                           java.util.Map<java.lang.String,​java.lang.String> parameters,
                           ErrorRequestLimiter errorRequestLimiter,
                           java.lang.String remoteAddress,
                           HTTPServerConfig config)
                    throws java.lang.Exception
        Throws:
        java.lang.Exception
      • handleLanguagesRequest

        private void handleLanguagesRequest​(com.sun.net.httpserver.HttpExchange httpExchange)
                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • handleMaxTextLengthRequest

        private void handleMaxTextLengthRequest​(com.sun.net.httpserver.HttpExchange httpExchange,
                                                HTTPServerConfig config)
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • handleGetConfigurationInfoRequest

        private void handleGetConfigurationInfoRequest​(com.sun.net.httpserver.HttpExchange httpExchange,
                                                       java.util.Map<java.lang.String,​java.lang.String> parameters,
                                                       HTTPServerConfig config)
                                                throws java.io.IOException
        Throws:
        java.io.IOException
      • handleCheckRequest

        private void handleCheckRequest​(com.sun.net.httpserver.HttpExchange httpExchange,
                                        java.util.Map<java.lang.String,​java.lang.String> parameters,
                                        ErrorRequestLimiter errorRequestLimiter,
                                        java.lang.String remoteAddress)
                                 throws java.lang.Exception
        Throws:
        java.lang.Exception
      • handleWordsRequest

        private void handleWordsRequest​(com.sun.net.httpserver.HttpExchange httpExchange,
                                        java.util.Map<java.lang.String,​java.lang.String> params,
                                        HTTPServerConfig config)
                                 throws java.lang.Exception
        Throws:
        java.lang.Exception
      • handleWordAddRequest

        private void handleWordAddRequest​(com.sun.net.httpserver.HttpExchange httpExchange,
                                          java.util.Map<java.lang.String,​java.lang.String> parameters,
                                          HTTPServerConfig config)
                                   throws java.lang.Exception
        Throws:
        java.lang.Exception
      • handleWordDeleteRequest

        private void handleWordDeleteRequest​(com.sun.net.httpserver.HttpExchange httpExchange,
                                             java.util.Map<java.lang.String,​java.lang.String> parameters,
                                             HTTPServerConfig config)
                                      throws java.lang.Exception
        Throws:
        java.lang.Exception
      • handleRuleExamplesRequest

        private void handleRuleExamplesRequest​(com.sun.net.httpserver.HttpExchange httpExchange,
                                               java.util.Map<java.lang.String,​java.lang.String> params)
                                        throws java.lang.Exception
        Throws:
        java.lang.Exception
      • ensureGetMethod

        private void ensureGetMethod​(com.sun.net.httpserver.HttpExchange httpExchange,
                                     java.lang.String url)
      • ensurePostMethod

        private void ensurePostMethod​(com.sun.net.httpserver.HttpExchange httpExchange,
                                      java.lang.String url)
      • getUserLimits

        @NotNull
        private @NotNull UserLimits getUserLimits​(java.util.Map<java.lang.String,​java.lang.String> parameters,
                                                  HTTPServerConfig config)
      • writeResponse

        private void writeResponse​(java.lang.String fieldName,
                                   boolean added,
                                   com.sun.net.httpserver.HttpExchange httpExchange)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • writeListResponse

        private void writeListResponse​(java.lang.String fieldName,
                                       java.util.List<UserDictEntry> words,
                                       com.sun.net.httpserver.HttpExchange httpExchange)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • sendJson

        private void sendJson​(com.sun.net.httpserver.HttpExchange httpExchange,
                              java.io.StringWriter sw)
                       throws java.io.IOException
        Throws:
        java.io.IOException
      • handleLogRequest

        private void handleLogRequest​(com.sun.net.httpserver.HttpExchange httpExchange,
                                      java.util.Map<java.lang.String,​java.lang.String> parameters)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • getAnnotatedTextFromString

        private org.languagetool.markup.AnnotatedText getAnnotatedTextFromString​(com.fasterxml.jackson.databind.JsonNode data,
                                                                                 java.lang.String text)
      • getAnnotatedTextFromJson

        private org.languagetool.markup.AnnotatedText getAnnotatedTextFromJson​(com.fasterxml.jackson.databind.JsonNode data)
      • getLanguages

        java.lang.String getLanguages()
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • getConfigurationInfo

        java.lang.String getConfigurationInfo​(org.languagetool.Language lang,
                                              HTTPServerConfig config)
                                       throws java.io.IOException
        Throws:
        java.io.IOException