Skip to content

Commit

Permalink
[RESTEASY-1471] (#936)
Browse files Browse the repository at this point in the history
In ResteasyProviderFactory, user defined context providers should be
registered as "not builtin".
  • Loading branch information
ronsigal authored and asoldano committed Sep 12, 2016
1 parent 840cb66 commit 52d440f
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1334,7 +1334,7 @@ public void registerProvider(Class provider, Integer priorityOverride, boolean i
{
try
{
addContextResolver(provider, true);
addContextResolver(provider, isBuiltin);
int priority = getPriority(priorityOverride, contracts, ContextResolver.class, provider);
newContracts.put(ContextResolver.class, priority);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package org.jboss.resteasy.test.providers;

import java.lang.annotation.Annotation;

import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.ContextResolver;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;

import org.jboss.resteasy.plugins.providers.jaxb.JAXBContextFinder;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.junit.Assert;
import org.junit.Test;

/**
* @tpSubChapter Providers
* @tpChapter Unit tests
* @tpTestCaseDetails Regression test for RESTEASY-1471
* @tpSince RESTEasy 3.1.0.Final
*/
public class UserDefinedContextResolverTest {

public static class TestException extends RuntimeException {
private static final long serialVersionUID = 1L;
}

@Produces({"text/*+xml", "application/*+xml"})
@SuppressWarnings("rawtypes")
public static class TestContextFinder implements JAXBContextFinder {

@Override
public JAXBContext findCachedContext(Class type, MediaType mediaType, Annotation[] parameterAnnotations) throws JAXBException {
return null;
}
@Override
public JAXBContext findCacheContext(MediaType mediaType, Annotation[] paraAnnotations, Class... classes) throws JAXBException {
return null;
}
@Override
public JAXBContext findCacheXmlTypeContext(MediaType mediaType, Annotation[] paraAnnotations, Class... classes) throws JAXBException {
return null;
}
@Override
public JAXBContext createContext(Annotation[] parameterAnnotations, Class... classes) throws JAXBException {
return null;
}
}

@Produces({"text/*+xml", "application/*+xml"})
public static class TestContextResolver implements ContextResolver<JAXBContextFinder> {

@Override
public JAXBContextFinder getContext(Class<?> type) {
return new TestContextFinder();
}
}

@Test
public void testUserDefinedContextResolver() {

ResteasyProviderFactory providerFactory = ResteasyProviderFactory.getInstance();
ContextResolver<JAXBContextFinder> finder1 = providerFactory.getContextResolver(JAXBContextFinder.class, MediaType.TEXT_XML_TYPE);
Assert.assertNotNull(finder1);
System.out.println(finder1);
providerFactory.register(TestContextResolver.class);
ContextResolver<JAXBContextFinder> finder2 = providerFactory.getContextResolver(JAXBContextFinder.class, MediaType.TEXT_XML_TYPE);
System.out.println(finder2);
JAXBContextFinder finder = finder2.getContext(JAXBContextFinder.class);
System.out.println(finder);
Assert.assertTrue(finder instanceof TestContextFinder);
}
}

0 comments on commit 52d440f

Please sign in to comment.