Skip to content

Commit

Permalink
support also annotations with value
Browse files Browse the repository at this point in the history
Signed-off-by: jansupol <jan.supol@oracle.com>
  • Loading branch information
jansupol committed May 3, 2024
1 parent 75324cb commit bc4d50e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,7 @@ public FormDataParamValueProvider(Parameter parameter, MultivaluedParameterExtra
@Override
public Object apply(ContainerRequest request) {
// Return the field value for the field specified by the sourceName property.
final String sourceName = parameter.getSourceName() != null
? parameter.getSourceName()
: Arrays.stream(parameter.getAnnotations())
final String sourceName = Arrays.stream(parameter.getAnnotations())
.filter(ann -> FormDataParam.class.isInstance(ann))
.map(ann -> FormDataParam.class.cast(ann))
.findFirst().get().value();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
import org.glassfish.jersey.media.multipart.MultiPartFeature;
import org.glassfish.jersey.message.internal.ReaderWriter;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.server.model.ParamQualifier;
import org.glassfish.jersey.test.JerseyTest;
import org.junit.jupiter.api.Test;

import javax.validation.constraints.NotNull;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
Expand All @@ -34,23 +34,34 @@
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class OrderParamTest extends JerseyTest {
@Target({ElementType.PARAMETER, ElementType.METHOD, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@ParamQualifier
public static @interface AnnoWithValue {
String value() default "";
}

@Path("/order")
public static class OrderTestResource {
@POST
@Path("/dataAfter")
@Consumes(value = MediaType.MULTIPART_FORM_DATA)
public String orderBefore(@FormDataParam("file") @NotNull InputStream inputStream) throws IOException {
public String orderBefore(@FormDataParam("file") @AnnoWithValue("xxx") InputStream inputStream) throws IOException {
return ReaderWriter.readFromAsString(inputStream, MediaType.TEXT_PLAIN_TYPE);
}

@POST
@Path("/dataBefore")
@Consumes(value = MediaType.MULTIPART_FORM_DATA)
public String orderAfter(@NotNull @FormDataParam("file") InputStream inputStream) throws IOException {
public String orderAfter(@AnnoWithValue("zzz") @FormDataParam("file") InputStream inputStream) throws IOException {
return ReaderWriter.readFromAsString(inputStream, MediaType.TEXT_PLAIN_TYPE);
}
}
Expand Down

0 comments on commit bc4d50e

Please sign in to comment.