resourcePropertiesBuildItems) {
for (ResourcePropertiesBuildItem resourcePropertiesBuildItem : resourcePropertiesBuildItems) {
@@ -143,10 +104,13 @@ private boolean hasValidatorCapability(Capabilities capabilities) {
return capabilities.isPresent(Capability.HIBERNATE_VALIDATOR);
}
- private boolean hasHalCapability(Capabilities capabilities) {
+ private boolean hasAnyJsonCapabilityForResteasyClassic(Capabilities capabilities) {
return capabilities.isPresent(Capability.RESTEASY_JSON_JSONB)
- || capabilities.isPresent(Capability.RESTEASY_JSON_JACKSON)
- || capabilities.isPresent(Capability.RESTEASY_REACTIVE_JSON_JSONB)
+ || capabilities.isPresent(Capability.RESTEASY_JSON_JACKSON);
+ }
+
+ private boolean hasAnyJsonCapabilityForResteasyReactive(Capabilities capabilities) {
+ return capabilities.isPresent(Capability.RESTEASY_REACTIVE_JSON_JSONB)
|| capabilities.isPresent(Capability.RESTEASY_REACTIVE_JSON_JACKSON);
}
}
diff --git a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/AddMethodImplementor.java b/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/AddMethodImplementor.java
index 19836c02c87d6..8ffddc7a573dc 100644
--- a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/AddMethodImplementor.java
+++ b/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/AddMethodImplementor.java
@@ -13,7 +13,6 @@
import io.quarkus.rest.data.panache.RestDataResource;
import io.quarkus.rest.data.panache.deployment.ResourceMetadata;
import io.quarkus.rest.data.panache.deployment.properties.ResourceProperties;
-import io.quarkus.rest.data.panache.deployment.utils.ResponseImplementor;
import io.quarkus.rest.data.panache.deployment.utils.UniImplementor;
import io.smallrye.mutiny.Uni;
@@ -109,7 +108,7 @@ protected void implementInternal(ClassCreator classCreator, ResourceMetadata res
addPathAnnotation(methodCreator, resourceProperties.getPath(RESOURCE_METHOD_NAME));
addPostAnnotation(methodCreator);
addConsumesAnnotation(methodCreator, APPLICATION_JSON);
- addProducesAnnotation(methodCreator, APPLICATION_JSON);
+ addProducesJsonAnnotation(methodCreator, resourceProperties);
addLinksAnnotation(methodCreator, resourceMetadata.getEntityType(), REL);
// Add parameter annotations
if (withValidation) {
@@ -124,7 +123,7 @@ protected void implementInternal(ClassCreator classCreator, ResourceMetadata res
ResultHandle entity = tryBlock.invokeVirtualMethod(
ofMethod(resourceMetadata.getResourceClass(), RESOURCE_METHOD_NAME, Object.class, Object.class),
resource, entityToSave);
- tryBlock.returnValue(ResponseImplementor.created(tryBlock, entity));
+ tryBlock.returnValue(responseImplementor.created(tryBlock, entity));
tryBlock.close();
} else {
ResultHandle uniEntity = methodCreator.invokeVirtualMethod(
@@ -132,7 +131,7 @@ protected void implementInternal(ClassCreator classCreator, ResourceMetadata res
resource, entityToSave);
methodCreator.returnValue(UniImplementor.map(methodCreator, uniEntity, EXCEPTION_MESSAGE,
- (body, item) -> body.returnValue(ResponseImplementor.created(body, item))));
+ (body, item) -> body.returnValue(responseImplementor.created(body, item))));
}
methodCreator.close();
diff --git a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/DeleteMethodImplementor.java b/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/DeleteMethodImplementor.java
index 93265c9bec692..a312b8d7ece56 100644
--- a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/DeleteMethodImplementor.java
+++ b/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/DeleteMethodImplementor.java
@@ -13,7 +13,6 @@
import io.quarkus.rest.data.panache.RestDataResource;
import io.quarkus.rest.data.panache.deployment.ResourceMetadata;
import io.quarkus.rest.data.panache.deployment.properties.ResourceProperties;
-import io.quarkus.rest.data.panache.deployment.utils.ResponseImplementor;
import io.quarkus.rest.data.panache.deployment.utils.UniImplementor;
import io.smallrye.mutiny.Uni;
@@ -105,8 +104,8 @@ protected void implementInternal(ClassCreator classCreator, ResourceMetadata res
// Return response
BranchResult entityWasDeleted = tryBlock.ifNonZero(deleted);
- entityWasDeleted.trueBranch().returnValue(ResponseImplementor.noContent(entityWasDeleted.trueBranch()));
- entityWasDeleted.falseBranch().returnValue(ResponseImplementor.notFound(entityWasDeleted.falseBranch()));
+ entityWasDeleted.trueBranch().returnValue(responseImplementor.noContent(entityWasDeleted.trueBranch()));
+ entityWasDeleted.falseBranch().returnValue(responseImplementor.notFound(entityWasDeleted.falseBranch()));
tryBlock.close();
} else {
@@ -124,9 +123,10 @@ protected void implementInternal(ClassCreator classCreator, ResourceMetadata res
ofMethod(Boolean.class, "compareTo", int.class, Boolean.class), deleted, falseDefault);
BranchResult entityWasDeleted = body.ifNonZero(deletedAsInt);
- entityWasDeleted.trueBranch().returnValue(ResponseImplementor.noContent(entityWasDeleted.trueBranch()));
+ entityWasDeleted.trueBranch()
+ .returnValue(responseImplementor.noContent(entityWasDeleted.trueBranch()));
entityWasDeleted.falseBranch()
- .returnValue(ResponseImplementor.notFound(entityWasDeleted.falseBranch()));
+ .returnValue(responseImplementor.notFound(entityWasDeleted.falseBranch()));
}));
}
diff --git a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/GetMethodImplementor.java b/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/GetMethodImplementor.java
index d495d467d9bcf..0d3b4a1a5121f 100644
--- a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/GetMethodImplementor.java
+++ b/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/GetMethodImplementor.java
@@ -13,7 +13,6 @@
import io.quarkus.rest.data.panache.RestDataResource;
import io.quarkus.rest.data.panache.deployment.ResourceMetadata;
import io.quarkus.rest.data.panache.deployment.properties.ResourceProperties;
-import io.quarkus.rest.data.panache.deployment.utils.ResponseImplementor;
import io.quarkus.rest.data.panache.deployment.utils.UniImplementor;
import io.smallrye.mutiny.Uni;
@@ -93,7 +92,8 @@ protected void implementInternal(ClassCreator classCreator, ResourceMetadata res
// Add method annotations
addPathAnnotation(methodCreator, appendToPath(resourceProperties.getPath(RESOURCE_METHOD_NAME), "{id}"));
addGetAnnotation(methodCreator);
- addProducesAnnotation(methodCreator, APPLICATION_JSON);
+ addProducesJsonAnnotation(methodCreator, resourceProperties);
+
addPathParamAnnotation(methodCreator.getParameterAnnotations(0), "id");
addLinksAnnotation(methodCreator, resourceMetadata.getEntityType(), REL);
@@ -108,8 +108,8 @@ protected void implementInternal(ClassCreator classCreator, ResourceMetadata res
// Return response
BranchResult wasNotFound = tryBlock.ifNull(entity);
- wasNotFound.trueBranch().returnValue(ResponseImplementor.notFound(wasNotFound.trueBranch()));
- wasNotFound.falseBranch().returnValue(ResponseImplementor.ok(wasNotFound.falseBranch(), entity));
+ wasNotFound.trueBranch().returnValue(responseImplementor.notFound(wasNotFound.trueBranch()));
+ wasNotFound.falseBranch().returnValue(responseImplementor.ok(wasNotFound.falseBranch(), entity));
tryBlock.close();
} else {
@@ -121,9 +121,9 @@ protected void implementInternal(ClassCreator classCreator, ResourceMetadata res
(body, entity) -> {
BranchResult entityWasNotFound = body.ifNull(entity);
entityWasNotFound.trueBranch()
- .returnValue(ResponseImplementor.notFound(entityWasNotFound.trueBranch()));
+ .returnValue(responseImplementor.notFound(entityWasNotFound.trueBranch()));
entityWasNotFound.falseBranch()
- .returnValue(ResponseImplementor.ok(entityWasNotFound.falseBranch(), entity));
+ .returnValue(responseImplementor.ok(entityWasNotFound.falseBranch(), entity));
}));
}
diff --git a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/ListMethodImplementor.java b/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/ListMethodImplementor.java
index 6bd29edd5d6a3..bfd1544b8c988 100644
--- a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/ListMethodImplementor.java
+++ b/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/ListMethodImplementor.java
@@ -21,7 +21,6 @@
import io.quarkus.rest.data.panache.deployment.ResourceMetadata;
import io.quarkus.rest.data.panache.deployment.properties.ResourceProperties;
import io.quarkus.rest.data.panache.deployment.utils.PaginationImplementor;
-import io.quarkus.rest.data.panache.deployment.utils.ResponseImplementor;
import io.quarkus.rest.data.panache.deployment.utils.SortImplementor;
import io.quarkus.rest.data.panache.deployment.utils.UniImplementor;
import io.smallrye.mutiny.Uni;
@@ -171,7 +170,7 @@ private void implementPaged(ClassCreator classCreator, ResourceMetadata resource
resource, page, sort);
// Return response
- tryBlock.returnValue(ResponseImplementor.ok(tryBlock, entities, links));
+ tryBlock.returnValue(responseImplementor.ok(tryBlock, entities, links));
tryBlock.close();
} else {
ResultHandle uniPageCount = methodCreator.invokeVirtualMethod(
@@ -188,7 +187,7 @@ private void implementPaged(ClassCreator classCreator, ResourceMetadata resource
Sort.class),
resource, page, sort);
body.returnValue(UniImplementor.map(body, uniEntities, EXCEPTION_MESSAGE,
- (listBody, list) -> listBody.returnValue(ResponseImplementor.ok(listBody, list, links))));
+ (listBody, list) -> listBody.returnValue(responseImplementor.ok(listBody, list, links))));
}));
}
@@ -218,7 +217,7 @@ private void implementNotPaged(ClassCreator classCreator, ResourceMetadata resou
ofMethod(resourceMetadata.getResourceClass(), RESOURCE_METHOD_NAME,
List.class, Page.class, Sort.class),
resource, tryBlock.loadNull(), sort);
- tryBlock.returnValue(ResponseImplementor.ok(tryBlock, entities));
+ tryBlock.returnValue(responseImplementor.ok(tryBlock, entities));
tryBlock.close();
} else {
ResultHandle uniEntities = methodCreator.invokeVirtualMethod(
@@ -227,7 +226,7 @@ private void implementNotPaged(ClassCreator classCreator, ResourceMetadata resou
resource, methodCreator.loadNull(), sort);
methodCreator.returnValue(UniImplementor.map(methodCreator, uniEntities, EXCEPTION_MESSAGE,
- (body, entities) -> body.returnValue(ResponseImplementor.ok(body, entities))));
+ (body, entities) -> body.returnValue(responseImplementor.ok(body, entities))));
}
methodCreator.close();
diff --git a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/StandardMethodImplementor.java b/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/StandardMethodImplementor.java
index cf90e6b3b0e35..1cb56a8484253 100644
--- a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/StandardMethodImplementor.java
+++ b/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/StandardMethodImplementor.java
@@ -24,6 +24,7 @@
import io.quarkus.rest.data.panache.RestDataPanacheException;
import io.quarkus.rest.data.panache.deployment.ResourceMetadata;
import io.quarkus.rest.data.panache.deployment.properties.ResourceProperties;
+import io.quarkus.rest.data.panache.deployment.utils.ResponseImplementor;
import io.quarkus.rest.data.panache.runtime.sort.SortQueryParamValidator;
/**
@@ -33,12 +34,14 @@ public abstract class StandardMethodImplementor implements MethodImplementor {
private static final Logger LOGGER = Logger.getLogger(StandardMethodImplementor.class);
+ protected final ResponseImplementor responseImplementor;
private final boolean isResteasyClassic;
private final boolean isReactivePanache;
protected StandardMethodImplementor(boolean isResteasyClassic, boolean isReactivePanache) {
this.isResteasyClassic = isResteasyClassic;
this.isReactivePanache = isReactivePanache;
+ this.responseImplementor = new ResponseImplementor(isResteasyClassic);
}
/**
@@ -121,6 +124,14 @@ protected void addDefaultValueAnnotation(AnnotatedElement element, String value)
element.addAnnotation(DefaultValue.class).addValue("value", value);
}
+ protected void addProducesJsonAnnotation(AnnotatedElement element, ResourceProperties properties) {
+ if (properties.isHal()) {
+ addProducesAnnotation(element, APPLICATION_JSON, APPLICATION_HAL_JSON);
+ } else {
+ addProducesAnnotation(element, APPLICATION_JSON);
+ }
+ }
+
protected void addProducesAnnotation(AnnotatedElement element, String... mediaTypes) {
element.addAnnotation(Produces.class).addValue("value", mediaTypes);
}
@@ -147,6 +158,10 @@ protected String appendToPath(String path, String suffix) {
return String.join("/", path, suffix);
}
+ protected boolean isResteasyClassic() {
+ return isResteasyClassic;
+ }
+
protected boolean isNotReactivePanache() {
return !isReactivePanache;
}
diff --git a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/UpdateMethodImplementor.java b/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/UpdateMethodImplementor.java
index c5b64ff2129b4..6924d7ab17bab 100644
--- a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/UpdateMethodImplementor.java
+++ b/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/UpdateMethodImplementor.java
@@ -23,7 +23,6 @@
import io.quarkus.rest.data.panache.RestDataResource;
import io.quarkus.rest.data.panache.deployment.ResourceMetadata;
import io.quarkus.rest.data.panache.deployment.properties.ResourceProperties;
-import io.quarkus.rest.data.panache.deployment.utils.ResponseImplementor;
import io.quarkus.rest.data.panache.deployment.utils.UniImplementor;
import io.quarkus.rest.data.panache.runtime.UpdateExecutor;
import io.smallrye.mutiny.Uni;
@@ -142,7 +141,7 @@ protected void implementInternal(ClassCreator classCreator, ResourceMetadata res
addPutAnnotation(methodCreator);
addPathParamAnnotation(methodCreator.getParameterAnnotations(0), "id");
addConsumesAnnotation(methodCreator, APPLICATION_JSON);
- addProducesAnnotation(methodCreator, APPLICATION_JSON);
+ addProducesJsonAnnotation(methodCreator, resourceProperties);
addLinksAnnotation(methodCreator, resourceMetadata.getEntityType(), REL);
// Add parameter annotations
if (withValidation) {
@@ -185,9 +184,9 @@ private void implementReactiveVersion(MethodCreator methodCreator, ResourceMetad
(updateBody, itemUpdated) -> {
BranchResult ifEntityIsNew = updateBody.ifNull(itemWasFound);
ifEntityIsNew.trueBranch()
- .returnValue(ResponseImplementor.created(ifEntityIsNew.trueBranch(), itemUpdated));
+ .returnValue(responseImplementor.created(ifEntityIsNew.trueBranch(), itemUpdated));
ifEntityIsNew.falseBranch()
- .returnValue(ResponseImplementor.noContent(ifEntityIsNew.falseBranch()));
+ .returnValue(responseImplementor.noContent(ifEntityIsNew.falseBranch()));
}));
}));
}
@@ -206,8 +205,8 @@ private void implementClassicVersion(MethodCreator methodCreator, ResourceMetada
updateExecutor, updateFunction);
BranchResult createdNewEntity = tryBlock.ifNotNull(newEntity);
- createdNewEntity.trueBranch().returnValue(ResponseImplementor.created(createdNewEntity.trueBranch(), newEntity));
- createdNewEntity.falseBranch().returnValue(ResponseImplementor.noContent(createdNewEntity.falseBranch()));
+ createdNewEntity.trueBranch().returnValue(responseImplementor.created(createdNewEntity.trueBranch(), newEntity));
+ createdNewEntity.falseBranch().returnValue(responseImplementor.noContent(createdNewEntity.falseBranch()));
}
private ResultHandle getUpdateFunction(BytecodeCreator creator, String resourceClass, ResultHandle resource,
diff --git a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/hal/AddHalMethodImplementor.java b/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/hal/AddHalMethodImplementor.java
deleted file mode 100644
index 36323f7824366..0000000000000
--- a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/hal/AddHalMethodImplementor.java
+++ /dev/null
@@ -1,143 +0,0 @@
-package io.quarkus.rest.data.panache.deployment.methods.hal;
-
-import static io.quarkus.gizmo.MethodDescriptor.ofMethod;
-
-import javax.validation.Valid;
-import javax.ws.rs.core.Response;
-
-import io.quarkus.gizmo.ClassCreator;
-import io.quarkus.gizmo.FieldDescriptor;
-import io.quarkus.gizmo.MethodCreator;
-import io.quarkus.gizmo.ResultHandle;
-import io.quarkus.gizmo.TryBlock;
-import io.quarkus.rest.data.panache.RestDataResource;
-import io.quarkus.rest.data.panache.deployment.ResourceMetadata;
-import io.quarkus.rest.data.panache.deployment.properties.ResourceProperties;
-import io.quarkus.rest.data.panache.deployment.utils.ResponseImplementor;
-import io.quarkus.rest.data.panache.deployment.utils.UniImplementor;
-import io.smallrye.mutiny.Uni;
-
-public final class AddHalMethodImplementor extends HalMethodImplementor {
-
- private static final String METHOD_NAME = "addHal";
-
- private static final String RESOURCE_METHOD_NAME = "add";
-
- private static final String EXCEPTION_MESSAGE = "Failed to add an entity";
-
- private final boolean withValidation;
-
- public AddHalMethodImplementor(boolean withValidation, boolean isResteasyClassic, boolean isReactivePanache) {
- super(isResteasyClassic, isReactivePanache);
- this.withValidation = withValidation;
- }
-
- /**
- * Generate HAL JAX-RS POST method.
- *
- * The RESTEasy Classic version exposes {@link RestDataResource#add(Object)} via HAL JAX-RS method.
- * Generated code looks more or less like this:
- *
- *
- * {@code
- * @POST
- * @Path("")
- * @Consumes({"application/json"})
- * @Produces({"application/hal+json"})
- * public Response addHal(Entity entityToSave) {
- * try {
- * Entity entity = resource.add(entityToSave);
- * HalEntityWrapper wrapper = new HalEntityWrapper(entity);
- * String location = new ResourceLinksProvider().getSelfLink(entity);
- * if (location != null) {
- * ResponseBuilder responseBuilder = Response.status(201);
- * responseBuilder.entity(wrapper);
- * responseBuilder.location(URI.create(location));
- * return responseBuilder.build();
- * } else {
- * throw new RuntimeException("Could not extract a new entity URL");
- * }
- * } catch (Throwable t) {
- * throw new RestDataPanacheException(t);
- * }
- * }
- * }
- *
- *
- * The RESTEasy Reactive version exposes {@link io.quarkus.rest.data.panache.ReactiveRestDataResource#add(Object)}
- * and the generated code looks more or less like this:
- *
- *
- * {@code
- * @POST
- * @Path("")
- * @Consumes({"application/json"})
- * @Produces({"application/hal+json"})
- * public Uni addHal(Entity entityToSave) {
- *
- * return resource.add(entityToSave).map(entity -> {
- * HalEntityWrapper wrapper = new HalEntityWrapper(entity);
- * String location = new ResourceLinksProvider().getSelfLink(entity);
- * if (location != null) {
- * ResponseBuilder responseBuilder = Response.status(201);
- * responseBuilder.entity(wrapper);
- * responseBuilder.location(URI.create(location));
- * return responseBuilder.build();
- * } else {
- * throw new RuntimeException("Could not extract a new entity URL");
- * }
- * }).onFailure().invoke(t -> throw new RestDataPanacheException(t));
- * }
- * }
- *
- *
- */
- @Override
- protected void implementInternal(ClassCreator classCreator, ResourceMetadata resourceMetadata,
- ResourceProperties resourceProperties, FieldDescriptor resourceField) {
- MethodCreator methodCreator = classCreator.getMethodCreator(METHOD_NAME,
- isNotReactivePanache() ? Response.class : Uni.class,
- resourceMetadata.getEntityType());
-
- // Add method annotations
- addPathAnnotation(methodCreator, resourceProperties.getPath(RESOURCE_METHOD_NAME));
- addPostAnnotation(methodCreator);
- addConsumesAnnotation(methodCreator, APPLICATION_JSON);
- addProducesAnnotation(methodCreator, APPLICATION_HAL_JSON);
- // Add parameter annotations
- if (withValidation) {
- methodCreator.getParameterAnnotations(0).addAnnotation(Valid.class);
- }
-
- ResultHandle resource = methodCreator.readInstanceField(resourceField, methodCreator.getThis());
- ResultHandle entityToSave = methodCreator.getMethodParam(0);
-
- if (isNotReactivePanache()) {
- TryBlock tryBlock = implementTryBlock(methodCreator, EXCEPTION_MESSAGE);
- ResultHandle entity = tryBlock.invokeVirtualMethod(
- ofMethod(resourceMetadata.getResourceClass(), RESOURCE_METHOD_NAME, Object.class, Object.class),
- resource, entityToSave);
-
- // Wrap and return response
- tryBlock.returnValue(ResponseImplementor.created(tryBlock, wrapHalEntity(tryBlock, entity),
- ResponseImplementor.getEntityUrl(tryBlock, entity)));
-
- tryBlock.close();
- } else {
- ResultHandle uniEntity = methodCreator.invokeVirtualMethod(
- ofMethod(resourceMetadata.getResourceClass(), RESOURCE_METHOD_NAME, Uni.class, Object.class),
- resource, entityToSave);
-
- methodCreator.returnValue(UniImplementor.map(methodCreator, uniEntity, EXCEPTION_MESSAGE,
- (body, item) -> body.returnValue(ResponseImplementor.created(body, wrapHalEntity(body, item),
- ResponseImplementor.getEntityUrl(body, item)))));
- }
-
- methodCreator.close();
- }
-
- @Override
- protected String getResourceMethodName() {
- return RESOURCE_METHOD_NAME;
- }
-}
diff --git a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/hal/GetHalMethodImplementor.java b/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/hal/GetHalMethodImplementor.java
deleted file mode 100644
index ba632e8f9063e..0000000000000
--- a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/hal/GetHalMethodImplementor.java
+++ /dev/null
@@ -1,128 +0,0 @@
-package io.quarkus.rest.data.panache.deployment.methods.hal;
-
-import static io.quarkus.gizmo.MethodDescriptor.ofMethod;
-
-import javax.ws.rs.core.Response;
-
-import io.quarkus.gizmo.BranchResult;
-import io.quarkus.gizmo.BytecodeCreator;
-import io.quarkus.gizmo.ClassCreator;
-import io.quarkus.gizmo.FieldDescriptor;
-import io.quarkus.gizmo.MethodCreator;
-import io.quarkus.gizmo.ResultHandle;
-import io.quarkus.gizmo.TryBlock;
-import io.quarkus.rest.data.panache.RestDataResource;
-import io.quarkus.rest.data.panache.deployment.ResourceMetadata;
-import io.quarkus.rest.data.panache.deployment.properties.ResourceProperties;
-import io.quarkus.rest.data.panache.deployment.utils.ResponseImplementor;
-import io.quarkus.rest.data.panache.deployment.utils.UniImplementor;
-import io.smallrye.mutiny.Uni;
-
-public final class GetHalMethodImplementor extends HalMethodImplementor {
-
- private static final String METHOD_NAME = "getHal";
-
- private static final String RESOURCE_METHOD_NAME = "get";
-
- private static final String EXCEPTION_MESSAGE = "Failed to get an entity";
-
- public GetHalMethodImplementor(boolean isResteasyClassic, boolean isReactivePanache) {
- super(isResteasyClassic, isReactivePanache);
- }
-
- /**
- * Generate HAL JAX-RS GET method.
- *
- * The RESTEasy Classic version exposes {@link RestDataResource#get(Object)} via HAL JAX-RS method.
- * Generated code looks more or less like this:
- *
- *
- * {@code
- * @GET
- * @Produces({"application/hal+json"})
- * @Path("{id}")
- * public Response getHal(@PathParam("id") ID id) {
- * try {
- * Entity entity = resource.get(id);
- * if (entity != null) {
- * return Response.ok(new HalEntityWrapper(entity)).build();
- * } else {
- * return Response.status(404).build();
- * }
- * } catch (Throwable t) {
- * throw new RestDataPanacheException(t);
- * }
- * }
- * }
- *
- *
- * The RESTEasy Reactive version exposes {@link io.quarkus.rest.data.panache.ReactiveRestDataResource#get(Object)}
- * and the generated code looks more or less like this:
- *
- *
- * {@code
- * @GET
- * @Produces({"application/hal+json"})
- * @Path("{id}")
- * public Uni getHal(@PathParam("id") ID id) {
- * return resource.get(id).map(entity -> {
- * if (entity != null) {
- * return Response.ok(new HalEntityWrapper(entity)).build();
- * } else {
- * return Response.status(404).build();
- * }
- * }).onFailure().invoke(t -> throw new RestDataPanacheException(t));
- * }
- * }
- *
- */
- @Override
- protected void implementInternal(ClassCreator classCreator, ResourceMetadata resourceMetadata,
- ResourceProperties resourceProperties, FieldDescriptor resourceField) {
- MethodCreator methodCreator = classCreator.getMethodCreator(METHOD_NAME,
- isNotReactivePanache() ? Response.class : Uni.class,
- resourceMetadata.getIdType());
-
- // Add method annotations
- addPathAnnotation(methodCreator, appendToPath(resourceProperties.getPath(RESOURCE_METHOD_NAME), "{id}"));
- addGetAnnotation(methodCreator);
- addProducesAnnotation(methodCreator, APPLICATION_HAL_JSON);
- addPathParamAnnotation(methodCreator.getParameterAnnotations(0), "id");
-
- ResultHandle resource = methodCreator.readInstanceField(resourceField, methodCreator.getThis());
- ResultHandle id = methodCreator.getMethodParam(0);
-
- if (isNotReactivePanache()) {
- TryBlock tryBlock = implementTryBlock(methodCreator, EXCEPTION_MESSAGE);
- ResultHandle entity = tryBlock.invokeVirtualMethod(
- ofMethod(resourceMetadata.getResourceClass(), RESOURCE_METHOD_NAME, Object.class, Object.class),
- resource, id);
-
- // Wrap and return response
- ifNullReturnNotFound(tryBlock, entity);
-
- tryBlock.close();
- } else {
- ResultHandle uniEntity = methodCreator.invokeVirtualMethod(
- ofMethod(resourceMetadata.getResourceClass(), RESOURCE_METHOD_NAME, Uni.class, Object.class),
- resource, id);
-
- methodCreator.returnValue(UniImplementor.map(methodCreator, uniEntity, EXCEPTION_MESSAGE,
- (body, entity) -> ifNullReturnNotFound(body, entity)));
- }
-
- methodCreator.close();
- }
-
- @Override
- protected String getResourceMethodName() {
- return RESOURCE_METHOD_NAME;
- }
-
- private void ifNullReturnNotFound(BytecodeCreator body, ResultHandle entity) {
- BranchResult wasNotFound = body.ifNull(entity);
- wasNotFound.trueBranch().returnValue(ResponseImplementor.notFound(wasNotFound.trueBranch()));
- wasNotFound.falseBranch().returnValue(
- ResponseImplementor.ok(wasNotFound.falseBranch(), wrapHalEntity(wasNotFound.falseBranch(), entity)));
- }
-}
diff --git a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/hal/HalMethodImplementor.java b/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/hal/HalMethodImplementor.java
index 73f27d5ec1496..4a880938bd89e 100644
--- a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/hal/HalMethodImplementor.java
+++ b/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/hal/HalMethodImplementor.java
@@ -1,17 +1,25 @@
package io.quarkus.rest.data.panache.deployment.methods.hal;
+import static io.quarkus.gizmo.MethodDescriptor.ofMethod;
+
+import java.lang.annotation.Annotation;
import java.util.Collection;
+import io.quarkus.arc.Arc;
+import io.quarkus.arc.ArcContainer;
+import io.quarkus.arc.InstanceHandle;
import io.quarkus.gizmo.BytecodeCreator;
import io.quarkus.gizmo.ClassCreator;
import io.quarkus.gizmo.FieldDescriptor;
import io.quarkus.gizmo.MethodDescriptor;
import io.quarkus.gizmo.ResultHandle;
+import io.quarkus.hal.HalCollectionWrapper;
+import io.quarkus.hal.HalService;
import io.quarkus.rest.data.panache.deployment.ResourceMetadata;
import io.quarkus.rest.data.panache.deployment.methods.StandardMethodImplementor;
import io.quarkus.rest.data.panache.deployment.properties.ResourceProperties;
-import io.quarkus.rest.data.panache.runtime.hal.HalCollectionWrapper;
-import io.quarkus.rest.data.panache.runtime.hal.HalEntityWrapper;
+import io.quarkus.resteasy.links.runtime.hal.ResteasyHalService;
+import io.quarkus.resteasy.reactive.links.runtime.hal.ResteasyReactiveHalService;
/**
* HAL JAX-RS method implementor.
@@ -33,15 +41,19 @@ public void implement(ClassCreator classCreator, ResourceMetadata resourceMetada
}
}
- protected ResultHandle wrapHalEntity(BytecodeCreator creator, ResultHandle entity) {
- return creator.newInstance(MethodDescriptor.ofConstructor(HalEntityWrapper.class, Object.class), entity);
- }
-
protected ResultHandle wrapHalEntities(BytecodeCreator creator, ResultHandle entities, String entityType,
String collectionName) {
- return creator.newInstance(
- MethodDescriptor.ofConstructor(HalCollectionWrapper.class, Collection.class, Class.class, String.class),
- entities, creator.loadClassFromTCCL(entityType),
- creator.load(collectionName));
+ ResultHandle arcContainer = creator.invokeStaticMethod(ofMethod(Arc.class, "container", ArcContainer.class));
+ ResultHandle instanceHandle = creator.invokeInterfaceMethod(
+ ofMethod(ArcContainer.class, "instance", InstanceHandle.class, Class.class, Annotation[].class),
+ arcContainer,
+ creator.loadClassFromTCCL(isResteasyClassic() ? ResteasyHalService.class : ResteasyReactiveHalService.class),
+ creator.newArray(Annotation.class, 0));
+ ResultHandle halService = creator.invokeInterfaceMethod(
+ ofMethod(InstanceHandle.class, "get", Object.class), instanceHandle);
+
+ return creator.invokeVirtualMethod(MethodDescriptor.ofMethod(HalService.class, "toHalCollectionWrapper",
+ HalCollectionWrapper.class, Collection.class, String.class, Class.class),
+ halService, entities, creator.load(collectionName), creator.loadClassFromTCCL(entityType));
}
}
diff --git a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/hal/ListHalMethodImplementor.java b/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/hal/ListHalMethodImplementor.java
index 2c963d25be481..cd5f899397b15 100644
--- a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/hal/ListHalMethodImplementor.java
+++ b/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/hal/ListHalMethodImplementor.java
@@ -16,6 +16,7 @@
import io.quarkus.gizmo.MethodCreator;
import io.quarkus.gizmo.ResultHandle;
import io.quarkus.gizmo.TryBlock;
+import io.quarkus.hal.HalCollectionWrapper;
import io.quarkus.panache.common.Page;
import io.quarkus.panache.common.Sort;
import io.quarkus.rest.data.panache.RestDataResource;
@@ -23,10 +24,8 @@
import io.quarkus.rest.data.panache.deployment.ResourceMetadata;
import io.quarkus.rest.data.panache.deployment.properties.ResourceProperties;
import io.quarkus.rest.data.panache.deployment.utils.PaginationImplementor;
-import io.quarkus.rest.data.panache.deployment.utils.ResponseImplementor;
import io.quarkus.rest.data.panache.deployment.utils.SortImplementor;
import io.quarkus.rest.data.panache.deployment.utils.UniImplementor;
-import io.quarkus.rest.data.panache.runtime.hal.HalCollectionWrapper;
import io.smallrye.mutiny.Uni;
public final class ListHalMethodImplementor extends HalMethodImplementor {
@@ -190,9 +189,10 @@ private void returnWrappedHalEntitiesWithLinks(BytecodeCreator body, ResourceMet
ResultHandle wrapper = wrapHalEntities(body, entities, resourceMetadata.getEntityType(),
resourceProperties.getHalCollectionName());
+
body.invokeVirtualMethod(
ofMethod(HalCollectionWrapper.class, "addLinks", void.class, Link[].class), wrapper, links);
- body.returnValue(ResponseImplementor.ok(body, wrapper, links));
+ body.returnValue(responseImplementor.ok(body, wrapper, links));
}
private void implementNotPaged(ClassCreator classCreator, ResourceMetadata resourceMetadata,
@@ -237,6 +237,6 @@ private void returnWrappedHalEntities(BytecodeCreator body, ResourceMetadata res
ResultHandle entities) {
ResultHandle wrapper = wrapHalEntities(body, entities, resourceMetadata.getEntityType(),
resourceProperties.getHalCollectionName());
- body.returnValue(ResponseImplementor.ok(body, wrapper));
+ body.returnValue(responseImplementor.ok(body, wrapper));
}
}
diff --git a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/hal/UpdateHalMethodImplementor.java b/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/hal/UpdateHalMethodImplementor.java
deleted file mode 100644
index 457338aeb1017..0000000000000
--- a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/hal/UpdateHalMethodImplementor.java
+++ /dev/null
@@ -1,259 +0,0 @@
-package io.quarkus.rest.data.panache.deployment.methods.hal;
-
-import static io.quarkus.gizmo.MethodDescriptor.ofMethod;
-
-import java.lang.annotation.Annotation;
-import java.util.function.Supplier;
-
-import javax.validation.Valid;
-import javax.ws.rs.core.Response;
-
-import io.quarkus.arc.Arc;
-import io.quarkus.arc.ArcContainer;
-import io.quarkus.arc.InstanceHandle;
-import io.quarkus.gizmo.AssignableResultHandle;
-import io.quarkus.gizmo.BranchResult;
-import io.quarkus.gizmo.BytecodeCreator;
-import io.quarkus.gizmo.ClassCreator;
-import io.quarkus.gizmo.FieldDescriptor;
-import io.quarkus.gizmo.FunctionCreator;
-import io.quarkus.gizmo.MethodCreator;
-import io.quarkus.gizmo.ResultHandle;
-import io.quarkus.gizmo.TryBlock;
-import io.quarkus.rest.data.panache.RestDataResource;
-import io.quarkus.rest.data.panache.deployment.ResourceMetadata;
-import io.quarkus.rest.data.panache.deployment.properties.ResourceProperties;
-import io.quarkus.rest.data.panache.deployment.utils.ResponseImplementor;
-import io.quarkus.rest.data.panache.deployment.utils.UniImplementor;
-import io.quarkus.rest.data.panache.runtime.UpdateExecutor;
-import io.smallrye.mutiny.Uni;
-
-public final class UpdateHalMethodImplementor extends HalMethodImplementor {
-
- private static final String METHOD_NAME = "updateHal";
-
- private static final String RESOURCE_UPDATE_METHOD_NAME = "update";
-
- private static final String RESOURCE_GET_METHOD_NAME = "get";
-
- private static final String EXCEPTION_MESSAGE = "Failed to update an entity";
-
- private final boolean withValidation;
-
- public UpdateHalMethodImplementor(boolean withValidation, boolean isResteasyClassic, boolean isReactivePanache) {
- super(isResteasyClassic, isReactivePanache);
- this.withValidation = withValidation;
- }
-
- /**
- * Generate HAL JAX-RS PUT method.
- *
- * The RESTEasy Classic version exposes {@link RestDataResource#update(Object, Object)} via HAL JAX-RS method.
- * Generated code looks more or less like this:
- *
- *
- * {@code
- * @PUT
- * @Path("{id}")
- * @Consumes({"application/json"})
- * @Produces({"application/hal+json"})
- * public Response updateHal(@PathParam("id") ID id, Entity entityToSave) {
- * try {
- * Object newEntity = updateExecutor.execute(() -> {
- * if (resource.get(id) == null) {
- * return resource.update(id, entityToSave);
- * } else {
- * resource.update(id, entityToSave);
- * return null;
- * }
- * });
- *
- * if (newEntity == null) {
- * return Response.status(204).build();
- * } else {
- * String location = new ResourceLinksProvider().getSelfLink(newEntity);
- * if (location != null) {
- * ResponseBuilder responseBuilder = Response.status(201);
- * responseBuilder.entity(new HalEntityWrapper(newEntity));
- * responseBuilder.location(URI.create(location));
- * return responseBuilder.build();
- * } else {
- * throw new RuntimeException("Could not extract a new entity URL")
- * }
- * }
- * } catch (Throwable t) {
- * throw new RestDataPanacheException(t);
- * }
- * }
- * }
- *
- *
- * The RESTEasy Reactive version exposes
- * {@link io.quarkus.rest.data.panache.ReactiveRestDataResource#update(Object, Object)}
- * and the generated code looks more or less like this:
- *
- *
- * {@code
- * @PUT
- * @Path("{id}")
- * @Consumes({"application/json"})
- * @Produces({"application/json"})
- * @LinkResource(
- * rel = "update",
- * entityClassName = "com.example.Entity"
- * )
- * public Uni update(@PathParam("id") ID id, Entity entityToSave) {
- * return resource.get(id).flatMap(entity -> {
- * if (entity == null) {
- * return Uni.createFrom().item(Response.status(204).build());
- * } else {
- * return resource.update(id, entityToSave).map(savedEntity -> {
- * String location = new ResourceLinksProvider().getSelfLink(savedEntity);
- * if (location != null) {
- * ResponseBuilder responseBuilder = Response.status(201);
- * responseBuilder.entity(new HalEntityWrapper(savedEntity));
- * responseBuilder.location(URI.create(location));
- * return responseBuilder.build();
- * } else {
- * throw new RuntimeException("Could not extract a new entity URL")
- * }
- * });
- * }
- * }).onFailure().invoke(t -> throw new RestDataPanacheException(t));
- * }
- * }
- *
- */
- @Override
- protected void implementInternal(ClassCreator classCreator, ResourceMetadata resourceMetadata,
- ResourceProperties resourceProperties, FieldDescriptor resourceField) {
- MethodCreator methodCreator = classCreator.getMethodCreator(METHOD_NAME,
- isNotReactivePanache() ? Response.class : Uni.class,
- resourceMetadata.getIdType(), resourceMetadata.getEntityType());
-
- // Add method annotations
- addPathAnnotation(methodCreator,
- appendToPath(resourceProperties.getPath(RESOURCE_UPDATE_METHOD_NAME), "{id}"));
- addPutAnnotation(methodCreator);
- addPathParamAnnotation(methodCreator.getParameterAnnotations(0), "id");
- addConsumesAnnotation(methodCreator, APPLICATION_JSON);
- addProducesAnnotation(methodCreator, APPLICATION_HAL_JSON);
- // Add parameter annotations
- if (withValidation) {
- methodCreator.getParameterAnnotations(1).addAnnotation(Valid.class);
- }
-
- ResultHandle resource = methodCreator.readInstanceField(resourceField, methodCreator.getThis());
- ResultHandle id = methodCreator.getMethodParam(0);
- ResultHandle entityToSave = methodCreator.getMethodParam(1);
-
- if (isNotReactivePanache()) {
- // Invoke resource methods inside a supplier function which will be given to an update executor.
- // For ORM, this update executor will have the @Transactional annotation to make
- // sure that all database operations are executed in a single transaction.
- TryBlock tryBlock = implementTryBlock(methodCreator, EXCEPTION_MESSAGE);
- ResultHandle updateExecutor = getUpdateExecutor(tryBlock);
- ResultHandle updateFunction = getUpdateFunction(tryBlock, resourceMetadata.getResourceClass(), resource, id,
- entityToSave);
- ResultHandle newEntity = tryBlock.invokeInterfaceMethod(
- ofMethod(UpdateExecutor.class, "execute", Object.class, Supplier.class),
- updateExecutor, updateFunction);
-
- BranchResult createdNewEntity = tryBlock.ifNotNull(newEntity);
- ResultHandle wrappedNewEntity = wrapHalEntity(createdNewEntity.trueBranch(), newEntity);
- ResultHandle newEntityUrl = ResponseImplementor.getEntityUrl(createdNewEntity.trueBranch(), newEntity);
- createdNewEntity.trueBranch().returnValue(
- ResponseImplementor.created(createdNewEntity.trueBranch(), wrappedNewEntity, newEntityUrl));
- createdNewEntity.falseBranch().returnValue(ResponseImplementor.noContent(createdNewEntity.falseBranch()));
- } else {
- ResultHandle uniResponse = methodCreator.invokeVirtualMethod(
- ofMethod(resourceMetadata.getResourceClass(), RESOURCE_GET_METHOD_NAME, Uni.class, Object.class),
- resource, id);
-
- methodCreator
- .returnValue(
- UniImplementor.flatMap(methodCreator, uniResponse, EXCEPTION_MESSAGE, (getBody, itemWasFound) -> {
- ResultHandle uniUpdateEntity = getBody.invokeVirtualMethod(
- ofMethod(resourceMetadata.getResourceClass(), RESOURCE_UPDATE_METHOD_NAME, Uni.class,
- Object.class,
- Object.class),
- resource, id, entityToSave);
-
- getBody.returnValue(UniImplementor.map(getBody, uniUpdateEntity, EXCEPTION_MESSAGE,
- (updateBody, itemUpdated) -> {
- ResultHandle wrappedNewEntity = wrapHalEntity(updateBody, itemUpdated);
- ResultHandle newEntityUrl = ResponseImplementor.getEntityUrl(updateBody,
- itemUpdated);
-
- BranchResult ifEntityIsNew = updateBody.ifNull(itemWasFound);
- ifEntityIsNew.trueBranch().returnValue(ResponseImplementor
- .created(ifEntityIsNew.trueBranch(), wrappedNewEntity, newEntityUrl));
- ifEntityIsNew.falseBranch()
- .returnValue(ResponseImplementor.noContent(ifEntityIsNew.falseBranch()));
- }));
- }));
- }
-
- methodCreator.close();
- }
-
- @Override
- protected String getResourceMethodName() {
- return RESOURCE_UPDATE_METHOD_NAME;
- }
-
- private ResultHandle getUpdateFunction(BytecodeCreator creator, String resourceClass, ResultHandle resource,
- ResultHandle id, ResultHandle entity) {
- FunctionCreator functionCreator = creator.createFunction(Supplier.class);
- BytecodeCreator functionBytecodeCreator = functionCreator.getBytecode();
-
- AssignableResultHandle entityToSave = functionBytecodeCreator.createVariable(Object.class);
- functionBytecodeCreator.assign(entityToSave, entity);
-
- BranchResult shouldUpdate = entityExists(functionBytecodeCreator, resourceClass, resource, id);
- // Update and return null
- updateAndReturn(shouldUpdate.trueBranch(), resourceClass, resource, id, entityToSave);
- // Update and return new entity
- createAndReturn(shouldUpdate.falseBranch(), resourceClass, resource, id, entityToSave);
-
- return functionCreator.getInstance();
- }
-
- private BranchResult entityExists(BytecodeCreator creator, String resourceClass, ResultHandle resource,
- ResultHandle id) {
- return creator.ifNotNull(creator.invokeVirtualMethod(
- ofMethod(resourceClass, RESOURCE_GET_METHOD_NAME, Object.class, Object.class), resource, id));
- }
-
- private void createAndReturn(BytecodeCreator creator, String resourceClass, ResultHandle resource,
- ResultHandle id, ResultHandle entityToSave) {
- ResultHandle newEntity = creator.invokeVirtualMethod(
- ofMethod(resourceClass, RESOURCE_UPDATE_METHOD_NAME, Object.class, Object.class, Object.class),
- resource, id, entityToSave);
- creator.returnValue(newEntity);
- }
-
- private void updateAndReturn(BytecodeCreator creator, String resourceClass, ResultHandle resource,
- ResultHandle id, ResultHandle entityToSave) {
- creator.invokeVirtualMethod(
- ofMethod(resourceClass, RESOURCE_UPDATE_METHOD_NAME, Object.class, Object.class, Object.class),
- resource, id, entityToSave);
- creator.returnValue(creator.loadNull());
- }
-
- private ResultHandle getUpdateExecutor(BytecodeCreator creator) {
- ResultHandle arcContainer = creator.invokeStaticMethod(ofMethod(Arc.class, "container", ArcContainer.class));
- ResultHandle instanceHandle = creator.invokeInterfaceMethod(
- ofMethod(ArcContainer.class, "instance", InstanceHandle.class, Class.class, Annotation[].class),
- arcContainer, creator.loadClassFromTCCL(UpdateExecutor.class), creator.newArray(Annotation.class, 0));
- ResultHandle instance = creator.invokeInterfaceMethod(
- ofMethod(InstanceHandle.class, "get", Object.class), instanceHandle);
-
- creator.ifNull(instance)
- .trueBranch()
- .throwException(RuntimeException.class,
- UpdateExecutor.class.getSimpleName() + " instance was not found");
-
- return instance;
- }
-}
diff --git a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/utils/ResponseImplementor.java b/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/utils/ResponseImplementor.java
index 71543ab82934d..ab14843701de0 100644
--- a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/utils/ResponseImplementor.java
+++ b/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/utils/ResponseImplementor.java
@@ -16,17 +16,25 @@
import io.quarkus.gizmo.BytecodeCreator;
import io.quarkus.gizmo.MethodDescriptor;
import io.quarkus.gizmo.ResultHandle;
-import io.quarkus.rest.data.panache.runtime.resource.ResourceLinksProvider;
+import io.quarkus.hal.HalService;
+import io.quarkus.resteasy.links.runtime.hal.ResteasyHalService;
+import io.quarkus.resteasy.reactive.links.runtime.hal.ResteasyReactiveHalService;
public final class ResponseImplementor {
- public static ResultHandle ok(BytecodeCreator creator, ResultHandle entity) {
+ private final boolean isResteasyClassic;
+
+ public ResponseImplementor(boolean isResteasyClassic) {
+ this.isResteasyClassic = isResteasyClassic;
+ }
+
+ public ResultHandle ok(BytecodeCreator creator, ResultHandle entity) {
ResultHandle builder = creator.invokeStaticMethod(
ofMethod(Response.class, "ok", ResponseBuilder.class, Object.class), entity);
return creator.invokeVirtualMethod(ofMethod(ResponseBuilder.class, "build", Response.class), builder);
}
- public static ResultHandle ok(BytecodeCreator creator, ResultHandle entity, ResultHandle links) {
+ public ResultHandle ok(BytecodeCreator creator, ResultHandle entity, ResultHandle links) {
ResultHandle builder = creator.invokeStaticMethod(
ofMethod(Response.class, "ok", ResponseBuilder.class, Object.class), entity);
creator.invokeVirtualMethod(
@@ -34,11 +42,11 @@ public static ResultHandle ok(BytecodeCreator creator, ResultHandle entity, Resu
return creator.invokeVirtualMethod(ofMethod(ResponseBuilder.class, "build", Response.class), builder);
}
- public static ResultHandle created(BytecodeCreator creator, ResultHandle entity) {
+ public ResultHandle created(BytecodeCreator creator, ResultHandle entity) {
return created(creator, entity, getEntityUrl(creator, entity));
}
- public static ResultHandle created(BytecodeCreator creator, ResultHandle entity, ResultHandle location) {
+ public ResultHandle created(BytecodeCreator creator, ResultHandle entity, ResultHandle location) {
ResultHandle builder = getResponseBuilder(creator, Response.Status.CREATED.getStatusCode());
creator.invokeVirtualMethod(
ofMethod(ResponseBuilder.class, "entity", ResponseBuilder.class, Object.class), builder, entity);
@@ -47,42 +55,44 @@ public static ResultHandle created(BytecodeCreator creator, ResultHandle entity,
return creator.invokeVirtualMethod(ofMethod(ResponseBuilder.class, "build", Response.class), builder);
}
- public static ResultHandle getEntityUrl(BytecodeCreator creator, ResultHandle entity) {
+ public ResultHandle getEntityUrl(BytecodeCreator creator, ResultHandle entity) {
ResultHandle arcContainer = creator
.invokeStaticMethod(MethodDescriptor.ofMethod(Arc.class, "container", ArcContainer.class));
ResultHandle instance = creator.invokeInterfaceMethod(
MethodDescriptor.ofMethod(ArcContainer.class, "instance", InstanceHandle.class, Class.class,
Annotation[].class),
- arcContainer, creator.loadClassFromTCCL(ResourceLinksProvider.class), creator.loadNull());
- ResultHandle linksProvider = creator.invokeInterfaceMethod(
+ arcContainer,
+ creator.loadClassFromTCCL(isResteasyClassic ? ResteasyHalService.class : ResteasyReactiveHalService.class),
+ creator.loadNull());
+ ResultHandle halService = creator.invokeInterfaceMethod(
MethodDescriptor.ofMethod(InstanceHandle.class, "get", Object.class),
instance);
- ResultHandle link = creator.invokeInterfaceMethod(
- ofMethod(ResourceLinksProvider.class, "getSelfLink", String.class, Object.class), linksProvider,
+ ResultHandle link = creator.invokeVirtualMethod(
+ ofMethod(HalService.class, "getSelfLink", String.class, Object.class), halService,
entity);
creator.ifNull(link).trueBranch().throwException(RuntimeException.class, "Could not extract a new entity URL");
return creator.invokeStaticMethod(ofMethod(URI.class, "create", URI.class, String.class), link);
}
- public static ResultHandle noContent(BytecodeCreator creator) {
+ public ResultHandle noContent(BytecodeCreator creator) {
return status(creator, Response.Status.NO_CONTENT.getStatusCode());
}
- public static ResultHandle notFound(BytecodeCreator creator) {
+ public ResultHandle notFound(BytecodeCreator creator) {
return status(creator, Response.Status.NOT_FOUND.getStatusCode());
}
- public static ResultHandle notFoundException(BytecodeCreator creator) {
+ public ResultHandle notFoundException(BytecodeCreator creator) {
return creator.newInstance(MethodDescriptor.ofConstructor(WebApplicationException.class, int.class),
creator.load(Response.Status.NOT_FOUND.getStatusCode()));
}
- private static ResultHandle status(BytecodeCreator creator, int status) {
+ private ResultHandle status(BytecodeCreator creator, int status) {
ResultHandle builder = getResponseBuilder(creator, status);
return creator.invokeVirtualMethod(ofMethod(ResponseBuilder.class, "build", Response.class), builder);
}
- private static ResultHandle getResponseBuilder(BytecodeCreator creator, int status) {
+ private ResultHandle getResponseBuilder(BytecodeCreator creator, int status) {
return creator.invokeStaticMethod(
ofMethod(Response.class, "status", ResponseBuilder.class, int.class), creator.load(status));
}
diff --git a/extensions/panache/rest-data-panache/runtime/pom.xml b/extensions/panache/rest-data-panache/runtime/pom.xml
index d0fa6e33a4859..7a0e30f04692d 100644
--- a/extensions/panache/rest-data-panache/runtime/pom.xml
+++ b/extensions/panache/rest-data-panache/runtime/pom.xml
@@ -17,6 +17,10 @@
io.quarkus
quarkus-panache-common