Class PlainJSONScreen
- java.lang.Object
-
- org.apache.turbine.modules.screens.RawScreen
-
- org.apache.turbine.modules.screens.PlainJSONScreen
-
- Direct Known Subclasses:
PlainJSONSecureAnnotatedScreen
public class PlainJSONScreen extends RawScreen
A Screen class for dealing with JSON requests. Typically you would extend this class and override the doOutput() method to use it by setting the JSON output into rundata.setMessage( serialized ). As convenience you may use inject in your extended class the Turbine service JsonService UsePlainJSONSecureAnnotatedScreenif you need the user to be logged in or having a special role in prior to executing the functions you provide.Here is an example from a subclass:
public void doOutput(PipelineData pipelineData) throws Exception { RunData data = pipelineData.getRunData(); JSONStrategy strategy = null; try { strategy = new XYStrategy(); // the result goes into rundata.message strategy.execute(data, jsonService); } catch ( Exception e ) { log.error( "init failed for "+strategy , e); String msg = new JSONObject().put("error", e.getMessage()).toString(); data.setMessage( msg ); } super.doOutput(data); }- Version:
- $Id$
- Author:
- gk
-
-
Field Summary
Fields Modifier and Type Field Description protected static intBUFFER_SIZEprotected static StringJSON_TYPE-
Fields inherited from interface org.apache.turbine.modules.Screen
CACHE_SIZE_DEFAULT, CACHE_SIZE_KEY, NAME, PREFIX
-
-
Constructor Summary
Constructors Constructor Description PlainJSONScreen()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voiddoOutput(PipelineData pipelineData)Output JSON content set intoRunData.getMessage().protected StringgetContentType(PipelineData pipelineData)Set the content type.
-
-
-
Field Detail
-
JSON_TYPE
protected static final String JSON_TYPE
- See Also:
- Constant Field Values
-
BUFFER_SIZE
protected static final int BUFFER_SIZE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PlainJSONScreen
public PlainJSONScreen()
-
-
Method Detail
-
getContentType
protected String getContentType(PipelineData pipelineData)
Description copied from class:RawScreenSet the content type. This method should be overridden to actually set the real content-type header of the output.- Specified by:
getContentTypein 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 JSON content set intoRunData.getMessage(). Encoding is UTF-8. @JSON_TYPE: "application/json;charset=utf-8".
-
-