Search in sources :

Example 1 with Endpoint

use of com.palantir.conjure.java.undertow.lib.Endpoint in project conjure-java by palantir.

the class ConjureHandlerTest method before.

@BeforeEach
public void before() {
    wrappersBeforeBlockingCallOrder = new ArrayList<>();
    HttpHandler httpHandler = _exchange -> {
        if (wrapperObserver.control() > 0) {
            innerObserver.control();
        }
    };
    HttpHandler handler = ConjureHandler.builder().services(EndpointService.of(Endpoint.builder().method(Methods.GET).template("/test").handler(httpHandler).serviceName("TestService").name("test").handler(httpHandler).build())).addWrapperBeforeBlocking(endpoint -> Optional.of(exchange -> {
        if (exchange.isInIoThread()) {
            wrappersBeforeBlockingCallOrder.add(1);
            endpoint.handler().handleRequest(exchange);
        }
    })).addWrapperBeforeBlocking(_endpoint -> Optional.empty()).addWrapperBeforeBlocking(endpoint -> Optional.of(exchange -> {
        if (exchange.isInIoThread()) {
            wrappersBeforeBlockingCallOrder.add(2);
            endpoint.handler().handleRequest(exchange);
        }
    })).build();
    server = Undertow.builder().addHttpListener(12345, "localhost").setHandler(handler).build();
    server.start();
}
Also used : Endpoint(com.palantir.conjure.java.undertow.lib.Endpoint) BeforeEach(org.junit.jupiter.api.BeforeEach) Request(okhttp3.Request) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Undertow(io.undertow.Undertow) HttpHandler(io.undertow.server.HttpHandler) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) Mockito.never(org.mockito.Mockito.never) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) OkHttpClient(okhttp3.OkHttpClient) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Optional(java.util.Optional) Response(okhttp3.Response) Methods(io.undertow.util.Methods) HttpHandler(io.undertow.server.HttpHandler) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with Endpoint

use of com.palantir.conjure.java.undertow.lib.Endpoint in project conjure-java by palantir.

the class ConjureUndertowEndpointsGenerator method generate.

public TypeSpec generate() {
    FieldSpec delegate = FieldSpec.builder(serviceDefinition.serviceInterface(), DELEGATE_NAME).addModifiers(Modifier.PRIVATE, Modifier.FINAL).build();
    ImmutableList<TypeSpec> endpoints = serviceDefinition.endpoints().stream().map(endpoint -> endpoint(serviceDefinition, endpoint)).collect(ImmutableList.toImmutableList());
    return TypeSpec.classBuilder(serviceDefinition.undertowService()).addAnnotation(AnnotationSpec.builder(ClassName.get(Generated.class)).addMember("value", "$S", getClass().getCanonicalName()).build()).addModifiers(Modifier.PUBLIC, Modifier.FINAL).addSuperinterface(ClassName.get(UndertowService.class)).addField(delegate).addMethod(MethodSpec.constructorBuilder().addModifiers(Modifier.PRIVATE).addParameter(serviceDefinition.serviceInterface(), DELEGATE_NAME).addStatement("this.$N = $N", delegate, DELEGATE_NAME).build()).addMethod(MethodSpec.methodBuilder("of").addParameter(serviceDefinition.serviceInterface(), DELEGATE_NAME).addModifiers(Modifier.PUBLIC, Modifier.STATIC).addStatement("return new $T($N)", serviceDefinition.undertowService(), DELEGATE_NAME).returns(UndertowService.class).build()).addMethod(MethodSpec.methodBuilder("endpoints").addModifiers(Modifier.PUBLIC).addAnnotation(Override.class).addParameter(UndertowRuntime.class, serviceDefinition.conjureRuntimeArgName()).returns(ParameterizedTypeName.get(List.class, Endpoint.class)).addStatement("return $T.of($L)", ImmutableList.class, endpoints.stream().map(endpoint -> CodeBlock.of("new $N($N, $N)", endpoint.name, RUNTIME_NAME, DELEGATE_NAME)).collect(CodeBlock.joining(", "))).build()).addTypes(endpoints).build();
}
Also used : ReturnType(com.palantir.conjure.java.undertow.processor.data.ReturnType) Endpoint(com.palantir.conjure.java.undertow.lib.Endpoint) SafeLoggingAnnotation(com.palantir.conjure.java.undertow.processor.data.ParameterType.SafeLoggingAnnotation) Modifier(javax.lang.model.element.Modifier) ServiceDefinition(com.palantir.conjure.java.undertow.processor.data.ServiceDefinition) UndertowService(com.palantir.conjure.java.undertow.lib.UndertowService) FieldSpec(com.squareup.javapoet.FieldSpec) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException) HttpServerExchange(io.undertow.server.HttpServerExchange) AuthHeader(com.palantir.tokens.auth.AuthHeader) ClassName(com.squareup.javapoet.ClassName) ReturnValueWriter(com.palantir.conjure.java.undertow.lib.ReturnValueWriter) CookieDeserializer(com.palantir.conjure.java.undertow.annotations.CookieDeserializer) PathMultiParamDeserializer(com.palantir.conjure.java.undertow.annotations.PathMultiParamDeserializer) BearerTokenCookieDeserializer(com.palantir.conjure.java.undertow.annotations.BearerTokenCookieDeserializer) RequestContext(com.palantir.conjure.java.undertow.lib.RequestContext) HttpString(io.undertow.util.HttpString) ArrayList(java.util.ArrayList) EndpointName(com.palantir.conjure.java.undertow.processor.data.EndpointName) EndpointDefinition(com.palantir.conjure.java.undertow.processor.data.EndpointDefinition) SafeArg(com.palantir.logsafe.SafeArg) ImmutableList(com.google.common.collect.ImmutableList) Value(org.immutables.value.Value) Generated(javax.annotation.processing.Generated) TypeMarker(com.palantir.conjure.java.undertow.lib.TypeMarker) StatusCodes(io.undertow.util.StatusCodes) CodeBlock(com.squareup.javapoet.CodeBlock) Serializer(com.palantir.conjure.java.undertow.lib.Serializer) ArgumentDefinition(com.palantir.conjure.java.undertow.processor.data.ArgumentDefinition) UsesRequestContextVisitor(com.palantir.conjure.java.undertow.processor.data.ParameterTypeVisitors.UsesRequestContextVisitor) MethodSpec(com.squareup.javapoet.MethodSpec) PathParamDeserializer(com.palantir.conjure.java.undertow.annotations.PathParamDeserializer) Cases(com.palantir.conjure.java.undertow.processor.data.ParameterType.Cases) ParameterizedTypeName(com.squareup.javapoet.ParameterizedTypeName) IOException(java.io.IOException) TypeSpec(com.squareup.javapoet.TypeSpec) HttpHandler(io.undertow.server.HttpHandler) List(java.util.List) HeaderParamDeserializer(com.palantir.conjure.java.undertow.annotations.HeaderParamDeserializer) UnsafeArg(com.palantir.logsafe.UnsafeArg) UndertowRuntime(com.palantir.conjure.java.undertow.lib.UndertowRuntime) AnnotationSpec(com.squareup.javapoet.AnnotationSpec) Deserializer(com.palantir.conjure.java.undertow.lib.Deserializer) QueryParamDeserializer(com.palantir.conjure.java.undertow.annotations.QueryParamDeserializer) TypeName(com.squareup.javapoet.TypeName) Optional(java.util.Optional) Methods(io.undertow.util.Methods) ParameterType(com.palantir.conjure.java.undertow.processor.data.ParameterType) FieldSpec(com.squareup.javapoet.FieldSpec) TypeSpec(com.squareup.javapoet.TypeSpec) UndertowService(com.palantir.conjure.java.undertow.lib.UndertowService)

Example 3 with Endpoint

use of com.palantir.conjure.java.undertow.lib.Endpoint in project conjure-java by palantir.

the class ConjureUndertowEndpointsGenerator method endpoint.

// TODO(ckozak): refactor
@SuppressWarnings("checkstyle:MethodLength")
private static TypeSpec endpoint(ServiceDefinition service, EndpointDefinition endpoint) {
    List<AdditionalField> additionalFields = new ArrayList<>();
    MethodSpec.Builder handlerBuilder = MethodSpec.methodBuilder("handleRequest").addModifiers(Modifier.PUBLIC).addAnnotation(Override.class).addParameter(HttpServerExchange.class, EXCHANGE_NAME).addException(Exception.class);
    ReturnType returnType = endpoint.returns();
    TypeName responseTypeName = returnType.asyncInnerType().orElseGet(returnType::returnType).box();
    if (usesRequestContext(endpoint)) {
        handlerBuilder.addStatement("$T $N = this.$N.contexts().createContext($N, this)", RequestContext.class, REQUEST_CONTEXT, RUNTIME_NAME, EXCHANGE_NAME);
    }
    endpoint.arguments().forEach(def -> def.paramType().match(new Cases<Void>() {

        @Override
        public Void body(CodeBlock deserializerFactory, String deserializerFieldName) {
            TypeName requestBodyType = def.argType().match(ArgTypeTypeName.INSTANCE).box();
            additionalFields.add(ImmutableAdditionalField.builder().field(FieldSpec.builder(ParameterizedTypeName.get(ClassName.get(Deserializer.class), requestBodyType), deserializerFieldName, Modifier.PRIVATE, Modifier.FINAL).build()).constructorInitializer(CodeBlock.builder().addStatement("this.$N = $L.deserializer(new $T<$T>() {}, $N, this)", deserializerFieldName, deserializerFactory, TypeMarker.class, requestBodyType, RUNTIME_NAME).build()).build());
            return null;
        }

        @Override
        public Void header(String variableName, String headerName, String deserializerFieldName, CodeBlock deserializerFactory, SafeLoggingAnnotation safeLoggable) {
            TypeName paramType = def.argType().match(ArgTypeTypeName.INSTANCE);
            additionalFields.add(ImmutableAdditionalField.builder().field(FieldSpec.builder(ParameterizedTypeName.get(ClassName.get(Deserializer.class), paramType.box()), deserializerFieldName, Modifier.PRIVATE, Modifier.FINAL).build()).constructorInitializer(CodeBlock.builder().addStatement("this.$N = new $T<>($S, $L)", deserializerFieldName, HeaderParamDeserializer.class, headerName, deserializerFactory).build()).build());
            handlerBuilder.addStatement("$T $N = $L", paramType, variableName, invokeDeserializer(def));
            getSafeLogging(headerName, variableName, safeLoggable).ifPresent(handlerBuilder::addStatement);
            return null;
        }

        @Override
        public Void path(String paramName, String deserializerFieldName, CodeBlock deserializerFactory, SafeLoggingAnnotation safeLoggable) {
            TypeName paramType = def.argType().match(ArgTypeTypeName.INSTANCE);
            additionalFields.add(ImmutableAdditionalField.builder().field(FieldSpec.builder(ParameterizedTypeName.get(ClassName.get(Deserializer.class), paramType.box()), deserializerFieldName, Modifier.PRIVATE, Modifier.FINAL).build()).constructorInitializer(CodeBlock.builder().addStatement("this.$N = new $T<>($S, $L)", deserializerFieldName, PathParamDeserializer.class, paramName, deserializerFactory).build()).build());
            handlerBuilder.addStatement("$T $N = $L", paramType, paramName, invokeDeserializer(def));
            getSafeLogging(paramName, paramName, safeLoggable).ifPresent(handlerBuilder::addStatement);
            return null;
        }

        @Override
        public Void pathMulti(String paramName, String deserializerFieldName, CodeBlock deserializerFactory, SafeLoggingAnnotation safeLoggable) {
            TypeName paramType = def.argType().match(ArgTypeTypeName.INSTANCE);
            additionalFields.add(ImmutableAdditionalField.builder().field(FieldSpec.builder(ParameterizedTypeName.get(ClassName.get(Deserializer.class), paramType.box()), deserializerFieldName, Modifier.PRIVATE, Modifier.FINAL).build()).constructorInitializer(CodeBlock.builder().addStatement("this.$N = new $T<>($S, $L)", deserializerFieldName, PathMultiParamDeserializer.class, "*", deserializerFactory).build()).build());
            handlerBuilder.addStatement("$T $N = $L", paramType, paramName, invokeDeserializer(def));
            getSafeLogging(paramName, paramName, safeLoggable).ifPresent(handlerBuilder::addStatement);
            return null;
        }

        @Override
        public Void query(String variableName, String paramName, String deserializerFieldName, CodeBlock deserializerFactory, SafeLoggingAnnotation safeLoggable) {
            TypeName paramType = def.argType().match(ArgTypeTypeName.INSTANCE);
            additionalFields.add(ImmutableAdditionalField.builder().field(FieldSpec.builder(ParameterizedTypeName.get(ClassName.get(Deserializer.class), paramType.box()), deserializerFieldName, Modifier.PRIVATE, Modifier.FINAL).build()).constructorInitializer(CodeBlock.builder().addStatement("this.$N = new $T<>($S, $L)", deserializerFieldName, QueryParamDeserializer.class, paramName, deserializerFactory).build()).build());
            handlerBuilder.addStatement("$T $N = $L", paramType, variableName, invokeDeserializer(def));
            getSafeLogging(paramName, variableName, safeLoggable).ifPresent(handlerBuilder::addStatement);
            return null;
        }

        @Override
        public Void cookie(String variableName, String cookieName, String deserializerFieldName, CodeBlock deserializerFactory, SafeLoggingAnnotation safeLoggable) {
            TypeName paramType = def.argType().match(ArgTypeTypeName.INSTANCE);
            additionalFields.add(ImmutableAdditionalField.builder().field(FieldSpec.builder(ParameterizedTypeName.get(ClassName.get(Deserializer.class), paramType.box()), deserializerFieldName, Modifier.PRIVATE, Modifier.FINAL).build()).constructorInitializer(CodeBlock.builder().addStatement("this.$N = new $T<>($S, $L)", deserializerFieldName, CookieDeserializer.class, cookieName, deserializerFactory).build()).build());
            handlerBuilder.addStatement("$T $N = $L", paramType, variableName, invokeDeserializer(def));
            getSafeLogging(cookieName, variableName, safeLoggable).ifPresent(handlerBuilder::addStatement);
            return null;
        }

        @Override
        public Void authCookie(String variableName, String cookieName, String deserializerFieldName) {
            TypeName paramType = def.argType().match(ArgTypeTypeName.INSTANCE);
            additionalFields.add(ImmutableAdditionalField.builder().field(FieldSpec.builder(ParameterizedTypeName.get(ClassName.get(Deserializer.class), paramType.box()), deserializerFieldName, Modifier.PRIVATE, Modifier.FINAL).build()).constructorInitializer(CodeBlock.builder().addStatement("this.$N = new $T(runtime, $S)", deserializerFieldName, BearerTokenCookieDeserializer.class, cookieName).build()).build());
            handlerBuilder.addStatement("$T $N = $L", paramType, variableName, invokeDeserializer(def));
            return null;
        }

        @Override
        public Void authHeader(String variableName) {
            handlerBuilder.addStatement("$T $N = $L", AuthHeader.class, variableName, invokeDeserializer(def));
            return null;
        }

        @Override
        public Void exchange() {
            return null;
        }

        @Override
        public Void context() {
            return null;
        }
    }));
    if (returnType.asyncInnerType().isEmpty() && returnType.isVoid()) {
        handlerBuilder.addStatement(invokeDelegate(endpoint)).addStatement("$N.setStatusCode($T.NO_CONTENT)", EXCHANGE_NAME, StatusCodes.class);
    } else {
        additionalFields.add(ImmutableAdditionalField.builder().field(FieldSpec.builder(ParameterizedTypeName.get(ClassName.get(Serializer.class), responseTypeName), returnType.serializerFieldName(), Modifier.PRIVATE, Modifier.FINAL).build()).constructorInitializer(CodeBlock.builder().addStatement("this.$N = $L.serializer(new $T<$T>() {}, $N, this)", returnType.serializerFieldName(), returnType.serializerFactory(), TypeMarker.class, responseTypeName, RUNTIME_NAME).build()).build());
        if (returnType.asyncInnerType().isPresent()) {
            handlerBuilder.addStatement("$N.async().register($L, this, $N)", RUNTIME_NAME, invokeDelegate(endpoint), EXCHANGE_NAME);
        } else {
            handlerBuilder.addStatement("write($L, $N)", invokeDelegate(endpoint), EXCHANGE_NAME);
        }
    }
    TypeSpec.Builder endpointBuilder = TypeSpec.classBuilder(endpointClassName(endpoint.endpointName())).addModifiers(Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL).addSuperinterface(HttpHandler.class).addSuperinterface(Endpoint.class).addField(UndertowRuntime.class, RUNTIME_NAME, Modifier.PRIVATE, Modifier.FINAL).addField(service.serviceInterface(), DELEGATE_NAME, Modifier.PRIVATE, Modifier.FINAL).addFields(additionalFields.stream().map(AdditionalField::field).collect(ImmutableList.toImmutableList())).addMethod(MethodSpec.constructorBuilder().addParameter(UndertowRuntime.class, RUNTIME_NAME).addParameter(service.serviceInterface(), DELEGATE_NAME).addStatement("this.$1N = $1N", RUNTIME_NAME).addStatement("this.$1N = $1N", DELEGATE_NAME).addCode(additionalFields.stream().map(AdditionalField::constructorInitializer).collect(CodeBlock.joining(""))).build()).addMethod(handlerBuilder.build());
    if (!TypeName.VOID.equals(returnType.returnType())) {
        endpointBuilder.addSuperinterface(ParameterizedTypeName.get(ClassName.get(ReturnValueWriter.class), responseTypeName));
        endpointBuilder.addMethod(MethodSpec.methodBuilder("write").addModifiers(Modifier.PUBLIC).addAnnotation(Override.class).addParameter(responseTypeName, RETURN_VALUE).addParameter(HttpServerExchange.class, EXCHANGE_NAME).addException(IOException.class).addStatement("this.$N.serialize($N, $N)", returnType.serializerFieldName(), RETURN_VALUE, EXCHANGE_NAME).build());
    }
    return endpointBuilder.addMethod(MethodSpec.methodBuilder("method").addModifiers(Modifier.PUBLIC).addAnnotation(Override.class).returns(HttpString.class).addStatement("return $T.$N", Methods.class, endpoint.httpMethod().name()).build()).addMethod(MethodSpec.methodBuilder("template").addModifiers(Modifier.PUBLIC).addAnnotation(Override.class).returns(String.class).addStatement("return $S", endpoint.httpPath().path()).build()).addMethod(MethodSpec.methodBuilder("serviceName").addModifiers(Modifier.PUBLIC).addAnnotation(Override.class).returns(String.class).addStatement("return $S", endpoint.serviceName().get()).build()).addMethod(MethodSpec.methodBuilder("name").addModifiers(Modifier.PUBLIC).addAnnotation(Override.class).returns(String.class).addStatement("return $S", endpoint.endpointName().get()).build()).addMethod(MethodSpec.methodBuilder("handler").addModifiers(Modifier.PUBLIC).addAnnotation(Override.class).returns(HttpHandler.class).addStatement("return this").build()).build();
}
Also used : ParameterizedTypeName(com.squareup.javapoet.ParameterizedTypeName) TypeName(com.squareup.javapoet.TypeName) MethodSpec(com.squareup.javapoet.MethodSpec) SafeLoggingAnnotation(com.palantir.conjure.java.undertow.processor.data.ParameterType.SafeLoggingAnnotation) ArrayList(java.util.ArrayList) CodeBlock(com.squareup.javapoet.CodeBlock) HttpString(io.undertow.util.HttpString) IOException(java.io.IOException) ReturnType(com.palantir.conjure.java.undertow.processor.data.ReturnType) HttpServerExchange(io.undertow.server.HttpServerExchange) Endpoint(com.palantir.conjure.java.undertow.lib.Endpoint) CookieDeserializer(com.palantir.conjure.java.undertow.annotations.CookieDeserializer) PathMultiParamDeserializer(com.palantir.conjure.java.undertow.annotations.PathMultiParamDeserializer) BearerTokenCookieDeserializer(com.palantir.conjure.java.undertow.annotations.BearerTokenCookieDeserializer) PathParamDeserializer(com.palantir.conjure.java.undertow.annotations.PathParamDeserializer) HeaderParamDeserializer(com.palantir.conjure.java.undertow.annotations.HeaderParamDeserializer) Deserializer(com.palantir.conjure.java.undertow.lib.Deserializer) QueryParamDeserializer(com.palantir.conjure.java.undertow.annotations.QueryParamDeserializer) UndertowRuntime(com.palantir.conjure.java.undertow.lib.UndertowRuntime) Cases(com.palantir.conjure.java.undertow.processor.data.ParameterType.Cases) Methods(io.undertow.util.Methods) Serializer(com.palantir.conjure.java.undertow.lib.Serializer) TypeSpec(com.squareup.javapoet.TypeSpec)

Example 4 with Endpoint

use of com.palantir.conjure.java.undertow.lib.Endpoint in project conjure-java by palantir.

the class UndertowServiceHandlerGenerator method generateParameterCodeBlock.

private CodeBlock generateParameterCodeBlock(EndpointDefinition endpoint, ParameterType.Visitor<Boolean> paramTypeVisitor, String paramsVarName, Function<ArgumentDefinition, String> toParamId, Map<com.palantir.conjure.spec.TypeName, TypeDefinition> typeDefinitions, TypeMapper typeMapper) {
    return CodeBlocks.of(endpoint.getArgs().stream().filter(param -> param.getParamType().accept(paramTypeVisitor)).map(arg -> {
        Type normalizedType = TypeFunctions.toConjureTypeWithoutAliases(arg.getType(), typeDefinitions);
        String paramName = sanitizeVarName(arg.getArgName().get(), endpoint);
        final CodeBlock retrieveParam;
        if (normalizedType.equals(arg.getType()) || // Collections of alias types are handled the same way as external imports
        TypeFunctions.isListOrSet(arg.getType())) {
            // type is not an alias or optional of an alias
            retrieveParam = decodePlainParameterCodeBlock(arg.getType(), typeMapper, paramName, paramsVarName, toParamId.apply(arg));
        } else {
            // type contains aliases: decode raw value and then construct real value from raw one
            String rawVarName = arg.getArgName().get() + "Raw";
            retrieveParam = CodeBlocks.of(decodePlainParameterCodeBlock(normalizedType, typeMapper, rawVarName, paramsVarName, toParamId.apply(arg)), CodeBlocks.statement("$1T $2N = $3L", typeMapper.getClassName(arg.getType()), paramName, createConstructorForTypeWithReference(arg.getType(), rawVarName, typeDefinitions, typeMapper)));
        }
        return CodeBlocks.of(retrieveParam, generateParamMetadata(arg, arg.getArgName().get(), paramName, typeMapper));
    }).collect(ImmutableList.toImmutableList()));
}
Also used : DefaultTypeVisitor(com.palantir.conjure.java.visitor.DefaultTypeVisitor) Endpoint(com.palantir.conjure.java.undertow.lib.Endpoint) HeaderAuthType(com.palantir.conjure.spec.HeaderAuthType) TypeVisitor(com.palantir.conjure.visitor.TypeVisitor) Modifier(javax.lang.model.element.Modifier) UndertowService(com.palantir.conjure.java.undertow.lib.UndertowService) HttpServerExchange(io.undertow.server.HttpServerExchange) AuthHeader(com.palantir.tokens.auth.AuthHeader) ClassName(com.squareup.javapoet.ClassName) ReturnValueWriter(com.palantir.conjure.java.undertow.lib.ReturnValueWriter) Collections2(com.google.common.collect.Collections2) ServiceDefinition(com.palantir.conjure.spec.ServiceDefinition) StringUtils(org.apache.commons.lang3.StringUtils) Options(com.palantir.conjure.java.Options) ParameterTypeVisitor(com.palantir.conjure.visitor.ParameterTypeVisitor) HttpString(io.undertow.util.HttpString) TypeMarker(com.palantir.conjure.java.undertow.lib.TypeMarker) Duration(java.time.Duration) Map(java.util.Map) CodeBlocks(com.palantir.conjure.java.types.CodeBlocks) OptionalType(com.palantir.conjure.spec.OptionalType) MoreVisitors(com.palantir.conjure.java.visitor.MoreVisitors) HumanReadableDuration(com.palantir.humanreadabletypes.HumanReadableDuration) ImmutableSet(com.google.common.collect.ImmutableSet) AuthType(com.palantir.conjure.spec.AuthType) MoreCollectors(com.google.common.collect.MoreCollectors) Collection(java.util.Collection) Set(java.util.Set) TypeMapper(com.palantir.conjure.java.types.TypeMapper) Streams(com.google.common.collect.Streams) ParameterType(com.palantir.conjure.spec.ParameterType) JavaFile(com.squareup.javapoet.JavaFile) List(java.util.List) Tags(com.palantir.conjure.java.util.Tags) UndertowRuntime(com.palantir.conjure.java.undertow.lib.UndertowRuntime) TypeName(com.squareup.javapoet.TypeName) Optional(java.util.Optional) Methods(io.undertow.util.Methods) PrimitiveType(com.palantir.conjure.spec.PrimitiveType) EndpointDefinition(com.palantir.conjure.spec.EndpointDefinition) Iterables(com.google.common.collect.Iterables) ListType(com.palantir.conjure.spec.ListType) ExternalReference(com.palantir.conjure.spec.ExternalReference) TypeFunctions(com.palantir.conjure.java.util.TypeFunctions) AuthTypeVisitor(com.palantir.conjure.visitor.AuthTypeVisitor) FieldSpec(com.squareup.javapoet.FieldSpec) Type(com.palantir.conjure.spec.Type) Deque(java.util.Deque) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) BearerToken(com.palantir.tokens.auth.BearerToken) ImmutableList(com.google.common.collect.ImmutableList) ConjureTags(com.palantir.conjure.java.ConjureTags) AsyncRequestProcessingMetadata(com.palantir.conjure.java.services.UndertowTypeFunctions.AsyncRequestProcessingMetadata) SetType(com.palantir.conjure.spec.SetType) ParameterOrder(com.palantir.conjure.java.util.ParameterOrder) StatusCodes(io.undertow.util.StatusCodes) CodeBlock(com.squareup.javapoet.CodeBlock) Serializer(com.palantir.conjure.java.undertow.lib.Serializer) TypeDefinition(com.palantir.conjure.spec.TypeDefinition) MethodSpec(com.squareup.javapoet.MethodSpec) Packages(com.palantir.conjure.java.util.Packages) CookieAuthType(com.palantir.conjure.spec.CookieAuthType) JavaNameSanitizer(com.palantir.conjure.java.util.JavaNameSanitizer) ParameterizedTypeName(com.squareup.javapoet.ParameterizedTypeName) IOException(java.io.IOException) TypeSpec(com.squareup.javapoet.TypeSpec) EndpointName(com.palantir.conjure.spec.EndpointName) HttpHandler(io.undertow.server.HttpHandler) AnnotationSpec(com.squareup.javapoet.AnnotationSpec) ConjureAnnotations(com.palantir.conjure.java.ConjureAnnotations) Deserializer(com.palantir.conjure.java.undertow.lib.Deserializer) ArgumentDefinition(com.palantir.conjure.spec.ArgumentDefinition) InputStream(java.io.InputStream) HeaderAuthType(com.palantir.conjure.spec.HeaderAuthType) OptionalType(com.palantir.conjure.spec.OptionalType) AuthType(com.palantir.conjure.spec.AuthType) ParameterType(com.palantir.conjure.spec.ParameterType) PrimitiveType(com.palantir.conjure.spec.PrimitiveType) ListType(com.palantir.conjure.spec.ListType) Type(com.palantir.conjure.spec.Type) SetType(com.palantir.conjure.spec.SetType) CookieAuthType(com.palantir.conjure.spec.CookieAuthType) CodeBlock(com.squareup.javapoet.CodeBlock) HttpString(io.undertow.util.HttpString)

Example 5 with Endpoint

use of com.palantir.conjure.java.undertow.lib.Endpoint in project conjure-java by palantir.

the class ConjureHandler method applyHeadEndpoints.

private static List<Endpoint> applyHeadEndpoints(RoutingHandler routingHandler, List<Endpoint> endpoints) {
    List<Endpoint> result = new ArrayList<>(endpoints.size());
    for (Endpoint endpoint : endpoints) {
        result.add(endpoint);
        if (Methods.GET.equals(endpoint.method())) {
            Endpoint headEndpoint = Endpoint.builder().from(endpoint).method(Methods.HEAD).build();
            result.add(headEndpoint);
            routingHandler.add(headEndpoint.method(), headEndpoint.template(), headEndpoint.handler());
        }
    }
    return result;
}
Also used : Endpoint(com.palantir.conjure.java.undertow.lib.Endpoint) ArrayList(java.util.ArrayList)

Aggregations

Endpoint (com.palantir.conjure.java.undertow.lib.Endpoint)5 ArrayList (java.util.ArrayList)5 Deserializer (com.palantir.conjure.java.undertow.lib.Deserializer)3 Serializer (com.palantir.conjure.java.undertow.lib.Serializer)3 UndertowRuntime (com.palantir.conjure.java.undertow.lib.UndertowRuntime)3 Methods (io.undertow.util.Methods)3 IOException (java.io.IOException)3 ImmutableList (com.google.common.collect.ImmutableList)2 BearerTokenCookieDeserializer (com.palantir.conjure.java.undertow.annotations.BearerTokenCookieDeserializer)2 CookieDeserializer (com.palantir.conjure.java.undertow.annotations.CookieDeserializer)2 HeaderParamDeserializer (com.palantir.conjure.java.undertow.annotations.HeaderParamDeserializer)2 PathMultiParamDeserializer (com.palantir.conjure.java.undertow.annotations.PathMultiParamDeserializer)2 PathParamDeserializer (com.palantir.conjure.java.undertow.annotations.PathParamDeserializer)2 QueryParamDeserializer (com.palantir.conjure.java.undertow.annotations.QueryParamDeserializer)2 ReturnValueWriter (com.palantir.conjure.java.undertow.lib.ReturnValueWriter)2 TypeMarker (com.palantir.conjure.java.undertow.lib.TypeMarker)2 UndertowService (com.palantir.conjure.java.undertow.lib.UndertowService)2 Cases (com.palantir.conjure.java.undertow.processor.data.ParameterType.Cases)2 SafeLoggingAnnotation (com.palantir.conjure.java.undertow.processor.data.ParameterType.SafeLoggingAnnotation)2 ReturnType (com.palantir.conjure.java.undertow.processor.data.ReturnType)2