php.java.servlet
Class HttpContext

java.lang.Object
  extended by php.java.bridge.http.Context
      extended by php.java.servlet.HttpContext
All Implemented Interfaces:
IContext, IManaged, Invocable
Direct Known Subclasses:
RemoteContext

public class HttpContext
extends Context

A custom context which keeps the HttpServletResponse. Used when JSR223 is not available.

Author:
jostb

Field Summary
 
Fields inherited from interface php.java.bridge.http.IContext
ENGINE_SCOPE, GLOBAL_SCOPE, JAVA_BRIDGE, PHP_PROCEDURE, SERVLET, SERVLET_CONFIG, SERVLET_CONTEXT, SERVLET_REQUEST, SERVLET_RESPONSE
 
Constructor Summary
HttpContext(javax.servlet.ServletContext kontext, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          Create a new context.
 
Method Summary
 java.lang.Object getAttribute(java.lang.String name)
          Retrieves the value for getAttribute(String, int) for the lowest scope in which it returns a non-null value.
 java.lang.Object getHttpServletRequest()
          Return the http servlet request
 java.lang.Object getHttpServletResponse()
          Return the http servlet response
 java.lang.String getRealPath(java.lang.String path)
          Get the full file system path for the given resource.
static java.lang.String getRealPathInternal(java.lang.String path, javax.servlet.ServletContext ctx)
          Deprecated. Use ServletUtil.getRealPath(ServletContext, String)
 java.lang.String getRedirectString()
          Deprecated.  
 java.lang.String getRedirectString(java.lang.String webPath)
          Deprecated.  
 java.lang.Object getServlet()
          Return the http servlet
 java.lang.Object getServletConfig()
          Return the servlet config
 java.lang.Object getServletContext()
          Return the servlet context
 java.lang.String getSocketName()
          Return the socket name, for example 8080
 java.io.Writer getWriter()
          Retrieves an instance of java.io.Writer which can be used by scripts to display their output.
static void handleManaged(java.lang.Object closeable, javax.servlet.ServletContext ctx)
          Only for internal use.
 java.lang.Object init(java.lang.Object callable)
          Initialize a library.
 void onShutdown(java.lang.Object closeable)
          Register a shutdown hook for the library.
 
Methods inherited from class php.java.bridge.http.Context
call, get, getAll, getAttribute, getAttributesScope, getManageable, getRealPathInternal, getRedirectURL, handleManaged, put, putAll, remove, removeAttribute, setAttribute
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpContext

public HttpContext(javax.servlet.ServletContext kontext,
                   javax.servlet.http.HttpServletRequest req,
                   javax.servlet.http.HttpServletResponse res)
Create a new context.

Parameters:
kontext - The servlet context
req - The servlet request
res - The HttpServletResponse
Method Detail

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
                              throws java.lang.IllegalArgumentException
Retrieves the value for getAttribute(String, int) for the lowest scope in which it returns a non-null value.

Specified by:
getAttribute in interface IContext
Overrides:
getAttribute in class Context
Parameters:
name - the name of the attribute
Returns:
the value of the attribute
Throws:
java.lang.IllegalArgumentException

getWriter

public java.io.Writer getWriter()
                         throws java.io.IOException
Retrieves an instance of java.io.Writer which can be used by scripts to display their output.

Specified by:
getWriter in interface IContext
Overrides:
getWriter in class Context
Returns:
an instance of java.io.Writer
Throws:
java.io.IOException

getHttpServletResponse

public java.lang.Object getHttpServletResponse()
Return the http servlet response

Specified by:
getHttpServletResponse in interface IContext
Overrides:
getHttpServletResponse in class Context
Returns:
The http servlet reponse

getHttpServletRequest

public java.lang.Object getHttpServletRequest()
Return the http servlet request

Specified by:
getHttpServletRequest in interface IContext
Overrides:
getHttpServletRequest in class Context
Returns:
The http servlet request

getServlet

public java.lang.Object getServlet()
Return the http servlet

Specified by:
getServlet in interface IContext
Overrides:
getServlet in class Context
Returns:
The http servlet

getServletConfig

public java.lang.Object getServletConfig()
Return the servlet config

Specified by:
getServletConfig in interface IContext
Overrides:
getServletConfig in class Context
Returns:
The servlet config

getServletContext

public java.lang.Object getServletContext()
Return the servlet context

Specified by:
getServletContext in interface IContext
Overrides:
getServletContext in class Context
Returns:
The servlet context

handleManaged

public static void handleManaged(java.lang.Object closeable,
                                 javax.servlet.ServletContext ctx)
Only for internal use.

Used when scripts are running within of a servlet environment: Either php.java.servlet.Context or the JSR223 Context (see PhpSimpleHttpScriptContext).
Outside of a servlet environment use the ContextLoaderListener instead: Either the Standalone or the JSR223 Standalone (see PhpScriptContext).

Parameters:
closeable - The manageable beforeShutdown(), will be called by the ContextLoaderListener.contextDestroyed(javax.servlet.ServletContextEvent)
ctx - The ServletContext

init

public java.lang.Object init(java.lang.Object callable)
                      throws java.lang.Exception
Initialize a library. This method may be called via java_context()->init(...) to initialize a library. Within init() onShutdown() may be called to register a shutdown hook for the library.

Specified by:
init in interface IManaged
Overrides:
init in class Context
Parameters:
callable - Its call() method will be called synchronized.
Returns:
The result of the call() invocation.
Throws:
java.lang.Exception - The result of the call() invocation.

onShutdown

public void onShutdown(java.lang.Object closeable)
Register a shutdown hook for the library. This method may be called via java_context()->onShutdown(...) to register a shutdown hook during init().

Specified by:
onShutdown in interface IManaged
Overrides:
onShutdown in class Context
Parameters:
closeable - Its close() method will be called before the context or the VM terminates.

getRealPathInternal

public static java.lang.String getRealPathInternal(java.lang.String path,
                                                   javax.servlet.ServletContext ctx)
Deprecated. Use ServletUtil.getRealPath(ServletContext, String)

Only for internal use

Parameters:
path - the path
ctx - the servlet context
Returns:
the real path

getRealPath

public java.lang.String getRealPath(java.lang.String path)
Get the full file system path for the given resource.

Specified by:
getRealPath in interface IContext
Overrides:
getRealPath in class Context
Parameters:
path - the relative path to an existing resource
Returns:
the file system path

getRedirectString

public java.lang.String getRedirectString()
Deprecated. 

Specified by:
getRedirectString in interface IContext
Overrides:
getRedirectString in class Context

getRedirectString

public java.lang.String getRedirectString(java.lang.String webPath)
Deprecated. 

Specified by:
getRedirectString in interface IContext
Overrides:
getRedirectString in class Context

getSocketName

public java.lang.String getSocketName()
Return the socket name, for example 8080

Specified by:
getSocketName in interface IContext
Overrides:
getSocketName in class Context
Returns:
the socket name