Package org.languagetool.server
Class LanguageToolHttpHandler
java.lang.Object
org.languagetool.server.LanguageToolHttpHandler
- All Implemented Interfaces:
com.sun.net.httpserver.HttpHandler
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final String
private final HTTPServerConfig
private static final String
private final ErrorRequestLimiter
private static final org.slf4j.Logger
private final RequestCounter
private final RequestLimiter
private final TextChecker
private final LinkedBlockingQueue
<Runnable> -
Constructor Summary
ConstructorsConstructorDescriptionLanguageToolHttpHandler
(HTTPServerConfig config, Set<String> allowedIps, boolean internal, RequestLimiter requestLimiter, ErrorRequestLimiter errorLimiter, LinkedBlockingQueue<Runnable> workQueue) -
Method Summary
Modifier and TypeMethodDescriptiongetParameterMap
(String query, com.sun.net.httpserver.HttpExchange httpExchange) private @Nullable 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.getRequestQuery
(com.sun.net.httpserver.HttpExchange httpExchange, URI requestedUri) private @NotNull String
getTextOrDataSizeMessage
(Map<String, String> parameters) void
handle
(com.sun.net.httpserver.HttpExchange httpExchange) private boolean
hasCause
(Exception e, Class<AuthException> clazz) private void
logError
(String errorMessage, int code, Map<String, String> params, com.sun.net.httpserver.HttpExchange httpExchange) private void
logError
(String errorMessage, int code, Map<String, String> params, com.sun.net.httpserver.HttpExchange httpExchange, boolean logToDb) private void
logError
(String remoteAddress, Exception e, int errorCode, com.sun.net.httpserver.HttpExchange httpExchange, Map<String, String> params, boolean textLoggingAllowed, boolean logStacktrace, long runtimeMillis) private void
logToDatabase
(Map<String, String> params, String message) parseQuery
(String query, com.sun.net.httpserver.HttpExchange httpExchange) private String
readerToString
(Reader reader, int maxTextLength) private void
(package private) void
shutdown()
private boolean
siteMatches
(String referrer, String blockedRef) private boolean
workQueueFull
(com.sun.net.httpserver.HttpExchange httpExchange, Map<String, String> parameters, String response)
-
Field Details
-
logger
private static final org.slf4j.Logger logger -
API_DOC_URL
- See Also:
-
ENCODING
- See Also:
-
allowedIps
-
requestLimiter
-
errorRequestLimiter
-
workQueue
-
textCheckerV2
-
config
-
reqCounter
-
-
Constructor Details
-
LanguageToolHttpHandler
LanguageToolHttpHandler(HTTPServerConfig config, Set<String> allowedIps, boolean internal, RequestLimiter requestLimiter, ErrorRequestLimiter errorLimiter, LinkedBlockingQueue<Runnable> workQueue)
-
-
Method Details
-
shutdown
void shutdown()- Since:
- 2.6
-
handle
- Specified by:
handle
in interfacecom.sun.net.httpserver.HttpHandler
- Throws:
IOException
-
hasCause
-
siteMatches
-
workQueueFull
private boolean workQueueFull(com.sun.net.httpserver.HttpExchange httpExchange, Map<String, String> parameters, String response) throws IOException- Throws:
IOException
-
getTextOrDataSizeMessage
-
logError
-
logError
-
logError
-
logToDatabase
-
getRealRemoteAddressOrNull
@Nullable private @Nullable 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, String response) throws IOException - Throws:
IOException
-
getRequestQuery
private Map<String,String> getRequestQuery(com.sun.net.httpserver.HttpExchange httpExchange, URI requestedUri) throws IOException - Throws:
IOException
-
readerToString
- Throws:
IOException
-
parseQuery
private Map<String,String> parseQuery(String query, com.sun.net.httpserver.HttpExchange httpExchange) throws UnsupportedEncodingException - Throws:
UnsupportedEncodingException
-
getParameterMap
private Map<String,String> getParameterMap(String query, com.sun.net.httpserver.HttpExchange httpExchange) throws UnsupportedEncodingException - Throws:
UnsupportedEncodingException
-