Can't override XML factory providers

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Can't override XML factory providers

Alejandro Pulver
Hello,

I'm creating an application with a custom resource config, where I'm adding a binder to setup XML factory providers. The binder is getting executed, but when using jersey the default SaxParserFactoryInjectionProvider is executed instead of the one I bound later. The version I'm using is 2.11.

The full existing initialization code is available at github:

What I've added is here, and called "resourceConfig.register(new JerseyXmlBinder())" (that is getting executed after the original MessagingBinders's configure, where the factories are defined for the first time).

public class JerseyXmlBinder extends AbstractBinder
{
    @Override
    protected void configure()
    {
        bindFactory(DocumentBuilderFactoryProvider.class).to(DocumentBuilderFactory.class).in(PerThread.class);
        bindFactory(SaxParserFactoryProvider.class).to(SAXParserFactory.class).in(PerThread.class);
        bindFactory(XmlInputFactoryProvider.class).to(XMLInputFactory.class).in(PerThread.class);
    }

public class SaxParserFactoryProvider implements Factory<SAXParserFactory>
{

    @Inject
    public SaxParserFactoryProvider(final Configuration config)
    {
    }

    @Override
    @PerThread
    public SAXParserFactory provide()
    {
        SAXParserFactory factory = SAXParserFactory.newInstance();

        factory.setNamespaceAware(true);
        factory = new SecureSaxParserFactory(factory);

        return factory;
    }

    @Override
    public void dispose(SAXParserFactory instance)
    {
        //not used
    }
}

Am I doing something wrong?

Thanks,
Alejandro