Package org.glassfish.jersey.server.model

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


    private void logResources(List<Resource> resources) {
        final List<ResourceDescription> resourceDescriptions = new ArrayList<>();
        for (Resource resource : resources) {
            for (ResourceMethod resourceMethod : resource.getAllMethods()) {
                String path = resource.getPath();
                Resource parent = resource.getParent();
                while (parent != null) {
                    if (!path.startsWith("/")) {
                        path = "/" + path;
                    }

                    path = parent.getPath() + path;
                    parent = parent.getParent();
                }

                resourceDescriptions.add(new ResourceDescription(resourceMethod.getHttpMethod(), path, resource.getHandlerClasses()));
            }
        }
View Full Code Here


                final String path = (pathAnnotation.value() == null ? "" : pathAnnotation.value());
                if (!path.startsWith("/"))
                    resourcePath.append("/");

                final Resource.Builder resourceBuilder = Resource.builder(pluginRestResource.getClass()).path(resourcePath.append(path).toString());
                final Resource resource = resourceBuilder.build();
                result.add(resource);
            }
        }
        return result;
    }
View Full Code Here

            final ExtendedUriInfo uriInfo = extendedUriInfoProvider.get();
            final List<RuntimeResource> matchedRuntimeResources = uriInfo.getMatchedRuntimeResources();
            if (matchedRuntimeResources.size() > 1) {
                // > 1 to check that we matched sub-resource
                final RuntimeResource lastMatchedRuntimeResource = matchedRuntimeResources.get(0);
                final Resource lastMatchedResource = lastMatchedRuntimeResource.getResources().get(0);

                String path = lastMatchedResource.getPath();

                if (path != null && !IMPLICIT_VIEW_PATH_PARAMETER_TEMPLATE.equals(path)) {
                    path = path.charAt(0) == '/' ? path.substring(1, path.length()) : path;
                    templateNames.add(path);
                }
View Full Code Here

        return newModelBuilder;
    }

    public static void enhanceResource(RuntimeResource resource, ResourceModel.Builder newModelBuilder,
                                       List<Method> methods, boolean extended) {
        final Resource firstResource = resource.getResources().get(0);

        if (methodsSuitableForResource(firstResource, methods)) {
            for (Method method : methods) {
                final Set<MediaType> produces = Sets.newHashSet(method.produces);

                for (ResourceMethod resourceMethod : resource.getResourceMethods()) {
                    for (final MediaType produce : method.produces) {
                        if (ModelProcessorUtil.isMethodOverridden(
                                resourceMethod,
                                method.httpMethod,
                                method.consumes.get(0),
                                produce)) {
                            produces.remove(produce);
                        }
                    }
                }

                if (!produces.isEmpty()) {
                    final Resource parentResource = resource.getParentResources().get(0);
                    if (parentResource != null && method.path != null) {
                        continue;
                    }

                    final Resource.Builder resourceBuilder = Resource.builder(firstResource.getPath());
                    final Resource.Builder builder = method.path != null
                            ? resourceBuilder.addChildResource(method.path) : resourceBuilder;
                    final ResourceMethod.Builder methodBuilder = builder
                            .addMethod(method.httpMethod)
                            .consumes(method.consumes)
                            .produces(produces);

                    if (method.inflector != null) {
                        methodBuilder.handledBy(method.inflector);
                    } else {
                        methodBuilder.handledBy(method.inflectorClass);
                    }
                    methodBuilder.extended(extended);

                    final Resource newResource = resourceBuilder.build();
                    if (parentResource != null) {
                        final Resource.Builder parentBuilder = Resource.builder(parentResource.getPath());
                        parentBuilder.addChildResource(newResource);
                        newModelBuilder.addResource(parentBuilder.build());
                    } else {
View Full Code Here

     */
    private ResourceModel.Builder processTemplateAnnotatedInvocables(ResourceModel resourceModel,
                                                                     final boolean subResourceModel) {
        ResourceModel.Builder modelBuilder = new ResourceModel.Builder(subResourceModel);
        for (Resource resource : resourceModel.getResources()) {
            Resource newResource = processResource(resource);
            modelBuilder.addResource(newResource);
        }
        return modelBuilder;
    }
View Full Code Here

            final ExtendedUriInfo uriInfo = extendedUriInfoProvider.get();
            final List<RuntimeResource> matchedRuntimeResources = uriInfo.getMatchedRuntimeResources();
            if (matchedRuntimeResources.size() > 1) {
                // > 1 to check that we matched sub-resource
                final RuntimeResource lastMatchedRuntimeResource = matchedRuntimeResources.get(0);
                final Resource lastMatchedResource = lastMatchedRuntimeResource.getResources().get(0);

                String path = lastMatchedResource.getPath();

                if (path != null && !IMPLICIT_VIEW_PATH_PARAMETER_TEMPLATE.equals(path)) {
                    path = path.charAt(0) == '/' ? path.substring(1, path.length()) : path;
                    templateNames.add(path);
                }
View Full Code Here

        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

TOP

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

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.