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 Stringprivate final HTTPServerConfigprivate static final Stringprivate final ErrorRequestLimiterprivate static final org.slf4j.Loggerprivate final RequestCounterprivate final RequestLimiterprivate final TextCheckerprivate 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 StringgetRealRemoteAddressOrNull(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 StringgetTextOrDataSizeMessage(Map<String, String> parameters) voidhandle(com.sun.net.httpserver.HttpExchange httpExchange) private booleanhasCause(Exception e, Class<AuthException> clazz) private voidlogError(String errorMessage, int code, Map<String, String> params, com.sun.net.httpserver.HttpExchange httpExchange) private voidlogError(String errorMessage, int code, Map<String, String> params, com.sun.net.httpserver.HttpExchange httpExchange, boolean logToDb) private voidlogError(String remoteAddress, Exception e, int errorCode, com.sun.net.httpserver.HttpExchange httpExchange, Map<String, String> params, boolean textLoggingAllowed, boolean logStacktrace, long runtimeMillis) private voidlogToDatabase(Map<String, String> params, String message) parseQuery(String query, com.sun.net.httpserver.HttpExchange httpExchange) private StringreaderToString(Reader reader, int maxTextLength) private void(package private) voidshutdown()private booleansiteMatches(String referrer, String blockedRef) private booleanworkQueueFull(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:
handlein 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
-