Skip to main content
Version: 7.2405.x.x LTS

Dispatcher object method

You can get a dispatcher with request:getDispatcher(name), see request object methods.

MethodDescriptionSample
dispatcher:forward(request, response)Send request to dispatcher. If response is the original response the dispatcher will send the answer directly to the client. Else you can access the status, header and body from the response for further steps.dispatcher = request:getDispatcher("MyHttpConnectorServlet")--Send the content of MyHttpConnectorServlet to client. request and response are the original object handed to this script as parameters.dispatcher:forward(request, response)newReq = nevis.filter.lua.request.new() newResp = nevis.filter.lua.response.new()dispatcher = request:getDispatcher("MyHttpConnectorServlet")--Send a new request and get a response decoupled from original request/response, newResp can be used for further steps within the script. The client did not get an answer so far.dispatcher:forward(newReq, newResp)

Configuration example of a script performing an HTTP side call:

<filter>
<filter-name>StatusUpdater</filter-name>
<filter-class>ch::nevis::isiweb4::filter::lua::LuaFilter</filter-class>
<init-param>
<param-name>Script</param-name>
<param-value>
function sidecall(request, response)
local trace = request:getTracer()

local sideRequest = nevis.filter.lua.request.new()
sideRequest:setUri("/statusupdate")
sideRequest:setMethod("GET")
sideRequest:setHeader("Host", "statusserver.zh.adnovum.ch:8080")
sideRequest:setHeader("User-Agent", "StatusUpdater")

local sideResponse = nevis.filter.lua.response.new()

local dispatcher = request:getDispatcher("StatusServlet")
local timer = nevis.sys.timer.new()
timeStart = timer:getTime()
dispatcher:forward(sideRequest, sideResponse)
timeEnd = timer:getTime()
local duration = timeEnd - timeStart
-- log response code and request duration in milliseconds:
local trID = request:getEnv("UNIQUE_ID")
local rc = sideResponse:getStatus()
trace:notice("StatusUpdater: sC=" .. rc .. " dT=" .. duration .. " trID=" .. trID)
end
</param-value>
</init-param>
<init-param>
<param-name>Script.InputHeaderFunctionName</param-name>
<param-value>sidecall</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>StatusUpdater</filter-name>
<url-pattern>/application/*</url-pattern>
</filter-mapping>

<servlet>
<servlet-name>StatusUpdater</servlet-name>
<servlet-class>
ch::nevis::isiweb4::servlet::connector::http::HttpConnectorServlet
</servlet-class>
<init-param>
<param-name>InetAddress</param-name>
<param-value> statusserver.zh.adnovum.ch:8080</param-value>
</init-param>
</servlet>