Class TemplateContextResponse


  • public class TemplateContextResponse
    extends java.lang.Object
    This class is used as a template context response object. Some request context is also included under templateContext.request This includes:
    • HTTP Method
    • Request path
    • Headers
    • Request parameters
    • The query string
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void sendRedirect​(java.lang.String url)
      Set response redirect url
      void setHeader​(java.lang.String key, java.lang.String value)
      Set response header
      void setStatus​(int code)
      Set response status code
      void write​(java.lang.String message)
      Send content to the output stream
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • TemplateContextResponse

        public TemplateContextResponse()
    • Method Detail

      • write

        public void write​(java.lang.String message)
        Send content to the output stream
         
         Example 
         
         templateContext.response.body.write("Hello")
         
         A macro can be retrieved and displayed to the output stream
         
         templateContext.macros["@TIMESTAMP@"]
         
         
        Parameters:
        message - message to be displayed
      • setHeader

        public void setHeader​(java.lang.String key,
                              java.lang.String value)
        Set response header
         
         
         Example
         To set the response header Content-Type
          
         templateContext.response.setHeader("Content-Type","application/json")
         
         
        Parameters:
        key - header key
        value - header value
      • sendRedirect

        public void sendRedirect​(java.lang.String url)
        Set response redirect url
         
         Example 
         To set the response redirect url
         
         templateContext.response.sendRedirect("https://www.ibm.com")
         
         
         
        Parameters:
        url - redirect url
      • setStatus

        public void setStatus​(int code)
        Set response status code
         
          
         Example 
         To set the response status code
         
         templateContext.response.setStatus(400)
         
         
        Parameters:
        code - status code