Global object for managing the servlet response.
All content produced via $res.print or Myna.print is appended to an internal response buffer. This content is nomally sent to the browser at the end of the request. By using the content maniplulation functions in this object (getContent, clear and print) you can alter content before it reaches the browser.
Note that flush sends content to the browser immediately and resets the buffer.
| $res | Global object for managing the servlet response. |
| Functions | |
| clear | Clears response buffer and returns the previous contents. |
| getContent | Returns current response buffer contents. |
| flush | Sends the current response buffer contents to the browser. |
| requestBasicAuth | returns a “Basic” http auth request |
| setContentType | sets the content MIME type of the response. |
| setStatusCode | returns an HTTP status code and optionally a message for this response |
| metaRedirect | Redirect this page using META HTTP-EQUIV=”refresh” tag. |
| redirect | Redirect this page using HTTP 302 temporary redirect. |
| redirectLogin | Redirect this page to the central login page |
| redirectWithToken | redirect to a URL, including an auth_token for the current user. |
| serveFile | Efficiently serves a file on the filesystem. |
| setHeader | sets a header to return to the browser |
| printBinary | sends binary data to the browser |
| Appends content to the response buffer. |
clear:function ()
Clears response buffer and returns the previous contents.
Response content before it wwas cleared
Response content created by $res.print is buffered internally. This function clears that buffer and returns it’s previous contents.
getContent:function ()
Returns current response buffer contents.
Current response buffer contents
Response content created by $res.print is buffered internally. This function returns the current contents of that buffer.
flush:function ( paddingSize )
Sends the current response buffer contents to the browser.
| paddingSize | Optional default 250 Number of space (“ “) charcters to append to encourage the browser to display the content immediately. |
Current response buffer contents.
Response content created by $res.print is buffered internally. This function sends the current contents of that buffer to the browser, and then clears the buffer and returns its former contents. No changes to the HTTP response can be sent after a call to flushContent, such as cookies.
requestBasicAuth:function( realm, message )
returns a “Basic” http auth request
| realm | Optional, default ‘Myna Application Server’ an organization or application name to indicate to the user what credentials to enter |
| message | Optional, default null A message to include withthe request. This may not be shown by the browser, or may only be shown after three failures |
sets the WWW-Authenticate header and returns a 401 HTTP status. any content sent after this function call will likely not be displayed by a browser
setContentType:function( type )
sets the content MIME type of the response.
| type | default ‘text/html’ MIME content type string Returns: Current response buffer contents. |
Response content created by $res.print is buffered internally. This function returns the current contents of that buffer.
setStatusCode:function( code, msg )
returns an HTTP status code and optionally a message for this response
| code | Numeric HTTP status code such as 403,401,500 etc |
| msg | Optional default null A string message to return to the browser |
$res.metaRedirect(“some_other_page.ejs”);
metaRedirect:function( url )
Redirect this page using META HTTP-EQUIV=”refresh” tag.
This method preserves any headers, such as cookies, sent to the browser during this request. Page processing continues after calling this function.
| url | absolurte url to redirect to |
$res.metaRedirect(“http://example.com/page.html”);
redirect:function( url )
Redirect this page using HTTP 302 temporary redirect.
This method does NOT preserve any headers, such as cookies, sent to the browser during this request. Page processing is aborted when calling this function
| url | absolute url (including server) to redirect to. See $server.resolveUrl for converting relative URLs to absolute URLs |
$res.redirect("http://example.com/page.html");
$res.redirect($server.resolveUrl("fusebox.sjs?fuseaction=main"));
redirectLogin:function( options )
Redirect this page to the central login page
| options | options object, see below |
| callbackUrl | URL relative to the current directory that the user should return to after login. |
| title | Optional, default “Login” Window title for login page |
| providers | Optional, default Myna.Permissions.getAuthTypes + “openid” An array or comma separated list of auth_types to include in the login window. |
| loginPage | Optional, default $server.rootUrl+”myna/auth/auth.sjs?fuseaction=login” If you want to provide a customized login page, indicate the URL here. Be sure that your page posts to auth.sjs in the same way that dsp_login.ejs does. |
| message | Optional, default “” A short one-line message to display above the login area |
Myna provides a centralized authentication application that can authenticate a users against any defined auth type, including OpenId. Calling this function will send an HTTP redirect to the browser to send the user to Myna’s authentication page. Once the user is authenticated he/she will be redirected back to callbackUrl and an authentication cookie for your application will be generated. You can examine the logged in user by calling $cookie.getAuthUser. Authorization can then be performed via Myna.Permissions.User.hasRight
This function calls Myna.abort, so no further processing will be done after a call to this function
redirectWithToken:function( url )
redirect to a URL, including an auth_token for the current user.
| url | url to redirect to |
serveFile:function( file, shouldDelete )
Efficiently serves a file on the filesystem.
| file | a Myna.File, java.io.File, or MynaPath to a file to serve to the client |
This function replaces the normal output of this response with the contents of file. Executing this function after a call to $res.flush will likely fail or corrupt the file. This function is appropriate for for large file downloads as it supports resuming.
When this function returns, the file may not have been downloaded yet. This is because some browsers/dowloaders have advanced multi-threaded download support, so you should plan for your download code the be called several times in parallel. Also if the client pauses and resumes the download you may get multiple calls.
setHeader:function( name, value )
sets a header to return to the browser
| name | Header name |
| value | Header value |
$res.setHeader(“Content-disposition”, ‘attachment; filename=”result.xls”’);
printBinary:function( data, contentType, filename )
sends binary data to the browser
| data | Binary data from Myna.File.readBinary or from binary database query (byte []) |
| contentType | Optional, default application/octet-stream MIME type of the binary data. If “” or null, the default will be used |
| filename | Optional, default null if defined, a “Content-disposition” response header is set to present the standard “Save or Open?” dialog to the client. Use this if offering a file for download, but not if you expect the content to be rendered inline |
This function replaces the normal output of this response with the contents of data. Executing this function after a call to $res.flush will likely fail or corrupt the file.
var bytes = new Myna.File(“path_to_doc.pdf”).readBinary(); $res.printBinary(bytes,”application/pdf”,”result.pdf”);
print:function ( text )
Appends content to the response buffer.
| text | text to append to response buffer |
void
Response content created by $res.print is buffered internally. At the end of the request this content is flushed to the browser
Clears response buffer and returns the previous contents.
clear:function ()
Returns current response buffer contents.
getContent:function ()
Sends the current response buffer contents to the browser.
flush:function ( paddingSize )
returns a “Basic” http auth request
requestBasicAuth:function( realm, message )
sets the content MIME type of the response.
setContentType:function( type )
returns an HTTP status code and optionally a message for this response
setStatusCode:function( code, msg )
Redirect this page using META HTTP-EQUIV=”refresh” tag.
metaRedirect:function( url )
Redirect this page using HTTP 302 temporary redirect.
redirect:function( url )
Redirect this page to the central login page
redirectLogin:function( options )
redirect to a URL, including an auth_token for the current user.
redirectWithToken:function( url )
Efficiently serves a file on the filesystem.
serveFile:function( file, shouldDelete )
sets a header to return to the browser
setHeader:function( name, value )
sends binary data to the browser
printBinary:function( data, contentType, filename )
Appends content to the response buffer.
print:function ( text )
This is an alias for $res.print
Myna.print=function Myna_print( string )
returns an array of valid auth type names for this system
getAuthTypes:function()
Return the result of Myna.Permissions.getUserById for the user_id in “myna_auth_cookie”, or null if there is no cookie
getAuthUser:function()
returns true if this user has been assigned the supplied appname and right name
Myna.Permissions.User.prototype.hasRight = function( appname, rightName )
Halts JavaScript execution, optionally showing a message or dumping an object
Myna.abort=function Myna_abort( label, value )
returns the contents of this file as a java byte[] array
Myna.File.prototype.readBinary = function()