Search in sources :

Example 16 with Annotation

use of java.lang.annotation.Annotation in project jersey by jersey.

the class IntrospectionModeller method doCreateResourceBuilder.

private Resource.Builder doCreateResourceBuilder() {
    if (!disableValidation) {
        checkForNonPublicMethodIssues();
    }
    final Class<?> annotatedResourceClass = ModelHelper.getAnnotatedResourceClass(handlerClass);
    final Path rPathAnnotation = annotatedResourceClass.getAnnotation(Path.class);
    final boolean keepEncodedParams = (null != annotatedResourceClass.getAnnotation(Encoded.class));
    final List<MediaType> defaultConsumedTypes = extractMediaTypes(annotatedResourceClass.getAnnotation(Consumes.class));
    final List<MediaType> defaultProducedTypes = extractMediaTypes(annotatedResourceClass.getAnnotation(Produces.class));
    final Collection<Class<? extends Annotation>> defaultNameBindings = ReflectionHelper.getAnnotationTypes(annotatedResourceClass, NameBinding.class);
    final MethodList methodList = new MethodList(handlerClass);
    final List<Parameter> resourceClassParameters = new LinkedList<>();
    checkResourceClassSetters(methodList, keepEncodedParams, resourceClassParameters);
    checkResourceClassFields(keepEncodedParams, InvocableValidator.isSingleton(handlerClass), resourceClassParameters);
    Resource.Builder resourceBuilder;
    if (null != rPathAnnotation) {
        resourceBuilder = Resource.builder(rPathAnnotation.value());
    } else {
        resourceBuilder = Resource.builder();
    }
    boolean extended = false;
    if (handlerClass.isAnnotationPresent(ExtendedResource.class)) {
        resourceBuilder.extended(true);
        extended = true;
    }
    resourceBuilder.name(handlerClass.getName());
    addResourceMethods(resourceBuilder, methodList, resourceClassParameters, keepEncodedParams, defaultConsumedTypes, defaultProducedTypes, defaultNameBindings, extended);
    addSubResourceMethods(resourceBuilder, methodList, resourceClassParameters, keepEncodedParams, defaultConsumedTypes, defaultProducedTypes, defaultNameBindings, extended);
    addSubResourceLocators(resourceBuilder, methodList, resourceClassParameters, keepEncodedParams, extended);
    if (LOGGER.isLoggable(Level.FINEST)) {
        LOGGER.finest(LocalizationMessages.NEW_AR_CREATED_BY_INTROSPECTION_MODELER(resourceBuilder.toString()));
    }
    return resourceBuilder;
}
Also used : Path(javax.ws.rs.Path) Annotation(java.lang.annotation.Annotation) LinkedList(java.util.LinkedList) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) MediaType(javax.ws.rs.core.MediaType)

Example 17 with Annotation

use of java.lang.annotation.Annotation in project jersey by jersey.

the class JaxbStringReaderProviderTest method stringReaderDoesNotReadExternalDtds.

@Test
public void stringReaderDoesNotReadExternalDtds() {
    Provider<SAXParserFactory> saxParserFactoryProvider = new Provider<SAXParserFactory>() {

        final SaxParserFactoryInjectionProvider spf = new SaxParserFactoryInjectionProvider(new CommonConfig(RuntimeType.SERVER, ComponentBag.INCLUDE_ALL));

        @Override
        public SAXParserFactory get() {
            return spf.get();
        }
    };
    JaxbStringReaderProvider.RootElementProvider provider = new JaxbStringReaderProvider.RootElementProvider(saxParserFactoryProvider, new Providers() {

        @Override
        public <T> MessageBodyReader<T> getMessageBodyReader(Class<T> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
            return null;
        }

        @Override
        public <T> MessageBodyWriter<T> getMessageBodyWriter(Class<T> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
            return null;
        }

        @Override
        public <T extends Throwable> ExceptionMapper<T> getExceptionMapper(Class<T> type) {
            return null;
        }

        @Override
        public <T> ContextResolver<T> getContextResolver(Class<T> contextType, MediaType mediaType) {
            return null;
        }
    });
    String content = "<!DOCTYPE x SYSTEM 'file:///no-such-file'> <rootObject/>";
    provider.getConverter(RootObject.class, null, null).fromString(content);
}
Also used : CommonConfig(org.glassfish.jersey.model.internal.CommonConfig) Providers(javax.ws.rs.ext.Providers) Annotation(java.lang.annotation.Annotation) Provider(javax.inject.Provider) MessageBodyReader(javax.ws.rs.ext.MessageBodyReader) RuntimeType(javax.ws.rs.RuntimeType) MediaType(javax.ws.rs.core.MediaType) Type(java.lang.reflect.Type) ExceptionMapper(javax.ws.rs.ext.ExceptionMapper) MediaType(javax.ws.rs.core.MediaType) ContextResolver(javax.ws.rs.ext.ContextResolver) MessageBodyWriter(javax.ws.rs.ext.MessageBodyWriter) SAXParserFactory(javax.xml.parsers.SAXParserFactory) Test(org.junit.Test)

Example 18 with Annotation

use of java.lang.annotation.Annotation in project jersey by jersey.

the class JsonEntityFilteringClientTest method testEntityAnnotationsDefaultView.

@Test
public void testEntityAnnotationsDefaultView() throws Exception {
    final OneFilteringOnClassEntity entity = target().request().post(Entity.entity(OneFilteringOnClassEntity.INSTANCE, MediaType.APPLICATION_JSON_TYPE, new Annotation[] { new DefaultFilteringScope() }), OneFilteringOnClassEntity.class);
    _testEmptyEntity(entity);
}
Also used : DefaultFilteringScope(org.glassfish.jersey.tests.e2e.entity.filtering.DefaultFilteringScope) Annotation(java.lang.annotation.Annotation) OneFilteringOnClassEntity(org.glassfish.jersey.tests.e2e.entity.filtering.domain.OneFilteringOnClassEntity) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 19 with Annotation

use of java.lang.annotation.Annotation in project jersey by jersey.

the class JsonEntityFilteringClientTest method testEntityAnnotationsInvalidView.

@Test
public void testEntityAnnotationsInvalidView() throws Exception {
    final OneFilteringOnClassEntity entity = target().request().post(Entity.entity(OneFilteringOnClassEntity.INSTANCE, MediaType.APPLICATION_JSON_TYPE, new Annotation[] { CustomAnnotationLiteral.INSTANCE }), OneFilteringOnClassEntity.class);
    _testEmptyEntity(entity);
}
Also used : Annotation(java.lang.annotation.Annotation) OneFilteringOnClassEntity(org.glassfish.jersey.tests.e2e.entity.filtering.domain.OneFilteringOnClassEntity) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 20 with Annotation

use of java.lang.annotation.Annotation in project flink by apache.

the class UdfAnalyzerTest method compareAnalyzerResultWithAnnotationsDualInputWithKeys.

@SuppressWarnings({ "rawtypes", "unchecked" })
public static void compareAnalyzerResultWithAnnotationsDualInputWithKeys(Class<?> baseClass, Class<?> clazz, String in1, String in2, String out, String[] keys1, String[] keys2) {
    final TypeInformation<?> in1Type = TypeInfoParser.parse(in1);
    final TypeInformation<?> in2Type = TypeInfoParser.parse(in2);
    final TypeInformation<?> outType = TypeInfoParser.parse(out);
    // expected
    final Set<Annotation> annotations = FunctionAnnotation.readDualForwardAnnotations(clazz);
    final DualInputSemanticProperties expected = SemanticPropUtil.getSemanticPropsDual(annotations, in1Type, in2Type, outType);
    // actual
    final UdfAnalyzer ua = new UdfAnalyzer(baseClass, clazz, "operator", in1Type, in2Type, outType, (keys1 == null) ? null : new Keys.ExpressionKeys(keys1, in1Type), (keys2 == null) ? null : new Keys.ExpressionKeys(keys2, in2Type), true);
    ua.analyze();
    final DualInputSemanticProperties actual = (DualInputSemanticProperties) ua.getSemanticProperties();
    assertEquals(expected.toString(), actual.toString());
}
Also used : DualInputSemanticProperties(org.apache.flink.api.common.operators.DualInputSemanticProperties) FunctionAnnotation(org.apache.flink.api.java.functions.FunctionAnnotation) Annotation(java.lang.annotation.Annotation)

Aggregations

Annotation (java.lang.annotation.Annotation)1784 Method (java.lang.reflect.Method)412 ArrayList (java.util.ArrayList)245 Field (java.lang.reflect.Field)172 Test (org.junit.Test)164 Type (java.lang.reflect.Type)149 HashMap (java.util.HashMap)146 HashSet (java.util.HashSet)129 Map (java.util.Map)95 List (java.util.List)92 IOException (java.io.IOException)71 Set (java.util.Set)71 ParameterizedType (java.lang.reflect.ParameterizedType)62 InvocationTargetException (java.lang.reflect.InvocationTargetException)53 Collection (java.util.Collection)52 LinkedHashMap (java.util.LinkedHashMap)36 Collectors (java.util.stream.Collectors)36 Constructor (java.lang.reflect.Constructor)33 LinkedHashSet (java.util.LinkedHashSet)32 Optional (java.util.Optional)32