Package com.sun.jersey.server.impl.model.method

Examples of com.sun.jersey.server.impl.model.method.ResourceMethod


        final Matcher m = new Matcher();
        final MatchStatus s = m.match(methods, request.getMediaType(), accept);

        if (s == MatchStatus.MATCH) {
            // If there is a match choose the first method
            final ResourceMethod method = m.rmSelected;

            if (method instanceof ViewResourceMethod) {
                // Set the content type to the most acceptable
                if (!m.mSelected.isWildcardType() &&
                        !m.mSelected.isWildcardSubtype()) {
                    response.getHttpHeaders().putSingle(HttpHeaders.CONTENT_TYPE, m.mSelected);
                }

                // Allow the view to be processed by the further matching view rule
                return false;

                // TODO what about resource specific request and response filters?
                // Should the viewable rule be responsible for those declared on
                // the class
            }

            // If a sub-resource method then need to push the resource
            // (again) as as to keep in sync with the ancestor URIs
            if (isSubResource) {
                context.pushResource(resource);
                // Set the template values
                context.pushMatch(method.getTemplate(), method.getTemplate().getTemplateVariables());
            }

            if (context.isTracingEnabled()) {
                if (isSubResource) {
                    context.trace(String.format("matched sub-resource method: @Path(\"%s\") %s",
                            method.getTemplate(),
                            method.getDispatcher()));
                } else {
                    context.trace(String.format("matched resource method: %s",
                            method.getDispatcher()));
                }
            }

            // Push the response filters
            context.pushContainerResponseFilters(method.getResponseFilters());

            ContainerRequest containerRequest = context.getContainerRequest();

            // Process the request filter
            if (!method.getRequestFilters().isEmpty()) {
                for (ContainerRequestFilter f : method.getRequestFilters()) {
                    containerRequest = f.filter(containerRequest);
                    context.setContainerRequest(containerRequest);
                }
            }

            context.pushMethod(method.getAbstractResourceMethod());

            // Dispatch to the resource method
            try {
                dispatchingListener.onResourceMethod(Thread.currentThread().getId(), method.getAbstractResourceMethod());

                SecurityContext sc = containerRequest.getSecurityContext();
                if (sc instanceof SubjectSecurityContext) {
                    ((SubjectSecurityContext) sc).doAsSubject(new PrivilegedAction() {
                        @Override
                        public Object run() {
                            method.getDispatcher().dispatch(resource, context);
                            return null;
                        }
                    });
                } else {
                    method.getDispatcher().dispatch(resource, context);
                }
            } catch (RuntimeException e) {
                if (m.rmSelected.isProducesDeclared() &&
                        !m.mSelected.isWildcardType() &&
                        !m.mSelected.isWildcardSubtype()) {
View Full Code Here


                Errors.error(String.format("Illegal URI template for sub-resource method %s: %s",
                        method.getMethod(), ex.getMessage()));
                continue;
            }

            final ResourceMethod rm = new ResourceHttpMethod(dp, ff, p.getTemplate(), method);
            ResourceMethodMap rmm = patternMethodMap.get(p);
            if (rmm == null) {
                rmm = new ResourceMethodMap();
                patternMethodMap.put(p, rmm);
            }
View Full Code Here

            final AbstractResource resource,
            final List<QualitySourceMediaType> implictProduces,
            final RulesMap<UriRule> rulesMap) {
        final ResourceMethodMap rmm = new ResourceMethodMap();
        for (final AbstractResourceMethod resourceMethod : resource.getResourceMethods()) {
            ResourceMethod rm = new ResourceHttpMethod(dp, ff, resourceMethod);

            if (isValidResourceMethod(rm, rmm)) {
                rmm.put(rm);
            }
        }
View Full Code Here

            final ResourceMethod rm,
            final ResourceMethodMap rmm) {
        final List<ResourceMethod> rml = rmm.get(rm.getHttpMethod());
        if (rml != null) {
            boolean conflict = false;
            ResourceMethod erm = null;
            for (int i = 0; i < rml.size() && !conflict; i++) {
                erm = rml.get(i);

                conflict = MediaTypes.intersects(rm.getConsumes(), erm.getConsumes())
                        && MediaTypes.intersects(rm.getProduces(), erm.getProduces());
            }

            if (conflict) {
                if (rm.getAbstractResourceMethod().hasEntity()) {
                    Errors.error(String.format("Consuming media type conflict. " +
                            "The resource methods %s and %s can consume the same media type",
                            rm.getAbstractResourceMethod().getMethod(), erm.getAbstractResourceMethod().getMethod()));
                } else {
                    Errors.error(String.format("Producing media type conflict. " +
                            "The resource methods %s and %s can produce the same media type",
                            rm.getAbstractResourceMethod().getMethod(), erm.getAbstractResourceMethod().getMethod()));
                }
            }

            if (conflict)
                return false;
View Full Code Here

            headList = new ArrayList<ResourceMethod>();
        }

        for (final ResourceMethod getMethod : getList) {
            if (!containsMediaOfMethod(headList, getMethod)) {
                final ResourceMethod headMethod = new ResourceHeadWrapperMethod(getMethod);
                methodMap.put(headMethod);
                headList = methodMap.get(HttpMethod.HEAD);
            }
        }
    }
View Full Code Here

        final List<ResourceMethod> l = methodMap.get("OPTIONS");
        if (l != null) {
            return;
        }

        ResourceMethod optionsMethod = wadlFactory.createWadlOptionsMethod(methodMap, resource, p);
        if (optionsMethod == null) {
            optionsMethod = new ResourceHttpOptionsMethod(methodMap);
        }
        methodMap.put(optionsMethod);
    }
View Full Code Here

        final Matcher m = new Matcher();
        final MatchStatus s = m.match(methods, request.getMediaType(), accept);

        if (s == MatchStatus.MATCH) {
            // If there is a match choose the first method
            final ResourceMethod method = m.rmSelected;

            if (method instanceof ViewResourceMethod) {
                // Set the content type to the most acceptable
                if (!m.mSelected.isWildcardType() &&
                        !m.mSelected.isWildcardSubtype()) {
                    response.getHttpHeaders().putSingle(HttpHeaders.CONTENT_TYPE, m.mSelected);
                }

                // Allow the view to be processed by the further matching view rule
                return false;

                // TODO what about resource specific request and response filters?
                // Should the viewable rule be responsible for those declared on
                // the class
            }

            // If a sub-resource method then need to push the resource
            // (again) as as to keep in sync with the ancestor URIs
            if (isSubResource) {
                context.pushResource(resource);
                // Set the template values
                context.pushMatch(method.getTemplate(), method.getTemplate().getTemplateVariables());
            }

            if (context.isTracingEnabled()) {
                if (isSubResource) {
                    context.trace(String.format("matched sub-resource method: @Path(\"%s\") %s",
                            method.getTemplate(),
                            method.getDispatcher()));
                } else {
                    context.trace(String.format("matched resource method: %s",
                            method.getDispatcher()));
                }
            }

            // Push the response filters
            context.pushContainerResponseFilters(method.getResponseFilters());

            // Process the request filter
            if (!method.getRequestFilters().isEmpty()) {
                ContainerRequest containerRequest = context.getContainerRequest();
                for (ContainerRequestFilter f : method.getRequestFilters()) {
                    containerRequest = f.filter(containerRequest);
                    context.setContainerRequest(containerRequest);
                }
            }

            context.pushMethod(method.getAbstractResourceMethod());

            // Dispatch to the resource method
            try {
                dispatchingListener.onResourceMethod(Thread.currentThread().getId(), method.getAbstractResourceMethod());

                method.getDispatcher().dispatch(resource, context);
            } catch (RuntimeException e) {
                if (m.rmSelected.isProducesDeclared() &&
                        !m.mSelected.isWildcardType() &&
                        !m.mSelected.isWildcardSubtype()) {
                    context.getProperties().put(CONTENT_TYPE_PROPERTY, m.mSelected);
View Full Code Here

        final Matcher m = new Matcher();
        final MatchStatus s = m.match(methods, request.getMediaType(), accept);

        if (s == MatchStatus.MATCH) {
            // If there is a match choose the first method
            final ResourceMethod method = m.rmSelected;

            if (method instanceof ViewResourceMethod) {
                // Allow any further matching rules to be processed
                return false;
            }
           
            // If a sub-resource method then need to push the resource
            // (again) as as to keep in sync with the ancestor URIs
            if (isSubResource) {
                context.pushResource(resource);       
                // Set the template values
                context.pushMatch(method.getTemplate(), method.getTemplate().getTemplateVariables());
            }

            // Push the response filters
            context.pushContainerResponseFilters(method.getResponseFilters());

            // Process the request filter
            if (!method.getRequestFilters().isEmpty()) {
                ContainerRequest containerRequest = context.getContainerRequest();
                for (ContainerRequestFilter f : method.getRequestFilters()) {
                    containerRequest = f.filter(containerRequest);
                    context.setContainerRequest(containerRequest);
                }
            }

            // Dispatch to the resource method
            method.getDispatcher().dispatch(resource, context);

            // If the content type is not explicitly set then set it
            // to the selected media type, if a concrete media type
            // and @Produces is declared on the resource method or the resource
            // class
View Full Code Here

        for (final AbstractSubResourceMethod method : this.resource.getSubResourceMethods()) {

            UriTemplate t = new PathTemplate(method.getPath().getValue());
            PathPattern p = new PathPattern(t, "(/)?");

            ResourceMethod rm = new ResourceHttpMethod(df, ff, t, method);
            addToPatternMethodMap(patternMethodMap, p, rm);
        }

        for (Map.Entry<PathPattern, ResourceMethodMap> e : patternMethodMap.entrySet()) {
            if (implictProduces != null) {
View Full Code Here

            List<QualitySourceMediaType> implictProduces,
            ResourceMethodDispatcherFactory df,
            FilterFactory ff) {
        final ResourceMethodMap methodMap = new ResourceMethodMap();
        for (final AbstractResourceMethod resourceMethod : this.resource.getResourceMethods()) {
            ResourceMethod rm = new ResourceHttpMethod(df, ff, resourceMethod);
            methodMap.put(rm);
        }

        if (implictProduces != null) {
            List<ResourceMethod> getList = methodMap.get(HttpMethod.GET);
View Full Code Here

TOP

Related Classes of com.sun.jersey.server.impl.model.method.ResourceMethod

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.