Class LoopbackRestClient

java.lang.Object
org.refcodes.rest.AbstractRestClient
org.refcodes.rest.LoopbackRestClient
All Implemented Interfaces:
DeleteRestClient, GetRestClient, PostRestClient, PutRestClient, RestClient, RestRequestClient, RestRequestHandler, BasicAuthCredentialsAccessor, BasicAuthCredentialsAccessor.BasicAuthCredentialsBuilder<RestClient>, BasicAuthCredentialsAccessor.BasicAuthCredentialsMutator, BasicAuthCredentialsAccessor.BasicAuthCredentialsProperty, MediaTypeFactoryLookup, MediaTypeFactoryLookup.MutableMediaTypeFactoryLookup, OauthTokenAccessor, OauthTokenAccessor.OauthTokenBuilder<RestClient>, OauthTokenAccessor.OauthTokenMutator, OauthTokenAccessor.OauthTokenProperty, UserAgentAccessor, UserAgentAccessor.UserAgentBuilder<RestClient>, UserAgentAccessor.UserAgentMutator, UserAgentAccessor.UserAgentProperty
Direct Known Subclasses:
LoopbackRestClientSingleton

public class LoopbackRestClient extends AbstractRestClient

Lightweight in memory implementation of a RestClient used for loopback style REST request processing without issuing physical HTTP or HTTPS network requests.

The LoopbackRestClient is primarily intended for:

  • testing RestRequestHandler implementations
  • testing REST client request generation
  • integration testing of REST client/server interactions
  • simulating REST communication fully in memory
  • testing request and response marshaling behavior
  • testing authentication and interceptor integration

Instead of issuing physical HTTP requests, outgoing requests are delegated directly to a registered RestRequestHandler through the onRestRequest(RestRequestHandler) method.

This enables deterministic in process simulation of REST interactions without:

  • socket allocation
  • HTTP protocol overhead
  • TLS/SSL setup
  • network latency
  • external infrastructure dependencies

The LoopbackRestClient internally reuses the request generation and marshaling infrastructure provided by AbstractRestClient, thereby enabling realistic simulation of:

  • HTTP request construction
  • header propagation
  • media type negotiation
  • request marshaling
  • response unmarshaling
  • authentication handling
  • observer and interceptor execution

This implementation is especially useful together with LoopbackRestServer for constructing fully in memory REST integration tests without requiring an actual transport layer.

Unlike JdkHttpRestClient, this implementation performs no actual network communication and therefore acts as a transport independent REST request dispatcher.

See Also: