Package org.atmosphere.interceptor
Class SimpleRestInterceptor
- java.lang.Object
-
- org.atmosphere.cpr.AtmosphereInterceptorAdapter
-
- org.atmosphere.interceptor.SimpleRestInterceptor
-
- All Implemented Interfaces:
AtmosphereInterceptor,AtmosphereConfigAware,InvokationOrder
public class SimpleRestInterceptor extends AtmosphereInterceptorAdapter
An Atmosphere interceptor to enable a simple rest binding protocol. This protocol is a simplified version of SwaggerSocket with some new features https://github.com/swagger-api/swaggersocket This interceptor currently handles both Websocket and SSE protocols. It was originally developed for enabling atmosphere for kafka-rest at https://github.com/elakito/kafka-rest-atmosphere- Author:
- elakito
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.atmosphere.interceptor.InvokationOrder
InvokationOrder.PRIORITY
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringPROTOCOL_DETACHED_KEYDeprecated.always use detached modeprotected static java.lang.StringREQUEST_DISPATCHEDprotected static java.lang.StringREQUEST_IDstatic java.lang.StringX_ATMOSPHERE_SIMPLE_REST_PROTOCOL_DETACHEDDeprecated.always use detached modestatic java.lang.StringX_REQUEST_KEYThe internal header consisting of the {tracking-id}#{request-id}-
Fields inherited from interface org.atmosphere.interceptor.InvokationOrder
AFTER_DEFAULT, BEFORE_DEFAULT, FIRST_BEFORE_DEFAULT
-
-
Constructor Summary
Constructors Constructor Description SimpleRestInterceptor()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidconfigure(AtmosphereConfig config)Configure an AtmosphereFramework object.protected AtmosphereRequestcreateAtmosphereRequest(AtmosphereRequest request, java.lang.String body)protected byte[]createResponse(AtmosphereResponse response, byte[] payload)protected static booleangetBoolean(org.json.JSONObject obj, java.lang.String key)protected java.lang.StringgetHeartbeatBroadcasterName()protected java.lang.StringgetHeartbeatTemplate()protected java.lang.Object[]getHeartbeatTemplateArguments()protected static java.lang.StringgetString(org.json.JSONObject obj, java.lang.String key)Actioninspect(AtmosphereResource r)Invoked before anAtmosphereResourcegets dispatched toAtmosphereHandler.protected static booleanisJSONObject(byte[] b)protected static booleanisLastResponse(AtmosphereRequest request, AtmosphereResponse response)protected static org.json.JSONObjectparseJsonPart(java.io.Reader reader)protected static byte[]quote(byte[] b)-
Methods inherited from class org.atmosphere.cpr.AtmosphereInterceptorAdapter
destroy, postInspect, priority, toString
-
-
-
-
Field Detail
-
PROTOCOL_DETACHED_KEY
public static final java.lang.String PROTOCOL_DETACHED_KEY
Deprecated.always use detached modeServlet init property to enable the detached mode in the response- See Also:
- Constant Field Values
-
X_ATMOSPHERE_SIMPLE_REST_PROTOCOL_DETACHED
public static final java.lang.String X_ATMOSPHERE_SIMPLE_REST_PROTOCOL_DETACHED
Deprecated.always use detached modeConnection request property to enable the detached mode in the response- See Also:
- Constant Field Values
-
X_REQUEST_KEY
public static final java.lang.String X_REQUEST_KEY
The internal header consisting of the {tracking-id}#{request-id}- See Also:
- Constant Field Values
-
REQUEST_DISPATCHED
protected static final java.lang.String REQUEST_DISPATCHED
- See Also:
- Constant Field Values
-
REQUEST_ID
protected static final java.lang.String REQUEST_ID
- See Also:
- Constant Field Values
-
-
Method Detail
-
configure
public void configure(AtmosphereConfig config)
Description copied from interface:AtmosphereConfigAwareConfigure an AtmosphereFramework object.- Specified by:
configurein interfaceAtmosphereConfigAware- Overrides:
configurein classAtmosphereInterceptorAdapter- Parameters:
config-AtmosphereConfig
-
inspect
public Action inspect(AtmosphereResource r)
Description copied from interface:AtmosphereInterceptorInvoked before anAtmosphereResourcegets dispatched toAtmosphereHandler.- Specified by:
inspectin interfaceAtmosphereInterceptor- Overrides:
inspectin classAtmosphereInterceptorAdapter- Parameters:
r- aAtmosphereResource- Returns:
Action.CONTINUEorAction.SUSPENDto dispatch theAtmosphereResourceto otherAtmosphereInterceptororAtmosphereHandler. ReturnAction.TYPE.CANCELLEDto stop the processing.
-
getHeartbeatBroadcasterName
protected java.lang.String getHeartbeatBroadcasterName()
-
getHeartbeatTemplate
protected java.lang.String getHeartbeatTemplate()
-
getHeartbeatTemplateArguments
protected java.lang.Object[] getHeartbeatTemplateArguments()
-
createAtmosphereRequest
protected AtmosphereRequest createAtmosphereRequest(AtmosphereRequest request, java.lang.String body) throws java.io.IOException
- Throws:
java.io.IOException
-
createResponse
protected byte[] createResponse(AtmosphereResponse response, byte[] payload)
-
isLastResponse
protected static boolean isLastResponse(AtmosphereRequest request, AtmosphereResponse response)
-
isJSONObject
protected static boolean isJSONObject(byte[] b)
-
quote
protected static byte[] quote(byte[] b)
-
parseJsonPart
protected static org.json.JSONObject parseJsonPart(java.io.Reader reader) throws org.json.JSONException- Throws:
org.json.JSONException
-
getString
protected static java.lang.String getString(org.json.JSONObject obj, java.lang.String key)
-
getBoolean
protected static boolean getBoolean(org.json.JSONObject obj, java.lang.String key)
-
-