Class BaseAriAction


  • public class BaseAriAction
    extends java.lang.Object
    Base functionality for ARI actions

    Provides asynchronous and synchronous methods for forwarding requests to the HTTP or WebSocket server.

    Provides serialize/deserialize interface for JSON encoded objects

    • Constructor Detail

      • BaseAriAction

        public BaseAriAction()
    • Method Detail

      • encodeUrlPart

        protected java.lang.String encodeUrlPart​(java.lang.String urlPart)
        Exception safe way to encode url parts
        Parameters:
        urlPart - the part to encode
        Returns:
        a encoded string
        See Also:
        ARIEncoder.ENCODING
      • httpActionSync

        protected java.lang.String httpActionSync​(BaseAriAction.AriRequest request)
                                           throws RestException
        Initiate synchronous HTTP interaction with server
        Parameters:
        request - the request object
        Returns:
        Response from server
        Throws:
        RestException - when error
      • httpActionSyncAsBytes

        protected byte[] httpActionSyncAsBytes​(BaseAriAction.AriRequest request)
                                        throws RestException
        Initiate synchronous HTTP interaction with server
        Parameters:
        request - the request object
        Returns:
        Response from server
        Throws:
        RestException - when error
      • httpActionAsync

        protected <A,​C extends A> void httpActionAsync​(BaseAriAction.AriRequest request,
                                                             AriCallback<java.util.List<A>> callback,
                                                             com.fasterxml.jackson.core.type.TypeReference<java.util.List<C>> klazzType)
      • serializeToJson

        public static java.lang.String serializeToJson​(java.lang.Object obj)
        Serialize an object to json
        Parameters:
        obj - the Object
        Returns:
        String
      • deserializeJson

        public static <T> T deserializeJson​(java.lang.String json,
                                            java.lang.Class<T> klazz)
                                     throws RestException
        Deserialize a type
        Type Parameters:
        T - the class to deserialize to
        Parameters:
        json - the json string
        klazz - the class to deserialize to
        Returns:
        Deserialized type
        Throws:
        RestException - when fail to deserialize
      • deserializeJson

        public static <T> T deserializeJson​(java.lang.String json,
                                            com.fasterxml.jackson.core.type.TypeReference<T> klazzType)
                                     throws RestException
        Deserialize a list
        Type Parameters:
        T - the class to deserialize to
        Parameters:
        json - the json string
        klazzType - the class to deserialize to
        Returns:
        The deserialized list
        Throws:
        RestException - when fail to deserialize
      • deserializeJsonAsAbstractList

        public static <A,​C extends A> java.util.List<A> deserializeJsonAsAbstractList​(java.lang.String json,
                                                                                            com.fasterxml.jackson.core.type.TypeReference<java.util.List<C>> refConcreteType)
                                                                                     throws RestException
        Deserialize an object as a list of interface. Class erasure in Java plain sucks, I tell ya.

        In theory we should be safe given the condition that A extends C. I hope at least. This is bug #17 - Avoid Lists of ? extends something

        Type Parameters:
        A - The abstract type for members of the list.
        C - The concrete type for members of the list.
        Parameters:
        json - Data in
        refConcreteType - The reference concrete type, should be a List<C>
        Returns:
        a list of A's
        Throws:
        RestException - when fail to deserialize
      • deserializeEvent

        public static Message deserializeEvent​(java.lang.String json,
                                               java.lang.Class<?> klazz)
                                        throws RestException
        Deserialize the event.
        Parameters:
        json - the json string
        klazz - the class to deserialize to
        Returns:
        The event deserialized.
        Throws:
        RestException - when fail to deserialize
      • setHttpClient

        public void setHttpClient​(HttpClient httpClient)
      • getHttpClient

        public HttpClient getHttpClient()
      • setWsClient

        public void setWsClient​(WsClient wsClient)
      • getWsClient

        public WsClient getWsClient()
      • setLiveActionList

        public void setLiveActionList​(java.util.List<BaseAriAction> liveActionList)
      • getLiveActionList

        public java.util.List<BaseAriAction> getLiveActionList()
      • setForcedResponse

        public void setForcedResponse​(java.lang.String forcedResponse)
      • getForcedResponse

        public java.lang.String getForcedResponse()
      • setObjectMapperLessStrict

        public static void setObjectMapperLessStrict()