samplest.hello.HelloResourceRouter Maven / Gradle / Ivy
package samplest.hello;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.google.common.base.Optional;
import com.google.common.base.Suppliers;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableList;
import restx.types.Types;
import restx.types.TypeReference;
import restx.*;
import restx.entity.*;
import restx.http.*;
import restx.endpoint.*;
import restx.exceptions.WrappedCheckedException;
import restx.factory.*;
import restx.security.*;
import restx.security.PermissionFactory;
import restx.description.*;
import restx.converters.MainStringConverter;
import static restx.common.MorePreconditions.checkPresent;
import jakarta.validation.Validator;
import static restx.validation.Validations.checkValid;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
@Component(priority = 0)
public class HelloResourceRouter extends RestxRouter {
public HelloResourceRouter(
final HelloResource resource,
final EntityRequestBodyReaderRegistry readerRegistry,
final EntityResponseWriterRegistry writerRegistry,
final MainStringConverter converter,
final PermissionFactory pf,
final Optional validator,
final RestxSecurityManager securityManager,
final EndpointParameterMapperRegistry paramMapperRegistry) {
super(
"default", "HelloResourceRouter", new RestxRoute[] {
new StdEntityRoute("default#HelloResource#hello",
readerRegistry.build(Void.class, Optional.absent()),
writerRegistry.build(java.lang.String.class, Optional.absent()),
Endpoint.of("GET", "/hello"),
HttpStatus.OK, RestxLogLevel.DEFAULT, pf,
paramMapperRegistry, new ParamDef[]{
}) {
@Override
protected Optional doRoute(RestxRequest request, RestxResponse response, RestxRequestMatch match, Void body) throws IOException {
securityManager.check(request, match, isAuthenticated());
try {
return Optional.of(resource.hello(
));
} catch(RuntimeException e) { throw e; }
catch(Exception e) { throw new WrappedCheckedException(e); }
}
@Override
protected void describeOperation(OperationDescription operation) {
super.describeOperation(operation);
operation.responseClass = "string";
operation.inEntitySchemaKey = "";
operation.inEntityType = Void.class;
operation.outEntitySchemaKey = "";
operation.outEntityType = java.lang.String.class;
operation.sourceLocation = "samplest.hello.HelloResource#hello()";
operation.annotations = ImmutableList.builder()
.add(new restx.annotations.GET() {
public Class annotationType() { return restx.annotations.GET.class; }
public java.lang.String value() { return "/hello"; }
})
.build();
}
},
});
}
}