Class SpincastUndertowServer

java.lang.Object
org.spincast.plugins.undertow.SpincastUndertowServer
All Implemented Interfaces:
org.spincast.core.server.Server

public class SpincastUndertowServer extends Object implements org.spincast.core.server.Server
Server implementation using Undertow.
  • Field Details

    • logger

      protected static final org.slf4j.Logger logger
    • UNDERTOW_EXCEPTION_CODE_REQUEST_TOO_LARGE

      public static final String UNDERTOW_EXCEPTION_CODE_REQUEST_TOO_LARGE
      See Also:
    • EXCHANGE_VARIABLE_EXCHANGE_COMPLETED

      public static final String EXCHANGE_VARIABLE_EXCHANGE_COMPLETED
  • Constructor Details

  • Method Details

    • getSpincastUndertowUtils

      protected SpincastUndertowUtils getSpincastUndertowUtils()
    • getConfig

      protected org.spincast.core.config.SpincastConfig getConfig()
    • getSpincastUndertowConfig

      protected SpincastUndertowConfig getSpincastUndertowConfig()
    • getFrontController

      protected org.spincast.core.controllers.FrontController getFrontController()
    • getSpincastUtils

      protected org.spincast.core.utils.SpincastUtils getSpincastUtils()
    • getCookieFactory

      protected org.spincast.core.cookies.CookieFactory getCookieFactory()
    • getCorsHandlerFactory

      protected CorsHandlerFactory getCorsHandlerFactory()
    • getGzipCheckerHandlerFactory

      protected GzipCheckerHandlerFactory getGzipCheckerHandlerFactory()
    • getSkipResourceOnQueryStringHandlerFactory

      protected SkipResourceOnQueryStringHandlerFactory getSkipResourceOnQueryStringHandlerFactory()
    • getSpincastResourceHandlerFactory

      protected SpincastResourceHandlerFactory getSpincastResourceHandlerFactory()
    • getCacheBusterRemovalHandlerFactory

      protected CacheBusterRemovalHandlerFactory getCacheBusterRemovalHandlerFactory()
    • getFileClassPathResourceManagerFactory

      protected SpincastClassPathResourceManagerFactory getFileClassPathResourceManagerFactory()
    • getSpincastHttpAuthIdentityManagerFactory

      protected SpincastHttpAuthIdentityManagerFactory getSpincastHttpAuthIdentityManagerFactory()
    • getSpincastWebsocketEndpointFactory

      protected WebsocketEndpointFactory getSpincastWebsocketEndpointFactory()
    • getStaticResourcesServedByUrlPath

      protected Map<String,org.spincast.core.routing.StaticResource<?>> getStaticResourcesServedByUrlPath()
    • getHttpAuthIdentityManagersByRealmName

      protected Map<String,SpincastHttpAuthIdentityManager> getHttpAuthIdentityManagersByRealmName()
    • getWebsocketEndpointsMap

      protected Map<String,WebsocketEndpoint> getWebsocketEndpointsMap()
    • getHttpAuthActiveRealms

      protected Map<String,String> getHttpAuthActiveRealms()
    • getSslContextFactory

      protected org.spincast.core.utils.ssl.SSLContextFactory getSslContextFactory()
    • getHttpAuthenticationRealms

      public Map<String,String> getHttpAuthenticationRealms()
      Specified by:
      getHttpAuthenticationRealms in interface org.spincast.core.server.Server
    • getFormParserFactory

      protected io.undertow.server.handlers.form.FormParserFactory getFormParserFactory()
    • createUndertowTempDir

      protected Path createUndertowTempDir()
    • isRunning

      public boolean isRunning()
      Specified by:
      isRunning in interface org.spincast.core.server.Server
    • start

      public void start()
      Specified by:
      start in interface org.spincast.core.server.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

      protected CacheBusterRemovalHandler 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

      public void createHttpAuthenticationRealm(String pathPrefix, String realmName)
      Specified by:
      createHttpAuthenticationRealm in interface org.spincast.core.server.Server
    • getRealmNameToDisplay

      protected String getRealmNameToDisplay(String pathPrefix, String realmName)
      The realm name to display.
    • getOrCreateHttpAuthIdentityManagersByRealmName

      protected SpincastHttpAuthIdentityManager getOrCreateHttpAuthIdentityManagersByRealmName(String realmName)
    • addHttpAuthentication

      public void addHttpAuthentication(String realmName, String username, String password)
      Specified by:
      addHttpAuthentication in interface org.spincast.core.server.Server
    • removeHttpAuthentication

      public void removeHttpAuthentication(String username, String realmName)
      Specified by:
      removeHttpAuthentication in interface org.spincast.core.server.Server
    • removeHttpAuthentication

      public void removeHttpAuthentication(String username)
      Specified by:
      removeHttpAuthentication in interface org.spincast.core.server.Server
    • getSpincastFrontControllerHandler

      protected io.undertow.server.HttpHandler getSpincastFrontControllerHandler()
    • stop

      public void stop()
      Specified by:
      stop in interface org.spincast.core.server.Server
    • stop

      public void stop(boolean sendClosingMessageToPeers)
      Specified by:
      stop in interface org.spincast.core.server.Server
    • getSecondsToWaitForWebSocketEndpointsToBeProperlyClosedBeforeKillingTheServer

      protected int getSecondsToWaitForWebSocketEndpointsToBeProperlyClosedBeforeKillingTheServer()
    • getMilliSecondsIncrementWhenWaitingForWebSocketEndpointsToBeProperlyClosedBeforeKillingTheServer

      protected int getMilliSecondsIncrementWhenWaitingForWebSocketEndpointsToBeProperlyClosedBeforeKillingTheServer()
    • sendWebsocketEnpointsClosedWhenServerStops

      protected void sendWebsocketEnpointsClosedWhenServerStops()
    • getStaticResourcesPathHandler

      protected io.undertow.server.handlers.PathHandler getStaticResourcesPathHandler()
    • addStaticResourceToServe

      public void addStaticResourceToServe(org.spincast.core.routing.StaticResource<?> staticResource)
      Specified by:
      addStaticResourceToServe in interface org.spincast.core.server.Server
    • removeStaticResourcesServed

      public void removeStaticResourcesServed(org.spincast.core.routing.StaticResourceType staticResourceType, String urlPath)
      Specified by:
      removeStaticResourcesServed in interface org.spincast.core.server.Server
    • removeAllStaticResourcesServed

      public void removeAllStaticResourcesServed()
      Specified by:
      removeAllStaticResourcesServed in interface org.spincast.core.server.Server
    • removeStaticResource

      protected void removeStaticResource(org.spincast.core.routing.StaticResourceType staticResourceType, String urlPath)
    • getStaticResourceServed

      public org.spincast.core.routing.StaticResource<?> getStaticResourceServed(String urlPath)
      Specified by:
      getStaticResourceServed in interface org.spincast.core.server.Server
    • getStaticResourcesServed

      public Set<org.spincast.core.routing.StaticResource<?>> getStaticResourcesServed()
      Specified by:
      getStaticResourcesServed in interface org.spincast.core.server.Server
    • getHttpMethod

      public org.spincast.core.routing.HttpMethod getHttpMethod(Object exchange)
      Specified by:
      getHttpMethod in interface org.spincast.core.server.Server
    • castExchange

      protected io.undertow.server.HttpServerExchange castExchange(Object exchange)
    • getContentTypeBestMatch

      public org.spincast.core.utils.ContentTypeDefaults getContentTypeBestMatch(Object exchangeObj)
      Specified by:
      getContentTypeBestMatch in interface org.spincast.core.server.Server
    • getFullUrlProxied

      public String getFullUrlProxied(Object exchangeObj)
      Specified by:
      getFullUrlProxied in interface org.spincast.core.server.Server
    • getFullUrlProxied

      public String getFullUrlProxied(Object exchangeObj, boolean keepCacheBusters)
      Specified by:
      getFullUrlProxied in interface org.spincast.core.server.Server
    • getFullUrlOriginal

      public String getFullUrlOriginal(Object exchangeObj)
      Specified by:
      getFullUrlOriginal in interface org.spincast.core.server.Server
    • getFullUrlOriginal

      public String getFullUrlOriginal(Object exchangeObj, boolean keepCacheBusters)
      Specified by:
      getFullUrlOriginal in interface org.spincast.core.server.Server
    • setResponseHeader

      public void setResponseHeader(Object exchangeObj, String name, List<String> values)
      Specified by:
      setResponseHeader in interface org.spincast.core.server.Server
    • setResponseHeaders

      public void setResponseHeaders(Object exchange, Map<String,List<String>> headers)
      Specified by:
      setResponseHeaders in interface org.spincast.core.server.Server
    • getResponseHeaders

      public Map<String,List<String>> getResponseHeaders(Object exchangeObj)
      Specified by:
      getResponseHeaders in interface org.spincast.core.server.Server
    • removeResponseHeader

      public void removeResponseHeader(Object exchange, String name)
      Specified by:
      removeResponseHeader in interface org.spincast.core.server.Server
    • setResponseStatusCode

      public void setResponseStatusCode(Object exchange, int statusCode)
      Specified by:
      setResponseStatusCode in interface org.spincast.core.server.Server
    • getDoNothingCallback

      protected io.undertow.io.IoCallback getDoNothingCallback()
    • getCloseExchangeCallback

      protected io.undertow.io.IoCallback getCloseExchangeCallback()
    • flushBytes

      public void flushBytes(Object exchange, byte[] bytes, boolean end)
      Specified by:
      flushBytes in interface org.spincast.core.server.Server
    • end

      public void end(Object exchange)
      Specified by:
      end in interface org.spincast.core.server.Server
    • isResponseClosed

      public boolean isResponseClosed(Object exchange)
      Specified by:
      isResponseClosed in interface org.spincast.core.server.Server
    • isResponseHeadersSent

      public boolean isResponseHeadersSent(Object exchange)
      Specified by:
      isResponseHeadersSent in interface org.spincast.core.server.Server
    • getRequestScheme

      public String getRequestScheme(Object exchange)
      Specified by:
      getRequestScheme in interface org.spincast.core.server.Server
    • addCookies

      public void addCookies(Object exchange, Map<String,org.spincast.core.cookies.Cookie> cookies)
      Specified by:
      addCookies in interface org.spincast.core.server.Server
    • getCookies

      public Map<String,String> getCookies(Object exchange)
      Specified by:
      getCookies in interface org.spincast.core.server.Server
    • getCookieEncoding

      protected String getCookieEncoding()
    • getQueryStringParams

      public Map<String,List<String>> getQueryStringParams(Object exchange)
      Specified by:
      getQueryStringParams in interface org.spincast.core.server.Server
    • getRawInputStream

      public InputStream getRawInputStream(Object exchangeObj)
      Specified by:
      getRawInputStream in interface org.spincast.core.server.Server
    • getFormData

      protected io.undertow.server.handlers.form.FormData getFormData(io.undertow.server.HttpServerExchange exchange)
      May return NULL.
    • getFormData

      public Map<String,List<String>> getFormData(Object exchangeObj)
      Specified by:
      getFormData in interface org.spincast.core.server.Server
    • getUploadedFiles

      public Map<String,List<org.spincast.core.server.UploadedFile>> getUploadedFiles(Object exchangeObj)
      Specified by:
      getUploadedFiles in interface org.spincast.core.server.Server
    • forceRequestSizeValidation

      public boolean forceRequestSizeValidation(Object exchangeObj)
      Specified by:
      forceRequestSizeValidation in interface org.spincast.core.server.Server
    • getRequestHeaders

      public Map<String,List<String>> getRequestHeaders(Object exchangeObj)
      The names of the headers are case insensitive.
      Specified by:
      getRequestHeaders in interface org.spincast.core.server.Server
    • getWebsocketEndpointCreationLock

      protected Object getWebsocketEndpointCreationLock(String endpointId)
      Gets the creation/close lock for a specific Websocket endpoint.
    • websocketCreateEndpoint

      public org.spincast.core.websocket.WebsocketEndpointManager websocketCreateEndpoint(String endpointId, org.spincast.core.websocket.WebsocketEndpointHandler appEndpointHandler)
      Specified by:
      websocketCreateEndpoint in interface org.spincast.core.server.Server
    • createUndertowWebsocketEndpointHandler

      protected org.spincast.core.websocket.WebsocketEndpointHandler createUndertowWebsocketEndpointHandler(String endpointId, org.spincast.core.websocket.WebsocketEndpointHandler appHandler)
    • websocketCloseEndpoint

      public void websocketCloseEndpoint(String endpointId)
      Specified by:
      websocketCloseEndpoint in interface org.spincast.core.server.Server
    • websocketCloseEndpoint

      public void websocketCloseEndpoint(String endpointId, int closingCode, String closingReason)
      Specified by:
      websocketCloseEndpoint in interface org.spincast.core.server.Server
    • websocketConnection

      public void websocketConnection(Object exchangeObj, String endpointId, String peerId)
      Specified by:
      websocketConnection in interface org.spincast.core.server.Server
    • getWebsocketEndpointManagers

      public List<org.spincast.core.websocket.WebsocketEndpointManager> getWebsocketEndpointManagers()
      Specified by:
      getWebsocketEndpointManagers in interface org.spincast.core.server.Server
    • getWebsocketEndpointManager

      public org.spincast.core.websocket.WebsocketEndpointManager getWebsocketEndpointManager(String endpointId)
      Specified by:
      getWebsocketEndpointManager in interface org.spincast.core.server.Server
    • getIp

      public String getIp(Object exchangeObj)
      Specified by:
      getIp in interface org.spincast.core.server.Server
    • convertHttpMethodToUndertowHttpString

      public io.undertow.util.HttpString convertHttpMethodToUndertowHttpString(org.spincast.core.routing.HttpMethod httpMethod)
    • convertHeadersToUndertowHeaderMap

      public io.undertow.util.HeaderMap convertHeadersToUndertowHeaderMap(Map<String,List<String>> headers)
    • push

      public void push(Object exchangeObj, Set<org.spincast.core.routing.ResourceToPush> resourcesToPush)
      Specified by:
      push in interface org.spincast.core.server.Server
    • 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, org.spincast.core.routing.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.