Class JdkHttpRestServer

java.lang.Object
org.refcodes.observer.AbstractObservable<RestEndpoint,org.refcodes.web.HttpRequest>
org.refcodes.rest.AbstractRestServer
org.refcodes.rest.JdkHttpRestServer
All Implemented Interfaces:
org.refcodes.component.Closable, org.refcodes.component.Closable.CloseBuilder<org.refcodes.component.ConnectionComponent.ConnectionComponentBuilder<org.refcodes.web.HttpServerContext,HttpRestServer>>, org.refcodes.component.ConnectionComponent<org.refcodes.web.HttpServerContext>, org.refcodes.component.ConnectionComponent.ConnectionComponentBuilder<org.refcodes.web.HttpServerContext,HttpRestServer>, org.refcodes.component.ConnectionOpenable<org.refcodes.web.HttpServerContext>, org.refcodes.component.ConnectionOpenable.ConnectionOpenBuilder<org.refcodes.web.HttpServerContext,org.refcodes.component.ConnectionComponent.ConnectionComponentBuilder<org.refcodes.web.HttpServerContext,HttpRestServer>>, org.refcodes.component.ConnectionStatusAccessor, org.refcodes.component.LinkComponent, org.refcodes.component.Openable, org.refcodes.component.OpenedAccessor, org.refcodes.io.MaxConnectionsAccessor, org.refcodes.io.MaxConnectionsAccessor.MaxConnectionsBuilder<HttpRestServer>, org.refcodes.io.MaxConnectionsAccessor.MaxConnectionsMutator, org.refcodes.io.MaxConnectionsAccessor.MaxConnectionsProperty, org.refcodes.mixin.Disposable, org.refcodes.mixin.PortAccessor, org.refcodes.mixin.PortAccessor.PortBuilder<HttpRestServer>, org.refcodes.mixin.PortAccessor.PortMutator, org.refcodes.mixin.PortAccessor.PortProperty, org.refcodes.observer.Observable<RestEndpoint>, org.refcodes.observer.Observers<RestEndpoint,RestServer>, HttpExceptionHandlerAccessor, HttpExceptionHandlerAccessor.HttpExceptionHandlerBuilder<HttpRestServer>, HttpExceptionHandlerAccessor.HttpExceptionHandlerMutator, HttpExceptionHandlerAccessor.HttpExceptionHandlerProperty, HttpExceptionHandlingAccessor, HttpExceptionHandlingAccessor.HttpExceptionHandlingBuilder<HttpRestServer>, HttpExceptionHandlingAccessor.HttpExceptionHandlingMutator, HttpExceptionHandlingAccessor.HttpExceptionHandlingProperty, HttpRestServer, RestServer, org.refcodes.security.KeyStoreDescriptorAccessor, org.refcodes.security.KeyStoreDescriptorAccessor.KeyStoreDescriptorBuilder<HttpRestServer>, org.refcodes.security.KeyStoreDescriptorAccessor.KeyStoreDescriptorMutator, org.refcodes.security.KeyStoreDescriptorAccessor.KeyStoreDescriptorProperty, org.refcodes.web.BaseLocatorAccessor, org.refcodes.web.BaseLocatorAccessor.BaseLocatorBuilder<RestServer>, org.refcodes.web.BaseLocatorAccessor.BaseLocatorMutator, org.refcodes.web.BaseLocatorAccessor.BaseLocatorProperty, org.refcodes.web.BasicAuthObservable<HttpRestServer>, org.refcodes.web.HttpsConnectionRequestObservable<HttpRestServer>, org.refcodes.web.HttpServerInterceptable, org.refcodes.web.MediaTypeFactoryLookup, org.refcodes.web.MediaTypeFactoryLookup.MutableMediaTypeFactoryLookup, org.refcodes.web.PostHttpInterceptable<org.refcodes.web.PostHttpServerInterceptor>, org.refcodes.web.PostHttpServerInterceptable, org.refcodes.web.PreHttpInterceptable<org.refcodes.web.PreHttpServerInterceptor>, org.refcodes.web.PreHttpServerInterceptable, org.refcodes.web.RealmAccessor, org.refcodes.web.RealmAccessor.RealmBuilder<RestServer>, org.refcodes.web.RealmAccessor.RealmMutator, org.refcodes.web.RealmAccessor.RealmProperty, org.refcodes.web.SchemeAccessor, org.refcodes.web.SchemeAccessor.SchemeBuilder<HttpRestServer>, org.refcodes.web.SchemeAccessor.SchemeMutator, org.refcodes.web.SchemeAccessor.SchemeProperty
Direct Known Subclasses:
JdkHttpRestServerSingleton

public class JdkHttpRestServer extends AbstractRestServer implements HttpRestServer

Implementation of the HttpRestServer interface using the HttpRestServer defined in the com.sun.net.httpserver package. The JdkHttpRestServer is being initialized with some common MediaTypeFactory instances (as implemented by the AbstractRestServer). At the time of writing this document the MediaTypeFactory instances being preconfigured are:

  • JsonMediaTypeFactory
  • XmlMediaTypeFactory
  • TextMediaTypeFactory
  • FormMediaTypeFactory

The JdkHttpRestServer supports HTTP as well as HTTPS protocols as being based on the HttpRestServer as well as on the HttpsServer. For opening up an HTTPS connection, refer to the methods such as HttpRestServer.open(String, KeyStoreDescriptor, int) or HttpRestServer.open(KeyStoreDescriptor, int) and the like.

Set the system property SystemProperty.LOG_DEBUG to true (set when invoking the JRA by passing the argument -Dlog.debug=true to the java executable) to log additional erroneous situations e.g. related to content types and accept types alongside marshaling and unmarshaling.

  • Field Details

    • CONTEXT_PATH

      protected static final String CONTEXT_PATH
  • Constructor Details

    • JdkHttpRestServer

      public JdkHttpRestServer(org.refcodes.controlflow.ThreadingModel aThreadingModel)
      Constructs a JdkHttpRestServer. Use HttpRestServer.open(int) or similar to make it listen on your port. The provided ThreadingModel defines whether to use a single-threaded or a multi-threaded threading model. Threads are created as daemon threads. For more control on thread generation use the constructor JdkHttpRestServer(ExecutorService).
      Parameters:
      aThreadingModel - Specifies to either use a single-threaded threading model (no ExecutorService) or a multi-threaded threading model with a default ExecutorService as of ControlFlowUtility.createCachedExecutorService(boolean).
    • JdkHttpRestServer

      public JdkHttpRestServer(org.refcodes.controlflow.ThreadingModel aThreadingModel, boolean isVerbose)
      Constructs a JdkHttpRestServer. Use HttpRestServer.open(int) or similar to make it listen on your port. The provided ThreadingModel defines whether to use a single-threaded or a multi-threaded threading model. Threads are created as daemon threads. For more control on thread generation use the constructor JdkHttpRestServer(ExecutorService).
      Parameters:
      aThreadingModel - Specifies to either use a single-threaded threading model (no ExecutorService) or a multi-threaded threading model with a default ExecutorService as of ControlFlowUtility.createCachedExecutorService(boolean).
      isVerbose - When true, any unknown content- and accept-types are logged.
    • JdkHttpRestServer

      public JdkHttpRestServer()
      Constructs a JdkHttpRestServer. Use HttpRestServer.open(int) or similar to make it listen on your port. Uses a multi threaded threading model with a default ExecutorService as of ControlFlowUtility.createCachedExecutorService(boolean). Threads are created as daemon threads. For more control on thread generation use the constructor JdkHttpRestServer(ExecutorService).
    • JdkHttpRestServer

      public JdkHttpRestServer(boolean isVerbose)
      Constructs a JdkHttpRestServer. Use HttpRestServer.open(int) or similar to make it listen on your port. Uses a multi threaded threading model with a default ExecutorService as of ControlFlowUtility.createCachedExecutorService(boolean). Threads are created as daemon threads. For more control on thread generation use the constructor JdkHttpRestServer(ExecutorService).
      Parameters:
      isVerbose - When true, any unknown content- and accept-types are logged.
    • JdkHttpRestServer

      public JdkHttpRestServer(ExecutorService aExecutorService)
      Constructs a JdkHttpRestServer. Use HttpRestServer.open(int) or similar to make it listen on your port. Uses a multi threaded threading model.
      Parameters:
      aExecutorService - An executor service to be used when creating Threads.
    • JdkHttpRestServer

      public JdkHttpRestServer(ExecutorService aExecutorService, boolean isVerbose)
      Constructs a JdkHttpRestServer. Use HttpRestServer.open(int) or similar to make it listen on your port. Uses a multi threaded threading model.
      Parameters:
      aExecutorService - An executor service to be used when creating Threads.
      isVerbose - When true, any unknown content- and accept-types are logged.
  • Method Details