Class LoopbackRestServer

java.lang.Object
org.refcodes.observer.AbstractObservable<RestEndpoint,org.refcodes.web.HttpRequest>
org.refcodes.rest.AbstractRestfulServer
org.refcodes.rest.LoopbackRestServer
All Implemented Interfaces:
org.refcodes.mixin.Disposable, org.refcodes.mixin.Loggable, org.refcodes.observer.Observable<RestEndpoint>, org.refcodes.observer.Observers<RestEndpoint,RestfulServer>, RestfulServer, org.refcodes.web.BaseLocatorAccessor, org.refcodes.web.BaseLocatorAccessor.BaseLocatorBuilder<RestfulServer>, org.refcodes.web.BaseLocatorAccessor.BaseLocatorMutator, org.refcodes.web.BaseLocatorAccessor.BaseLocatorProperty, org.refcodes.web.MediaTypeFactoryLookup, org.refcodes.web.MediaTypeFactoryLookup.MutableMediaTypeFactoryLookup, org.refcodes.web.RealmAccessor, org.refcodes.web.RealmAccessor.RealmBuilder<RestfulServer>, org.refcodes.web.RealmAccessor.RealmMutator, org.refcodes.web.RealmAccessor.RealmProperty
Direct Known Subclasses:
LoopbackRestServerSingleton

public class LoopbackRestServer extends AbstractRestfulServer implements RestfulServer
Implements a RestfulServer to be used as loopback device e.g. for testing purposes such as testing your RestRequestConsumer implementations. Use the onHttpRequest(InetSocketAddress, InetSocketAddress, HttpMethod, Url, RequestHeaderFields, InputStream, HttpServerResponse) method to simulate REST requests on the LoopbackRestServer. An registered RestEndpoint instances being targeted at will be invoked accordingly.
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.refcodes.web.BaseLocatorAccessor

    org.refcodes.web.BaseLocatorAccessor.BaseLocatorBuilder<B extends org.refcodes.web.BaseLocatorAccessor.BaseLocatorBuilder<B>>, org.refcodes.web.BaseLocatorAccessor.BaseLocatorMutator, org.refcodes.web.BaseLocatorAccessor.BaseLocatorProperty

    Nested classes/interfaces inherited from interface org.refcodes.web.MediaTypeFactoryLookup

    org.refcodes.web.MediaTypeFactoryLookup.MutableMediaTypeFactoryLookup

    Nested classes/interfaces inherited from interface org.refcodes.web.RealmAccessor

    org.refcodes.web.RealmAccessor.RealmBuilder<B extends org.refcodes.web.RealmAccessor.RealmBuilder<B>>, org.refcodes.web.RealmAccessor.RealmMutator, org.refcodes.web.RealmAccessor.RealmProperty
  • Field Summary

    Fields inherited from class org.refcodes.rest.AbstractRestfulServer

    _isVerbose

    Fields inherited from interface org.refcodes.mixin.Loggable

    RUNTIME_LOGGER_CLASS, RUNTIME_LOGGER_FACTORY_CLASS, RUNTIME_LOGGER_FACTORY_METHOD
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    onHttpRequest(InetSocketAddress aLocalAddress, InetSocketAddress aClientAddress, org.refcodes.web.HttpMethod aHttpMethod, org.refcodes.web.Url aUrl, org.refcodes.web.RequestHeaderFields aRequestHeaderFields, InputStream aHttpInputStream, org.refcodes.web.HttpServerResponse aHttpServerResponse)
    Invoke this method to simulate a REST request to be handled by the according registered RestEndpoint instances:.
    void
    onHttpRequest(InetSocketAddress aLocalAddress, InetSocketAddress aClientAddress, org.refcodes.web.HttpMethod aHttpMethod, org.refcodes.web.Url aUrl, org.refcodes.web.RequestHeaderFields aRequestHeaderFields, String aHttpBody, org.refcodes.web.HttpServerResponse aHttpServerResponse)
    Invoke this method to simulate a REST request to be handled by the according registered RestEndpoint instances:.
    withBaseLocator(String aBaseLocator)
    withObserversActive(boolean isActive)
    withRealm(String aRealm)

    Methods inherited from class org.refcodes.observer.AbstractObservable

    clear, doHandleEventListenerException, fireEvent, getThreadPriority, hasObserver, isEmpty, setThreadPriority, size

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.refcodes.web.BaseLocatorAccessor

    getBaseLocator

    Methods inherited from interface org.refcodes.web.BaseLocatorAccessor.BaseLocatorMutator

    setBaseLocator

    Methods inherited from interface org.refcodes.web.BaseLocatorAccessor.BaseLocatorProperty

    letBaseLocator

    Methods inherited from interface org.refcodes.mixin.Loggable

    alert, alert, critical, critical, debug, error, info, notice, panic, trace, warn, warn

    Methods inherited from interface org.refcodes.web.MediaTypeFactoryLookup

    getFactoryMediaTypes, hasMediaTypeFactory, toMediaTypeFactory

    Methods inherited from interface org.refcodes.web.MediaTypeFactoryLookup.MutableMediaTypeFactoryLookup

    addMediaTypeFactory

    Methods inherited from interface org.refcodes.observer.Observable

    hasObserver, subscribeObserver, unsubscribeObserver

    Methods inherited from interface org.refcodes.observer.Observers

    disableObservers, enableObservers, isObserversActive, observers, setObserversActive

    Methods inherited from interface org.refcodes.web.RealmAccessor

    getRealm

    Methods inherited from interface org.refcodes.web.RealmAccessor.RealmMutator

    setRealm

    Methods inherited from interface org.refcodes.web.RealmAccessor.RealmProperty

    letRealm

    Methods inherited from interface org.refcodes.rest.RestfulServer

    onDelete, onDelete, onGet, onGet, onPost, onPost, onPut, onPut, onRequest, onRequest, onRequest, onRequest, onRequest
  • Constructor Details

    • LoopbackRestServer

      public LoopbackRestServer()
  • Method Details

    • onHttpRequest

      public void onHttpRequest(InetSocketAddress aLocalAddress, InetSocketAddress aClientAddress, org.refcodes.web.HttpMethod aHttpMethod, org.refcodes.web.Url aUrl, org.refcodes.web.RequestHeaderFields aRequestHeaderFields, String aHttpBody, org.refcodes.web.HttpServerResponse aHttpServerResponse) throws org.refcodes.web.HttpStatusException
      Invoke this method to simulate a REST request to be handled by the according registered RestEndpoint instances:.
      Parameters:
      aLocalAddress - the local address
      aClientAddress - the client address
      aHttpMethod - The method for the simulated REST request to be used
      aUrl - The query string part of the request.
      aRequestHeaderFields - The simulated REST request's Header-Fields to be used
      aHttpBody - The raw body for the simulated REST request to be used.
      aHttpServerResponse - The HttpServerResponse to be filled with the complete result of processing the request.
      Throws:
      org.refcodes.web.HttpStatusException - thrown in case of HTTP status code related exceptions (e.g. as of a HTTP response was of an erroneous status).
    • onHttpRequest

      public void onHttpRequest(InetSocketAddress aLocalAddress, InetSocketAddress aClientAddress, org.refcodes.web.HttpMethod aHttpMethod, org.refcodes.web.Url aUrl, org.refcodes.web.RequestHeaderFields aRequestHeaderFields, InputStream aHttpInputStream, org.refcodes.web.HttpServerResponse aHttpServerResponse) throws org.refcodes.web.HttpStatusException
      Invoke this method to simulate a REST request to be handled by the according registered RestEndpoint instances:.
      Overrides:
      onHttpRequest in class AbstractRestfulServer
      Parameters:
      aLocalAddress - the local address
      aClientAddress - the client address
      aHttpMethod - The method for the simulated REST request to be used
      aUrl - The query string part of the request.
      aRequestHeaderFields - The simulated REST request's Header-Fields to be used
      aHttpInputStream - The HTTP InputStream representing the body for the simulated REST request to be used.
      aHttpServerResponse - The HttpServerResponse to be filled with the complete result of processing the request.
      Throws:
      org.refcodes.web.HttpStatusException - thrown in case of HTTP status code related exceptions (e.g. as of a HTTP response was of an erroneous status).
    • withBaseLocator

      public LoopbackRestServer withBaseLocator(String aBaseLocator)
      Specified by:
      withBaseLocator in interface org.refcodes.web.BaseLocatorAccessor.BaseLocatorBuilder<RestfulServer>
      Specified by:
      withBaseLocator in interface RestfulServer
    • withRealm

      public LoopbackRestServer withRealm(String aRealm)
      Specified by:
      withRealm in interface org.refcodes.web.RealmAccessor.RealmBuilder<RestfulServer>
      Specified by:
      withRealm in interface RestfulServer
    • withObserversActive

      public LoopbackRestServer withObserversActive(boolean isActive)
      Specified by:
      withObserversActive in interface org.refcodes.observer.Observers<RestEndpoint,RestfulServer>
      Specified by:
      withObserversActive in interface RestfulServer
    • withEnableObservers

      public LoopbackRestServer withEnableObservers()
      Specified by:
      withEnableObservers in interface org.refcodes.observer.Observers<RestEndpoint,RestfulServer>
      Specified by:
      withEnableObservers in interface RestfulServer
    • withDisableObservers

      public LoopbackRestServer withDisableObservers()
      Specified by:
      withDisableObservers in interface org.refcodes.observer.Observers<RestEndpoint,RestfulServer>
      Specified by:
      withDisableObservers in interface RestfulServer