Class ApiImplementor

    • Constructor Detail

      • ApiImplementor

        public ApiImplementor()
    • Method Detail

      • getApiViews

        public java.util.List<ApiView> getApiViews()
      • getApiActions

        public java.util.List<ApiAction> getApiActions()
      • getApiOthers

        public java.util.List<ApiOther> getApiOthers()
      • addApiView

        public void addApiView​(ApiView view)
      • addApiOthers

        public void addApiOthers​(ApiOther other)
      • addApiAction

        public void addApiAction​(ApiAction action)
      • addApiShortcut

        public void addApiShortcut​(java.lang.String shortcut)
      • addApiOptions

        public void addApiOptions​(AbstractParam param)
        Adds the given options to the API implementor.
        Parameters:
        param - the options for the API
        See Also:
        ZapApiIgnore
      • handleApiView

        public ApiResponse handleApiView​(java.lang.String name,
                                         net.sf.json.JSONObject params)
                                  throws ApiException
        Override if implementing one or more views
        Parameters:
        name - the name of the requested view
        params - the API request parameters
        Returns:
        the API response
        Throws:
        ApiException - if an error occurred while handling the API view endpoint
      • handleApiAction

        public ApiResponse handleApiAction​(java.lang.String name,
                                           net.sf.json.JSONObject params)
                                    throws ApiException
        Override if implementing one or more actions
        Parameters:
        name - the name of the requested action
        params - the API request parameters
        Returns:
        the API response
        Throws:
        ApiException - if an error occurred while handling the API action endpoint
      • handleApiOther

        public HttpMessage handleApiOther​(HttpMessage msg,
                                          java.lang.String name,
                                          net.sf.json.JSONObject params)
                                   throws ApiException
        Override if implementing one or more 'other' operations - these are operations that _dont_ return structured data
        Parameters:
        msg - the HTTP message containing the API request
        name - the name of the requested other endpoint
        params - the API request parameters
        Returns:
        the HTTP message with the API response
        Throws:
        ApiException - if an error occurred while handling the API other endpoint
      • handleApiPersistentConnection

        public void handleApiPersistentConnection​(HttpMessage msg,
                                                  HttpInputStream httpIn,
                                                  HttpOutputStream httpOut,
                                                  java.lang.String name,
                                                  net.sf.json.JSONObject params)
                                           throws ApiException
        Override if implementing one or more 'persistent connection' operations. These are operations that maintain long running connections, potentially staying alive as long as the client holds them open.
        Parameters:
        msg - the HTTP message containing the API request
        httpIn - the input stream
        httpOut - the output stream
        name - the name of the requested pconn endpoint
        params - the API request parameters
        Throws:
        ApiException - if an error occurred while handling the API pconn endpoint
      • handleCallBack

        public java.lang.String handleCallBack​(HttpMessage msg)
                                        throws ApiException
        Override if handling callbacks
        Parameters:
        msg - the HTTP message containing the API request and response
        Returns:
        the API response (set in the HTTP response body)
        Throws:
        ApiException - if an error occurred while handling the API callback
      • getPrefix

        public abstract java.lang.String getPrefix()
      • getI18nPrefix

        protected java.lang.String getI18nPrefix()
        Gets the prefix for default resource keys for the description of the API implementor and its elements.

        Defaults to getPrefix().

        Returns:
        the prefix for i18n keys.
        Since:
        2.10.0
      • getDescriptionKey

        public java.lang.String getDescriptionKey()
        Gets the resource key of the description.

        Defaults to getI18nPrefix() + ".api.desc".

        Returns:
        the key of the description.
        Since:
        2.9.0
        See Also:
        I18N.getString(String)
      • getApiAction

        public ApiAction getApiAction​(java.lang.String name)
      • getApiView

        public ApiView getApiView​(java.lang.String name)
      • getApiOther

        public ApiOther getApiOther​(java.lang.String name)
      • getApiShortcuts

        protected java.util.List<java.lang.String> getApiShortcuts()
      • getApiPersistentConnection

        public ApiPersistentConnection getApiPersistentConnection​(java.lang.String name)
      • getParam

        protected int getParam​(net.sf.json.JSONObject params,
                               java.lang.String name,
                               int defaultValue)
      • getParam

        protected long getParam​(net.sf.json.JSONObject params,
                                java.lang.String name,
                                long defaultValue)
      • getParam

        protected java.lang.String getParam​(net.sf.json.JSONObject params,
                                            java.lang.String name,
                                            java.lang.String defaultValue)
      • getParam

        protected boolean getParam​(net.sf.json.JSONObject params,
                                   java.lang.String name,
                                   boolean defaultValue)
      • validateParamExists

        protected void validateParamExists​(net.sf.json.JSONObject parameters,
                                           java.lang.String name)
                                    throws ApiException
        Validates that a parameter with the given name exists (and it has a value) in the given parameters.
        Parameters:
        parameters - the parameters
        name - the name of the parameter that must exist
        Throws:
        ApiException - if the parameter with the given name does not exist or it has no value.
        Since:
        2.6.0
      • addCustomHeaders

        public void addCustomHeaders​(java.lang.String name,
                                     API.RequestType type,
                                     HttpMessage msg)
        Override to add custom headers for specific API operations
        Parameters:
        name - the name of the operation
        type - the type of the operation
        msg - the HTTP response message to the API request