Class AbstractDevServerRunner
- All Implemented Interfaces:
DevModeHandler,RequestHandler,Serializable
- Direct Known Subclasses:
ViteHandler
This class is meant to be used during developing time.
For internal use only. May be renamed or removed in a future release.
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractDevServerRunner(Lookup lookup, int runningPort, File npmFolder, CompletableFuture<Void> waitFor) Craete an instance that waits for the given task to complete before starting or connecting to the server. -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanCheck the connection to the dev server.protected ProcessStarts the dev server and returns the started process.protected ApplicationConfigurationGets the application configuration.Return the dev server console output when a compilation error happened.protected FrontendToolsintgetPort()Get the listening port of the dev server.Gets the project root folder.protected abstract FileGets the binary that starts the dev server.protected abstract FileGets the main configuration file for the dev server.protected abstract PatternGets a pattern to match with the output to determine that the server has failed to start.protected abstract StringGets the name of the dev server for outputting to the user and statistics.protected PatternGets a pattern to match with the output to determine that the server has been restarted.protected PatternGets a pattern to match with the output to determine that the server is restarting.Gets the commands to run to start the dev server.protected abstract PatternGets a pattern to match with the output to determine that the server has started successfully.protected com.vaadin.base.devserver.DevServerWatchDogGets the server watch dog.booleanhandleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) Called when a request needs to be handled.protected voidCalled whenever the dev server output matche the success or failure pattern.prepareConnection(String path, String method) Prepare a HTTP connection against the dev server.booleanserveDevModeRequest(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Serve a file by proxying to the dev server.voidstop()Stop the dev-server.protected voidupdateServerStartupEnvironment(FrontendTools frontendTools, Map<String, String> environment) Defines the environment variables to use when starting the dev server.protected voidValidates that the needed server binary and config file(s) are available.voidWaits for the dev server to start.protected voidwriteStream(jakarta.servlet.ServletOutputStream outputStream, InputStream inputStream)
-
Field Details
-
DEV_SERVER_HOST
- See Also:
-
-
Constructor Details
-
AbstractDevServerRunner
protected AbstractDevServerRunner(Lookup lookup, int runningPort, File npmFolder, CompletableFuture<Void> waitFor) Craete an instance that waits for the given task to complete before starting or connecting to the server.- Parameters:
lookup- a lookup instancerunningPort- the port that a dev server is already running on or 0 to start a new servernpmFolder- the project rootwaitFor- the task to wait for before running the server.
-
-
Method Details
-
getFrontendTools
-
validateFiles
Validates that the needed server binary and config file(s) are available.- Throws:
ExecutionFailedException- if there is a problem
-
getServerBinary
Gets the binary that starts the dev server.- Returns:
- the dev server binary file
-
getServerConfig
Gets the main configuration file for the dev server.- Returns:
- the dev server configuration file
-
getServerName
Gets the name of the dev server for outputting to the user and statistics.- Returns:
- the dev server name
-
getServerStartupCommand
Gets the commands to run to start the dev server.- Parameters:
tools- the frontend tools object- Returns:
- the list of commands to start the dev server
-
updateServerStartupEnvironment
protected void updateServerStartupEnvironment(FrontendTools frontendTools, Map<String, String> environment) Defines the environment variables to use when starting the dev server.- Parameters:
frontendTools- frontend tools metadataenvironment- the environment variables to use
-
getServerSuccessPattern
Gets a pattern to match with the output to determine that the server has started successfully.- Returns:
- the success pattern
-
getServerFailurePattern
Gets a pattern to match with the output to determine that the server has failed to start.- Returns:
- the failure pattern
-
getServerRestartingPattern
Gets a pattern to match with the output to determine that the server is restarting. Defaults to null, meaning that server restart is not monitored. Server restart is monitored only if both this method andgetServerRestartedPattern()provides a pattern.- Returns:
- the restarting pattern, or
nullif restart monitoring is not used
-
getServerRestartedPattern
Gets a pattern to match with the output to determine that the server has been restarted. Defaults to null, meaning that server restart is not monitored. Server restart is monitored only if both this method andgetServerRestartingPattern()provides a pattern.- Returns:
- the restarted pattern, or
nullif restart monitoring is not used
-
doStartDevServer
Starts the dev server and returns the started process.- Returns:
- the started process or
nullif no process was started
-
onDevServerCompilation
Called whenever the dev server output matche the success or failure pattern.- Parameters:
result- the compilation result
-
getFailedOutput
Description copied from interface:DevModeHandlerReturn the dev server console output when a compilation error happened.- Specified by:
getFailedOutputin interfaceDevModeHandler- Returns:
- console output if error or null otherwise.
-
getWatchDog
protected com.vaadin.base.devserver.DevServerWatchDog getWatchDog()Gets the server watch dog.- Returns:
- the watch dog
-
getProjectRoot
Description copied from interface:DevModeHandlerGets the project root folder.- Specified by:
getProjectRootin interfaceDevModeHandler- Returns:
- the project root folder
-
getApplicationConfiguration
Gets the application configuration.- Returns:
- the application configuration
-
checkConnection
protected boolean checkConnection()Check the connection to the dev server.- Returns:
trueif the dev server is responding correctly,falseotherwise
-
getPort
public int getPort()Description copied from interface:DevModeHandlerGet the listening port of the dev server.- Specified by:
getPortin interfaceDevModeHandler- Returns:
- the listening port
-
waitForDevServer
public void waitForDevServer()Waits for the dev server to start.Suspends the caller's thread until the dev mode server is started (or failed to start).
-
stop
public void stop()Description copied from interface:DevModeHandlerStop the dev-server.- Specified by:
stopin interfaceDevModeHandler
-
prepareConnection
Description copied from interface:DevModeHandlerPrepare a HTTP connection against the dev server.- Specified by:
prepareConnectionin interfaceDevModeHandler- Parameters:
path- the file to request, needs to be safemethod- the http method to use- Returns:
- the connection
- Throws:
IOException- on connection error
-
handleRequest
public boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException Description copied from interface:RequestHandlerCalled when a request needs to be handled. If a response is written, this method should returntrueto indicate that no more request handlers should be invoked for the request.Note that request handlers by default do not lock the session. If you are using VaadinSession or anything inside the VaadinSession you must ensure the session is locked. This can be done by extending
SynchronizedRequestHandleror by usingVaadinSession.accessSynchronously(Command)orUI.accessSynchronously(Command).- Specified by:
handleRequestin interfaceRequestHandler- Parameters:
session- The session for the requestrequest- The request to handleresponse- The response object to which a response can be written.- Returns:
- true if a response has been written and no further request handlers should be called, otherwise false
- Throws:
IOException- If an IO error occurred
-
serveDevModeRequest
public boolean serveDevModeRequest(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws IOException Serve a file by proxying to the dev server.Note: it considers the
HttpServletRequest.getPathInfo()that will be the path passed to the dev server which is running in the context root folder of the application.Method returns
falseimmediately if dev server failed on its startup.- Specified by:
serveDevModeRequestin interfaceDevModeHandler- Parameters:
request- the servlet requestresponse- the servlet response- Returns:
- false if the dev server returned a not found, true otherwise
- Throws:
IOException- in the case something went wrong like connection refused
-
writeStream
protected void writeStream(jakarta.servlet.ServletOutputStream outputStream, InputStream inputStream) throws IOException - Throws:
IOException
-