Package org.languagetool.server
Class LanguageToolHttpHandler
- java.lang.Object
-
- org.languagetool.server.LanguageToolHttpHandler
-
- All Implemented Interfaces:
com.sun.net.httpserver.HttpHandler
class LanguageToolHttpHandler extends java.lang.Object implements com.sun.net.httpserver.HttpHandler
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Set<java.lang.String>
allowedIps
(package private) static java.lang.String
API_DOC_URL
private HTTPServerConfig
config
private static java.lang.String
ENCODING
private ErrorRequestLimiter
errorRequestLimiter
private static org.slf4j.Logger
logger
private RequestCounter
reqCounter
private RequestLimiter
requestLimiter
private TextChecker
textCheckerV2
private java.util.concurrent.LinkedBlockingQueue<java.lang.Runnable>
workQueue
-
Constructor Summary
Constructors Constructor Description 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 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)
-
-
-
Field Detail
-
logger
private static final org.slf4j.Logger logger
-
API_DOC_URL
static final java.lang.String API_DOC_URL
- See Also:
- Constant Field Values
-
ENCODING
private static final java.lang.String ENCODING
- See Also:
- Constant Field Values
-
allowedIps
private final java.util.Set<java.lang.String> allowedIps
-
requestLimiter
private final RequestLimiter requestLimiter
-
errorRequestLimiter
private final ErrorRequestLimiter errorRequestLimiter
-
workQueue
private final java.util.concurrent.LinkedBlockingQueue<java.lang.Runnable> workQueue
-
textCheckerV2
private final TextChecker textCheckerV2
-
config
private final HTTPServerConfig config
-
reqCounter
private final RequestCounter reqCounter
-
-
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 interfacecom.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
-
-