Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for generic metadata from custom annotation on jax-rs interface #76

Open
masterdany88 opened this issue Feb 28, 2022 · 1 comment

Comments

@masterdany88
Copy link

masterdany88 commented Feb 28, 2022

Lets assume user have JAX-RS resource interface as follow:

public interface UserService {

    @Path("/")
    @GET
    User get();
  }

He want to have it secured (JWT for example):
And creates for that custom annotation, f.e.:
Using filters mechanism f.e.

@javax.ws.rs.NameBinding
@Retention(RUNTIME)
@Target({TYPE, METHOD})
public @interface JWTTokenNeeded {
}

https://antoniogoncalves.org/2016/10/03/securing-jax-rs-endpoints-with-jwt/
And adds it to resource:

public interface UserService {

    @Path("/")
    @GET
    @JWTTokenNeeded
    User get();
  }

This custom annotation information should be passed to generated factory, F.e.:
Using MetaParameter:
setMetaParameter("JWTTokenNeeded", "true");

  @Request
  public class UserService_get extends ServerRequest<Void, TestOnCompleteHandlers.User> {
    UserService_get() {
      super(new RequestMeta(TestOnCompleteHandlers.UserService.class, "get", Void.class, TestOnCompleteHandlers.User.class), null);
      setHttpMethod("GET");
      setAccept(new String[]{"application/json"});
      setPath("/");
      setServiceRoot("");
      setContentType(new String[]{"application/json"});
      setMetaParameter("JWTTokenNeeded", "true");
      setResponseReader(response -> new AbstractObjectReader<TestOnCompleteHandlers.User>("org.dominokit.rest.processor.TestOnCompleteHandlers.User") {
        @Override
        protected JsonDeserializer<TestOnCompleteHandlers.User> newDeserializer() {
          return new TestOnCompleteHandlers_UserBeanJsonDeserializerImpl();
        }
      }.read(response.getBodyAsString()));
    }
  }
}

Then in creating requests or interceptors We cloud see that metadata and act accordingly.

Thanks to that, We would be able to pass ass much metadata to UI wihout any hard dependency.

Examples:
Annotation:
@JWT
Result:
setMetaParameter("JWT", "true");

Annotation:
@JWT(value="val")
Result
setMetaParameter("JWT", "val");

Annotation:
@JWT(value1="val1", value2="val2")
Result
setMetaParameter("JWT", "{value1:val1, value2: val2}");

@masterdany88
Copy link
Author

#77

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant