Class AbstractRestServer

    • Field Detail

      • _hasRequestCorrelation

        protected boolean _hasRequestCorrelation
      • _hasSessionCorrelation

        protected boolean _hasSessionCorrelation
    • Constructor Detail

      • AbstractRestServer

        public AbstractRestServer​()
        Constructs a AbstractRestServer pre-configured with MediaTypeFactory instances for JSON and REST.
      • AbstractRestServer

        public AbstractRestServer​(java.util.concurrent.ExecutorService aExecutorService)
        CConstructs a AbstractRestServer pre-configured with MediaTypeFactory instances for JSON and REST.
        aExecutorService - An executor service to be used when creating Threads.
    • Method Detail

      • initMedaTypeFactories

        protected void initMedaTypeFactories​()
        Adds the default MediaTypeFactory instances. Can be overridden.
      • setObserversActive

        public void setObserversActive​(boolean isActive)
        Specified by:
        setObserversActive in interface<RestEndpoint,RestServer>
        setObserversActive in class<RestEndpoint,>
      • isObserversActive

        public boolean isObserversActive​()
        Specified by:
        isObserversActive in interface<RestEndpoint,RestServer>
        isObserversActive in class<RestEndpoint,>
      • observers

        public java.util.Iterator<RestEndpoint> observers​()
        Specified by:
        observers in interface<RestEndpoint,RestServer>
        observers in class<RestEndpoint,>
      • setRequestCorrelation

        public void setRequestCorrelation​(boolean hasRequestCorrelation)
        Specified by:
        setRequestCorrelation in interface org.refcodes.runtime.RequestCorrelation<RestServer>
      • hasRequestCorrelation

        public boolean hasRequestCorrelation​()
        Specified by:
        hasRequestCorrelation in interface org.refcodes.runtime.RequestCorrelation<RestServer>
      • setSessionCorrelation

        public void setSessionCorrelation​(boolean hasSessionCorrelation)
        Specified by:
        setSessionCorrelation in interface org.refcodes.runtime.SessionCorrelation<RestServer>
      • hasSessionCorrelation

        public boolean hasSessionCorrelation​()
        Specified by:
        hasSessionCorrelation in interface org.refcodes.runtime.SessionCorrelation<RestServer>
      • getRealm

        public java.lang.String getRealm​()
        Specified by:
        getRealm in interface
      • setRealm

        public void setRealm​(java.lang.String aRealm)
        Specified by:
        setRealm in interface
      • getBaseLocator

        public java.lang.String getBaseLocator​()
        Specified by:
        getBaseLocator in interface
      • setBaseLocator

        public void setBaseLocator​(java.lang.String aBaseLocator)
        Specified by:
        setBaseLocator in interface
      • subscribeObserver

        public boolean subscribeObserver​(RestEndpoint aObserver)
        Specified by:
        subscribeObserver in interface<RestServer>
        subscribeObserver in class<RestEndpoint,>
      • unsubscribeObserver

        public boolean unsubscribeObserver​(RestEndpoint aObserver)
        Specified by:
        unsubscribeObserver in interface<RestServer>
        unsubscribeObserver in class<RestEndpoint,>
      • addMediaTypeFactory

        public boolean addMediaTypeFactory​( aMediaTypeFactory)
        Specified by:
        addMediaTypeFactory in interface
      • toMediaTypeFactory

        public toMediaTypeFactory​( aMediaType)
        Specified by:
        toMediaTypeFactory in interface
      • getFactoryMediaTypes

        public[] getFactoryMediaTypes​()
        Specified by:
        getFactoryMediaTypes in interface
      • dispose

        public void dispose​()
        dispose in class<RestEndpoint,>
      • onHttpRequest

        protected void onHttpRequest​( aLocalAddress,
        Extensions of this class disect an incoming request and pass it to this method for doing the actual invocation of the registered RestEndpoint instances. An extension might call this method from inside an event (request) handler.
        aLocalAddress - The host and port of your REST service.
        aRemoteAddress - The host and port for the caller.
        aHttpMethod - The HttpMethod of the request.
        aUrl - The Url from which to take the URL specific data.
        aRequestHeaderFields - The Header-Fields (HeaderFields) belonging to the request.
        aHttpInputStream - The body passed by the request.
        aHttpServerResponse - A HttpServerResponse instance to be used by the extension to produce an according HTTP-Response.
        Throws: - thrown in case of an RestEndpoint responsible for the given request encountered a problem or none RestEndpoint felt responsible to produce a HttpServerResponse.
      • toNegotiatedContenType

        protected toNegotiatedContenType​( aRequestHeaderFields)
        Determines the best fitting respone's ContentType. The default Content-Type-Negotiation implementation of this method makes use of the RequestHeaderFields and matches them against the supported MediaType types ( retrieved via getFactoryMediaTypes()). May be overwritten to enforce another Content-Type-Negotiation strategy.
        aRequestHeaderFields - The request's HeaderField instance to use when determining the best fitting respone's ContentType.
        The best fitting (as of the implemented Content-Type-Negotiation strategy) Content-Type to be used for the response.
      • toResponseBody

        protected byte[] toResponseBody​(java.lang.Object aResponse,
                                 throws org.refcodes.exception.MarshalException,
        Creates a String MediaType encoded as of the HeaderField.CONTENT_TYPE from the response header or if not set as of the HeaderField.ACCEPT from the request header or if not set as of the HeaderField.CONTENT_TYPE from the request header.
        aResponse - The response which to encode as of the detected MediaTypes.
        aRequestHeaderFields - The Header-Fields from the request.
        aResponseHeaderFields - The Header-Fields from the response.
        An accordingly encoded response as byte array.
        org.refcodes.exception.MarshalException - thrown when marshaling / serializing an object failed. - thrown in case none of the identified media types is supported, e.g. no required MediaTypeFactory has been registered as of addMediaTypeFactory(MediaTypeFactory).
      • fireEvent

        protected boolean fireEvent​( aEvent,
                                    RestEndpoint aObserver,
                                    org.refcodes.controlflow.ExecutionStrategy aExecutionStrategy)
                             throws org.refcodes.exception.VetoException
        Specified by:
        fireEvent in class<RestEndpoint,>
      • doRequestCorrelation

        protected void doRequestCorrelation​( aRequestHeaderFields,
        Do request correlation.
        aRequestHeaderFields - the request Header-Fields
        aServerResponse - the server response
      • doSessionCorrelation

        protected void doSessionCorrelation​( aRequestHeaderFields,
        Do session correlation.
        aRequestHeaderFields - the request Header-Fields
        aServerResponse - the server response