Package org.glassfish.jersey.server.model

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


        }

        @Override
        public void onEvent(RequestEvent event) {
            if (event.getType() == RequestEvent.Type.ON_EXCEPTION) {
                final ResourceMethod method = event.getUriInfo().getMatchedResourceMethod();
                final ExceptionMeterMetric metric = (method != null) ?
                        this.exceptionMeters.get(method.getInvocable().getDefinitionMethod()) : null;

                if (metric != null) {
                    if (metric.cause.isAssignableFrom(event.getException().getClass()) ||
                            (event.getException().getCause() != null &&
                                    metric.cause.isAssignableFrom(event.getException().getCause().getClass()))) {
View Full Code Here


            switch (event.getType()) {
                case RESOURCE_METHOD_START:
                    this.methodTimeStart = now;
                    break;
                case RESOURCE_METHOD_FINISHED:
                    final ResourceMethod method = event.getUriInfo().getMatchedResourceMethod();
                    methodStats = new MethodStats(method, methodTimeStart, now - methodTimeStart);
                    break;
                case EXCEPTION_MAPPING_FINISHED:
                    exceptionMapperEvents.add(event);
                    break;
View Full Code Here

            final MonitoringEventListener.TimeStats requestStats = event.getRequestStats();
            statisticsBuilder.addRequestExecution(requestStats.getStartTime(), requestStats.getDuration());

            final MonitoringEventListener.MethodStats methodStat = event.getMethodStats();
            if (methodStat != null) {
                final ResourceMethod method = methodStat.getMethod();
                statisticsBuilder.addExecution(event.getRequestUri(), method,
                        methodStat.getStartTime(), methodStat.getDuration(),
                        requestStats.getStartTime(), requestStats.getDuration());
            }
        }
View Full Code Here

     *
     * @return an error template annotation or {@code null} if the method is not annotated.
     */
    private ErrorTemplate getErrorTemplate() {
        final ExtendedUriInfo uriInfo = uriInfoProvider.get();
        final ResourceMethod matchedResourceMethod = uriInfo.getMatchedResourceMethod();

        if (matchedResourceMethod != null) {
            final Invocable invocable = matchedResourceMethod.getInvocable();

            ErrorTemplate errorTemplate = invocable.getHandlingMethod().getAnnotation(ErrorTemplate.class);
            if (errorTemplate == null) {
                Class<?> handlerClass = invocable.getHandler().getHandlerClass();

View Full Code Here

            }


            // if the resource contains subresource locator create new resource for this locator and return it instead
            // of this resource
            final ResourceMethod locator = resource.getResourceLocator();
            if (locator != null) {
                try {
                    org.glassfish.jersey.server.model.Resource.Builder builder = org.glassfish.jersey.server.model.Resource
                            .builder(locator.getInvocable().getRawResponseType());
                    if (builder == null) {
                        // for example in the case the return type of the sub resource locator is Object
                        builder = org.glassfish.jersey.server.model.Resource.builder().path(resource.getPath());
                    }
                    org.glassfish.jersey.server.model.Resource subResource = builder.build();

                    Resource wadlSubResource = generateResource(subResource,
                            resource.getPath(), visitedResources);
                    if (wadlSubResource == null) {
                        return null;
                    }
                    if (locator.isExtended()) {
                        wadlSubResource.getAny().add(WadlApplicationContextImpl.extendedElement);
                    }

                    for (Parameter param : locator.getInvocable().getParameters()) {
                        Param wadlParam = generateParam(resource, locator, param);

                        if (wadlParam != null && wadlParam.getStyle() == ParamStyle.TEMPLATE) {
                            wadlSubResource.getParam().add(wadlParam);
                        }
View Full Code Here

            Collections.sort(consumesProducesAcceptors.get(httpMethod), new Comparator<ConsumesProducesAcceptor>() {

                @Override
                public int compare(final ConsumesProducesAcceptor o1, final ConsumesProducesAcceptor o2) {
                    // Make sure that annotated (@Consumes, @Produces) goes first.
                    final ResourceMethod model1 = o1.methodAcceptorPair.model;
                    final ResourceMethod model2 = o2.methodAcceptorPair.model;

                    // @Consumes on method.
                    int compared = compare(model2.getConsumedTypes(), model1.getConsumedTypes());

                    if (compared == 0) {
                        // @Produces on method.
                        compared = compare(model2.getProducedTypes(), model1.getProducedTypes());

                        if (compared == 0) {
                            // Consumes media type of the acceptor.
                            compared = MediaTypes.MEDIA_TYPE_COMPARATOR.compare(o1.consumes.getMediaType(),
                                    o2.consumes.getMediaType());
View Full Code Here

        return router.apply(requestContext);
    }

    private void addAllConsumesProducesCombinations(final List<ConsumesProducesAcceptor> acceptors,
                                                    final MethodAcceptorPair methodAcceptorPair) {
        final ResourceMethod resourceMethod = methodAcceptorPair.model;

        final Set<MediaType> effectiveInputTypes = new LinkedHashSet<>();
        boolean consumesFromWorkers = fillMediaTypes(effectiveInputTypes, resourceMethod,
                resourceMethod.getConsumedTypes(), true);

        final Set<MediaType> effectiveOutputTypes = new LinkedHashSet<>();
        boolean producesFromWorkers = fillMediaTypes(effectiveOutputTypes, resourceMethod,
                resourceMethod.getProducedTypes(), false);

        final Set<ConsumesProducesAcceptor> acceptorSet = Sets.newHashSet();
        for (MediaType consumes : effectiveInputTypes) {
            for (MediaType produces : effectiveOutputTypes) {
View Full Code Here

        // Return pre-selected MediaType.
        if (usePreSelectedMediaType(selectedMethod, acceptableMediaTypes)) {
            return selectedMethod.produces.getCombinedMediaType();
        }

        final ResourceMethod resourceMethod = selectedMethod.methodAcceptorPair.model;
        final Invocable invocable = resourceMethod.getInvocable();

        // Entity class can be null when considering HEAD method || empty entity.
        final Class<?> responseEntityClass = entityClass == null ? invocable.getRawRoutingResponseType() : entityClass;
        final Method handlingMethod = invocable.getHandlingMethod();

        CombinedClientServerMediaType selected = null;

        for (final MediaType acceptableMediaType : acceptableMediaTypes) {
            // Use writers suitable for entity class to determine the media type.
            for (final MessageBodyWriter writer : workers.getMessageBodyWritersForType(responseEntityClass)) {
                for (final MediaType writerProduces : MediaTypes.createFrom(writer.getClass().getAnnotation(Produces.class))) {

                    if (writerProduces.isCompatible(acceptableMediaType)) {
                        // Media types producible by method.
                        final List<MediaType> methodProducesTypes = !resourceMethod.getProducedTypes().isEmpty() ?
                                resourceMethod.getProducedTypes() : Lists.newArrayList(MediaType.WILDCARD_TYPE);

                        for (final MediaType methodProducesType : methodProducesTypes) {
                            if (methodProducesType.isCompatible(writerProduces)) {

                                final CombinedClientServerMediaType.EffectiveMediaType effectiveProduces = new
View Full Code Here

        this.requestExecutionStatisticsBean.updateExecutionStatistics(resourceStatistics.getRequestExecutionStatistics());

        for (Map.Entry<ResourceMethod, ResourceMethodStatistics> entry
                : resourceStatistics.getResourceMethodStatistics().entrySet()) {
            final ResourceMethodStatistics methodStats = entry.getValue();
            final ResourceMethod method = entry.getKey();

            final String methodId = MonitoringUtils.getMethodUniqueId(method);

            ResourceMethodMXBeanImpl methodMXBean = this.resourceMethods.get(methodId);
            if (methodMXBean == null) {
View Full Code Here

    private void prepareAppEvent(String resourceMethodName) throws NoSuchMethodException {
        final Resource.Builder builder = Resource.builder();
        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();
View Full Code Here

TOP

Related Classes of org.glassfish.jersey.server.model.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.