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.
        Parameters:
        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 org.refcodes.observer.Observers<RestEndpoint,RestServer>
        Overrides:
        setObserversActive in class org.refcodes.observer.AbstractObservable<RestEndpoint,org.refcodes.net.HttpRequest>
      • isObserversActive

        public boolean isObserversActive​()
        Specified by:
        isObserversActive in interface org.refcodes.observer.Observers<RestEndpoint,RestServer>
        Overrides:
        isObserversActive in class org.refcodes.observer.AbstractObservable<RestEndpoint,org.refcodes.net.HttpRequest>
      • observers

        public java.util.Iterator<RestEndpoint> observers​()
        Specified by:
        observers in interface org.refcodes.observer.Observers<RestEndpoint,RestServer>
        Overrides:
        observers in class org.refcodes.observer.AbstractObservable<RestEndpoint,org.refcodes.net.HttpRequest>
      • 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 org.refcodes.net.RealmAccessor
      • setRealm

        public void setRealm​(java.lang.String aRealm)
        Specified by:
        setRealm in interface org.refcodes.net.RealmAccessor.RealmMutator
      • getBaseLocator

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

        public void setBaseLocator​(java.lang.String aBaseLocator)
        Specified by:
        setBaseLocator in interface org.refcodes.net.BaseLocatorAccessor.BaseLocatorMutator
      • subscribeObserver

        public boolean subscribeObserver​(RestEndpoint aObserver)
        Specified by:
        subscribeObserver in interface org.refcodes.observer.Observable<RestServer>
        Overrides:
        subscribeObserver in class org.refcodes.observer.AbstractObservable<RestEndpoint,org.refcodes.net.HttpRequest>
      • unsubscribeObserver

        public boolean unsubscribeObserver​(RestEndpoint aObserver)
        Specified by:
        unsubscribeObserver in interface org.refcodes.observer.Observable<RestServer>
        Overrides:
        unsubscribeObserver in class org.refcodes.observer.AbstractObservable<RestEndpoint,org.refcodes.net.HttpRequest>
      • addMediaTypeFactory

        public boolean addMediaTypeFactory​(org.refcodes.net.MediaTypeFactory aMediaTypeFactory)
        Specified by:
        addMediaTypeFactory in interface org.refcodes.net.MediaTypeFactoryLookup.MutableMediaTypeFactoryLookup
      • toMediaTypeFactory

        public org.refcodes.net.MediaTypeFactory toMediaTypeFactory​(org.refcodes.net.MediaType aMediaType)
        Specified by:
        toMediaTypeFactory in interface org.refcodes.net.MediaTypeFactoryLookup
      • getFactoryMediaTypes

        public org.refcodes.net.MediaType[] getFactoryMediaTypes​()
        Specified by:
        getFactoryMediaTypes in interface org.refcodes.net.MediaTypeFactoryLookup
      • dispose

        public void dispose​()
        Overrides:
        dispose in class org.refcodes.observer.AbstractObservable<RestEndpoint,org.refcodes.net.HttpRequest>
      • onHttpRequest

        protected void onHttpRequest​(java.net.InetSocketAddress aLocalAddress,
                                     java.net.InetSocketAddress aRemoteAddress,
                                     org.refcodes.net.HttpMethod aHttpMethod,
                                     org.refcodes.net.Url aUrl,
                                     org.refcodes.net.RequestHeaderFields aRequestHeaderFields,
                                     java.io.InputStream aHttpInputStream,
                                     org.refcodes.net.HttpServerResponse aHttpServerResponse)
                              throws org.refcodes.net.HttpStatusException
        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.
        Parameters:
        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:
        org.refcodes.net.HttpStatusException - 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 org.refcodes.net.ContentType toNegotiatedContenType​(org.refcodes.net.RequestHeaderFields 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.
        Parameters:
        aRequestHeaderFields - The request's HeaderField instance to use when determining the best fitting respone's ContentType.
        Returns:
        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,
                                        org.refcodes.net.RequestHeaderFields aRequestHeaderFields,
                                        org.refcodes.net.ResponseHeaderFields aResponseHeaderFields)
                                 throws org.refcodes.exception.MarshalException,
                                        org.refcodes.net.UnsupportedMediaTypeException
        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.
        Parameters:
        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.
        Returns:
        An accordingly encoded response as byte array.
        Throws:
        org.refcodes.exception.MarshalException - thrown when marshaling / serializing an object failed.
        org.refcodes.net.UnsupportedMediaTypeException - 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​(org.refcodes.net.HttpRequest aEvent,
                                    RestEndpoint aObserver,
                                    org.refcodes.controlflow.ExecutionStrategy aExecutionStrategy)
                             throws org.refcodes.exception.VetoException
        Specified by:
        fireEvent in class org.refcodes.observer.AbstractObservable<RestEndpoint,org.refcodes.net.HttpRequest>
        Throws:
        org.refcodes.exception.VetoException
      • doRequestCorrelation

        protected void doRequestCorrelation​(org.refcodes.net.RequestHeaderFields aRequestHeaderFields,
                                            org.refcodes.net.HttpServerResponse aServerResponse)
        Do request correlation.
        Parameters:
        aRequestHeaderFields - the request Header-Fields
        aServerResponse - the server response
      • doSessionCorrelation

        protected void doSessionCorrelation​(org.refcodes.net.RequestHeaderFields aRequestHeaderFields,
                                            org.refcodes.net.HttpServerResponse aServerResponse)
        Do session correlation.
        Parameters:
        aRequestHeaderFields - the request Header-Fields
        aServerResponse - the server response