Package org.apache.cxf.message

Examples of org.apache.cxf.message.MessageContentsList


            } else {
                parts = operation.getInput().getMessageParts();
                addOperationNode(nsStack, message, xmlWriter, false, operation);
            }
           
            MessageContentsList objs = MessageContentsList.getContentsList(message);
            if (objs == null) {
                return;
            }
           
           
            for (MessagePartInfo part : parts) {
                if (objs.hasValue(part)) {
                    Object o = objs.get(part);
                    if (o == null) {
                        //WSI-BP R2211 - RPC/Lit parts are not allowed to be xsi:nil
                        throw new Fault(
                            new org.apache.cxf.common.i18n.Message("BP_2211_RPCLIT_CANNOT_BE_NULL",
                                                                   LOG, part.getConcreteName()));
View Full Code Here


        }

        ServiceInfo si = operation.getBinding().getService();

        DataReader<XMLStreamReader> dr = getDataReader(message);
        MessageContentsList objects = new MessageContentsList();

        MessageInfo msgInfo = setMessage(message, operation, requestor, si);
       
        // Determine if there is a wrapper class
        if (operation.isUnwrappedCapable()
            && msgInfo.getMessageParts().get(0).getTypeClass() != null) {
            Object wrappedObject = dr.read(msgInfo.getMessageParts().get(0), xmlReader);
            objects.put(msgInfo.getMessageParts().get(0), wrappedObject);

        } else {
            // Unwrap each part individually if we don't have a wrapper

            if (operation.isUnwrappedCapable()) {
                operation = operation.getUnwrappedOperation();
            }

            msgInfo = setMessage(message, operation, requestor, si);
            List<MessagePartInfo> messageParts = msgInfo.getMessageParts();
            Iterator<MessagePartInfo> itr = messageParts.iterator();

            // advance just past the wrapped element so we don't get stuck
            if (xmlReader.getEventType() == XMLStreamConstants.START_ELEMENT) {
                StaxUtils.nextEvent(xmlReader);
            }

            // loop through each child element
            while (StaxUtils.toNextElement(xmlReader)) {
                MessagePartInfo part = itr.next();
                objects.put(part, dr.read(part, xmlReader));
            }
        }

        message.setContent(List.class, objects);
    }
View Full Code Here

    public void handleMessage(Message m) throws Fault {
        SoapMessage message = (SoapMessage) m;
        Exchange exchange = message.getExchange();

        MessageContentsList parameters = MessageContentsList.getContentsList(message);

        if (null == parameters) {
            parameters = new MessageContentsList();
        }

        BindingOperationInfo bop = exchange.getBindingOperationInfo();
        if (null == bop) {
            return;
        }

        if (bop.isUnwrapped()) {
            bop = bop.getWrappedOperation();
        }
       
        boolean client = isRequestor(message);
        BindingMessageInfo bmi = client ? bop.getOutput() : bop.getInput();
        if (bmi == null) {
            // one way operation.
            return;
        }
       
        List<SoapHeaderInfo> headers = bmi.getExtensors(SoapHeaderInfo.class);
        if (headers == null || headers.size() == 0) {
            return;
        }
       
        boolean supportsNode = this.supportsDataReader(message, Node.class);
        for (SoapHeaderInfo header : headers) {
            MessagePartInfo mpi = header.getPart();
            if (mpi.getTypeClass() != null) {

                Header param = findHeader(message, mpi);
               
                Object object = null;
                if (param != null) {
                    message.getHeaders().remove(param);
                   
                    if (param.getDataBinding() == null) {
                        Node source = (Node)param.getObject();
                        if (supportsNode) {
                            object = getNodeDataReader(message).read(mpi, source);
                        } else {
                            W3CDOMStreamReader reader = new W3CDOMStreamReader((Element)source);
                            try {
                                reader.nextTag(); //advance into the first tag
                            } catch (XMLStreamException e) {
                                //ignore
                            }
                            object = getDataReader(message, XMLStreamReader.class).read(mpi, reader);
                        }
                    } else {
                        object = param.getObject();
                    }
                   
                }
                parameters.put(mpi, object);
            }
        }
        if (parameters.size() > 0) {
            message.setContent(List.class, parameters);
        }
    }
View Full Code Here

        Source source = (Source)content.get(0);
        DataReader<XMLStreamReader> reader =
            message.getExchange().getService().getDataBinding().createReader(XMLStreamReader.class);
        MessagePartInfo mpi = getMessageInfo(message).getMessagePart(0);
        Object wrappedObject = reader.read(mpi, StaxUtils.createXMLStreamReader(source));
        MessageContentsList parameters = new MessageContentsList();
        parameters.put(mpi, wrappedObject);

        message.setContent(List.class, parameters);
    }
View Full Code Here

    protected boolean isChunkingSupported(Message message, String httpMethod) {
        if (HTTP_POST_METHOD.equals(httpMethod)) {
            return true;
        }
        if (HTTP_PUT_METHOD.equals(httpMethod)) {
            MessageContentsList objs = MessageContentsList.getContentsList(message);
            if (objs != null && objs.size() > 0) {
                Object obj = objs.get(0);
                if (obj.getClass() != String.class
                    || (obj.getClass() == String.class && ((String)obj).length() > 0)) {
                    return true;
                }
            }
View Full Code Here

    protected boolean isChunkingSupported(Message message, String httpMethod) {
        if (HTTP_POST_METHOD.equals(httpMethod)) {
            return true;
        }
        if (HTTP_PUT_METHOD.equals(httpMethod)) {
            MessageContentsList objs = MessageContentsList.getContentsList(message);
            if (objs != null && objs.size() > 0) {
                Object obj = objs.get(0);
                if (obj.getClass() != String.class
                    || (obj.getClass() == String.class && ((String)obj).length() > 0)) {
                    return true;
                }
            }
View Full Code Here

            //TODO: should we remove response from exchange ?
            //      or should we rather ignore content list and have
            //      Response set here for all cases and extract it
            //      in the out interceptor instead of dealing with the contents list ?
            return new MessageContentsList(response);
        }
        ResourceProvider provider = getResourceProvider(exchange);
        Object rootInstance = getServiceObject(exchange);
        Object serviceObject = getActualServiceObject(exchange, rootInstance);
       
View Full Code Here

       
        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(exchange.getInMessage())) {
                contextLoader = ClassLoaderUtils
                    .setThreadContextClassloader(resourceObject.getClass().getClassLoader());
            }
            result = invoke(exchange, resourceObject, methodToInvoke, params);
        } catch (Fault ex) {
            String errorMessage = ex.getCause().getMessage();
            if (errorMessage != null
                && errorMessage.contains(PROXY_INVOCATION_ERROR_FRAGMENT)) {
                org.apache.cxf.common.i18n.Message errorM =
                    new org.apache.cxf.common.i18n.Message("PROXY_INVOCATION_FAILURE",
                                                           BUNDLE,
                                                           methodToInvoke,
                                                           cri.getServiceClass().getName());
                LOG.severe(errorM.toString());
            }
            Response excResponse = JAXRSUtils.convertFaultToResponse(ex.getCause(),
                                                                     exchange.getInMessage());
            if (excResponse == null) {
                ProviderFactory.getInstance(exchange.getInMessage()).clearThreadLocalProxies();
                ClassResourceInfo criRoot =
                    (ClassResourceInfo)exchange.get(JAXRSUtils.ROOT_RESOURCE_CLASS);
                if (criRoot != null) {
                    criRoot.clearThreadLocalProxies();
                }
                exchange.put(Message.PROPOGATE_EXCEPTION,
                             JAXRSUtils.propogateException(exchange.getInMessage()));
                throw ex;
            }
            return new MessageContentsList(excResponse);
        } finally {
            exchange.put(LAST_SERVICE_OBJECT, resourceObject);
            if (contextLoader != null) {
                contextLoader.reset();
            }
        }
        ClassResourceInfo subCri = null;
        if (ori.isSubResourceLocator()) {
            try {
                Message msg = exchange.getInMessage();
                MultivaluedMap<String, String> values = getTemplateValues(msg);
                String subResourcePath = values.getFirst(URITemplate.FINAL_MATCH_GROUP);
                String httpMethod = (String)msg.get(Message.HTTP_REQUEST_METHOD);
                String contentType = (String)msg.get(Message.CONTENT_TYPE);
                if (contentType == null) {
                    contentType = "*/*";
                }
                List<MediaType> acceptContentType =
                    (List<MediaType>)msg.getExchange().get(Message.ACCEPT_CONTENT_TYPE);

                result = checkResultObject(result, subResourcePath);

                subCri = cri.getSubResource(
                     methodToInvoke.getReturnType(),
                     ClassHelper.getRealClass(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 new WebApplicationException(404);
                }

                OperationResourceInfo subOri = JAXRSUtils.findTargetMethod(subCri,
                                                         exchange.getInMessage(),
                                                         httpMethod,
                                                         values,
                                                         contentType,
                                                         acceptContentType,
                                                         true);


                exchange.put(OperationResourceInfo.class, subOri);
                msg.put(URITemplate.TEMPLATE_PARAMETERS, values);
                // work out request parameters for the sub-resource class. Here we
                // presume InputStream has not been consumed yet by the root resource class.
                List<Object> newParams = JAXRSUtils.processParameters(subOri, values, msg);
                msg.setContent(List.class, newParams);

                return this.invoke(exchange, newParams, result);
            } catch (IOException ex) {
                Response resp = JAXRSUtils.convertFaultToResponse(ex, exchange.getInMessage());
                if (resp == null) {
                    resp = JAXRSUtils.convertFaultToResponse(new WebApplicationException(ex),
                                                             exchange.getInMessage());
                }
                return new MessageContentsList(resp);
            } catch (WebApplicationException ex) {
                Response excResponse;
                if (JAXRSUtils.noResourceMethodForOptions(ex.getResponse(),
                        (String)exchange.getInMessage().get(Message.HTTP_REQUEST_METHOD))) {
                    excResponse = JAXRSUtils.createResponse(subCri, null, null, 200, true);
                } else {
                    excResponse = JAXRSUtils.convertFaultToResponse(ex, exchange.getInMessage());
                }
                return new MessageContentsList(excResponse);
            }
        }

        return result;
    }
View Full Code Here

        if (isResponseAlreadyHandled(message)) {
            return;
        }
        message.put(Message.REST_MESSAGE, Boolean.TRUE);
       
        MessageContentsList objs = MessageContentsList.getContentsList(message);
        if (objs == null || objs.size() == 0) {
            return;
        }
       
        Object responseObj = objs.get(0);
       
        Response response = null;
        if (responseObj instanceof Response) {
            response = (Response)responseObj;
        } else {
View Full Code Here

            OutputStream os = outMessage.getContent(OutputStream.class);
            if ((os == null && outMessage.getContent(XMLStreamWriter.class) == null)
                || ori == null) {
                return;
            }
            MessageContentsList objs = MessageContentsList.getContentsList(outMessage);
            if (objs == null || objs.size() == 0) {
                return;
            }
            MultivaluedMap<String, String> headers =
                (MultivaluedMap)outMessage.get(Message.PROTOCOL_HEADERS);
            Method method = ori.getMethodToInvoke();
            int bodyIndex = (Integer)outMessage.get("BODY_INDEX");
            Method aMethod = ori.getAnnotatedMethod();
            Annotation[] anns = aMethod == null || bodyIndex == -1 ? new Annotation[0]
                                                  : aMethod.getParameterAnnotations()[bodyIndex];
            Object body = objs.get(0);
            try {
                if (bodyIndex != -1) {
                    Type paramType = method.getGenericParameterTypes()[bodyIndex];
                   
                    writeBody(body, outMessage, body.getClass(), paramType,
View Full Code Here

TOP

Related Classes of org.apache.cxf.message.MessageContentsList

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.