samplest.hello.HeaderResourceRouter 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 HeaderResourceRouter extends RestxRouter {
public HeaderResourceRouter(
final HeaderResource resource,
final EntityRequestBodyReaderRegistry readerRegistry,
final EntityResponseWriterRegistry writerRegistry,
final MainStringConverter converter,
final PermissionFactory pf,
final Optional validator,
final RestxSecurityManager securityManager,
final EndpointParameterMapperRegistry paramMapperRegistry) {
super(
"default", "HeaderResourceRouter", new RestxRoute[] {
new StdEntityRoute>("default#HeaderResource#headers",
readerRegistry.build(Void.class, Optional.absent()),
writerRegistry.>build(Types.newParameterizedType(java.util.Map.class, java.lang.String.class, java.lang.String.class), Optional.absent()),
Endpoint.of("GET", "/headers"),
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.headers(
/* [CONTEXT] request */ request
));
} catch(RuntimeException e) { throw e; }
catch(Exception e) { throw new WrappedCheckedException(e); }
}
@Override
protected void describeOperation(OperationDescription operation) {
super.describeOperation(operation);
operation.responseClass = "MAP[string, string]";
operation.inEntitySchemaKey = "";
operation.inEntityType = Void.class;
operation.outEntitySchemaKey = "";
operation.outEntityType = Types.newParameterizedType(java.util.Map.class, java.lang.String.class, java.lang.String.class);
operation.sourceLocation = "samplest.hello.HeaderResource#headers(restx.RestxRequest)";
operation.annotations = ImmutableList.builder()
.add(new restx.annotations.GET() {
public Class annotationType() { return restx.annotations.GET.class; }
public java.lang.String value() { return "/headers"; }
})
.build();
}
},
});
}
}