Java Code Examples for org.apache.cxf.jaxrs.model.ProviderInfo#getProvider()
The following examples show how to use
org.apache.cxf.jaxrs.model.ProviderInfo#getProvider() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProviderFactory.java From cxf with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") public <T> ContextProvider<T> createContextProvider(Type contextType, Message m) { Class<?> contextCls = InjectionUtils.getActualType(contextType); if (contextCls == null) { return null; } for (ProviderInfo<ContextProvider<?>> cr : contextProviders) { Type[] types = cr.getProvider().getClass().getGenericInterfaces(); for (Type t : types) { if (t instanceof ParameterizedType) { ParameterizedType pt = (ParameterizedType)t; Type[] args = pt.getActualTypeArguments(); if (args.length > 0) { Class<?> argCls = InjectionUtils.getActualType(args[0]); if (argCls != null && argCls.isAssignableFrom(contextCls)) { return (ContextProvider<T>)cr.getProvider(); } } } } } return null; }
Example 2
Source File: ServerProviderFactory.java From cxf with Apache License 2.0 | 6 votes |
public int compare(ProviderInfo<?> p1, ProviderInfo<?> p2) { if (makeDefaultWaeLeastSpecific) { if (p1.getProvider() instanceof WebApplicationExceptionMapper && !p1.isCustom()) { return 1; } else if (p2.getProvider() instanceof WebApplicationExceptionMapper && !p2.isCustom()) { return -1; } } int result = super.compare(p1, p2); if (result == 0) { result = comparePriorityStatus(p1.getProvider().getClass(), p2.getProvider().getClass()); } return result; }
Example 3
Source File: ProviderFactory.java From cxf with Apache License 2.0 | 6 votes |
public int compare(ProviderInfo<MessageBodyReader<?>> p1, ProviderInfo<MessageBodyReader<?>> p2) { MessageBodyReader<?> e1 = p1.getProvider(); MessageBodyReader<?> e2 = p2.getProvider(); List<MediaType> types1 = JAXRSUtils.getProviderConsumeTypes(e1); types1 = JAXRSUtils.sortMediaTypes(types1, null); List<MediaType> types2 = JAXRSUtils.getProviderConsumeTypes(e2); types2 = JAXRSUtils.sortMediaTypes(types2, null); int result = JAXRSUtils.compareSortedMediaTypes(types1, types2, null); if (result != 0) { return result; } result = compareClasses(e1, e2); if (result != 0) { return result; } result = compareCustomStatus(p1, p2); if (result != 0) { return result; } return comparePriorityStatus(p1.getProvider().getClass(), p2.getProvider().getClass()); }
Example 4
Source File: ProviderFactory.java From cxf with Apache License 2.0 | 6 votes |
public int compare(ProviderInfo<MessageBodyWriter<?>> p1, ProviderInfo<MessageBodyWriter<?>> p2) { MessageBodyWriter<?> e1 = p1.getProvider(); MessageBodyWriter<?> e2 = p2.getProvider(); int result = compareClasses(e1, e2); if (result != 0) { return result; } List<MediaType> types1 = JAXRSUtils.sortMediaTypes(JAXRSUtils.getProviderProduceTypes(e1), JAXRSUtils.MEDIA_TYPE_QS_PARAM); List<MediaType> types2 = JAXRSUtils.sortMediaTypes(JAXRSUtils.getProviderProduceTypes(e2), JAXRSUtils.MEDIA_TYPE_QS_PARAM); result = JAXRSUtils.compareSortedMediaTypes(types1, types2, JAXRSUtils.MEDIA_TYPE_QS_PARAM); if (result != 0) { return result; } result = compareCustomStatus(p1, p2); if (result != 0) { return result; } return comparePriorityStatus(p1.getProvider().getClass(), p2.getProvider().getClass()); }
Example 5
Source File: ProviderFactoryTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testCustomProviderSortingWIOnly() { ProviderFactory pf = ServerProviderFactory.getInstance(); pf.setUserProviders( Arrays.asList( new DWriterInterceptor(), new CWriterInterceptor(), new AWriterInterceptor(), new BWriterInterceptor())); Comparator<ProviderInfo<WriterInterceptor>> comp = new Comparator<ProviderInfo<WriterInterceptor>>() { @Override public int compare( ProviderInfo<WriterInterceptor> o1, ProviderInfo<WriterInterceptor> o2) { WriterInterceptor provider1 = o1.getProvider(); WriterInterceptor provider2 = o2.getProvider(); return provider1.getClass().getName().compareTo( provider2.getClass().getName()); } }; pf.setProviderComparator(comp); Collection<ProviderInfo<WriterInterceptor>> values = pf.writerInterceptors.values(); assertEquals(4, values.size()); Iterator<ProviderInfo<WriterInterceptor>> iterator = values.iterator(); assertEquals(AWriterInterceptor.class, iterator.next().getProvider().getClass()); assertEquals(BWriterInterceptor.class, iterator.next().getProvider().getClass()); assertEquals(CWriterInterceptor.class, iterator.next().getProvider().getClass()); assertEquals(DWriterInterceptor.class, iterator.next().getProvider().getClass()); }
Example 6
Source File: ProviderFactoryTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testCustomProviderSortingMBWOnly() { ProviderFactory pf = ServerProviderFactory.getInstance(); Comparator<ProviderInfo<MessageBodyWriter<?>>> comp = new Comparator<ProviderInfo<MessageBodyWriter<?>>>() { @Override public int compare(ProviderInfo<MessageBodyWriter<?>> o1, ProviderInfo<MessageBodyWriter<?>> o2) { MessageBodyWriter<?> provider1 = o1.getProvider(); MessageBodyWriter<?> provider2 = o2.getProvider(); if (provider1 instanceof StringTextProvider) { return 1; } else if (provider2 instanceof StringTextProvider) { return -1; } else { return 0; } } }; pf.setProviderComparator(comp); // writers List<ProviderInfo<MessageBodyWriter<?>>> writers = pf.getMessageWriters(); assertEquals(10, writers.size()); Object lastWriter = writers.get(9).getProvider(); assertTrue(lastWriter instanceof StringTextProvider); //readers List<ProviderInfo<MessageBodyReader<?>>> readers = pf.getMessageReaders(); assertEquals(9, readers.size()); Object lastReader = readers.get(8).getProvider(); assertFalse(lastReader instanceof StringTextProvider); }
Example 7
Source File: ProviderFactoryTest.java From cxf with Apache License 2.0 | 5 votes |
@SuppressWarnings("rawtypes") @Test public void testCustomProviderSortingMBROnly() { ProviderFactory pf = ServerProviderFactory.getInstance(); Comparator<ProviderInfo<MessageBodyReader>> comp = new Comparator<ProviderInfo<MessageBodyReader>>() { @Override public int compare(ProviderInfo<MessageBodyReader> o1, ProviderInfo<MessageBodyReader> o2) { MessageBodyReader<?> provider1 = o1.getProvider(); MessageBodyReader<?> provider2 = o2.getProvider(); if (provider1 instanceof StringTextProvider) { return 1; } else if (provider2 instanceof StringTextProvider) { return -1; } else { return 0; } } }; pf.setProviderComparator(comp); // writers List<ProviderInfo<MessageBodyWriter<?>>> writers = pf.getMessageWriters(); assertEquals(10, writers.size()); Object lastWriter = writers.get(8).getProvider(); assertFalse(lastWriter instanceof StringTextProvider); //readers List<ProviderInfo<MessageBodyReader<?>>> readers = pf.getMessageReaders(); assertEquals(9, readers.size()); Object lastReader = readers.get(8).getProvider(); assertTrue(lastReader instanceof StringTextProvider); }
Example 8
Source File: ProviderFactoryTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testCustomProviderSorting() { ProviderFactory pf = ServerProviderFactory.getInstance(); Comparator<?> comp = new Comparator<ProviderInfo<?>>() { @Override public int compare(ProviderInfo<?> o1, ProviderInfo<?> o2) { Object provider1 = o1.getProvider(); Object provider2 = o2.getProvider(); if (provider1 instanceof StringTextProvider) { return 1; } else if (provider2 instanceof StringTextProvider) { return -1; } else { return 0; } } }; pf.setProviderComparator(comp); // writers List<ProviderInfo<MessageBodyWriter<?>>> writers = pf.getMessageWriters(); assertEquals(10, writers.size()); Object lastWriter = writers.get(9).getProvider(); assertTrue(lastWriter instanceof StringTextProvider); //readers List<ProviderInfo<MessageBodyReader<?>>> readers = pf.getMessageReaders(); assertEquals(9, readers.size()); Object lastReader = readers.get(8).getProvider(); assertTrue(lastReader instanceof StringTextProvider); }
Example 9
Source File: ServerProviderFactory.java From cxf with Apache License 2.0 | 5 votes |
private boolean isRegistered(Collection<?> list, Object o) { Collection<ProviderInfo<?>> list2 = CastUtils.cast(list); for (ProviderInfo<?> pi : list2) { if (pi.getProvider() == o) { return true; } } return false; }
Example 10
Source File: ServerProviderFactory.java From cxf with Apache License 2.0 | 5 votes |
private void addContainerRequestFilter( List<ProviderInfo<ContainerRequestFilter>> postMatchFilters, ProviderInfo<ContainerRequestFilter> p) { ContainerRequestFilter filter = p.getProvider(); if (isWadlGenerator(filter.getClass())) { wadlGenerator = p; } else { if (isPrematching(filter.getClass())) { addProviderToList(preMatchContainerRequestFilters, p); } else { postMatchFilters.add(p); } } }
Example 11
Source File: ProviderFactory.java From cxf with Apache License 2.0 | 5 votes |
public MessageBodyWriter<?> getDefaultJaxbWriter() { for (ProviderInfo<MessageBodyWriter<?>> pi : this.messageWriters) { Class<?> cls = pi.getProvider().getClass(); if (cls.getName().equals(JAXB_PROVIDER_NAME)) { return pi.getProvider(); } } return null; }
Example 12
Source File: ProviderFactory.java From cxf with Apache License 2.0 | 5 votes |
public int compare(ProviderInfo<ContextResolver<?>> p1, ProviderInfo<ContextResolver<?>> p2) { ContextResolver<?> e1 = p1.getProvider(); ContextResolver<?> e2 = p2.getProvider(); List<MediaType> types1 = JAXRSUtils.sortMediaTypes(JAXRSUtils.getProduceTypes( e1.getClass().getAnnotation(Produces.class)), JAXRSUtils.MEDIA_TYPE_QS_PARAM); List<MediaType> types2 = JAXRSUtils.sortMediaTypes(JAXRSUtils.getProduceTypes( e2.getClass().getAnnotation(Produces.class)), JAXRSUtils.MEDIA_TYPE_QS_PARAM); return JAXRSUtils.compareSortedMediaTypes(types1, types2, JAXRSUtils.MEDIA_TYPE_QS_PARAM); }
Example 13
Source File: ProviderFactory.java From cxf with Apache License 2.0 | 5 votes |
private boolean isWriteable(ProviderInfo<MessageBodyWriter<?>> pi, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, Message m) { MessageBodyWriter<?> ep = pi.getProvider(); if (m.get(ACTIVE_JAXRS_PROVIDER_KEY) != ep) { injectContextValues(pi, m); } return ep.isWriteable(type, genericType, annotations, mediaType); }
Example 14
Source File: ProviderFactory.java From cxf with Apache License 2.0 | 5 votes |
private <T> boolean matchesWriterMediaTypes(ProviderInfo<MessageBodyWriter<?>> pi, MediaType mediaType) { MessageBodyWriter<?> ep = pi.getProvider(); List<MediaType> supportedMediaTypes = JAXRSUtils.getProviderProduceTypes(ep); return JAXRSUtils.doMimeTypesIntersect(Collections.singletonList(mediaType), supportedMediaTypes); }
Example 15
Source File: ProviderFactory.java From cxf with Apache License 2.0 | 5 votes |
private boolean isReadable(ProviderInfo<MessageBodyReader<?>> pi, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, Message m) { MessageBodyReader<?> ep = pi.getProvider(); if (m.get(ACTIVE_JAXRS_PROVIDER_KEY) != ep) { injectContextValues(pi, m); } return ep.isReadable(type, genericType, annotations, mediaType); }
Example 16
Source File: ProviderFactory.java From cxf with Apache License 2.0 | 5 votes |
private <T> boolean matchesReaderMediaTypes(ProviderInfo<MessageBodyReader<?>> pi, MediaType mediaType) { MessageBodyReader<?> ep = pi.getProvider(); List<MediaType> supportedMediaTypes = JAXRSUtils.getProviderConsumeTypes(ep); return JAXRSUtils.doMimeTypesIntersect(Collections.singletonList(mediaType), supportedMediaTypes); }
Example 17
Source File: ProviderFactory.java From cxf with Apache License 2.0 | 5 votes |
protected void addProviderToList(List<?> list, ProviderInfo<?> provider) { List<ProviderInfo<?>> list2 = CastUtils.cast(list); for (ProviderInfo<?> pi : list2) { if (pi.getProvider() == provider.getProvider()) { return; } } list2.add(provider); }
Example 18
Source File: JAXRSUtils.java From cxf with Apache License 2.0 | 4 votes |
public static <T> T createContextValue(Message m, Type genericType, Class<T> clazz) { Message contextMessage = getContextMessage(m); Object o = null; if (UriInfo.class.isAssignableFrom(clazz)) { o = createUriInfo(contextMessage); } else if (HttpHeaders.class.isAssignableFrom(clazz) || ProtocolHeaders.class.isAssignableFrom(clazz)) { o = createHttpHeaders(contextMessage, clazz); } else if (SecurityContext.class.isAssignableFrom(clazz)) { SecurityContext customContext = contextMessage.get(SecurityContext.class); o = customContext == null ? new SecurityContextImpl(contextMessage) : customContext; } else if (MessageContext.class.isAssignableFrom(clazz)) { o = new MessageContextImpl(m); } else if (ResourceInfo.class.isAssignableFrom(clazz)) { o = new ResourceInfoImpl(contextMessage); } else if (ResourceContext.class.isAssignableFrom(clazz)) { o = new ResourceContextImpl(contextMessage, contextMessage.getExchange().get(OperationResourceInfo.class)); } else if (Request.class.isAssignableFrom(clazz)) { o = new RequestImpl(contextMessage); } else if (Providers.class.isAssignableFrom(clazz)) { o = new ProvidersImpl(contextMessage); } else if (ContextResolver.class.isAssignableFrom(clazz)) { o = createContextResolver(genericType, contextMessage); } else if (Configuration.class.isAssignableFrom(clazz)) { o = ProviderFactory.getInstance(contextMessage).getConfiguration(contextMessage); } else if (Application.class.isAssignableFrom(clazz)) { ProviderInfo<?> providerInfo = (ProviderInfo<?>)contextMessage.getExchange().getEndpoint().get(Application.class.getName()); o = providerInfo == null ? null : providerInfo.getProvider(); } else if (contextMessage != null) { ContextProvider<?> provider = ProviderFactory.getInstance(contextMessage).createContextProvider(clazz, contextMessage); if (provider != null) { o = provider.createContext(contextMessage); } } if (o == null && contextMessage != null && !MessageUtils.isRequestor(contextMessage)) { o = HttpUtils.createServletResourceValue(contextMessage, clazz); } return clazz.cast(o); }