Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1183] - rename Entity annotation to Body #1189

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.Body;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.HeaderParam;
Expand All @@ -13,7 +14,6 @@
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.container.AsyncResponse;
import jakarta.ws.rs.Entity;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.UriInfo;
import jakarta.ws.rs.sse.Sse;
Expand Down Expand Up @@ -49,10 +49,10 @@ public String getMessage() {
return bean.getMessage(lang) + " " + who;
}

// Use of @Entity is required
// Use of @Body is required
@POST
@Consumes(MediaType.TEXT_PLAIN)
public void putMessage(@QueryParam("override") boolean override, @Entity String message) {
public void putMessage(@QueryParam("override") boolean override, @Body String message) {
if (bean.getMessage(lang).isEmpty() || override) {
bean.setMessage(message);
}
Expand All @@ -62,7 +62,7 @@ public void putMessage(@QueryParam("override") boolean override, @Entity String
@POST
@Path("async")
@Consumes(MediaType.TEXT_PLAIN)
public void putMessageAsync(@QueryParam("override") boolean override, @Entity String message, AsyncResponse ar) {
public void putMessageAsync(@QueryParam("override") boolean override, @Body String message, AsyncResponse ar) {
Executors.newSingleThreadExecutor().submit(() -> {
if (bean.getMessage(lang).isEmpty() || override) {
bean.setMessage(message);
Expand Down
2 changes: 1 addition & 1 deletion jaxrs-api/src/main/java/jakarta/ws/rs/BeanParam.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* <p>
* The JAX-RS runtime will instantiate the object and inject all it's fields and properties annotated with either one of
* the {@code @XxxParam} annotation ({@link PathParam &#64;PathParam}, {@link FormParam &#64;FormParam} ...) or the
* {@link Entity &#64;Entity} annotation. For the POJO classes same instantiation and injection rules
* {@link Body &#64;Body} annotation. For the POJO classes same instantiation and injection rules
* apply as in case of instantiation and injection of request-scoped root resource classes.
* </p>
* For example:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -23,13 +23,13 @@
import java.lang.annotation.Target;

/**
* <p>Annotation that identifies the entity parameter.</p>
* <p>Annotation that identifies the body parameter.</p>
*
* @author Santiago Pericas-Geertsen
* @since 4.0
*/
@Target({ ElementType.PARAMETER })
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Entity {
public @interface Body {
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
////
*******************************************************************
* Copyright (c) 2019 Eclipse Foundation
* Copyright (c) 2019, 2023 Eclipse Foundation
*
* This specification document is made available under the terms
* of the Eclipse Foundation Specification License v1.0, which is
Expand Down Expand Up @@ -30,7 +30,7 @@ Let us illustrate these concepts via an example:
public class MyResource {

@GET
public void longRunningOp(@Suspended final AsyncResponse ar) {
public void longRunningOp(final AsyncResponse ar) {
executor.submit(
new Runnable() {
public void run() {
Expand All @@ -44,14 +44,14 @@ public class MyResource {
----

A resource method that elects to produce a response asynchronously must
inject as a method parameter an instance of the class `AsyncResponse`
using the special annotation `@Suspended`. In the example above, the
method `longRunningOp` is called upon receiving a `GET` request. Rather
than producing a response immediately, this method forks a (non-request)
thread to execute a long running operation and returns immediately. Once
the execution of the long running operation is complete, the connection
is resumed and the response returned by calling `resume` on the injected
instance of `AsyncResponse`.
have an instance of the class `AsyncResponse` as a method parameter.

In the example above, the method `longRunningOp` is called upon receiving
a `GET` request. Rather than producing a response immediately, this method
forks a (non-request) thread to execute a long running operation and returns
immediately. Once the execution of the long running operation is complete,
the connection is resumed and the response returned by calling `resume` on
the injected instance of `AsyncResponse`.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am leaving these changed (minus the @Body section) since I think I've made it easier to read. I can remove this if you want.


For more information on executors, concurrency and thread management in
a Jakarta EE environment, the reader is referred to Jakarta Concurrency
Expand All @@ -71,7 +71,7 @@ is resumed.
[source,java]
----
@GET
public void longRunningOp(@Suspended final AsyncResponse ar) {
public void longRunningOp(final AsyncResponse ar) {
// Register handler and set timeout
ar.setTimeoutHandler(new TimeoutHandler() {
public void handleTimeout(AsyncResponse ar) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ parameters. See <<consuming_multipart_formdata>> for more details.

The value of a parameter not annotated with `@FormParam` or any of the
annotations listed in in <<resource_field>>, called the entity
parameter, is mapped from the request entity body. Conversion between an
parameter, is mapped from the request entity body. This parameter MUST
be annotated with the `@Body` annotation. Conversion between an
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@spericas I moved the @Body requirement here.

entity body and a Java type is the responsibility of an entity provider,
see <<entity_providers>>. Resource methods MUST have at most one
entity parameter.
Expand Down
Loading