Package org.apache.cxf.jaxrs.model

Examples of org.apache.cxf.jaxrs.model.OperationResourceInfo


                                                                    values,
                                                                    m);
        if (resource == null) {
            return null;
        }
        OperationResourceInfo ori = findPreflightMethod(resource, requestUri, httpMethod, values, m);
        return ori == null ? null : ori.getAnnotatedMethod();
    }
View Full Code Here


                                                      String httpMethod,
                                                      MultivaluedMap<String, String> values,
                                                      Message m) {
        final String contentType = MediaType.WILDCARD;
        final MediaType acceptType = MediaType.WILDCARD_TYPE;
        OperationResourceInfo ori = JAXRSUtils.findTargetMethod(resource,
                                    m, httpMethod, values,
                                    contentType,
                                    Collections.singletonList(acceptType),
                                    true);
        if (ori == null) {
            return null;
        }
        if (ori.isSubResourceLocator()) {
            Class<?> cls = ori.getMethodToInvoke().getReturnType();
            ClassResourceInfo subcri = resource.getSubResource(cls, cls);
            if (subcri == null) {
                return null;
            } else {
                MultivaluedMap<String, String> newValues = new MetadataMap<String, String>();
View Full Code Here

    }
   
    @SuppressWarnings("unchecked")
    public Object invoke(Exchange exchange, Object request, Object resourceObject) {

        final OperationResourceInfo ori = exchange.get(OperationResourceInfo.class);
        final ClassResourceInfo cri = ori.getClassResourceInfo();
        final Message inMessage = exchange.getInMessage();
        final ProviderFactory providerFactory = ProviderFactory.getInstance(inMessage);

        boolean wasSuspended = exchange.remove(REQUEST_WAS_SUSPENDED) != null;
       
        if (!wasSuspended) {
            pushOntoStack(ori, ClassHelper.getRealClass(resourceObject), inMessage);
        }
           
        final boolean contextsAvailable = cri.contextsAvailable();
        final boolean paramsAvailable = cri.paramsAvailable();
        if (contextsAvailable || paramsAvailable) {
            Object realResourceObject = ClassHelper.getRealObject(resourceObject);
            if (paramsAvailable) {
                JAXRSUtils.injectParameters(ori, realResourceObject, inMessage);
            }
            if (contextsAvailable) {
                InjectionUtils.injectContexts(realResourceObject, cri, inMessage);
            }
        }
        if (cri.isRoot()) {
            ProviderInfo<?> appProvider =
                (ProviderInfo<?>)exchange.getEndpoint().get(Application.class.getName());
            if (appProvider != null) {
                InjectionUtils.injectContexts(appProvider.getProvider(),
                                              appProvider,
                                              inMessage);
            }
        }
       
        Method resourceMethod = cri.getMethodDispatcher().getMethod(ori);
       
        Method methodToInvoke = null;
        if (Proxy.class.isInstance(resourceObject)) {
            methodToInvoke = cri.getMethodDispatcher().getProxyMethod(resourceMethod);
            if (methodToInvoke == null) {
                methodToInvoke = InjectionUtils.checkProxy(resourceMethod, resourceObject);
                cri.getMethodDispatcher().addProxyMethod(resourceMethod, methodToInvoke);
            }
        } else {
            methodToInvoke = resourceMethod;
        }
       
        List<Object> params = null;
        if (request instanceof List) {
            params = CastUtils.cast((List<?>)request);
        } else if (request != null) {
            params = new MessageContentsList(request);
        }

        Object result = null;
        ClassLoaderHolder contextLoader = null;
        try {
            if (setServiceLoaderAsContextLoader(inMessage)) {
                contextLoader = ClassLoaderUtils
                    .setThreadContextClassloader(resourceObject.getClass().getClassLoader());
            }
            AsyncResponseImpl asyncResponse = null;
            if (!ori.isSubResourceLocator()) {
                asyncResponse = (AsyncResponseImpl)inMessage.get(AsyncResponse.class);
            }
            result = invoke(exchange, resourceObject, methodToInvoke, params);
            if (asyncResponse != null) {
                if (!asyncResponse.isSuspended() && !asyncResponse.isResumedByApplication()) {
                    asyncResponse.suspendContinuation();
                    providerFactory.clearThreadLocalProxies();
                } else {
                    result = handleAsyncResponse(exchange, asyncResponse.getResponseObject());
                }
            }
        } catch (Fault ex) {
            return handleFault(ex, inMessage, cri, methodToInvoke);
        } finally {
            exchange.put(LAST_SERVICE_OBJECT, resourceObject);
            if (contextLoader != null) {
                contextLoader.reset();
            }
        }
        ClassResourceInfo subCri = null;
        if (ori.isSubResourceLocator()) {
            try {
                MultivaluedMap<String, String> values = getTemplateValues(inMessage);
                String subResourcePath = values.getFirst(URITemplate.FINAL_MATCH_GROUP);
                String httpMethod = (String)inMessage.get(Message.HTTP_REQUEST_METHOD);
                String contentType = (String)inMessage.get(Message.CONTENT_TYPE);
                if (contentType == null) {
                    contentType = "*/*";
                }
                List<MediaType> acceptContentType =
                    (List<MediaType>)exchange.get(Message.ACCEPT_CONTENT_TYPE);

                result = checkResultObject(result, subResourcePath);

                subCri = cri.getSubResource(methodToInvoke.getReturnType(),
                    ClassHelper.getRealClass(result), result);
                if (subCri == null) {
                    org.apache.cxf.common.i18n.Message errorM =
                        new org.apache.cxf.common.i18n.Message("NO_SUBRESOURCE_FOUND",
                                                               BUNDLE,
                                                               subResourcePath);
                    LOG.severe(errorM.toString());
                    throw ExceptionUtils.toNotFoundException(null, null);
                }

                OperationResourceInfo subOri = JAXRSUtils.findTargetMethod(subCri,
                                                         inMessage,
                                                         httpMethod,
                                                         values,
                                                         contentType,
                                                         acceptContentType,
                                                         true);
                exchange.put(OperationResourceInfo.class, subOri);
                inMessage.put(URITemplate.TEMPLATE_PARAMETERS, values);
           
                if (JAXRSUtils.runContainerRequestFilters(providerFactory,
                                                      inMessage,
                                                      false, subOri.getNameBindings())) {
                    return new MessageContentsList(exchange.get(Response.class));
                }
               
                // work out request parameters for the sub-resource class. Here we
                // presume InputStream has not been consumed yet by the root resource class.
View Full Code Here

    }
   
    private ResourceProvider getResourceProvider(Exchange exchange) {
        Object provider = exchange.remove(JAXRSUtils.ROOT_PROVIDER);
        if (provider == null) {
            OperationResourceInfo ori = exchange.get(OperationResourceInfo.class);
            ClassResourceInfo cri = ori.getClassResourceInfo();
            return cri.getResourceProvider();
        } else {
            return (ResourceProvider)provider;
        }
    }
View Full Code Here

        Object root = exchange.remove(JAXRSUtils.ROOT_INSTANCE);
        if (root != null) {
            return root;
        }
       
        OperationResourceInfo ori = exchange.get(OperationResourceInfo.class);
        ClassResourceInfo cri = ori.getClassResourceInfo();

        return cri.getResourceProvider().getInstance(exchange.getInMessage());
    }
View Full Code Here

        if (!candidateList.isEmpty()) {
            Map.Entry<OperationResourceInfo, MultivaluedMap<String, String>> firstEntry =
                candidateList.entrySet().iterator().next();
            values.clear();
            values.putAll(firstEntry.getValue());
            OperationResourceInfo ori = firstEntry.getKey();
            if (headMethodPossible(ori.getHttpMethod(), httpMethod)) {
                LOG.info(new org.apache.cxf.common.i18n.Message("GET_INSTEAD_OF_HEAD",
                         BUNDLE, resource.getServiceClass().getName(),
                         ori.getMethodToInvoke().getName()).toString());
            }
            if (isFineLevelLoggable) {
                LOG.fine(new org.apache.cxf.common.i18n.Message("OPER_SELECTED",
                               BUNDLE, ori.getMethodToInvoke().getName(),
                               resource.getServiceClass().getName()).toString());
            }
            if (!ori.isSubResourceLocator()) {
                MediaType responseMediaType = intersectSortMediaTypes(acceptContentTypes,
                                                                      ori.getProduceTypes(),
                                                                      false).get(0);
                message.getExchange().put(Message.CONTENT_TYPE, mediaTypeToString(responseMediaType,
                                                                                  MEDIA_TYPE_Q_PARAM,
                                                                                  MEDIA_TYPE_QS_PARAM));
            }
View Full Code Here

                protected void persistParamsOnMessage(MultivaluedMap<String, String> params) {
                    messageImpl.put(FormUtils.FORM_PARAM_MAP, params);   
                }
            });
       
        List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
                                                               new ClassResourceInfo(Customer.class)),
                                                           new MetadataMap<String, String>(), messageImpl);
        assertEquals("3 params should've been identified", 3, params.size());
       
        MultivaluedMap<String, String> map = (MultivaluedMap<String, String>)params.get(0);
View Full Code Here

    }
   
    @Test
    public void testSelectResourceMethod() throws Exception {
        ClassResourceInfo cri = new ClassResourceInfo(Customer.class);
        OperationResourceInfo ori1 = new OperationResourceInfo(
                                         Customer.class.getMethod("getItAsXML", new Class[]{}),
                                         cri);
        ori1.setHttpMethod("GET");
        ori1.setURITemplate(new URITemplate("/"));
        OperationResourceInfo ori2 = new OperationResourceInfo(
                                         Customer.class.getMethod("getItPlain", new Class[]{}),
                                         cri);
        ori2.setHttpMethod("GET");
        ori2.setURITemplate(new URITemplate("/"));
        MethodDispatcher md = new MethodDispatcher();
        md.bind(ori1, Customer.class.getMethod("getItAsXML", new Class[]{}));
        md.bind(ori2, Customer.class.getMethod("getItPlain", new Class[]{}));
        cri.setMethodDispatcher(md);
       
        OperationResourceInfo ori = JAXRSUtils.findTargetMethod(cri, createMessage2(), "GET",
              new MetadataMap<String, String>(), "*/*", getTypes("text/plain"), true);
       
        assertSame(ori, ori2);
       
        ori = JAXRSUtils.findTargetMethod(cri, createMessage2(), "GET", new MetadataMap<String, String>(),
View Full Code Here

    @SuppressWarnings("unchecked")
    @Test
    public void testHttpContextParameters() throws Exception {
       
        ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
        OperationResourceInfo ori =
            new OperationResourceInfo(
                Customer.class.getMethod("testParams",
                                         new Class[]{UriInfo.class,
                                                     HttpHeaders.class,
                                                     Request.class,
                                                     SecurityContext.class,
                                                     Providers.class,
                                                     String.class,
                                                     List.class}),
                cri);
        ori.setHttpMethod("GET");
        MultivaluedMap<String, String> headers = new MetadataMap<String, String>();
        headers.add("Foo", "bar, baz");
       
        Message m = new MessageImpl();
        m.put("org.apache.cxf.http.header.split", "true");
View Full Code Here

       
        ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
        Method methodToInvoke =
            Customer.class.getMethod("setUriInfoContext",
                                     new Class[]{UriInfo.class});
        OperationResourceInfo ori =
            new OperationResourceInfo(methodToInvoke,
                                      AnnotationUtils.getAnnotatedMethod(methodToInvoke), cri);
        ori.setHttpMethod("GET");
       
        Message m = new MessageImpl();
       
        List<Object> params =
            JAXRSUtils.processParameters(ori, new MetadataMap<String, String>(), m);
View Full Code Here

TOP

Related Classes of org.apache.cxf.jaxrs.model.OperationResourceInfo

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.