Package org.glassfish.jersey.server.model

Examples of org.glassfish.jersey.server.model.Resource$Data


        final ResourceModel.Builder builder = ModelProcessorUtil.enhanceResourceModel(resourceModel, false, methodList, true);

        // Do not add WadlResource if already present in the classes (i.e. added during scanning).
        if (!configuration.getClasses().contains(WadlResource.class)) {
            final Resource wadlResource = Resource.builder(WadlResource.class).build();
            builder.addResource(wadlResource);
        }

        return builder.build();
View Full Code Here


    private List<MethodAcceptorPair> createAcceptors(RuntimeResource runtimeResource, boolean subResourceMode) {
        List<MethodAcceptorPair> acceptorPairList = Lists.newArrayList();
        int i = 0;
        for (Resource resource : runtimeResource.getResources()) {

            final Resource parentResource = runtimeResource.getParent() == null
                    ? null : runtimeResource.getParentResources().get(i++);

            final UriTemplate template = resource.getPathPattern().getTemplate();

            final PushMatchedTemplateRouter templateRouter = parentResource == null ?
                    getTemplateRouter(subResourceMode, template, null)
                    : getTemplateRouter(subResourceMode, parentResource.getPathPattern().getTemplate(), template);

            for (ResourceMethod resourceMethod : resource.getResourceMethods()) {
                acceptorPairList.add(new MethodAcceptorPair(resourceMethod,
                        templateRouter,
                        new PushMatchedMethodRouter(resourceMethod),
View Full Code Here

            }

            // Introspecting classes & instances
            for (final Class<?> c : runtimeConfig.getClasses()) {
                try {
                    final Resource resource = Resource.from(c, disableValidation);
                    if (resource != null) {
                        resourceBagBuilder.registerResource(c, resource);
                    }
                } catch (final IllegalArgumentException ex) {
                    LOGGER.warning(ex.getMessage());
                }
            }

            for (final Object o : runtimeConfig.getSingletons()) {
                try {
                    final Resource resource = Resource.from(o.getClass(), disableValidation);
                    if (resource != null) {
                        resourceBagBuilder.registerResource(o, resource);
                    }
                } catch (final IllegalArgumentException ex) {
                    LOGGER.warning(ex.getMessage());
View Full Code Here

                    null, String.class);
            if (accessUri == null) {
                accessUri = accessTokenUri == null ? "accessToken" : accessTokenUri;
            }

            final Resource requestResource = Resource.builder(RequestTokenResource.class).path(requestUri).build();
            final Resource accessResource = Resource.builder(AccessTokenResource.class).path(accessUri).build();

            context.register(new OAuthModelProcessor(requestResource, accessResource));
        }
        return true;
    }
View Full Code Here

        }

        private void registerModel(Resource resourceModel) {
            final String path = resourceModel.getPath();
            if (path != null) {
                Resource existing = rootResourceMap.get(path);
                if (existing != null) {
                    // merge resources
                    existing = Resource.builder(existing).mergeWith(resourceModel).build();
                    rootResourceMap.put(path, existing);
                } else {
View Full Code Here

        if (subResourceInstance == null) {
            throw new NotFoundException();
        }

        Resource subResource;
        if (subResourceInstance.getClass().isAssignableFrom(Resource.class)) {
            subResource = (Resource) subResourceInstance;
        } else {
            if (subResourceInstance.getClass().isAssignableFrom(Class.class)) {
                final Class<?> clazz = (Class<?>) subResourceInstance;
                subResourceInstance = Injections.getOrCreate(locator, clazz);
            } else {
                routingContext.pushMatchedResource(subResourceInstance);
                resourceContext.bindResourceIfSingleton(subResourceInstance);
            }

            Resource.Builder builder = Resource.builder(subResourceInstance.getClass());
            if (builder == null) {
                // resource is empty - do not throw 404, wait if ModelProcessors add any method
                builder = Resource.builder().name(subResourceInstance.getClass().getName());
            }
            subResource = builder.build();
        }

        ResourceModel resourceModel = new ResourceModel.Builder(true).addResource(subResource).build();
        resourceModel = processSubResource(resourceModel);
        if (!disableValidation) {
            validate(resourceModel, ignoreValidationErrors);
        }

        subResource = resourceModel.getResources().get(0);
        routingContext.pushLocatorSubResource(subResource);
        processingContext.triggerEvent(RequestEvent.Type.SUBRESOURCE_LOCATED);


        for (Class<?> handlerClass : subResource.getHandlerClasses()) {
            resourceContext.bindResource(handlerClass);
        }

        // TODO: implement generated sub-resource methodAcceptorPair caching
        Router subResourceAcceptor = runtimeModelBuilder.buildModel(resourceModel.getRuntimeResourceModel(), true);
View Full Code Here

        final MockResource mockResource = new MockResource();
        final Method method = mockResource.getClass().getMethod(resourceMethodName);
        final ResourceMethod resourceMethod = builder.addMethod()
                .handlingMethod(method)
                .handledBy(mockResource, method).build();
        final Resource resource = builder.build();
        final ResourceModel model = new ResourceModel.Builder(false).addResource(resource).build();

        when(appEvent.getResourceModel()).thenReturn(model);
        when(uriInfo.getMatchedResourceMethod()).thenReturn(resourceMethod);
    }
View Full Code Here

                                    .builder(i.getRawResponseType());
                            if (builder == null) {
                                // for example in the case the return type of the sub resource locator is Object
                                builder = Resource.builder().path(resourceMethod.getParent().getPath());
                            }
                            Resource subResource = builder.build();
                           
                            visitChildResource(subResource);
                        }
                        finally {
                           
View Full Code Here

            }

            // Introspecting classes & instances
            for (final Class<?> c : runtimeConfig.getClasses()) {
                try {
                    final Resource resource = Resource.from(c, disableValidation);
                    if (resource != null) {
                        resourceBagBuilder.registerResource(c, resource);
                    }
                } catch (final IllegalArgumentException ex) {
                    LOGGER.warning(ex.getMessage());
                }
            }

            for (final Object o : runtimeConfig.getSingletons()) {
                try {
                    final Resource resource = Resource.from(o.getClass(), disableValidation);
                    if (resource != null) {
                        resourceBagBuilder.registerResource(o, resource);
                    }
                } catch (final IllegalArgumentException ex) {
                    LOGGER.warning(ex.getMessage());
View Full Code Here

        private static class SimpleModelProcessor implements ModelProcessor {

            @Override
            public ResourceModel processResourceModel(ResourceModel resourceModel, Configuration configuration) {
                ResourceModel.Builder builder = new ResourceModel.Builder(resourceModel.getRootResources(), false);
                final Resource singletonResource = Resource.from(SingletonResource.class);
                builder.addResource(singletonResource);

                final Resource requestScopeResource = Resource.from(RequestScopeResource.class);
                builder.addResource(requestScopeResource);

                final Resource.Builder resourceBuilder = Resource.builder("instance");
                resourceBuilder.addMethod("GET").handledBy(new Inflector<ContainerRequestContext, String>() {
                    private int counter = 0;

                    @Override
                    public String apply(ContainerRequestContext containerRequestContext) {
                        return String.valueOf("Inflector:" + counter++);
                    }
                });
                final Resource instanceResource = resourceBuilder.build();

                builder.addResource(instanceResource);

                return builder.build();
            }
View Full Code Here

TOP

Related Classes of org.glassfish.jersey.server.model.Resource$Data

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.