@Test public void resolvesPerRequestMessageBodyWriter() { componentResolver.addPerRequest(StringEntityProvider.class); verify(providers).addMessageBodyWriter(StringEntityProvider.class); }
@SuppressWarnings({"unchecked"}) public void addPerRequest(Class clazz) { if (clazz.getAnnotation(Provider.class) != null) { if (ContextResolver.class.isAssignableFrom(clazz)) { providers.addContextResolver(clazz); } if (ExceptionMapper.class.isAssignableFrom(clazz)) { providers.addExceptionMapper(clazz); } if (MessageBodyReader.class.isAssignableFrom(clazz)) { providers.addMessageBodyReader(clazz); } if (MessageBodyWriter.class.isAssignableFrom(clazz)) { providers.addMessageBodyWriter(clazz); } } else if (clazz.getAnnotation(Filter.class) != null) { if (MethodInvokerFilter.class.isAssignableFrom(clazz)) { providers.addMethodInvokerFilter(clazz); } if (RequestFilter.class.isAssignableFrom(clazz)) { providers.addRequestFilter(clazz); } if (ResponseFilter.class.isAssignableFrom(clazz)) { providers.addResponseFilter(clazz); } } else if (clazz.getAnnotation(Path.class) != null) { resources.addResource(clazz, null); } }
RestComponentResolver { @SuppressWarnings({"unchecked"}) public void addPerRequest(Class clazz) { if (clazz.getAnnotation(Provider.class) != null) { if (ContextResolver.class.isAssignableFrom(clazz)) { providers.addContextResolver(clazz); } if (ExceptionMapper.class.isAssignableFrom(clazz)) { providers.addExceptionMapper(clazz); } if (MessageBodyReader.class.isAssignableFrom(clazz)) { providers.addMessageBodyReader(clazz); } if (MessageBodyWriter.class.isAssignableFrom(clazz)) { providers.addMessageBodyWriter(clazz); } } else if (clazz.getAnnotation(Filter.class) != null) { if (MethodInvokerFilter.class.isAssignableFrom(clazz)) { providers.addMethodInvokerFilter(clazz); } if (RequestFilter.class.isAssignableFrom(clazz)) { providers.addRequestFilter(clazz); } if (ResponseFilter.class.isAssignableFrom(clazz)) { providers.addResponseFilter(clazz); } } else if (clazz.getAnnotation(Path.class) != null) { resources.addResource(clazz, null); } } }
RestComponentResolver { @SuppressWarnings({"unchecked"}) public void addPerRequest(Class clazz) { if (clazz.getAnnotation(Provider.class) != null) { if (ContextResolver.class.isAssignableFrom(clazz)) { providers.addContextResolver(clazz); } if (ExceptionMapper.class.isAssignableFrom(clazz)) { providers.addExceptionMapper(clazz); } if (MessageBodyReader.class.isAssignableFrom(clazz)) { providers.addMessageBodyReader(clazz); } if (MessageBodyWriter.class.isAssignableFrom(clazz)) { providers.addMessageBodyWriter(clazz); } } else if (clazz.getAnnotation(Filter.class) != null) { if (MethodInvokerFilter.class.isAssignableFrom(clazz)) { providers.addMethodInvokerFilter(clazz); } if (RequestFilter.class.isAssignableFrom(clazz)) { providers.addRequestFilter(clazz); } if (ResponseFilter.class.isAssignableFrom(clazz)) { providers.addResponseFilter(clazz); } } else if (clazz.getAnnotation(Path.class) != null) { resources.addResource(clazz, null); } } RestComponentResolver(ResourceBinder resources, ProviderBinder providers); }
RestComponentResolver { @SuppressWarnings({"unchecked"}) public void addPerRequest(Class clazz) { if (clazz.getAnnotation(Provider.class) != null) { if (ContextResolver.class.isAssignableFrom(clazz)) { providers.addContextResolver(clazz); } if (ExceptionMapper.class.isAssignableFrom(clazz)) { providers.addExceptionMapper(clazz); } if (MessageBodyReader.class.isAssignableFrom(clazz)) { providers.addMessageBodyReader(clazz); } if (MessageBodyWriter.class.isAssignableFrom(clazz)) { providers.addMessageBodyWriter(clazz); } } else if (clazz.getAnnotation(Filter.class) != null) { if (MethodInvokerFilter.class.isAssignableFrom(clazz)) { providers.addMethodInvokerFilter(clazz); } if (RequestFilter.class.isAssignableFrom(clazz)) { providers.addRequestFilter(clazz); } if (ResponseFilter.class.isAssignableFrom(clazz)) { providers.addResponseFilter(clazz); } } else if (clazz.getAnnotation(Path.class) != null) { resources.addResource(clazz, null); } } RestComponentResolver(ResourceBinder resources, ProviderBinder providers); @SuppressWarnings({"unchecked"}) void addSingleton(Object instance); @SuppressWarnings({"unchecked"}) void addPerRequest(Class clazz); @SuppressWarnings({"unchecked"}) void addFactory(ObjectFactory factory); }
RestComponentResolver { @SuppressWarnings({"unchecked"}) public void addPerRequest(Class clazz) { if (clazz.getAnnotation(Provider.class) != null) { if (ContextResolver.class.isAssignableFrom(clazz)) { providers.addContextResolver(clazz); } if (ExceptionMapper.class.isAssignableFrom(clazz)) { providers.addExceptionMapper(clazz); } if (MessageBodyReader.class.isAssignableFrom(clazz)) { providers.addMessageBodyReader(clazz); } if (MessageBodyWriter.class.isAssignableFrom(clazz)) { providers.addMessageBodyWriter(clazz); } } else if (clazz.getAnnotation(Filter.class) != null) { if (MethodInvokerFilter.class.isAssignableFrom(clazz)) { providers.addMethodInvokerFilter(clazz); } if (RequestFilter.class.isAssignableFrom(clazz)) { providers.addRequestFilter(clazz); } if (ResponseFilter.class.isAssignableFrom(clazz)) { providers.addResponseFilter(clazz); } } else if (clazz.getAnnotation(Path.class) != null) { resources.addResource(clazz, null); } } RestComponentResolver(ResourceBinder resources, ProviderBinder providers); @SuppressWarnings({"unchecked"}) void addSingleton(Object instance); @SuppressWarnings({"unchecked"}) void addPerRequest(Class clazz); @SuppressWarnings({"unchecked"}) void addFactory(ObjectFactory factory);  }