public class HttpActor extends TypedAtomicActor implements HttpService, ExceptionSubscriber
WebServer
, which discovers this actor and
delegates HTTP requests to a servlet that this actor creates.
It also requires that the model containing this actor provide
exactly one input to either the response
or setCookies
input port (or both) in response to every output request,
and that such responses are delivered in the same order as
the requests they are responding to.
The path parameter specifies which HTTP requests will be delegated to this actor. If the base URL for the web server is "http://localhost:8080", say, then request of the form "http://localhost:8080/path" will be delegated to this actor.
When this actor receives an HTTP request from the WebServer, it
issues a request for the director to fire it at the greater of
the current time of the director or the time elapsed since
the last invocation of initialize() (in seconds).
When the actor fires, it produces on its output ports the details
of the request, time stamped by the elapsed time since the model
started executing. It expects to be in a model that will send
it data to either the response
or setCookies
input port (or both) with the response to HTTP request.
If that response does not arrive within timeout
(default 30000) milliseconds, then this actor will a issue
timeout response and will discard the response when it eventually
arrives.
This actor is designed to be used in a DE model (with a DEDirector).
Since a model using this actor must deliver a response for
every request, the model must put this actor in a feedback
loop. The requests appear on the outputs of this actor,
and the responses appear on the inputs. Each such feedback
loop is required to include an instance of MicrostepDelay
(or TimeDelay
, if you wish to model response times) in order
to break the causality loop that the feedback loop would
otherwise incur.
The downstream model should be used to construct a response.
For example, to simply serve a web page, put a
FileReader
actor to read the response from a local
file and a MicrostepDelay
downstream in a feedback
loop connected back to the response input.
WebServer
Modifier and Type | Class and Description |
---|---|
protected class |
HttpActor.ActorServlet
A servlet providing implementations of get and post.
|
protected static class |
HttpActor.HttpRequestItems
A data structure with all the relevant information about an
HTTP request.
|
protected static class |
HttpActor.HttpResponseItems
A data structure with all the relevant information about an
HTTP response.
|
Entity.ContainedObjectsIterator
Modifier and Type | Field and Description |
---|---|
TypedIOPort |
getCookies
An output that sends the cookies specified by the
requestedCookies parameter, with values
provided by a get request. |
TypedIOPort |
getParameters
An output port that sends parameters included in a get request.
|
TypedIOPort |
getRequestURI
An output port that sends the relative URI of a get request,
which must match the pattern given by the path parameter.
|
StringParameter |
path
The relative URL of HTTP requests that this actor handles.
|
TypedIOPort |
postBody
An output that sends the body of the request, if any.
|
TypedIOPort |
postCookies
An output that sends the cookies specified by the
requestedCookies parameter, with values
provided by a post request. |
TypedIOPort |
postParameters
An output port that sends parameters included in a post request.
|
TypedIOPort |
postRequestURI
An output port that sends the relative URI of a post request,
which must match the pattern given by the path parameter.
|
TypedIOPort |
putBody
An output that sends the body of the request, if any.
|
TypedIOPort |
putCookies
An output that sends the cookies specified by the
requestedCookies parameter, with values
provided by a put request. |
TypedIOPort |
putParameters
An output port that sends parameters included in a put request.
|
TypedIOPort |
putRequestURI
An output port that sends the relative URI of a put request,
which must match the pattern given by the path parameter.
|
Parameter |
requestedCookies
An array of names of cookies that this actor should retrieve from
an HTTP request and produce on the getCookies and putCookies output
ports.
|
TypedIOPort |
response
An input port on which to provide the
response to issue to an HTTP request.
|
TypedIOPort |
setCookies
An input on which to provide new cookies and/or new cookie values.
|
Parameter |
timeout
The time in milliseconds to wait after producing the details
of a request on the output ports for a response to appear at
the input ports.
|
_typesValid
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
COMPLETED, NOT_READY, STOP_ITERATING
Constructor and Description |
---|
HttpActor(CompositeEntity container,
java.lang.String name)
Create an instance of the actor.
|
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 actor.
|
boolean |
exceptionHandled(boolean succesful,
java.lang.String message)
Not used here.
|
boolean |
exceptionOccurred(java.lang.String policy,
java.lang.Throwable exception)
Generate an HTTP response for the client if an exception occurs.
|
void |
fire()
If there are input tokens on the
response or
setCookies ports, then queue a response to be
sent by the servelet for a corresponding request. |
java.net.URI |
getRelativePath()
Return the relative path that this HttpService is mapped to,
which is the value of the path parameter.
|
javax.servlet.http.HttpServlet |
getServlet()
Create and return an HttpServlet that is used to handle requests that
arrive at the path given by the path parameter.
|
void |
initialize()
Record the current model time and the current real time
so that output events can be time stamped with the elapsed
time since model start.
|
void |
setRelativePath(java.net.URI path)
Set the relative path that this HttpService is mapped to.
|
void |
setWebServer(WebServer server)
Specify the web server for this service.
|
_containedTypeConstraints, _customTypeConstraints, _defaultTypeConstraints, _fireAt, _fireAt, attributeTypeChanged, clone, isBackwardTypeInferenceEnabled, newPort, typeConstraintList, typeConstraints
_actorFiring, _actorFiring, _declareDelayDependency, addActorFiringListener, addInitializable, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, postfire, prefire, preinitialize, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate, wrapup
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
_addPort, _description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, notifyOfNameChange, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
isFireFunctional, isStrict, iterate, postfire, prefire, stop, stopFire, terminate
addInitializable, preinitialize, removeInitializable, wrapup
description, getContainer, getDisplayName, getFullName, getName, getName, setName
getDerivedLevel, getDerivedList, propagateValue
public TypedIOPort getCookies
requestedCookies
parameter, with values
provided by a get request. If the get request does
have cookies with names matching those in requestedCookies,
then those values will be empty strings.
The output will be a RecordToken with the field names given by
requestedCookies, and the field values being strings.public TypedIOPort getParameters
public TypedIOPort getRequestURI
public StringParameter path
public TypedIOPort postBody
public TypedIOPort postCookies
requestedCookies
parameter, with values
provided by a post request. If the post request does
have cookies with names matching those in requestedCookies,
then those values will be empty strings.
The output will be a RecordToken with the field names given by
requestedCookies, and the field values being strings.public TypedIOPort postParameters
public TypedIOPort postRequestURI
public TypedIOPort putBody
public TypedIOPort putCookies
requestedCookies
parameter, with values
provided by a put request. If the put request does
have cookies with names matching those in requestedCookies,
then those values will be empty strings.
The output will be a RecordToken with the field names given by
requestedCookies, and the field values being strings.public TypedIOPort putParameters
public TypedIOPort putRequestURI
public Parameter requestedCookies
public TypedIOPort response
public TypedIOPort setCookies
response
input in the same firing, or if there is no token on the response
input, will be treated as cookies accompanying an empty string response.
This has type record.public Parameter timeout
public HttpActor(CompositeEntity container, java.lang.String name) throws IllegalActionException, NameDuplicationException
container
- The containername
- The name.IllegalActionException
- If the superclass throws it.NameDuplicationException
- If the superpublic 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 TypedAtomicActor
workspace
- The workspace in which to place the cloned attribute.java.lang.CloneNotSupportedException
- Not thrown in this base class.Object.clone()
public boolean exceptionHandled(boolean succesful, java.lang.String message)
exceptionHandled
in interface ExceptionSubscriber
succesful
- True if the exception was successfully handled; false
otherwisemessage
- A status message from the exception handlerpublic boolean exceptionOccurred(java.lang.String policy, java.lang.Throwable exception)
exceptionOccurred
in interface ExceptionSubscriber
policy
- The exception handling policy of the exception handler;
see CatchExceptionAttribute
exception
- The exception that occurredpublic java.net.URI getRelativePath()
getRelativePath
in interface HttpService
setRelativePath(URI)
public javax.servlet.http.HttpServlet getServlet()
getServlet
in interface HttpService
public void fire() throws IllegalActionException
response
or
setCookies
ports, then queue a response to be
sent by the servelet for a corresponding request.
If the servlet has received
an HTTP request, then also produce on the output ports
the details of the request.
If there is an HTTP request, but the current superdense time
matches the time of the previously produced output,
then request a refiring at the current time (next microstep)
so that the outputs are produced at the next microstep.
This actor is designed to normally be fired twice at each superdense
time, first to produce outputs corresponding to an HTTP
request, and next to send back the response to that request.
This strategy avoids creating signals with multiple values
at the same superdense time instant.fire
in interface Executable
fire
in class AtomicActor<TypedIOPort>
IllegalActionException
- If sending the
outputs fails.public void initialize() throws IllegalActionException
initialize
in interface Initializable
initialize
in class AtomicActor<TypedIOPort>
IllegalActionException
- If the superclass throws it.public void setRelativePath(java.net.URI path)
setRelativePath
in interface HttpService
path
- The relative path that this HttpService is mapped to.getRelativePath()
public void setWebServer(WebServer server)
WebServer
attribute of a model,
if there is one, and will enable this service to access
information about the web server (such as
the resourcePath, resourceLocation, or temporaryFileLocation).setWebServer
in interface HttpService
server
- The WebServer for this service