getContext
The j2eeLib.getContext() system
function returns an object that holds details specific to the context
in which your code invokes the j2eeLib library
functions. The context might be JavaServer Faces, REST-RPC services,
or SOAP services. Within SOAP services, the context is different for
JAX-RPC or JAX-WS.
You must define an external type and cast the return value to that
type. See the examples in this topic.
Syntax
j2eeLib.getContext()
returns (context Object)
- context
- Depending on the environment, the function returns one of the
following context objects:
- javax.faces.context.ExternalContext
- The call is made from within a JSF application.
- javax.servlet.http.HttpServletRequest
- The call is made from within an EGL REST-RPC service.
- javax.xml.rpc.server.ServletEndpointContext
- The call is made from within an EGL SOAP service that uses JAX-RPC.
- javax.xml.ws.WebServiceContext
- The call is made from within an EGL SOAP service that uses JAX-WS.
Example
The following code is part of a
program called from an EGL REST-RPC service:
context Object = j2eelib.getContext();
if(context isa HttpServletRequest)
writestdout("----------this is an EGL REST-RPC service");
session HttpSession = (context as HttpServletRequest).getSession();
writestdout("----------http sessionid:" + session.getId());
end
You must define the
HttpServletRequest type
as an ExternalType:
externalType HttpServletRequest type JavaObject {packageName = "javax.servlet.http"}
function getSession() returns(HttpSession);
end
That definition in turn requires the definition
of the
HttpSession ExternalType:
externalType HttpSession type JavaObject {packageName = "javax.servlet.http"}
function getId() returns(STRING);
end