Skip to content
This repository was archived by the owner on May 28, 2018. It is now read-only.

JERSEY-3186 mitigation #247

Open
wants to merge 2 commits into
base: 2.x
Choose a base branch
from
Open
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 @@ -39,6 +39,17 @@
*/
package org.glassfish.jersey.server.model;

import javax.ws.rs.BeanParam;
import javax.ws.rs.CookieParam;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.Encoded;
import javax.ws.rs.FormParam;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.MatrixParam;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.container.Suspended;
import javax.ws.rs.core.Context;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Constructor;
Expand All @@ -56,19 +67,6 @@
import java.util.WeakHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.ws.rs.BeanParam;
import javax.ws.rs.CookieParam;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.Encoded;
import javax.ws.rs.FormParam;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.MatrixParam;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.container.Suspended;
import javax.ws.rs.core.Context;

import org.glassfish.jersey.internal.util.ReflectionHelper;
import org.glassfish.jersey.internal.util.collection.ClassTypePair;
import org.glassfish.jersey.server.Uri;
Expand Down Expand Up @@ -572,6 +570,15 @@ public Annotation getSourceAnnotation() {
return sourceAnnotation;
}

/**
* Get the parameter source annotation type.
*
* @return parameter source annotation type or null.
*/
private Class<? extends Annotation> getSourceAnnotationType() {
return sourceAnnotation != null ? sourceAnnotation.annotationType() : null;
}

/**
* Get the parameter value source type.
*
Expand Down Expand Up @@ -682,8 +689,8 @@ public Annotation[] getDeclaredAnnotations() {

@Override
public String toString() {
return String.format("Parameter [type=%s, source=%s, defaultValue=%s]",
getRawType(), getSourceName(), getDefaultValue());
return String.format("Parameter [type=%s, sourceAnnotationType=%s, source=%s, defaultValue=%s, paramSource=%s]",
getRawType(), getSourceAnnotationType(), getSourceName(), getDefaultValue(), getSource());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ error.monitoring.queue.mapper=Failed to add the monitoring event into the Except
error.monitoring.queue.flooded=A Monitoring Event Queue is being flooded. The monitoring statistics will show inaccurate \
measurements; especially in case of short time window statistics. The queue size is {0}.
error.parameter.invalid.char.value=Value "{0}" is not a character.
error.parameter.missing.value.provider=No injection source found for a parameter of type {1} at index {0}.
error.parameter.missing.value.provider=No injection source found for a parameter of type {1} at index {0}. For extension's annotations make sure the annotation is the latest declared.
error.parameter.type.processing=Could not process parameter type {0}.
error.primitive.type.null=The request entity cannot be empty.
error.processing.method=Error processing resource method, {0}, for ResourceMethodDispatchProvider, {1}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@

import javax.inject.Inject;
import java.lang.annotation.Annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Method;
import java.util.List;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -179,4 +180,28 @@ public Class<? extends Annotation> annotationType() {
assertNotEquals(param1.hashCode(), param3.hashCode());
}

@Test
public void test_toString_JERSEY_3186() {
Annotation[] annotations = new Annotation[]{new DocumentParameter() {
@Override
public Class<? extends Annotation> annotationType() {
return DocumentParameter.class;
}

@Override
public String value() {
return "represents something";
}
}};

Parameter param = Parameter.create(String.class, String.class, false, String.class, String.class, annotations);

assertEquals("Parameter [type=class java.lang.String, sourceAnnotationType=interface org.glassfish.jersey.server.model.ParameterTest$DocumentParameter, source=represents something, defaultValue=null, paramSource=UNKNOWN]",
param.toString());
}

@Retention(RetentionPolicy.RUNTIME)
@interface DocumentParameter {
String value();
}
}