public abstract class AbstractDevServerRunner extends Object implements DevModeHandler
This class is meant to be used during developing time.
For internal use only. May be renamed or removed in a future release.
Modifier | Constructor and Description |
---|---|
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.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
checkConnection()
Check the connection to the dev server.
|
protected Process |
doStartDevServer()
Starts the dev server and returns the started process.
|
protected ApplicationConfiguration |
getApplicationConfiguration()
Gets the application configuration.
|
String |
getFailedOutput()
Return the dev server console output when a compilation error happened.
|
int |
getPort()
Get the listening port of the dev server.
|
File |
getProjectRoot()
Gets the project root folder.
|
protected abstract File |
getServerBinary()
Gets the binary that starts the dev server.
|
protected abstract File |
getServerConfig()
Gets the main configuration file for the dev server.
|
protected abstract Pattern |
getServerFailurePattern()
Gets a pattern to match with the output to determine that the server has
failed to start.
|
protected abstract String |
getServerName()
Gets the name of the dev server for outputting to the user and
statistics.
|
protected abstract List<String> |
getServerStartupCommand(String nodeExec)
Gets the commands to run to start the dev server.
|
protected abstract Pattern |
getServerSuccessPattern()
Gets a pattern to match with the output to determine that the server has
started successfully.
|
protected com.vaadin.base.devserver.DevServerWatchDog |
getWatchDog()
Gets the server watch dog.
|
boolean |
handleRequest(VaadinSession session,
VaadinRequest request,
VaadinResponse response)
Called when a request needs to be handled.
|
protected void |
onDevServerCompilation(DevServerOutputTracker.Result result)
Called whenever the dev server output matche the success or failure
pattern.
|
HttpURLConnection |
prepareConnection(String path,
String method)
Prepare a HTTP connection against the dev server.
|
boolean |
serveDevModeRequest(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Serve a file by proxying to the dev server.
|
void |
stop()
Stop the dev-server.
|
protected void |
triggerLiveReload()
Triggers live reload.
|
protected void |
updateServerStartupEnvironment(FrontendTools frontendTools,
Map<String,String> environment)
Defines the environment variables to use when starting the dev server.
|
protected void |
validateFiles()
Validates that the needed server binary and config file(s) are available.
|
void |
waitForDevServer()
Waits for the dev server to start.
|
protected void |
writeStream(javax.servlet.ServletOutputStream outputStream,
InputStream inputStream) |
protected AbstractDevServerRunner(Lookup lookup, int runningPort, File npmFolder, CompletableFuture<Void> waitFor)
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.protected void validateFiles() throws ExecutionFailedException
ExecutionFailedException
- if there is a problemprotected abstract File getServerBinary()
protected abstract File getServerConfig()
protected abstract String getServerName()
protected abstract List<String> getServerStartupCommand(String nodeExec)
nodeExec
- the path to the node binaryprotected void updateServerStartupEnvironment(FrontendTools frontendTools, Map<String,String> environment)
frontendTools
- frontend tools metadataenvironment
- the environment variables to useprotected abstract Pattern getServerSuccessPattern()
protected abstract Pattern getServerFailurePattern()
protected Process doStartDevServer()
null
if no process was startedprotected void onDevServerCompilation(DevServerOutputTracker.Result result)
public String getFailedOutput()
DevModeHandler
getFailedOutput
in interface DevModeHandler
protected com.vaadin.base.devserver.DevServerWatchDog getWatchDog()
protected void triggerLiveReload()
public File getProjectRoot()
DevModeHandler
getProjectRoot
in interface DevModeHandler
protected ApplicationConfiguration getApplicationConfiguration()
protected boolean checkConnection()
true
if the dev server is responding correctly,
false
otherwisepublic int getPort()
public void waitForDevServer()
Suspends the caller's thread until the dev mode server is started (or failed to start).
public void stop()
DevModeHandler
stop
in interface DevModeHandler
public HttpURLConnection prepareConnection(String path, String method) throws IOException
DevModeHandler
prepareConnection
in interface DevModeHandler
path
- the file to request, needs to be safemethod
- the http method to useIOException
- on connection errorpublic boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException
RequestHandler
true
to 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
SynchronizedRequestHandler
or by using
VaadinSession.accessSynchronously(Command)
or
UI.accessSynchronously(Command)
.
handleRequest
in interface RequestHandler
session
- The session for the requestrequest
- The request to handleresponse
- The response object to which a response can be written.IOException
- If an IO error occurredpublic boolean serveDevModeRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException
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 false
immediately if dev server failed on its
startup.
serveDevModeRequest
in interface DevModeHandler
request
- the servlet requestresponse
- the servlet responseIOException
- in the case something went wrong like connection refusedprotected void writeStream(javax.servlet.ServletOutputStream outputStream, InputStream inputStream) throws IOException
IOException
Copyright © 2022. All rights reserved.