Search in sources :

Example 16 with ProviderInfo

use of org.apache.cxf.jaxrs.model.ProviderInfo in project cxf by apache.

the class ProviderFactoryTest method testCustomProviderSortingWIOnly.

@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());
}
Also used : WriterInterceptor(javax.ws.rs.ext.WriterInterceptor) ProviderInfo(org.apache.cxf.jaxrs.model.ProviderInfo) Comparator(java.util.Comparator) Test(org.junit.Test)

Example 17 with ProviderInfo

use of org.apache.cxf.jaxrs.model.ProviderInfo in project cxf by apache.

the class ProviderFactoryTest method testCustomProviderSortingWithBus.

@Test
public void testCustomProviderSortingWithBus() {
    WildcardReader wc1 = new WildcardReader();
    WildcardReader2 wc2 = new WildcardReader2();
    Bus bus = BusFactory.newInstance().createBus();
    bus.setProperty(MessageBodyReader.class.getName(), wc1);
    ProviderFactory pf = ServerProviderFactory.createInstance(bus);
    pf.registerUserProvider(wc2);
    List<ProviderInfo<MessageBodyReader<?>>> readers = pf.getMessageReaders();
    assertEquals(11, readers.size());
    assertSame(wc2, readers.get(7).getProvider());
    assertSame(wc1, readers.get(8).getProvider());
}
Also used : Bus(org.apache.cxf.Bus) MessageBodyReader(javax.ws.rs.ext.MessageBodyReader) ProviderInfo(org.apache.cxf.jaxrs.model.ProviderInfo) Test(org.junit.Test)

Example 18 with ProviderInfo

use of org.apache.cxf.jaxrs.model.ProviderInfo in project cxf by apache.

the class ProviderFactoryTest method indexOf.

private int indexOf(List<? extends Object> providerInfos, Class<?> providerType) {
    int index = 0;
    for (Object pi : providerInfos) {
        Object p = ((ProviderInfo<?>) pi).getProvider();
        if (p.getClass().isAssignableFrom(providerType)) {
            break;
        }
        index++;
    }
    return index;
}
Also used : ProviderInfo(org.apache.cxf.jaxrs.model.ProviderInfo) Endpoint(org.apache.cxf.endpoint.Endpoint)

Example 19 with ProviderInfo

use of org.apache.cxf.jaxrs.model.ProviderInfo in project cxf by apache.

the class ProviderFactoryTest method testCustomProviderSortingParamConverterProvider.

@Test
public void testCustomProviderSortingParamConverterProvider() {
    ParamConverterProvider h = new CustomerParameterHandler();
    ParamConverterProvider hp = new PriorityCustomerParameterHandler();
    ProviderFactory pf = ServerProviderFactory.getInstance();
    pf.setUserProviders(Arrays.asList(h, hp));
    Comparator<ProviderInfo<ParamConverterProvider>> comp = new Comparator<ProviderInfo<ParamConverterProvider>>() {

        @Override
        public int compare(ProviderInfo<ParamConverterProvider> o1, ProviderInfo<ParamConverterProvider> o2) {
            ParamConverterProvider provider1 = o1.getProvider();
            ParamConverterProvider provider2 = o2.getProvider();
            return provider1.getClass().getName().compareTo(provider2.getClass().getName());
        }
    };
    pf.setProviderComparator(comp);
    ParamConverter<Customer> h2 = pf.createParameterHandler(Customer.class, Customer.class, null, new MessageImpl());
    assertSame(h2, h);
}
Also used : PriorityCustomerParameterHandler(org.apache.cxf.jaxrs.PriorityCustomerParameterHandler) ProviderInfo(org.apache.cxf.jaxrs.model.ProviderInfo) Customer(org.apache.cxf.jaxrs.Customer) ParamConverterProvider(javax.ws.rs.ext.ParamConverterProvider) MessageImpl(org.apache.cxf.message.MessageImpl) PriorityCustomerParameterHandler(org.apache.cxf.jaxrs.PriorityCustomerParameterHandler) CustomerParameterHandler(org.apache.cxf.jaxrs.CustomerParameterHandler) Comparator(java.util.Comparator) Test(org.junit.Test)

Example 20 with ProviderInfo

use of org.apache.cxf.jaxrs.model.ProviderInfo in project cxf by apache.

the class ProviderFactoryTest method testCreateMessageBodyReaderInterceptorWithFaultMessageAndReaderInterceptor.

@Test
public void testCreateMessageBodyReaderInterceptorWithFaultMessageAndReaderInterceptor() throws Exception {
    ReaderInterceptor ri = readerInterceptorContext -> readerInterceptorContext.proceed();
    ProviderInfo<ReaderInterceptor> pi = new ProviderInfo<>(ri, null, true);
    ServerProviderFactory spf = ServerProviderFactory.getInstance();
    spf.readerInterceptors.put(new ProviderFactory.NameKey("org.apache.cxf.filter.binding", 1, ri.getClass()), pi);
    final Message message = prepareFaultMessage(MediaType.APPLICATION_XML, MediaType.APPLICATION_XML);
    List<ReaderInterceptor> interceptors = spf.createMessageBodyReaderInterceptor(Book.class, Book.class, new Annotation[0], MediaType.APPLICATION_XML_TYPE, message, true, null);
    assertSame(2, interceptors.size());
}
Also used : Arrays(java.util.Arrays) Produces(javax.ws.rs.Produces) Assert.assertNotSame(org.junit.Assert.assertNotSame) Priorities(javax.ws.rs.Priorities) ExceptionMapper(javax.ws.rs.ext.ExceptionMapper) MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) MessageBodyWriter(javax.ws.rs.ext.MessageBodyWriter) ParamConverter(javax.ws.rs.ext.ParamConverter) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Assert.assertThat(org.junit.Assert.assertThat) ContextResolver(javax.ws.rs.ext.ContextResolver) JAXBContextProvider2(org.apache.cxf.jaxrs.JAXBContextProvider2) MediaType(javax.ws.rs.core.MediaType) Consumes(javax.ws.rs.Consumes) ReaderInterceptor(javax.ws.rs.ext.ReaderInterceptor) Map(java.util.Map) ParamConverterProvider(javax.ws.rs.ext.ParamConverterProvider) JAXBContextProvider(org.apache.cxf.jaxrs.JAXBContextProvider) RuntimeType(javax.ws.rs.RuntimeType) SuperBook(org.apache.cxf.jaxrs.resources.SuperBook) Collection(java.util.Collection) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Customer(org.apache.cxf.jaxrs.Customer) Priority(javax.annotation.Priority) List(java.util.List) WriterInterceptorContext(javax.ws.rs.ext.WriterInterceptorContext) Response(javax.ws.rs.core.Response) Type(java.lang.reflect.Type) PriorityCustomerParameterHandler(org.apache.cxf.jaxrs.PriorityCustomerParameterHandler) Assert.assertFalse(org.junit.Assert.assertFalse) Annotation(java.lang.annotation.Annotation) WebApplicationException(javax.ws.rs.WebApplicationException) Bus(org.apache.cxf.Bus) MessageImpl(org.apache.cxf.message.MessageImpl) Feature(javax.ws.rs.core.Feature) DataHandler(javax.activation.DataHandler) Schema(javax.xml.validation.Schema) ArrayList(java.util.ArrayList) Assert.assertSame(org.junit.Assert.assertSame) ProviderInfo(org.apache.cxf.jaxrs.model.ProviderInfo) ConstrainedTo(javax.ws.rs.ConstrainedTo) WriterInterceptor(javax.ws.rs.ext.WriterInterceptor) Status(javax.ws.rs.core.Response.Status) JAXBContext(javax.xml.bind.JAXBContext) WebApplicationExceptionMapper(org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper) Before(org.junit.Before) OutputStream(java.io.OutputStream) Iterator(java.util.Iterator) CustomerParameterHandler(org.apache.cxf.jaxrs.CustomerParameterHandler) Message(org.apache.cxf.message.Message) Assert.assertNotNull(org.junit.Assert.assertNotNull) JAXBElement(javax.xml.bind.JAXBElement) IOUtils(org.apache.cxf.helpers.IOUtils) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) EasyMock(org.easymock.EasyMock) XmlRootElement(javax.xml.bind.annotation.XmlRootElement) Book(org.apache.cxf.jaxrs.resources.Book) Exchange(org.apache.cxf.message.Exchange) File(java.io.File) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) AbstractResourceInfo(org.apache.cxf.jaxrs.model.AbstractResourceInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) Assert.assertNull(org.junit.Assert.assertNull) BusFactory(org.apache.cxf.BusFactory) DataSource(javax.activation.DataSource) Comparator(java.util.Comparator) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) MessageBodyReader(javax.ws.rs.ext.MessageBodyReader) ReaderInterceptor(javax.ws.rs.ext.ReaderInterceptor) ProviderInfo(org.apache.cxf.jaxrs.model.ProviderInfo) Message(org.apache.cxf.message.Message) Test(org.junit.Test)

Aggregations

ProviderInfo (org.apache.cxf.jaxrs.model.ProviderInfo)26 Endpoint (org.apache.cxf.endpoint.Endpoint)9 FilterProviderInfo (org.apache.cxf.jaxrs.model.FilterProviderInfo)7 Response (javax.ws.rs.core.Response)6 Message (org.apache.cxf.message.Message)5 Test (org.junit.Test)5 IOException (java.io.IOException)4 Comparator (java.util.Comparator)4 Map (java.util.Map)4 WriterInterceptor (javax.ws.rs.ext.WriterInterceptor)4 MessageImpl (org.apache.cxf.message.MessageImpl)4 List (java.util.List)3 ContainerRequestContext (javax.ws.rs.container.ContainerRequestContext)3 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)3 MessageBodyReader (javax.ws.rs.ext.MessageBodyReader)3 ReaderInterceptor (javax.ws.rs.ext.ReaderInterceptor)3 Bus (org.apache.cxf.Bus)3 ContainerRequestContextImpl (org.apache.cxf.jaxrs.impl.ContainerRequestContextImpl)3 MetadataMap (org.apache.cxf.jaxrs.impl.MetadataMap)3 File (java.io.File)2