Search in sources :

Example 1 with CommonConfig

use of org.glassfish.jersey.model.internal.CommonConfig in project jersey by jersey.

the class ValidatorTest method createInjectionManager.

private InjectionManager createInjectionManager() {
    InjectionManager injectionManager = InjectionManagerFactory.createInjectionManager();
    injectionManager.register(new AbstractBinder() {

        @Override
        protected void configure() {
            bind(new CommonConfig(RuntimeType.SERVER, ComponentBag.EXCLUDE_EMPTY)).to(Configuration.class);
        }
    });
    return injectionManager;
}
Also used : Configuration(javax.ws.rs.core.Configuration) AbstractBinder(org.glassfish.jersey.internal.inject.AbstractBinder) CommonConfig(org.glassfish.jersey.model.internal.CommonConfig) InjectionManager(org.glassfish.jersey.internal.inject.InjectionManager)

Example 2 with CommonConfig

use of org.glassfish.jersey.model.internal.CommonConfig in project jersey by jersey.

the class JaxbStringReaderProviderTest method stringReaderDoesNotReadExternalDtds.

@Test
public void stringReaderDoesNotReadExternalDtds() {
    Provider<SAXParserFactory> saxParserFactoryProvider = new Provider<SAXParserFactory>() {

        final SaxParserFactoryInjectionProvider spf = new SaxParserFactoryInjectionProvider(new CommonConfig(RuntimeType.SERVER, ComponentBag.INCLUDE_ALL));

        @Override
        public SAXParserFactory get() {
            return spf.get();
        }
    };
    JaxbStringReaderProvider.RootElementProvider provider = new JaxbStringReaderProvider.RootElementProvider(saxParserFactoryProvider, new Providers() {

        @Override
        public <T> MessageBodyReader<T> getMessageBodyReader(Class<T> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
            return null;
        }

        @Override
        public <T> MessageBodyWriter<T> getMessageBodyWriter(Class<T> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
            return null;
        }

        @Override
        public <T extends Throwable> ExceptionMapper<T> getExceptionMapper(Class<T> type) {
            return null;
        }

        @Override
        public <T> ContextResolver<T> getContextResolver(Class<T> contextType, MediaType mediaType) {
            return null;
        }
    });
    String content = "<!DOCTYPE x SYSTEM 'file:///no-such-file'> <rootObject/>";
    provider.getConverter(RootObject.class, null, null).fromString(content);
}
Also used : CommonConfig(org.glassfish.jersey.model.internal.CommonConfig) Providers(javax.ws.rs.ext.Providers) Annotation(java.lang.annotation.Annotation) Provider(javax.inject.Provider) MessageBodyReader(javax.ws.rs.ext.MessageBodyReader) RuntimeType(javax.ws.rs.RuntimeType) MediaType(javax.ws.rs.core.MediaType) Type(java.lang.reflect.Type) ExceptionMapper(javax.ws.rs.ext.ExceptionMapper) MediaType(javax.ws.rs.core.MediaType) ContextResolver(javax.ws.rs.ext.ContextResolver) MessageBodyWriter(javax.ws.rs.ext.MessageBodyWriter) SAXParserFactory(javax.xml.parsers.SAXParserFactory) Test(org.junit.Test)

Example 3 with CommonConfig

use of org.glassfish.jersey.model.internal.CommonConfig in project jersey by jersey.

the class CommittingOutputStreamTest method checkBufferSize.

private void checkBufferSize(int expectedSize, Map<String, Object> properties, RuntimeType runtime) throws IOException {
    OutboundMessageContext outboundMessageContext = new OutboundMessageContext();
    final Passed passed = new Passed();
    outboundMessageContext.setStreamProvider(new OutboundMessageContext.StreamProvider() {

        @Override
        public OutputStream getOutputStream(int contentLength) throws IOException {
            assertEquals(-1, contentLength);
            passed.pass();
            return null;
        }
    });
    CommonConfig configuration = new CommonConfig(runtime, ComponentBag.INCLUDE_ALL);
    configuration.setProperties(properties);
    outboundMessageContext.enableBuffering(configuration);
    final OutputStream entityStream = outboundMessageContext.getEntityStream();
    for (int i = 1; (i < 1000000) && (!passed.b); i++) {
        entityStream.write((byte) 65);
        if (i >= expectedSize + 1) {
            break;
        } else {
            assertFalse("committed already with byte #" + i, passed.b);
        }
    }
    assertTrue(passed.b);
}
Also used : OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CommonConfig(org.glassfish.jersey.model.internal.CommonConfig) IOException(java.io.IOException)

Aggregations

CommonConfig (org.glassfish.jersey.model.internal.CommonConfig)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 Annotation (java.lang.annotation.Annotation)1 Type (java.lang.reflect.Type)1 Provider (javax.inject.Provider)1 RuntimeType (javax.ws.rs.RuntimeType)1 Configuration (javax.ws.rs.core.Configuration)1 MediaType (javax.ws.rs.core.MediaType)1 ContextResolver (javax.ws.rs.ext.ContextResolver)1 ExceptionMapper (javax.ws.rs.ext.ExceptionMapper)1 MessageBodyReader (javax.ws.rs.ext.MessageBodyReader)1 MessageBodyWriter (javax.ws.rs.ext.MessageBodyWriter)1 Providers (javax.ws.rs.ext.Providers)1 SAXParserFactory (javax.xml.parsers.SAXParserFactory)1 AbstractBinder (org.glassfish.jersey.internal.inject.AbstractBinder)1 InjectionManager (org.glassfish.jersey.internal.inject.InjectionManager)1 Test (org.junit.Test)1