Package org.apache.wink.common.internal.registry

Examples of org.apache.wink.common.internal.registry.ProvidersRegistry$ProviderRecord


        Object entity = request.getEntity();
        if (entity == null) {
            return;
        }

        ProvidersRegistry providersRegistry = request.getAttribute(ProvidersRegistry.class);
        ClientRuntimeContext runtimeContext = new ClientRuntimeContext(providersRegistry);
        RuntimeContext saved = RuntimeContextTLS.getRuntimeContext();
        RuntimeContextTLS.setRuntimeContext(runtimeContext);
        try {
            Class<?> type = entity.getClass();
            Type genericType = type;
            if (entity instanceof GenericEntity) {
                GenericEntity<?> genericEntity = (GenericEntity<?>)entity;
                type = genericEntity.getRawType();
                genericType = genericEntity.getType();
                entity = genericEntity.getEntity();
            }
            String contentType = request.getHeaders().getFirst(HttpHeaders.CONTENT_TYPE);
            if (contentType == null) {
                contentType = MediaType.APPLICATION_OCTET_STREAM;
            }
            MediaType contentMediaType = MediaType.valueOf(contentType);
            MessageBodyWriter writer =
                providersRegistry.getMessageBodyWriter(type,
                                                       genericType,
                                                       null,
                                                       contentMediaType,
                                                       runtimeContext);
            if (writer == null) {
View Full Code Here


                }

                if (providers == null) {
                    LifecycleManagersRegistry ofFactoryRegistry = new LifecycleManagersRegistry();
                    ofFactoryRegistry.addFactoryFactory(new ScopeLifecycleManager<Object>());
                    ProvidersRegistry providersRegistry =
                        new ProvidersRegistry(ofFactoryRegistry, new ApplicationValidator());

                    final Set<Class<?>> classes = new ApplicationFileLoader(true).getClasses();

                    processApplication(providersRegistry, new WinkApplication() {
                        @Override
View Full Code Here

    protected void setUp() throws Exception {
        super.setUp();

        LifecycleManagersRegistry ofFactoryRegistry = new LifecycleManagersRegistry();
        ofFactoryRegistry.addFactoryFactory(new ScopeLifecycleManager<Object>());
        ProvidersRegistry providersRegistry =
            new ProvidersRegistry(ofFactoryRegistry, new ApplicationValidator());

        Set<Class<?>> classes = new ApplicationFileLoader(true).getClasses();
        if (classes != null) {
            for (Class<?> cls : classes) {
                if (ProviderMetadataCollector.isProvider(cls)) {
                    providersRegistry.addProvider(cls);
                }
            }
        }
        AbstractRuntimeContext runtimeContext = new AbstractRuntimeContext() {
View Full Code Here

    private void initProvidersRegistry() {
        // setup OFFactoryRegistry to support default and scope
        LifecycleManagersRegistry ofFactoryRegistry = new LifecycleManagersRegistry();
        ofFactoryRegistry.addFactoryFactory(new ScopeLifecycleManager<Object>());
        providersRegistry = new ProvidersRegistry(ofFactoryRegistry, new ApplicationValidator());

        // process all applications
        for (Application app : config.getApplications()) {
            processApplication(app);
        }
View Full Code Here

        ClientRequest request =
            createClientRequest(method, responseEntity, responseEntityType, requestEntity);
        HandlerContext context = createHandlerContext();

        ProvidersRegistry providersRegistry = request.getAttribute(ProvidersRegistry.class);
        ClientRuntimeContext runtimeContext = new ClientRuntimeContext(providersRegistry);
        RuntimeContext saved = RuntimeContextTLS.getRuntimeContext();
        RuntimeContextTLS.setRuntimeContext(runtimeContext);

        try {
View Full Code Here

        Object entity = request.getEntity();
        if (entity == null) {
            return;
        }

        ProvidersRegistry providersRegistry = request.getAttribute(ProvidersRegistry.class);
        ClientRuntimeContext runtimeContext = new ClientRuntimeContext(providersRegistry);
        RuntimeContext saved = RuntimeContextTLS.getRuntimeContext();
        RuntimeContextTLS.setRuntimeContext(runtimeContext);
        try {
            Class<?> type = entity.getClass();
            Type genericType = type;
            if (entity instanceof GenericEntity) {
                GenericEntity<?> genericEntity = (GenericEntity<?>)entity;
                type = genericEntity.getRawType();
                genericType = genericEntity.getType();
                entity = genericEntity.getEntity();
            }
            MessageBodyWriter writer = null;
            MediaType contentMediaType = null;
            String contentType = request.getHeaders().getFirst(HttpHeaders.CONTENT_TYPE);
            if (contentType == null) {
                // attempt to infer the media type based on the providers
                // available for this type
                contentMediaType =
                    providersRegistry
                        .getMessageBodyWriterMediaTypeLimitByIsWritable(type, runtimeContext);
                if (contentMediaType == null) {
                    // default if we still couldn't find it
                    contentType = MediaType.APPLICATION_OCTET_STREAM;
                }
            } else
                contentMediaType = MediaType.valueOf(contentType);
            request.getHeaders().putSingle(HttpHeaders.CONTENT_TYPE, contentMediaType.toString());
            writer =
                providersRegistry.getMessageBodyWriter(type,
                                                       genericType,
                                                       null,
                                                       contentMediaType,
                                                       runtimeContext);
            if (writer == null) {
View Full Code Here

            return Collections.emptyList();
        }
    }

    private ProvidersRegistry createProvidersRegistryImpl() {
        ProvidersRegistry providers =
            new ProvidersRegistry(new LifecycleManagersRegistry(), new ApplicationValidator());
        ;
        return providers;
    }
View Full Code Here

        ;
        return providers;
    }

    public void testContextResolvers() {
        ProvidersRegistry providers = createProvidersRegistryImpl();
        assertTrue(providers.addProvider(new AtomContextResolver()));
        assertTrue(providers.addProvider(new StringContextResolver()));
        assertTrue(providers.addProvider(new IntegerContextResolver()));
        assertTrue(providers.addProvider(new ByteContextResolver()));
        assertTrue(providers.addProvider(new ListContextResolver()));

        try {
            providers.addProvider(new NotAProvider());
            fail("expected IllegalArgumentException");
        } catch (IllegalArgumentException e) {
        }

        /*
         * String and text/pain, should invoke StringContextResolver
         */
        assertEquals(STRING, providers.getContextResolver(String.class,
                                                          MediaType.TEXT_PLAIN_TYPE,
                                                          null).getContext(null));

        /*
         * byte[] and text/plain, should invoke ByteContextResolver
         */
        assertEquals(BYTE, providers.getContextResolver(byte[].class,
                                                        MediaType.TEXT_PLAIN_TYPE,
                                                        null).getContext(null));

        /*
         * There is no context resolver that handlers Integer and /
         */
        assertEquals(_12345, providers.getContextResolver(Integer.class,
                                                          MediaType.WILDCARD_TYPE,
                                                          null).getContext(null));

        /*
         * StringContextResolver is registered after AtomContextResolver,
         * therefore it should be invoked
         */
        assertEquals(STRING, providers.getContextResolver(String.class,
                                                          MediaType.WILDCARD_TYPE,
                                                          null).getContext(null));

        /*
         * AtomContextResolver returns null, if the parameter is not null,
         * therefore StringContextResolver should be invoked
         */
        assertEquals(STRING, providers.getContextResolver(String.class,
                                                          MediaType.WILDCARD_TYPE,
                                                          null).getContext(String.class));

        /*
         * test ContextResolver with collections
         */
        assertEquals(Collections.emptyList(), providers.getContextResolver(List.class,
                                                                           MediaType.WILDCARD_TYPE,
                                                                           null).getContext(null));
    }
View Full Code Here

                                                                           MediaType.WILDCARD_TYPE,
                                                                           null).getContext(null));
    }

    public void testContextResolverWildCards() {
        ProvidersRegistry providers = createProvidersRegistryImpl();
        assertTrue(providers.addProvider(new MyContextResolver()));
        assertTrue(providers.addProvider(new StringContextResolver3()));

        /*
         * Check various wildcard permutations
         */
        assertSame(MYCLASS, providers.getContextResolver(MyClass.class,
                                                         MediaType.WILDCARD_TYPE,
                                                         null).getContext(MyClass.class));
        assertSame(MYCLASS, providers.getContextResolver(MyClass.class,
                                                         new MediaType("*", "*"),
                                                         null).getContext(MyClass.class));
        assertSame(MYCLASS, providers.getContextResolver(MyClass.class,
                                                         new MediaType("application", "*"),
                                                         null).getContext(MyClass.class));
        assertSame(MYCLASS, providers.getContextResolver(MyClass.class,
                                                         new MediaType("application",
                                                                       "x-www-form-urlencoded"),
                                                         null).getContext(MyClass.class));
        assertSame(MYCLASS, providers
            .getContextResolver(MyClass.class, new MediaType("*", "x-www-form-urlencoded"), null)
            .getContext(MyClass.class));

        // should hit an exact match when search expands out to "text/*"
        assertSame(STRING3, providers.getContextResolver(String.class,
                                                         new MediaType("text", "blarg"),
                                                         null).getContext(String.class));
    }
View Full Code Here

                                                         new MediaType("text", "blarg"),
                                                         null).getContext(String.class));
    }

    public void testContextResolverSortingAlgorithm() {
        ProvidersRegistry providers = createProvidersRegistryImpl();
        // note: the order these are added is important to the test
        assertTrue(providers.addProvider(new StringContextResolver4()));
        assertTrue(providers.addProvider(new StringContextResolver3()));
        assertTrue(providers.addProvider(new StringContextResolver2()));

        // StringContextResolver2 takes priority over the others due to the
        // media type in @Produces
        assertSame(STRING2, providers.getContextResolver(String.class,
                                                         new MediaType("text", "*"),
                                                         null).getContext(String.class));

        // StringContextResolver2 takes priority over the others due to the
        // media type in @Produces
        assertSame(STRING2, providers.getContextResolver(String.class,
                                                         new MediaType("*", "*"),
                                                         null).getContext(String.class));

        // StringContextResolver2 takes priority over the others due to the
        // media type in @Produces
        assertSame(STRING2, providers.getContextResolver(String.class,
                                                         new MediaType("text", "plain"),
                                                         null).getContext(String.class));
    }
View Full Code Here

TOP

Related Classes of org.apache.wink.common.internal.registry.ProvidersRegistry$ProviderRecord

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.