Class RestEndpointBuilderImpl

  • All Implemented Interfaces:
    org.refcodes.component.Closable, org.refcodes.component.Closable.CloseBuilder<RestEndpointBuilder>, org.refcodes.component.ConnectionStatusAccessor, org.refcodes.component.LinkComponent, org.refcodes.component.LinkComponent.LinkComponentBuilder<RestEndpointBuilder>, org.refcodes.component.Openable, org.refcodes.component.Openable.OpenBuilder<RestEndpointBuilder>, org.refcodes.net.HttpMethodAccessor, org.refcodes.net.HttpMethodAccessor.HttpMethodBuilder<RestEndpointBuilder>, org.refcodes.net.HttpMethodAccessor.HttpMethodMutator, org.refcodes.net.HttpMethodAccessor.HttpMethodProperty, RestEndpoint, RestEndpointBuilder, RestRequestObserver


    public class RestEndpointBuilderImpl
    extends java.lang.Object
    implements RestEndpointBuilder
    The implementation of the RestEndpointBuilder interface as good old POJO for use by different RestServer implementations.
    • Field Detail

      • _httpMethod

        protected org.refcodes.net.HttpMethod _httpMethod
      • _locatorPathPattern

        protected java.lang.String _locatorPathPattern
      • _locatorRegExp

        protected java.util.regex.Pattern _locatorRegExp
      • _connectionStatus

        protected org.refcodes.component.ConnectionStatus _connectionStatus
    • Method Detail

      • setLocatorPathPattern

        public void setLocatorPathPattern​(java.lang.String aLocatorPathPattern)
        Sets the resource locator pattern. The locator may contain wildcards as known from file-systems as follows: A single asterisk ("*") matches zero or more characters within a locator name. A double asterisk ("**") matches zero or more characters across directory levels. A question mark ("?") matches exactly one character within a locator name. You may name a wildcard by prefixing it with "${someWildcardName}". For example a named wildcard may look as follows: "${arg1}=*" or "${arg2}=**" or "${arg3}=?". You can get the text substituting a named wildcard using the method WildcardSubstitutes.getWildcardReplacement(String). For ease of use, a named wildcard with single asterisk ("*") such as "${arg1}=*" can be abbreviated as "${arg1}".
        Specified by:
        setLocatorPathPattern in interface RestEndpointBuilder
        Parameters:
        aLocatorPathPattern - the new locator pattern
      • setLocatorRegExp

        public void setLocatorRegExp​(java.util.regex.Pattern aLocatorRegExp)
        Sets the resource locator (regular expression) pattern.
        Specified by:
        setLocatorRegExp in interface RestEndpointBuilder
        Parameters:
        aLocatorRegExp - the new locator (regular expression) pattern
      • setHttpMethod

        public void setHttpMethod​(org.refcodes.net.HttpMethod aHttpMethod)
        Specified by:
        setHttpMethod in interface org.refcodes.net.HttpMethodAccessor.HttpMethodMutator
      • onRequest

        public void onRequest​(RestRequestEvent aRequest,
                              org.refcodes.net.HttpServerResponse aResponse)
                       throws org.refcodes.net.HttpStatusException
        The invoker provides a request context being a RestRequestEvent) describing the request and a response being a HttpServerResponse to be processed upon by your lambda's code. The method works synchronously and waits (blocks the caller's thread) till it finishes execution.
        Specified by:
        onRequest in interface RestRequestObserver
        Parameters:
        aRequest - The request of type RestRequestEvent describing the request context. Use HttpServerRequest.getRequest(Class) to retrieve the caller's request body or HeaderFieldsAccessor.getHeaderFields() to retrieve the request's cookies and other Header-Fields.
        aResponse - The response of type HttpServerResponse do be processed upon by the method's implementation. Use HttpServerResponse.setResponse(Object) to provide a response for the client. Use HeaderFieldsAccessor.getHeaderFields() to set cookies or modify Header-Fields. Throw one of the HttpStatusException sub-types to signal an according erroneous HTTP state.
        Throws:
        org.refcodes.net.HttpStatusException - to be thrown in case something went wrong.
      • getHttpMethod

        public org.refcodes.net.HttpMethod getHttpMethod​()
        Specified by:
        getHttpMethod in interface org.refcodes.net.HttpMethodAccessor
      • getLocatorPathPattern

        public java.lang.String getLocatorPathPattern​()
        Retrieves the resource Locator-Pattern this endpoint has been registered to. The Locator-Pattern may contain wildcards as known from file-systems as follows: A single asterisk ("*") matches zero or more characters within a locator name. A double asterisk ("**") matches zero or more characters across directory levels. A question mark ("?") matches exactly one character within a locator name. The single asterisk ("*"), the double asterisk ("**") and the question mark ("?") we refer to as wildcard: You get an array with the substitutes of the wildcards using the RestRequestEvent's method WildcardSubstitutes.getWildcardReplacements() inside the RestRequestObserver.onRequest(RestRequestEvent, org.refcodes.net.HttpServerResponse) method. You may name a wildcard by prefixing it with "{someWildcardName}". For example a named wildcard may look as follows: "{arg1}*" or "{arg2}**" or "{arg3}?". The RestRequestEvent lets you access the wildcard substitutes either by index or by name.
        Specified by:
        getLocatorPathPattern in interface RestEndpoint
      • getLocatorRegExp

        public java.util.regex.Pattern getLocatorRegExp​()
        Retrieves the resource locator (regular expression) pattern this endpoint has been registered to. The RestRequestEvent lets you access the matching regular expression groups either by index or by name.
        Specified by:
        getLocatorRegExp in interface RestEndpoint
      • open

        public void open​()
                  throws org.refcodes.component.OpenException
        Specified by:
        open in interface org.refcodes.component.Openable
        Throws:
        org.refcodes.component.OpenException
      • close

        public void close​()
                   throws org.refcodes.component.CloseException
        Specified by:
        close in interface org.refcodes.component.Closable
        Throws:
        org.refcodes.component.CloseException
      • getConnectionStatus

        public org.refcodes.component.ConnectionStatus getConnectionStatus​()
        Specified by:
        getConnectionStatus in interface org.refcodes.component.ConnectionStatusAccessor