Skip to content

Provide RequestTemplate.getParams() to access template variables (@Param) within an interceptor #601

Description

@d0x

It would be nice having a method to access @PARAM annotated parameters within an Interceptor.
Currently @PARAM template variables are only applied to header, requestline or the body.

As example this kind of RequestTemplate.getParams() would really help us.

public class MyServce {
   private final MyClient client;

   public void doSmth() {
      // Set the codec to some value. e.g. MP3. The key thing is that only the class "MyService"
      // knows which codec to choose.
      client.getSomething("MP3");
   }
}

public interface MyClient {
    // define the template variable "codec".
    // codec is not used in RequestLine, Body or Header
    @RequestLine("GET /")
    Object getSomething(@Param("codec") String codec);
}

public class CodecInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        // use params.get("codec") to get the codec and generate the headers
        Map<String, Object> params = requestTemplate.getParams();
        // ... 
    }
}

Since the business logic to detect which "codec" is required, is and should be placed in MyService, there is currently no way to pass this information (in a thread safe manner) to the interceptor. If there would be a RequestTemplate.getParams(), the business logic to detect the codec could stay in MyService and the logic to translate the codec into headers could be done within the interceptor.

That would help to accomplish separation of concerns (Service=BusinessLogic, Interceptor=HttpMagic).

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposalProposed Specification or API changewaiting for votesEnhancements or changes proposed that need more support before consideration

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions