java.lang.Object
ru.vyarus.dropwizard.guice.test.client.builder.track.RequestTracker

public class RequestTracker extends Object
Tracks jersey client api configuration. Could be used to record all applied changes for WebTarget and Invocation.Builder.

Limitations: rx and async apis are not tracked. Also, invocation calls not handled, so for example, in case of buildGet().invoke(Some.class), requested mapping class would not be recorded because Invocation object is not tracked.

For example, to track real request configuration:


     RequestTracker tracker = new RequestTracker();
     WebTarget target = tracker.track(originalTarget);
     target.path("..").request().get();
     // print changes to console
     System.out.println(tracker.getLog());
 

track() could be used to record modifications for a target mock. This could be used to test request configuration api (when only applied changes must be verified).

Runnable could be used to execute something just before request execution (when all data collected):


      RequestTracker tracker = new RequestTracker()'
      WebTarget target = tracker.track(originalTarget, ()-> System.out.println(tracker.getLog()));
 

Tracker could be resolved from tarcked WebTarget and Invocation.Builder objects with lookupTracker(jakarta.ws.rs.client.WebTarget) and lookupTracker(jakarta.ws.rs.client.Invocation.Builder).

Since:
04.10.2025
  • Constructor Details

    • RequestTracker

      public RequestTracker()
  • Method Details

    • lookupTracker

      public static Optional<RequestTracker> lookupTracker(jakarta.ws.rs.client.WebTarget object)
      Lookup tracker in request builder object.
      Parameters:
      object - request object
      Returns:
      tracker or null if the object doesn't support tracking
    • lookupTracker

      public static Optional<RequestTracker> lookupTracker(jakarta.ws.rs.client.Invocation.Builder object)
      Lookup tracker in request builder object.
      Parameters:
      object - request object
      Returns:
      tracker or null if the object doesn't support tracking
    • track

      public jakarta.ws.rs.client.WebTarget track()
      Record request changes without actual request execution. Useful for testing apis, modifying request. Use mocker WebTarget inside (TargetMock) which does not implement request processing methods (just accept configuration).
      Returns:
      tracked target
    • track

      public jakarta.ws.rs.client.WebTarget track(@Nullable Runnable preRequestAction)
      Record request changes without actual request execution. Useful for testing apis, modifying request. Use mocker WebTarget inside (TargetMock) which does not implement request processing methods (just accept configuration).
      Parameters:
      preRequestAction - action to execute before request execution (could be used to log changes)
      Returns:
      tracked target
    • track

      public jakarta.ws.rs.client.WebTarget track(jakarta.ws.rs.client.WebTarget target)
      Track real request. Useful to track request configuration (with sources).

      IMPORTANT: tracked target object can't be re-used (it does not create new target instances for each call (whereas original target is correctly re-created).

      Parameters:
      target - original web target
      Returns:
      tracked target
    • track

      public jakarta.ws.rs.client.WebTarget track(jakarta.ws.rs.client.WebTarget target, @Nullable Runnable preRequestAction)
      Track real request. Useful to track request configuration (with sources).

      IMPORTANT: tracked target object can't be re-used (it does not create new target instances for each call (whereas original target is correctly re-created).

      Parameters:
      target - original web target
      preRequestAction - action to execute before request execution (could be used to log changes)
      Returns:
      tracked target
    • getQueryParams

      public Map<String,Object> getQueryParams()
      WebTarget.queryParam(String, Object...).

      Note: returned value may contain array if multiple values configured.

      Returns:
      applied query params
    • getMatrixParams

      public Map<String,Object> getMatrixParams()
      WebTarget.matrixParam(String, Object...).

      Note: returned value may contain array if multiple values configured.

      Returns:
      applied matric params
    • getPathParams

      public Map<String,Object> getPathParams()
      WebTarget.resolveTemplate(String, Object) (and all other variations).

      See RequestData.getPathParams() for encoding info.

      Returns:
      applied path params
    • getHeaders

      public Map<String,Object> getHeaders()
      Invocation.Builder.header(String, Object).
      Returns:
      applied headers
    • getCookies

      public Map<String,jakarta.ws.rs.core.Cookie> getCookies()
      Invocation.Builder.cookie(String, String).
      Returns:
      applied cookies
    • getProperties

      public Map<String,Object> getProperties()
      Configurable.property(String, Object), Invocation.Builder.property(String, Object).
      Returns:
      applied properties
    • getExtensions

      public Map<Class<?>,Object> getExtensions()
      Configurable.register(Class).

      Values in returned map could be a class or instance (if instance was used for configuration).

      See RequestData.getExtensions() for applied contracts.

      Returns:
      applied extensions
    • getPaths

      public List<String> getPaths()
      WebTarget.path(String).

      NOTE: does not count WebTarget.getUriBuilder() changes.

      Returns:
      applied paths
    • getAcceptHeader

      public List<String> getAcceptHeader()
      WebTarget.request(String...), Invocation.Builder.accept(String...).
      Returns:
      applied expected response types
    • getLanguageHeader

      public List<String> getLanguageHeader()
      Invocation.Builder.acceptLanguage(String...).
      Returns:
      applied expected languages
    • getEncodingHeader

      public List<String> getEncodingHeader()
      Invocation.Builder.acceptEncoding(String...).
      Returns:
      applied expected encodings
    • getCache

      public jakarta.ws.rs.core.CacheControl getCache()
      Invocation.Builder.cacheControl(jakarta.ws.rs.core.CacheControl).
      Returns:
      applied cache control object (cache header)
      See Also:
    • getCacheHeader

      public String getCacheHeader()
      Invocation.Builder.cacheControl(jakarta.ws.rs.core.CacheControl).
      Returns:
      applied cache header
      See Also:
    • getHttpMethod

      public @Nullable String getHttpMethod()
      SyncInvoker.method(String) and shortcuts like SyncInvoker.get().
      Returns:
      request HTTP method or null (if request method wasn't configred)
    • getEntity

      public @Nullable jakarta.ws.rs.client.Entity<?> getEntity()
      SyncInvoker.method(String, jakarta.ws.rs.client.Entity) and shortcuts like SyncInvoker.post(jakarta.ws.rs.client.Entity).
      Returns:
      request entity or null
    • getResultMapping

      public @Nullable Type getResultMapping()
      Result mapping from apis like SyncInvoker.get(Class).
      Returns:
      result mapping type or null
    • getResultMappingClass

      public @Nullable Class<?> getResultMappingClass()
      Result mapping from apis like SyncInvoker.get(Class).
      Returns:
      result class (for GenericType it would be just a root class without generics)
    • getResultMappingString

      public @Nullable String getResultMappingString()
      Result mapping from apis like SyncInvoker.get(Class).
      Returns:
      string representation of resulted type, including generics (like "List<Something>")
    • getUrl

      public @Nullable String getUrl()
      WebTarget.getUri().

      Url is recorded only after invocation builder creation with WebTarget.request().

      Returns:
      the resulted url or null
    • getLog

      public String getLog()
      Log shows what changed, where and at what order.
      Returns:
      request modifications log (with source references)
    • getRawData

      public RequestData getRawData()
      Could be used when modification source data is also required (shortcuts above remove modification source info).
      Returns:
      raw collected data object