Class HTTPServerConfig
java.lang.Object
org.languagetool.server.HTTPServerConfig
- Direct Known Subclasses:
HTTPSServerConfig
- Since:
- 2.0
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Stringprotected Stringprotected intprotected longprotected Stringprotected booleanprotected Stringprotected Stringprotected Stringstatic final Stringstatic final intThe default port on which the server is running (8081).protected Fileprotected Fileprotected org.languagetool.GlobalConfigprotected List<org.languagetool.Language> protected Stringprotected intprotected intprotected int(package private) static final Stringprotected Fileprotected intprotected longprotected longprotected floatprotected intprotected intprotected intprotected intprotected intprotected intprotected HTTPServerConfig.Modeprotected File(package private) static final Stringprotected booleanprotected intprotected booleanprotected intprotected booleanprotected intprotected booleanprotected intprotected intprotected intprotected Fileprotected Stringprotected URIprotected booleanprotected booleanprotected intprotected intprotected booleanprotected boolean(package private) static final Stringprotected File -
Constructor Summary
ConstructorsConstructorDescriptionCreate a server configuration for the default port (DEFAULT_PORT).HTTPServerConfig(int serverPort) HTTPServerConfig(int serverPort, boolean verbose) HTTPServerConfig(String[] args) Parse command line options. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddDynamicLanguages(Properties props) @Nullable String@Nullable StringValue to set as the "Access-Control-Allow-Origin" http header.A list of HTTP referrers that are blocked and will only get an error message.(package private) intCache size (in number of sentences).(package private) longCache entry TTL; refreshed on access; in seconds(package private) @Nullable String(package private) boolean(package private) @Nullable String(package private) @Nullable String(package private) @Nullable String@Nullable FileGet binary path for fasttext language detection@Nullable FileGet model path for fasttext language detection(package private) List<org.languagetool.Language> Languages for whichgetHiddenMatchesServer()will be queried.(package private) @Nullable StringURL of server that is queried to add additional (but hidden) matches to the result.(package private) intPeriod to skip requests to hidden matches server after a timeout (in milliseconds)(package private) intTimeout in milliseconds for queryinggetHiddenMatchesServer().(package private) intsince 4.4(package private) @Nullable FileGet language model directory (which contains '3grams' sub directory) ornull.(package private) int(package private) long(package private) long(package private) floatMaximum errors per word rate, checking will stop if the rate is higher.int(package private) intMaximum number of spelling errors for which a suggestion will be generated per check.(package private) intLimit for maximum text length - text cannot be longer than this, even if user has valid secret token.(package private) int(package private) intMaximum text length for users that can identify themselves with an API key.(package private) int(package private) HTTPServerConfig.ModegetMode()Get base directory for neural network models ornullprotected StringgetOptionalProperty(Properties props, String propertyName, String defaultValue) intintgetPort()intprotected StringgetProperty(Properties props, String propertyName, File config) (package private) int(package private) int(package private) int(package private) @Nullable File(package private) @Nullable StringOptional JWT token key.@Nullable URIint(package private) int(package private) boolean(package private) @Nullable FileGet word2vec model directory (which contains 'en' sub directories and final_embeddings.txt and dictionary.txt) ornull.booleanbooleanbooleanbooleanboolean(package private) booleanbooleanprivate voidparseConfigFile(File file, boolean loadLangModel, boolean loadWord2VecModel, boolean loadNeuralNetworkModel) voidvoidsetAllowOriginUrl(String allowOriginUrl) (package private) voidsetBlockedReferrers(List<String> blockedReferrers) (package private) voidsetCacheSize(int sentenceCacheSize) Set cache size (in number of sentences).(package private) voidsetCacheTTLSeconds(long cacheTTLSeconds) Set cache entry TTL in seconds(package private) voidsetDatabaseDriver(String dbDriver) (package private) voidsetDatabaseLogging(boolean logging) Whether meta data about each search (like in the logfile) should be logged to the database.(package private) voidsetDatabasePassword(String dbPassword) (package private) voidsetDatabaseUrl(String dbUrl) (package private) voidsetDatabaseUsername(String dbUsername) voidsetFasttextBinary(File binary) Set binary path for fasttext language detectionvoidsetFasttextModel(File model) Set model path for fasttext language detectionprivate voidsetFasttextPaths(String fasttextModelPath, String fasttextBinaryPath) voidsetLanguageModelDirectory(String langModelDir) (package private) voidsetMaxCheckThreads(int maxCheckThreads) (package private) voidsetMaxCheckTimeMillis(int maxCheckTimeMillis) voidsetMaxPipelinePoolSize(int maxPipelinePoolSize) voidsetMaxTextHardLength(int len) voidsetMaxTextLength(int len) private voidsetNeuralNetworkModelDir(String nnModelDir) voidsetPipelineCaching(boolean pipelineCaching) voidsetPipelineExpireTime(int pipelineExpireTime) voidsetPipelinePrewarming(boolean pipelinePrewarming) (package private) voidsetSecretTokenKey(String secretTokenKey) voidsetServerURL(@Nullable String url) (package private) voidsetTrustXForwardForHeader(boolean trustXForwardForHeader) Set totrueif this is running behind a (reverse) proxy which sets theX-forwarded-forHTTP header.private voidsetWord2VecModelDirectory(String w2vModelDir)
-
Field Details
-
DEFAULT_HOST
- See Also:
-
DEFAULT_PORT
public static final int DEFAULT_PORTThe default port on which the server is running (8081).- See Also:
-
LANGUAGE_MODEL_OPTION
- See Also:
-
WORD2VEC_MODEL_OPTION
- See Also:
-
NN_MODEL_OPTION
- See Also:
-
verbose
protected boolean verbose -
publicAccess
protected boolean publicAccess -
port
protected int port -
allowOriginUrl
-
serverURL
-
maxTextLength
protected int maxTextLength -
maxTextHardLength
protected int maxTextHardLength -
maxTextLengthWithApiKey
protected int maxTextLengthWithApiKey -
secretTokenKey
-
maxCheckTimeMillis
protected long maxCheckTimeMillis -
maxCheckTimeWithApiKeyMillis
protected long maxCheckTimeWithApiKeyMillis -
maxCheckThreads
protected int maxCheckThreads -
mode
-
languageModelDir
-
word2vecModelDir
-
pipelineCaching
protected boolean pipelineCaching -
pipelinePrewarming
protected boolean pipelinePrewarming -
maxPipelinePoolSize
protected int maxPipelinePoolSize -
pipelineExpireTime
protected int pipelineExpireTime -
fasttextModel
-
fasttextBinary
-
neuralNetworkModelDir
-
requestLimit
protected int requestLimit -
requestLimitInBytes
protected int requestLimitInBytes -
timeoutRequestLimit
protected int timeoutRequestLimit -
requestLimitPeriodInSeconds
protected int requestLimitPeriodInSeconds -
ipFingerprintFactor
protected int ipFingerprintFactor -
trustXForwardForHeader
protected boolean trustXForwardForHeader -
maxWorkQueueSize
protected int maxWorkQueueSize -
rulesConfigFile
-
cacheSize
protected int cacheSize -
cacheTTLSeconds
protected long cacheTTLSeconds -
maxErrorsPerWordRate
protected float maxErrorsPerWordRate -
maxSpellingSuggestions
protected int maxSpellingSuggestions -
blockedReferrers
-
dbDriver
-
dbUrl
-
dbUsername
-
dbPassword
-
dbLogging
protected boolean dbLogging -
prometheusMonitoring
protected boolean prometheusMonitoring -
prometheusPort
protected int prometheusPort -
globalConfig
protected org.languagetool.GlobalConfig globalConfig -
disabledRuleIds
-
skipLoggingRuleMatches
protected boolean skipLoggingRuleMatches -
skipLoggingChecks
protected boolean skipLoggingChecks -
slowRuleLoggingThreshold
protected int slowRuleLoggingThreshold -
abTest
-
-
Constructor Details
-
HTTPServerConfig
public HTTPServerConfig()Create a server configuration for the default port (DEFAULT_PORT). -
HTTPServerConfig
public HTTPServerConfig(int serverPort) - Parameters:
serverPort- the port to bind to- Since:
- 2.8
-
HTTPServerConfig
public HTTPServerConfig(int serverPort, boolean verbose) - Parameters:
serverPort- the port to bind toverbose- when set to true, the input text will be logged in case there is an exception
-
HTTPServerConfig
HTTPServerConfig(String[] args) Parse command line options.
-
-
Method Details
-
parseConfigFile
private void parseConfigFile(File file, boolean loadLangModel, boolean loadWord2VecModel, boolean loadNeuralNetworkModel) -
addDynamicLanguages
- Throws:
IOException
-
setLanguageModelDirectory
-
setWord2VecModelDirectory
-
setNeuralNetworkModelDir
-
setFasttextPaths
-
isVerbose
public boolean isVerbose() -
isPublicAccess
public boolean isPublicAccess() -
getPort
public int getPort() -
getAllowOriginUrl
Value to set as the "Access-Control-Allow-Origin" http header.nullwill not return that header at all. With*your server can be used from any other web site from Javascript/Ajax (search Cross-origin resource sharing (CORS) for details). -
setAllowOriginUrl
- Since:
- 4.2
-
getServerURL
- Returns:
- prefix / base URL for API requests
- Since:
- 4.8
-
setServerURL
- Parameters:
url- prefix / base URL for API requests- Since:
- 4.8
-
setMaxTextLength
public void setMaxTextLength(int len) - Parameters:
len- the maximum text length allowed (in number of characters), texts that are longer will cause an exception when being checked, unless the user can provide a JWT 'token' parameter with a 'maxTextLength' claim
-
setMaxTextHardLength
public void setMaxTextHardLength(int len) - Parameters:
len- the maximum text length allowed (in number of characters), texts that are longer will cause an exception when being checked even if the user can provide a JWT token- Since:
- 3.9
-
getMaxTextLength
int getMaxTextLength() -
getMaxTextLengthWithApiKey
@Experimental int getMaxTextLengthWithApiKey()Maximum text length for users that can identify themselves with an API key.- Since:
- 4.2
-
getMaxTextHardLength
int getMaxTextHardLength()Limit for maximum text length - text cannot be longer than this, even if user has valid secret token.- Since:
- 3.9
-
getSecretTokenKey
Optional JWT token key. Can be used to circumvent the maximum text length (but not maxTextHardLength).- Since:
- 3.9
-
setSecretTokenKey
- Since:
- 4.0
-
getRequestLimit
int getRequestLimit() -
getTimeoutRequestLimit
int getTimeoutRequestLimit()- Since:
- 4.0
-
getRequestLimitInBytes
int getRequestLimitInBytes()- Since:
- 4.0
-
getRequestLimitPeriodInSeconds
int getRequestLimitPeriodInSeconds() -
getIpFingerprintFactor
int getIpFingerprintFactor()since 4.4 -
setMaxCheckTimeMillis
void setMaxCheckTimeMillis(int maxCheckTimeMillis) - Parameters:
maxCheckTimeMillis- The maximum duration allowed for a single check in milliseconds, checks that take longer will stop with an exception. Use-1for no limit.- Since:
- 2.6
-
getMaxCheckTimeMillis
long getMaxCheckTimeMillis()- Since:
- 2.6
-
getMaxCheckTimeWithApiKeyMillis
@Experimental long getMaxCheckTimeWithApiKeyMillis()- Since:
- 4.2
-
getLanguageModelDir
Get language model directory (which contains '3grams' sub directory) ornull.- Since:
- 2.7
-
getWord2VecModelDir
Get word2vec model directory (which contains 'en' sub directories and final_embeddings.txt and dictionary.txt) ornull.- Since:
- 4.0
-
getNeuralNetworkModelDir
Get base directory for neural network models ornull- Since:
- 4.4
-
getFasttextModel
Get model path for fasttext language detection- Since:
- 4.3
-
setFasttextModel
-
getFasttextBinary
Get binary path for fasttext language detection- Since:
- 4.3
-
setFasttextBinary
Set binary path for fasttext language detection- Since:
- 4.4
-
getMode
HTTPServerConfig.Mode getMode()- Since:
- 2.7
-
setMaxCheckThreads
void setMaxCheckThreads(int maxCheckThreads) - Parameters:
maxCheckThreads- The maximum number of threads serving requests running at the same time. If there are more requests, they will be queued until a thread can work on them.- Since:
- 2.7
-
getMaxCheckThreads
int getMaxCheckThreads()- Since:
- 2.7
-
setTrustXForwardForHeader
void setTrustXForwardForHeader(boolean trustXForwardForHeader) Set totrueif this is running behind a (reverse) proxy which sets theX-forwarded-forHTTP header. The last IP address (but not local IP addresses) in that header will then be used for enforcing a request limitation.- Since:
- 2.8
-
getTrustXForwardForHeader
boolean getTrustXForwardForHeader()- Since:
- 2.8
-
getMaxWorkQueueSize
int getMaxWorkQueueSize()- Since:
- 2.9
-
isPipelineCachingEnabled
public boolean isPipelineCachingEnabled()- Since:
- 4.4 Cache initalized JLanguageTool instances and share between non-parallel requests with identical paramenters Improves response time (especially when dealing with many small requests without specific settings), but increases memory usage
-
isPipelinePrewarmingEnabled
public boolean isPipelinePrewarmingEnabled()- Since:
- 4.4 Before starting to listen for requests, create a few pipelines for frequently used request settings and run simple checks on them; prevents long response time / request overload on the first real incoming requests
-
getMaxPipelinePoolSize
public int getMaxPipelinePoolSize()- Since:
- 4.4 Keep pipelines ready for this many different request settings
-
getPipelineExpireTime
public int getPipelineExpireTime()- Since:
- 4.4 Expire pipelines for a specific request setting after this many seconds without any matching request elapsed
-
setPipelineCaching
public void setPipelineCaching(boolean pipelineCaching) - Since:
- 4.4
-
setPipelinePrewarming
public void setPipelinePrewarming(boolean pipelinePrewarming) - Since:
- 4.4
-
setMaxPipelinePoolSize
public void setMaxPipelinePoolSize(int maxPipelinePoolSize) - Since:
- 4.4
-
setPipelineExpireTime
public void setPipelineExpireTime(int pipelineExpireTime) - Since:
- 4.4
-
getCacheSize
int getCacheSize()Cache size (in number of sentences).- Since:
- 3.7
-
setCacheSize
void setCacheSize(int sentenceCacheSize) Set cache size (in number of sentences).- Since:
- 4.2
-
getCacheTTLSeconds
long getCacheTTLSeconds()Cache entry TTL; refreshed on access; in seconds- Since:
- 4.6
-
setCacheTTLSeconds
void setCacheTTLSeconds(long cacheTTLSeconds) Set cache entry TTL in seconds- Since:
- 4.6
-
getMaxErrorsPerWordRate
float getMaxErrorsPerWordRate()Maximum errors per word rate, checking will stop if the rate is higher. For example, with a rate of 0.33, the checking would stop if the user's text has so many errors that more than every 3rd word causes a rule match. Note that this may not apply for very short texts.- Since:
- 4.0
-
getMaxSpellingSuggestions
int getMaxSpellingSuggestions()Maximum number of spelling errors for which a suggestion will be generated per check. It makes sense to limit this as generating suggestions is a CPU-heavy task.- Since:
- 4.2
-
getBlockedReferrers
-
setBlockedReferrers
-
getHiddenMatchesServer
URL of server that is queried to add additional (but hidden) matches to the result.- Since:
- 4.0
-
getHiddenMatchesServerTimeout
@Experimental int getHiddenMatchesServerTimeout()Timeout in milliseconds for queryinggetHiddenMatchesServer().- Since:
- 4.0
-
getHiddenMatchesServerFailTimeout
@Experimental int getHiddenMatchesServerFailTimeout()Period to skip requests to hidden matches server after a timeout (in milliseconds)- Since:
- 4.5
-
getHiddenMatchesLanguages
Languages for whichgetHiddenMatchesServer()will be queried.- Since:
- 4.0
-
getRulesConfigFile
- Returns:
- the file from which server rules configuration should be loaded, or
null - Since:
- 3.0
-
getDatabaseDriver
- Returns:
- the database driver name like
org.mariadb.jdbc.Driver, ornull - Since:
- 4.2
-
setDatabaseDriver
- Since:
- 4.2
-
getDatabaseUrl
- Returns:
- the database url like
jdbc:mysql://localhost:3306/languagetool, ornull - Since:
- 4.2
-
setDatabaseUrl
- Since:
- 4.2
-
getDatabaseUsername
- Returns:
- the database username, or
null - Since:
- 4.2
-
setDatabaseUsername
- Since:
- 4.2
-
getDatabasePassword
- Returns:
- the database password matching
getDatabaseUsername(), ornull - Since:
- 4.2
-
setDatabasePassword
- Since:
- 4.2
-
setDatabaseLogging
@Experimental void setDatabaseLogging(boolean logging) Whether meta data about each search (like in the logfile) should be logged to the database.- Since:
- 4.4
-
getDatabaseLogging
@Experimental boolean getDatabaseLogging()- Since:
- 4.4
-
isPrometheusMonitoring
public boolean isPrometheusMonitoring()- Returns:
- Since:
- 4.6
-
getPrometheusPort
public int getPrometheusPort()- Returns:
- Since:
- 4.6
-
getSlowRuleLoggingThreshold
@Experimental public int getSlowRuleLoggingThreshold()- Returns:
- threshold for rule computation time until a warning gets logged, in milliseconds
- Since:
- 4.5
-
isSkipLoggingRuleMatches
boolean isSkipLoggingRuleMatches()- Since:
- 4.5
-
isSkipLoggingChecks
public boolean isSkipLoggingChecks()- Since:
- 4.6
-
getDisabledRuleIds
-
getAbTest
- Since:
- 4.4 See if a specific A/B-Test is to be run
-
setAbTest
- Since:
- 4.4 Enable a specific A/B-Test to be run (or null to disable all tests)
-
getProperty
- Throws:
IllegalConfigurationException- if property is not set
-
getOptionalProperty
-