Class SpincastUndertowServer
- All Implemented Interfaces:
Server
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSpincastUndertowServer(SpincastUndertowUtils spincastUndertowUtils, SpincastConfig config, SpincastUndertowConfig spincastUndertowConfig, FrontController frontController, SpincastUtils spincastUtils, CookieFactory cookieFactory, CorsHandlerFactory corsHandlerFactory, GzipCheckerHandlerFactory gzipCheckerHandlerFactory, SkipResourceOnQueryStringHandlerFactory skipResourceOnQueryStringHandlerFactory, SpincastResourceHandlerFactory spincastResourceHandlerFactory, CacheBusterRemovalHandlerFactory cacheBusterRemovalHandlerFactory, SpincastClassPathResourceManagerFactory fileClassPathResourceManagerFactory, SpincastHttpAuthIdentityManagerFactory spincastHttpAuthIdentityManagerFactory, WebsocketEndpointFactory spincastWebsocketEndpointFactory, SSLContextFactory sslContextFactory) Constructor -
Method Summary
Modifier and TypeMethodDescriptionprotected io.undertow.Undertow.BuilderaddBuilderOptions(io.undertow.Undertow.Builder builder) voidaddCookies(Object exchange, Map<String, Cookie> cookies) Adds cookies.voidaddHttpAuthentication(String realmName, String username, String password) Adds a user to an HTTP protected realm.protected voidaddHttpListener(io.undertow.Undertow.Builder builder, String serverHost, int httpServerPort) protected voidaddHttpsListener(io.undertow.Undertow.Builder builder, String serverHost, int httpsServerPort) protected voidaddMaxEntitySize(io.undertow.Undertow.Builder builder) voidaddStaticResourceToServe(StaticResource<?> staticResource) Adds a static resource to serve directly by the server.protected io.undertow.server.HttpServerExchangecastExchange(Object exchange) io.undertow.util.HeaderMapconvertHeadersToUndertowHeaderMap(Map<String, List<String>> headers) io.undertow.util.HttpStringconvertHttpMethodToUndertowHttpString(HttpMethod httpMethod) voidcreateHttpAuthenticationRealm(String pathPrefix, String realmName) Creates HTTP authentication protection (realm) for the specified path prefix.protected io.undertow.server.handlers.LearningPushHandlerprotected Pathprotected WebsocketEndpointHandlercreateUndertowWebsocketEndpointHandler(String endpointId, WebsocketEndpointHandler appHandler) protected voidenableHttp2(io.undertow.Undertow.Builder builder) voidEnds the exchange.voidflushBytes(Object exchange, byte[] bytes, boolean end) Flushes some bytes to the response.booleanforceRequestSizeValidation(Object exchangeObj) Is the request size valid?protected CacheBusterRemovalHandlerHandler to remove cache busters from the request's URL.protected CacheBusterRemovalHandlerFactoryprotected io.undertow.io.IoCallbackprotected SpincastConfiggetContentTypeBestMatch(Object exchangeObj) Gets the bestContent-Typeto use for the current request.protected Stringprotected CookieFactorygetCookies(Object exchange) Gets the request cookies values.protected CorsHandlerFactoryprotected io.undertow.io.IoCallbackprotected SpincastClassPathResourceManagerFactoryprotected io.undertow.server.HttpHandlerThe very first handler considered by Undertow.protected io.undertow.server.handlers.form.FormDatagetFormData(io.undertow.server.HttpServerExchange exchange) May return NULL.getFormData(Object exchangeObj) The form data, if any.protected io.undertow.server.handlers.form.FormParserFactoryprotected FrontControllergetFullUrlOriginal(Object exchangeObj) The full encoded URL of the original, non proxied, request, including the queryString.getFullUrlOriginal(Object exchangeObj, boolean keepCacheBusters) The full encoded URL of the original, non proxied, request, including the queryString.getFullUrlProxied(Object exchangeObj) The full encoded URL of the potentially proxied request, including the queryString.getFullUrlProxied(Object exchangeObj, boolean keepCacheBusters) The full encoded URL of the potentially proxied request, including the queryString.protected GzipCheckerHandlerFactoryprotected io.undertow.server.handlers.PathHandlerHandler to check for HTTP authentication requirement.Returns the existing HTTP authentication realms, the key being the realm's name and the value being the prefix path associated to this realm.protected io.undertow.server.HttpHandlerprotected Map<String,SpincastHttpAuthIdentityManager> getHttpMethod(Object exchange) Gets the HTTP method associated with the request.Gets the IP of the current request.protected io.undertow.server.HttpHandlerprotected intprotected SpincastHttpAuthIdentityManagergetQueryStringParams(Object exchange) Gets the queryString parameters.getRawInputStream(Object exchangeObj) The raw InputStream of the current request.protected StringgetRealmNameToDisplay(String pathPrefix, String realmName) The realm name to display.getRequestHeaders(Object exchangeObj) The names of the headers are case insensitive.getRequestScheme(Object exchange) Gets the request scheme, "http" for example.getResponseHeaders(Object exchangeObj) Gets the response headers.protected intprotected io.undertow.Undertow.Builderprotected intprotected SkipResourceOnQueryStringHandlerFactoryprotected io.undertow.server.HttpHandlerprotected SpincastHttpAuthIdentityManagerFactoryprotected SpincastResourceHandlerFactoryprotected SpincastUndertowConfigprotected SpincastUndertowUtilsprotected SpincastUtilsprotected WebsocketEndpointFactoryprotected SSLContextFactoryprotected longgetStaticResourceServed(String urlPath) Gets a static resource served directly by the server, using its path.protected io.undertow.server.handlers.PathHandlerSet<StaticResource<?>>Gets all static resource served directly by the server.protected Map<String,StaticResource<?>> getUploadedFiles(Object exchangeObj) The uploaded files, if any.protected ObjectgetWebsocketEndpointCreationLock(String endpointId) Gets the creation/close lock for a specific Websocket endpoint.getWebsocketEndpointManager(String endpointId) Returns the manager for a Websockets endpoint.Returns the managers of the existing Websockets endpoints.protected Map<String,WebsocketEndpoint> protected booleanisPushSupported(io.undertow.server.ServerConnection connection) booleanisResponseClosed(Object exchange) Is the response closed?booleanisResponseHeadersSent(Object exchange) Are the response headers sent?booleanIs this server running (started)?voidpush(Object exchangeObj, Set<ResourceToPush> resourcesToPush) IfHTTP/2is used, you can push extra resources at the same time you response to a request.protected voidpushResource(io.undertow.server.ServerConnection connection, String path, io.undertow.util.HttpString httpMethod, io.undertow.util.HeaderMap headerMap) voidRemoves all static resources served directly by the server.voidremoveHttpAuthentication(String username) Removes a user from all HTTP protected realms.voidremoveHttpAuthentication(String username, String realmName) Removes a user to an HTTP protected realm.voidremoveResponseHeader(Object exchange, String name) Removes a response header.protected voidremoveStaticResource(StaticResourceType staticResourceType, String urlPath) voidremoveStaticResourcesServed(StaticResourceType staticResourceType, String urlPath) Removes a static resource served directly by the server.protected voidsendPushHeaders(io.undertow.server.HttpServerExchange exchange, ResourceToPush resourceToPush) In case the server is behind a reverse-proxy such as Nginx: it is this proxy that will do the actual push of the resource.protected voidvoidsetResponseHeader(Object exchangeObj, String name, List<String> values) Sets a response header.voidSets the response headers.voidsetResponseStatusCode(Object exchange, int statusCode) Sets the response status code.voidstart()Starts the server.voidstop()Stops the servervoidstop(boolean sendClosingMessageToPeers) Stops the servervoidwebsocketCloseEndpoint(String endpointId) Closes a Websocket endpoint.voidwebsocketCloseEndpoint(String endpointId, int closingCode, String closingReason) Closes the entire Websocket endpoint.voidwebsocketConnection(Object exchangeObj, String endpointId, String peerId) Transforms the request to a peer Websocket connection on the endpoint 'endpointId'.websocketCreateEndpoint(String endpointId, WebsocketEndpointHandler appEndpointHandler) Creates a new Websocket endpoint.
-
Field Details
-
logger
protected static final org.slf4j.Logger logger -
UNDERTOW_EXCEPTION_CODE_REQUEST_TOO_LARGE
- See Also:
-
EXCHANGE_VARIABLE_EXCHANGE_COMPLETED
-
-
Constructor Details
-
SpincastUndertowServer
@Inject public SpincastUndertowServer(SpincastUndertowUtils spincastUndertowUtils, SpincastConfig config, SpincastUndertowConfig spincastUndertowConfig, FrontController frontController, SpincastUtils spincastUtils, CookieFactory cookieFactory, CorsHandlerFactory corsHandlerFactory, GzipCheckerHandlerFactory gzipCheckerHandlerFactory, SkipResourceOnQueryStringHandlerFactory skipResourceOnQueryStringHandlerFactory, SpincastResourceHandlerFactory spincastResourceHandlerFactory, CacheBusterRemovalHandlerFactory cacheBusterRemovalHandlerFactory, SpincastClassPathResourceManagerFactory fileClassPathResourceManagerFactory, SpincastHttpAuthIdentityManagerFactory spincastHttpAuthIdentityManagerFactory, WebsocketEndpointFactory spincastWebsocketEndpointFactory, SSLContextFactory sslContextFactory) Constructor
-
-
Method Details
-
getSpincastUndertowUtils
-
getConfig
-
getSpincastUndertowConfig
-
getFrontController
-
getSpincastUtils
-
getCookieFactory
-
getCorsHandlerFactory
-
getGzipCheckerHandlerFactory
-
getSkipResourceOnQueryStringHandlerFactory
-
getSpincastResourceHandlerFactory
-
getCacheBusterRemovalHandlerFactory
-
getFileClassPathResourceManagerFactory
-
getSpincastHttpAuthIdentityManagerFactory
-
getSpincastWebsocketEndpointFactory
-
getStaticResourcesServedByUrlPath
-
getHttpAuthIdentityManagersByRealmName
-
getWebsocketEndpointsMap
-
getHttpAuthActiveRealms
-
getSslContextFactory
-
getHttpAuthenticationRealms
Description copied from interface:ServerReturns the existing HTTP authentication realms, the key being the realm's name and the value being the prefix path associated to this realm.The map is immutable.
- Specified by:
getHttpAuthenticationRealmsin interfaceServer
-
getFormParserFactory
protected io.undertow.server.handlers.form.FormParserFactory getFormParserFactory() -
createUndertowTempDir
-
isRunning
public boolean isRunning()Description copied from interface:ServerIs this server running (started)? -
start
public void start()Description copied from interface:ServerStarts the server. -
getServerStartTryNbr
protected int getServerStartTryNbr() -
getStartServerSleepMilliseconds
protected long getStartServerSleepMilliseconds() -
getServerBuilder
protected io.undertow.Undertow.Builder getServerBuilder() -
addHttpListener
protected void addHttpListener(io.undertow.Undertow.Builder builder, String serverHost, int httpServerPort) -
addHttpsListener
protected void addHttpsListener(io.undertow.Undertow.Builder builder, String serverHost, int httpsServerPort) -
addBuilderOptions
protected io.undertow.Undertow.Builder addBuilderOptions(io.undertow.Undertow.Builder builder) -
addMaxEntitySize
protected void addMaxEntitySize(io.undertow.Undertow.Builder builder) -
enableHttp2
protected void enableHttp2(io.undertow.Undertow.Builder builder) -
getFinalHandler
protected io.undertow.server.HttpHandler getFinalHandler()The very first handler considered by Undertow. -
getCacheBusterRemovalHandler
Handler to remove cache busters from the request's URL. -
getHttpAuthenticationHandler
protected io.undertow.server.handlers.PathHandler getHttpAuthenticationHandler()Handler to check for HTTP authentication requirement. -
getHttpAuthHandlerNextHandler
protected io.undertow.server.HttpHandler getHttpAuthHandlerNextHandler() -
getLearningPushHandler
protected io.undertow.server.HttpHandler getLearningPushHandler() -
createLearningPushHandler
protected io.undertow.server.handlers.LearningPushHandler createLearningPushHandler() -
createHttpAuthenticationRealm
Description copied from interface:ServerCreates HTTP authentication protection (realm) for the specified path prefix.- Specified by:
createHttpAuthenticationRealmin interfaceServerrealmName- The name of the realm. Must be unique on this server, otherwise an exception is thrown. This allows the application to add user to the realm using its name.
-
getRealmNameToDisplay
The realm name to display. -
getOrCreateHttpAuthIdentityManagersByRealmName
protected SpincastHttpAuthIdentityManager getOrCreateHttpAuthIdentityManagersByRealmName(String realmName) -
addHttpAuthentication
Description copied from interface:ServerAdds a user to an HTTP protected realm.- Specified by:
addHttpAuthenticationin interfaceServer
-
removeHttpAuthentication
Description copied from interface:ServerRemoves a user to an HTTP protected realm.- Specified by:
removeHttpAuthenticationin interfaceServer
-
removeHttpAuthentication
Description copied from interface:ServerRemoves a user from all HTTP protected realms.- Specified by:
removeHttpAuthenticationin interfaceServer
-
getSpincastFrontControllerHandler
protected io.undertow.server.HttpHandler getSpincastFrontControllerHandler() -
stop
public void stop()Description copied from interface:ServerStops the serverWill try to send a "closing" message to any WebSocket peer before closing their connections.
-
stop
public void stop(boolean sendClosingMessageToPeers) Description copied from interface:ServerStops the server -
getSecondsToWaitForWebSocketEndpointsToBeProperlyClosedBeforeKillingTheServer
protected int getSecondsToWaitForWebSocketEndpointsToBeProperlyClosedBeforeKillingTheServer() -
getMilliSecondsIncrementWhenWaitingForWebSocketEndpointsToBeProperlyClosedBeforeKillingTheServer
protected int getMilliSecondsIncrementWhenWaitingForWebSocketEndpointsToBeProperlyClosedBeforeKillingTheServer() -
sendWebsocketEnpointsClosedWhenServerStops
protected void sendWebsocketEnpointsClosedWhenServerStops() -
getStaticResourcesPathHandler
protected io.undertow.server.handlers.PathHandler getStaticResourcesPathHandler() -
addStaticResourceToServe
Description copied from interface:ServerAdds a static resource to serve directly by the server.- Specified by:
addStaticResourceToServein interfaceServer
-
removeStaticResourcesServed
Description copied from interface:ServerRemoves a static resource served directly by the server.- Specified by:
removeStaticResourcesServedin interfaceServer
-
removeAllStaticResourcesServed
public void removeAllStaticResourcesServed()Description copied from interface:ServerRemoves all static resources served directly by the server.- Specified by:
removeAllStaticResourcesServedin interfaceServer
-
removeStaticResource
-
getStaticResourceServed
Description copied from interface:ServerGets a static resource served directly by the server, using its path.- Specified by:
getStaticResourceServedin interfaceServer
-
getStaticResourcesServed
Description copied from interface:ServerGets all static resource served directly by the server.- Specified by:
getStaticResourcesServedin interfaceServer
-
getHttpMethod
Description copied from interface:ServerGets the HTTP method associated with the request.- Specified by:
getHttpMethodin interfaceServer
-
castExchange
-
getContentTypeBestMatch
Description copied from interface:ServerGets the bestContent-Typeto use for the current request.- Specified by:
getContentTypeBestMatchin interfaceServer
-
getFullUrlProxied
Description copied from interface:ServerThe full encoded URL of the potentially proxied request, including the queryString. Cache buster codes are removed, if there were any.Is a reverse proxy is used (such as Nginx or Apache), this is going to be the proxied URL, as forwarded by the reverse proxy. If no reverse proxy is used, this is going to be the original URL, as seen by the user.
Even if the request is forwarded elsewhere in the framework, this URL won't change, it will still be the original one.
- Specified by:
getFullUrlProxiedin interfaceServer
-
getFullUrlProxied
Description copied from interface:ServerThe full encoded URL of the potentially proxied request, including the queryString.Is a reverse proxy is used (such as Nginx or Apache), this is going to be the proxied URL, as forwarded by the reverse proxy. If no reverse proxy is used, this is going to be the original URL, as seen by the user.
Even if the request is forwarded elsewhere in the framework, this URL won't change, it will still be the original one.
- Specified by:
getFullUrlProxiedin interfaceServerkeepCacheBusters- iftrue, the returned URL will contain the cache buster codes, if there were any. The default behavior is to automatically remove them.
-
getFullUrlOriginal
Description copied from interface:ServerThe full encoded URL of the original, non proxied, request, including the queryString. Cache buster codes are removed, if there were any.This is going to be the *original* URL, as seen by the user, even if a reverse proxy is used (such as Nginx or Apache).
Even if the request is forwarded elsewhere in the framework, this URL won't change, it will still be the original one.
- Specified by:
getFullUrlOriginalin interfaceServer
-
getFullUrlOriginal
Description copied from interface:ServerThe full encoded URL of the original, non proxied, request, including the queryString.This is going to be the *original* URL, as seen by the user, even if a reverse proxy is used (such as Nginx or Apache).
Even if the request is forwarded elsewhere in the framework, this URL won't change, it will still be the original one.
- Specified by:
getFullUrlOriginalin interfaceServerkeepCacheBusters- iftrue, the returned URL will contain the cache buster codes, if there were any. The default behavior is to automatically remove them.
-
setResponseHeader
Description copied from interface:ServerSets a response header. Override any existing one with the same name.- Specified by:
setResponseHeaderin interfaceServer
-
setResponseHeaders
Description copied from interface:ServerSets the response headers. Override any existing ones.- Specified by:
setResponseHeadersin interfaceServer
-
getResponseHeaders
Description copied from interface:ServerGets the response headers.- Specified by:
getResponseHeadersin interfaceServer
-
removeResponseHeader
Description copied from interface:ServerRemoves a response header.- Specified by:
removeResponseHeaderin interfaceServer
-
setResponseStatusCode
Description copied from interface:ServerSets the response status code.- Specified by:
setResponseStatusCodein interfaceServer
-
getDoNothingCallback
protected io.undertow.io.IoCallback getDoNothingCallback() -
getCloseExchangeCallback
protected io.undertow.io.IoCallback getCloseExchangeCallback() -
flushBytes
Description copied from interface:ServerFlushes some bytes to the response.- Specified by:
flushBytesin interfaceServerend- iftrue, the exchange will be closed and nothing more can be send.
-
end
Description copied from interface:ServerEnds the exchange. Nothing more can be send. -
isResponseClosed
Description copied from interface:ServerIs the response closed?- Specified by:
isResponseClosedin interfaceServer
-
isResponseHeadersSent
Description copied from interface:ServerAre the response headers sent?- Specified by:
isResponseHeadersSentin interfaceServer
-
getRequestScheme
Description copied from interface:ServerGets the request scheme, "http" for example.- Specified by:
getRequestSchemein interfaceServer
-
addCookies
Description copied from interface:ServerAdds cookies.- Specified by:
addCookiesin interfaceServer
-
getCookies
Description copied from interface:ServerGets the request cookies values.- Specified by:
getCookiesin interfaceServer
-
getCookieEncoding
-
getQueryStringParams
Description copied from interface:ServerGets the queryString parameters.- Specified by:
getQueryStringParamsin interfaceServer
-
getRawInputStream
Description copied from interface:ServerThe raw InputStream of the current request.- Specified by:
getRawInputStreamin interfaceServer
-
getFormData
protected io.undertow.server.handlers.form.FormData getFormData(io.undertow.server.HttpServerExchange exchange) May return NULL. -
getFormData
Description copied from interface:ServerThe form data, if any.- Specified by:
getFormDatain interfaceServer
-
getUploadedFiles
Description copied from interface:ServerThe uploaded files, if any. The key of the map if the HTML'snameattribute.- Specified by:
getUploadedFilesin interfaceServer
-
forceRequestSizeValidation
Description copied from interface:ServerIs the request size valid?- Specified by:
forceRequestSizeValidationin interfaceServer
-
getRequestHeaders
The names of the headers are case insensitive.- Specified by:
getRequestHeadersin interfaceServer
-
getWebsocketEndpointCreationLock
Gets the creation/close lock for a specific Websocket endpoint. -
websocketCreateEndpoint
public WebsocketEndpointManager websocketCreateEndpoint(String endpointId, WebsocketEndpointHandler appEndpointHandler) Description copied from interface:ServerCreates a new Websocket endpoint.- Specified by:
websocketCreateEndpointin interfaceServer- Returns:
- the manager for this endpoint.
-
createUndertowWebsocketEndpointHandler
protected WebsocketEndpointHandler createUndertowWebsocketEndpointHandler(String endpointId, WebsocketEndpointHandler appHandler) -
websocketCloseEndpoint
Description copied from interface:ServerCloses a Websocket endpoint. No more connections will be accepter- Specified by:
websocketCloseEndpointin interfaceServer
-
websocketCloseEndpoint
Description copied from interface:ServerCloses the entire Websocket endpoint. All peer connections of this endpoint will be closed.- Specified by:
websocketCloseEndpointin interfaceServerclosingCode- The closing code.closingReason- The closing reason.
-
websocketConnection
Description copied from interface:ServerTransforms the request to a peer Websocket connection on the endpoint 'endpointId'.- Specified by:
websocketConnectionin interfaceServer
-
getWebsocketEndpointManagers
Description copied from interface:ServerReturns the managers of the existing Websockets endpoints.- Specified by:
getWebsocketEndpointManagersin interfaceServer
-
getWebsocketEndpointManager
Description copied from interface:ServerReturns the manager for a Websockets endpoint.- Specified by:
getWebsocketEndpointManagerin interfaceServer- Returns:
- the manager or
nullif not found.
-
getIp
Description copied from interface:ServerGets the IP of the current request. -
convertHttpMethodToUndertowHttpString
-
convertHeadersToUndertowHeaderMap
-
push
Description copied from interface:ServerIfHTTP/2is used, you can push extra resources at the same time you response to a request.If the embedded server deals with a HTTTP/2 request, it will push the extra resources by itself. If it deals with an HTTP/1.X request (for example if it is behind a reverse-proxy) it will send
Linkheaders to the potential proxy in front of it and it is the proxy that will be in charge of doing the actual push.Beware that pushing resources does not always result in an increase of performance and may lead to wasted bandwidth (the client may decide to not use the pushed resources).
-
isPushSupported
protected boolean isPushSupported(io.undertow.server.ServerConnection connection) -
pushResource
protected void pushResource(io.undertow.server.ServerConnection connection, String path, io.undertow.util.HttpString httpMethod, io.undertow.util.HeaderMap headerMap) -
sendPushHeaders
protected void sendPushHeaders(io.undertow.server.HttpServerExchange exchange, ResourceToPush resourceToPush) In case the server is behind a reverse-proxy such as Nginx: it is this proxy that will do the actual push of the resource. We tell it to do so using special response headers.
-