Class JSONScreen
- java.lang.Object
-
- org.apache.turbine.modules.screens.RawScreen
-
- org.apache.turbine.modules.screens.JSONScreen
-
- Direct Known Subclasses:
JSONSecureScreen
public class JSONScreen extends RawScreen
A Screen class for dealing with JSON-RPC requests. Typically you would extend this class and override the doOutput() method to use TurbineJsonRpc to register the POJOs that will provide the functions you are making available via JSON-RPC. Use JSONSecureScreen if you need the user to be logged in prior to executing the functions you provide.Here is an example from a superclass:
public void doOutput(PipelineData data) throws Exception { User user = data.getUser(); MyJsonFunctions myFunctions = new MyJsonFunctions(user.getName()); // Session specific TurbineJsonRpc.registerObject(data.getSession(), "myFunctions", myFunctions); // Global //TurbineJsonRpc.registerObjectGlobal("testGlobal", testObject); super.doOutput(data); }
The class MyFunctions would be something like:
public class MyJsonFunctions { private String getHello(String clientParameter) { return "Hello " + clientParameter; } }
This code is derived from the com.metaparadigm.jsonrpc.JSONRPCServlet and (after upgrade) checked against org.jabsorb.JSONRPCServlet.
- Version:
- $Id$
- Author:
- brad@folkens.com, Scott Eade
-
-
Field Summary
Fields Modifier and Type Field Description protected static int
BUFFER_SIZE
protected static String
JSONRPC_CONTENT_TYPE
protected JsonRpcService
jsonRpcService
Injected service instance-
Fields inherited from interface org.apache.turbine.modules.Screen
CACHE_SIZE_DEFAULT, CACHE_SIZE_KEY, NAME, PREFIX
-
-
Constructor Summary
Constructors Constructor Description JSONScreen()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
doOutput(PipelineData pipelineData)
Output the dynamic content.protected String
getContentType(PipelineData pipelineData)
Set the content type.
-
-
-
Field Detail
-
JSONRPC_CONTENT_TYPE
protected static final String JSONRPC_CONTENT_TYPE
- See Also:
- Constant Field Values
-
BUFFER_SIZE
protected static final int BUFFER_SIZE
- See Also:
- Constant Field Values
-
jsonRpcService
protected JsonRpcService jsonRpcService
Injected service instance
-
-
Constructor Detail
-
JSONScreen
public JSONScreen()
-
-
Method Detail
-
getContentType
protected String getContentType(PipelineData pipelineData)
Description copied from class:RawScreen
Set the content type. This method should be overridden to actually set the real content-type header of the output.- Specified by:
getContentType
in classRawScreen
- Parameters:
pipelineData
- Turbine information.- Returns:
- A String with the content type.
- See Also:
RawScreen.getContentType(org.apache.turbine.pipeline.PipelineData)
-
doOutput
protected void doOutput(PipelineData pipelineData) throws Exception
Output the dynamic content. Encoding is UTF-8. @JSONRPC_CONTENT_TYPE
: "application/json;charset=utf-8".
-
-