Putting it all together - by example

37 views
Skip to first unread message

John D. Ament

unread,
Oct 4, 2017, 7:26:48 AM10/4/17
to Eclipse MicroProfile
Hi All,

When looking at examples for MicroProfile, I think its good if we start looking at how the specs are meant to work with one another.  I hope to use this thread for myself and others to bounce ideas about what should and shouldn't work together to make sure we have comprehensive examples.

Below is a health check that uses JWT and Config to run some additional pieces of information back to the caller depending on a user having a role.  I know this works in Hammock today, does this type of check work on everyone else's runtime?

@Dependent
public class ExampleCheck implements HealthCheck{
   
@Inject
    @ConfigProperty(name="include.full.details.with.auth", defaultValue = "false")
   
private boolean includeFullDetails;
   
@Inject
    @Claim(standard = Claims.groups)
   
private ClaimValue<Set<String>> groups;
   
@Inject
    private SomeService someService;
   
   
@Override
    public HealthCheckResponse call() {
       
try {
           
someService.simpleOperationThatThrowsException();
           
return HealthCheckResponse.builder().name("SomeService").up().build();
       
}
       
catch (Exception e) {
           
HealthCheckResponseBuilder builder = HealthCheckResponse.builder().name("SomeService").down();
           
if(includeFullDetails && groups.getValue().contains("privileged")){
                builder
.withData("error", e.getMessage());
           
}
           
return builder.build();
       
}
   
}
}

E.g. does the config property get injected correctly, does the JWT get set properly in the check?  If the property isn't set, it should never look at the JWT's claims.

Scott Stark

unread,
Oct 7, 2017, 3:48:51 PM10/7/17
to Eclipse MicroProfile
It should work for us, so I'll test this example.
Reply all
Reply to author
Forward
0 new messages