Search in sources :

Example 1 with GeneratedJaxRsResourceGizmoAdaptor

use of io.quarkus.resteasy.reactive.spi.GeneratedJaxRsResourceGizmoAdaptor in project quarkus by quarkusio.

the class RestDataProcessor method implementResources.

@BuildStep
void implementResources(CombinedIndexBuildItem index, List<RestDataResourceBuildItem> resourceBuildItems, List<ResourcePropertiesBuildItem> resourcePropertiesBuildItems, Capabilities capabilities, BuildProducer<GeneratedBeanBuildItem> resteasyClassicImplementationsProducer, BuildProducer<GeneratedJaxRsResourceBuildItem> resteasyReactiveImplementationsProducer) {
    boolean isReactivePanache = capabilities.isPresent(Capability.HIBERNATE_REACTIVE);
    boolean isResteasyClassic = capabilities.isPresent(Capability.RESTEASY);
    if (isReactivePanache && isResteasyClassic) {
        throw new IllegalStateException("Reactive REST Data Panache does not work with 'quarkus-resteasy'. Only 'quarkus-resteasy-reactive' extensions are supported");
    }
    ClassOutput classOutput = isResteasyClassic ? new GeneratedBeanGizmoAdaptor(resteasyClassicImplementationsProducer) : new GeneratedJaxRsResourceGizmoAdaptor(resteasyReactiveImplementationsProducer);
    JaxRsResourceImplementor jaxRsResourceImplementor = new JaxRsResourceImplementor(hasValidatorCapability(capabilities), isResteasyClassic, isReactivePanache);
    ResourcePropertiesProvider resourcePropertiesProvider = new ResourcePropertiesProvider(index.getIndex());
    for (RestDataResourceBuildItem resourceBuildItem : resourceBuildItems) {
        ResourceMetadata resourceMetadata = resourceBuildItem.getResourceMetadata();
        ResourceProperties resourceProperties = getResourceProperties(resourcePropertiesProvider, resourceMetadata, resourcePropertiesBuildItems);
        if (resourceProperties.isHal() && !hasHalCapability(capabilities)) {
            throw new IllegalStateException("Cannot generate HAL endpoints without a RESTEasy JSON-B or Jackson capability");
        }
        if (resourceProperties.isExposed()) {
            jaxRsResourceImplementor.implement(classOutput, resourceMetadata, resourceProperties);
        }
    }
}
Also used : GeneratedJaxRsResourceGizmoAdaptor(io.quarkus.resteasy.reactive.spi.GeneratedJaxRsResourceGizmoAdaptor) ClassOutput(io.quarkus.gizmo.ClassOutput) ResourceProperties(io.quarkus.rest.data.panache.deployment.properties.ResourceProperties) GeneratedBeanGizmoAdaptor(io.quarkus.arc.deployment.GeneratedBeanGizmoAdaptor) ResourcePropertiesProvider(io.quarkus.rest.data.panache.deployment.properties.ResourcePropertiesProvider) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 2 with GeneratedJaxRsResourceGizmoAdaptor

use of io.quarkus.resteasy.reactive.spi.GeneratedJaxRsResourceGizmoAdaptor in project quarkus by quarkusio.

the class GeneratedJaxRsResourceTest method buildCustomizer.

protected static Consumer<BuildChainBuilder> buildCustomizer() {
    return new Consumer<>() {

        /**
         * This represents the extension that generates a JAX-RS resource like:
         *
         * <pre>
         * {@code
         *      &#64;Path("/test')
         *      public class TestResource {
         *
         *          &#64;GET
         *          public String test() {
         *              return "test";
         *          }
         *      }
         * }
         * </pre>
         */
        @Override
        public void accept(BuildChainBuilder builder) {
            builder.addBuildStep(context -> {
                BuildProducer<GeneratedJaxRsResourceBuildItem> producer = context::produce;
                ClassOutput classOutput = new GeneratedJaxRsResourceGizmoAdaptor(producer);
                try (ClassCreator classCreator = ClassCreator.builder().classOutput(classOutput).className("com.example.TestResource").build()) {
                    classCreator.addAnnotation(Path.class).addValue("value", "test");
                    MethodCreator methodCreator = classCreator.getMethodCreator("test", String.class);
                    methodCreator.addAnnotation(GET.class);
                    methodCreator.returnValue(methodCreator.load("test"));
                }
            }).produces(GeneratedJaxRsResourceBuildItem.class).build();
        }
    };
}
Also used : GeneratedJaxRsResourceGizmoAdaptor(io.quarkus.resteasy.reactive.spi.GeneratedJaxRsResourceGizmoAdaptor) Path(javax.ws.rs.Path) Consumer(java.util.function.Consumer) BuildChainBuilder(io.quarkus.builder.BuildChainBuilder) MethodCreator(io.quarkus.gizmo.MethodCreator) GeneratedJaxRsResourceBuildItem(io.quarkus.resteasy.reactive.spi.GeneratedJaxRsResourceBuildItem) ClassOutput(io.quarkus.gizmo.ClassOutput) ClassCreator(io.quarkus.gizmo.ClassCreator)

Aggregations

ClassOutput (io.quarkus.gizmo.ClassOutput)2 GeneratedJaxRsResourceGizmoAdaptor (io.quarkus.resteasy.reactive.spi.GeneratedJaxRsResourceGizmoAdaptor)2 GeneratedBeanGizmoAdaptor (io.quarkus.arc.deployment.GeneratedBeanGizmoAdaptor)1 BuildChainBuilder (io.quarkus.builder.BuildChainBuilder)1 BuildStep (io.quarkus.deployment.annotations.BuildStep)1 ClassCreator (io.quarkus.gizmo.ClassCreator)1 MethodCreator (io.quarkus.gizmo.MethodCreator)1 ResourceProperties (io.quarkus.rest.data.panache.deployment.properties.ResourceProperties)1 ResourcePropertiesProvider (io.quarkus.rest.data.panache.deployment.properties.ResourcePropertiesProvider)1 GeneratedJaxRsResourceBuildItem (io.quarkus.resteasy.reactive.spi.GeneratedJaxRsResourceBuildItem)1 Consumer (java.util.function.Consumer)1 Path (javax.ws.rs.Path)1