public class WebServer extends AbstractInitializableAttribute
HttpService
. The server is set up during
initialize()
and taken down during
wrapup()
. The resourceLocation
parameter gives a directory or URL relative to which this
web server should look for resources (like image files and
the like).
You can add additional resource bases by adding additional
parameters of type ptolemy.data.expr.FileParameter to
this WebServer (select Configure in the context menu).
http://wiki.eclipse.org/Jetty/Tutorial - The Jetty Tutorial
NamedObj.ContainedObjectsIterator
Modifier and Type | Field and Description |
---|---|
StringParameter |
applicationPath
The URL prefix to map this model to.
|
Parameter |
deployedPort
The port number the server is listening to.
|
Parameter |
preferredPort
The preferred port number for the server to listen to.
|
FileParameter |
resourceLocation
A directory or URL where the web server will look for resources
(like image files and the like).
|
StringParameter |
resourcePath
The URL prefix used to request resources (files) from this web service.
|
FileParameter |
temporaryFileLocation
A directory where the web server will look for resources
(like image files and the like).
|
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
Constructor and Description |
---|
WebServer(NamedObj container,
java.lang.String name)
Construct an instance of the attribute.
|
Modifier and Type | Method and Description |
---|---|
void |
attributeChanged(Attribute attribute)
React to a change in an attribute.
|
java.lang.Object |
clone(Workspace workspace)
Clone the attribute.
|
void |
initialize()
Collect servlets from all model objects implementing HttpService
and WebSocketService and start the web server in a new thread.
|
void |
wrapup()
Unregister this application with the web server manager.
|
_getInitializableContainer, addInitializable, hierarchyChanged, hierarchyWillChange, preinitialize, removeInitializable, setContainer
_checkContainer, _getContainedObject, _propagateExistence, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, setName, updateContent
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _description, _executeChangeRequests, _exportMoMLContents, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, attributeTypeChanged, clone, containedObjectsIterator, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getElementName, getFullName, getModelErrorHandler, getName, getName, getPrototypeList, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, notifyOfNameChange, propagateExistence, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, uniqueName, validateSettables, workspace
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
description, getContainer, getDisplayName, getFullName, getName, getName, setName
public StringParameter applicationPath
preferredPort
8078
of localhost, the model will handle all requests that begin with
http://localhost:8078/If multiple applications are running on the same server, it's typical to assign a unique application prefix for each. For example, two applications with application paths of "/calendar" and "/music" would receive requests directed to
http://localhost:8078/calendar http://localhost:8078/musicrespectively. Applications may contain multiple servlets (provided by e.g.
HttpActor
s).
Each servlet typically defines a servlet path which is appended to
the application path for request routing. For example, two servlets
with servlet paths "/play" and "/upload" in the music application
would receive requests directed to:
http://localhost:8078/music/play http://localhost:8078/music/uploadrespectively.
public Parameter deployedPort
public Parameter preferredPort
public StringParameter resourcePath
preferredPort
8078 of localhost, the client can request file "image.png"
using:
http://localhost:8078/image.pngThe resourcePath is added as a prefix before the file's name in the URL. For example, given the resourcePath "/files", the client can request file "image.png" using:
http://localhost:8078/files/image.pngRelative URLs are permissible for files requested by pages served by this WebServer (common for e.g. custom Javascript libraries). For example, given the resourcePath "/files", a file named "custom.js" may be retrieved at the relative URL:
/files/custom.jsNote that the name of the directory containing resources does NOT have to match the URL used to access these resources. See
resourceLocation
regarding the resource directory.
Subdirectory search is supported (here, for subdirectories to the
directory specified by resourceLocation
). Add the subdirectory
path to the URL. For example, given the resourcePath "/files",
a file in subdirectory /user/photos named "selfie.png" may be
retrieved at URL:
http://localhost:8078/files/user/photos/selfie.png
public FileParameter resourceLocation
resourcePath
regarding the URL.public FileParameter temporaryFileLocation
resourceLocation
, but the
directory specified here may be used by components implementing
HttpService
as a place to write temporary files
that will be found by the web server.
This defaults to "$TMPDIR", a built-in variable
that specifies a temporary file location.
See the explanation of resourcePath
.public WebServer(NamedObj container, java.lang.String name) throws IllegalActionException, NameDuplicationException
container
- The container.name
- The name.IllegalActionException
- If the superclass throws it.NameDuplicationException
- If the superclass throws it.public void attributeChanged(Attribute attribute) throws IllegalActionException
attributeChanged
in class NamedObj
attribute
- The attribute that changed.IllegalActionException
- If the change is not acceptable
to this container (not thrown in this base class).public java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
clone
in class AbstractInitializableAttribute
workspace
- The workspace in which to place the cloned attribute.java.lang.CloneNotSupportedException
- Not thrown in this base class.Object.clone()
public void initialize() throws IllegalActionException
In the current implementation, servlets must be registered before the Jetty server starts. Servlets are not allowed to be added to a running ContextHandler. Currently, the Jetty server is started once and runs until the model finishes executing. It would also be possible to pause the server, add a servlet, and restart the server, which would allow a model to dynamically add servlets. This might cause strange behavior to an outside observer, however, since some HttpRequests could fail if a servlet has not been loaded yet. References:
initialize
in interface Initializable
initialize
in class AbstractInitializableAttribute
IllegalActionException
- Not thrown in this base class.public void wrapup() throws IllegalActionException
wrapup
in interface Initializable
wrapup
in class AbstractInitializableAttribute
IllegalActionException
- if there is a problem unregistering
the application