Search in sources :

Example 31 with MessageInfo

use of org.apache.cxf.service.model.MessageInfo in project cxf by apache.

the class DocLiteralInInterceptor method handleMessage.

public void handleMessage(Message message) {
    if (isGET(message) && message.getContent(List.class) != null) {
        LOG.fine("DocLiteralInInterceptor skipped in HTTP GET method");
        return;
    }
    DepthXMLStreamReader xmlReader = getXMLStreamReader(message);
    MessageContentsList parameters = new MessageContentsList();
    Exchange exchange = message.getExchange();
    BindingOperationInfo bop = exchange.getBindingOperationInfo();
    boolean client = isRequestor(message);
    // operation anymore, just return
    if (bop != null && !StaxUtils.toNextElement(xmlReader)) {
        // body may be empty for partial response to decoupled request
        return;
    }
    Service service = ServiceModelUtil.getService(message.getExchange());
    bop = getBindingOperationInfo(xmlReader, exchange, bop, client);
    boolean forceDocLitBare = false;
    if (bop != null && bop.getBinding() != null) {
        forceDocLitBare = Boolean.TRUE.equals(bop.getBinding().getService().getProperty("soap.force.doclit.bare"));
    }
    DataReader<XMLStreamReader> dr = getDataReader(message);
    try {
        if (!forceDocLitBare && bop != null && bop.isUnwrappedCapable()) {
            ServiceInfo si = bop.getBinding().getService();
            // Wrapped case
            MessageInfo msgInfo = setMessage(message, bop, client, si);
            setDataReaderValidation(service, message, dr);
            // Determine if we should keep the parameters wrapper
            if (shouldWrapParameters(msgInfo, message)) {
                QName startQName = xmlReader.getName();
                MessagePartInfo mpi = msgInfo.getFirstMessagePart();
                if (!mpi.getConcreteName().equals(startQName)) {
                    throw new Fault("UNEXPECTED_WRAPPER_ELEMENT", LOG, null, startQName, mpi.getConcreteName());
                }
                Object wrappedObject = dr.read(mpi, xmlReader);
                parameters.put(mpi, wrappedObject);
            } else {
                // Unwrap each part individually if we don't have a wrapper
                bop = bop.getUnwrappedOperation();
                msgInfo = setMessage(message, bop, client, si);
                List<MessagePartInfo> messageParts = msgInfo.getMessageParts();
                Iterator<MessagePartInfo> itr = messageParts.iterator();
                // stuck
                if (xmlReader.getEventType() == XMLStreamConstants.START_ELEMENT) {
                    StaxUtils.nextEvent(xmlReader);
                }
                // loop through each child element
                getPara(xmlReader, dr, parameters, itr, message);
            }
        } else {
            // Bare style
            BindingMessageInfo msgInfo = null;
            Endpoint ep = exchange.getEndpoint();
            ServiceInfo si = ep.getEndpointInfo().getService();
            if (bop != null) {
                // for xml binding or client side
                if (client) {
                    msgInfo = bop.getOutput();
                } else {
                    msgInfo = bop.getInput();
                    if (bop.getOutput() == null) {
                        exchange.setOneWay(true);
                    }
                }
                if (msgInfo == null) {
                    return;
                }
                setMessage(message, bop, client, si, msgInfo.getMessageInfo());
            }
            final Collection<OperationInfo> operations = new ArrayList<>(si.getInterface().getOperations());
            if (xmlReader == null || !StaxUtils.toNextElement(xmlReader)) {
                // empty input
                getBindingOperationForEmptyBody(operations, ep, exchange);
                return;
            }
            setDataReaderValidation(service, message, dr);
            int paramNum = 0;
            do {
                QName elName = xmlReader.getName();
                MessagePartInfo p;
                if (!client && msgInfo != null && msgInfo.getMessageParts() != null && msgInfo.getMessageParts().isEmpty()) {
                    // no input messagePartInfo
                    return;
                }
                if (msgInfo != null && msgInfo.getMessageParts() != null && msgInfo.getMessageParts().size() > 0) {
                    if (msgInfo.getMessageParts().size() > paramNum) {
                        p = msgInfo.getMessageParts().get(paramNum);
                    } else {
                        p = null;
                    }
                } else {
                    p = findMessagePart(exchange, operations, elName, client, paramNum, message);
                }
                if (!forceDocLitBare) {
                    // Make sure the elName found on the wire is actually OK for
                    // the purpose we need it
                    validatePart(p, elName, message);
                }
                final Object o = dr.read(p, xmlReader);
                if (forceDocLitBare && parameters.isEmpty()) {
                    // webservice provider does not need to ensure size
                    parameters.add(o);
                } else {
                    parameters.put(p, o);
                }
                paramNum++;
                if (message.getContent(XMLStreamReader.class) == null || o == xmlReader) {
                    xmlReader = null;
                }
            } while (xmlReader != null && StaxUtils.toNextElement(xmlReader));
        }
        message.setContent(List.class, parameters);
    } catch (Fault f) {
        if (!isRequestor(message)) {
            f.setFaultCode(Fault.FAULT_CODE_CLIENT);
        }
        throw f;
    }
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) XMLStreamReader(javax.xml.stream.XMLStreamReader) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) MessageContentsList(org.apache.cxf.message.MessageContentsList) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) Service(org.apache.cxf.service.Service) Fault(org.apache.cxf.interceptor.Fault) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) MessageInfo(org.apache.cxf.service.model.MessageInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) Exchange(org.apache.cxf.message.Exchange) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) Endpoint(org.apache.cxf.endpoint.Endpoint)

Example 32 with MessageInfo

use of org.apache.cxf.service.model.MessageInfo in project cxf by apache.

the class ServiceJavascriptBuilder method end.

// we do this at the end so we can inventory name conflicts sooner.
@Override
public void end(OperationInfo op) {
    // we only process the wrapped operation, not the unwrapped alternative.
    if (op.isUnwrapped()) {
        isInUnwrappedOperation = false;
        return;
    }
    isWrapped = op.isUnwrappedCapable();
    StringBuilder parameterList = new StringBuilder();
    inputParameterNames = new ArrayList<>();
    if (isWrapped) {
        collectWrapperElementInfo();
    } else {
        collectUnwrappedInputInfo();
    }
    buildParameterList(parameterList);
    MessageInfo outputMessage = op.getOutput();
    nonVoidOutput = outputMessage != null && outputMessage.getMessageParts().size() != 0;
    if (!op.isOneWay()) {
        buildSuccessFunction(outputMessage);
        // fault part some day.
        buildErrorFunction();
    }
    buildOperationFunction(parameterList);
    createInputSerializer();
    if (nonVoidOutput) {
        createResponseDeserializer(outputMessage);
    }
}
Also used : MessageInfo(org.apache.cxf.service.model.MessageInfo)

Example 33 with MessageInfo

use of org.apache.cxf.service.model.MessageInfo in project cxf by apache.

the class ServiceJavascriptBuilder method createInputSerializer.

private void createInputSerializer() {
    // If are working on a wrapped method, then we use the wrapper element.
    // If we are working on an unwrapped method, we will have to work from the unwrapped parts.
    MessageInfo message = currentOperation.getInput();
    String serializerFunctionGlobalName = getFunctionGlobalName(message.getName(), "serializeInput");
    String serializerFunctionPropertyName = getFunctionPropertyName(inputMessagesWithNameConflicts, message, message.getName()) + "_serializeInput";
    code.append("function ").append(serializerFunctionGlobalName).append("(cxfjsutils, args) {\n");
    String wrapperXmlElementName = null;
    // we could use the wrapped part, or we could use a conventional name.
    if (isWrapped) {
        wrapperXmlElementName = prefixAccumulator.xmlElementString(inputWrapperPartInfo.getConcreteName());
        utils.appendLine("var wrapperObj = new " + inputWrapperClassName + "();");
        int px = 0;
        for (String param : inputParameterNames) {
            utils.appendLine("wrapperObj.set" + StringUtils.capitalize(param) + "(args[" + px + "]);");
            px++;
        }
    } else if (isRPC) {
        // make sure the rpc element has a valid prefix
        prefixAccumulator.xmlElementString(currentOperation.getName());
    }
    if (soapBindingInfo != null) {
        SoapVersion soapVersion = soapBindingInfo.getSoapVersion();
        assert soapVersion.getVersion() == 1.1;
        utils.appendLine("var xml;");
        utils.appendLine("xml = cxfjsutils.beginSoap11Message(\"" + prefixAccumulator.getAttributes() + "\");");
    } else {
        // other alternative is XML, which isn't really all here yet.
        unsupportedConstruct("XML_BINDING", currentInterfaceClassName, xmlBindingInfo.getName());
    }
    utils.setXmlStringAccumulator("xml");
    if (isWrapped) {
        ParticleInfo elementInfo = ParticleInfo.forPartElement(inputWrapperElement, xmlSchemaCollection, "wrapperObj", wrapperXmlElementName);
        elementInfo.setContainingType(null);
        utils.generateCodeToSerializeElement(elementInfo, "", xmlSchemaCollection);
    } else {
        String operationXmlElement = null;
        if (isRPC) {
            operationXmlElement = prefixAccumulator.xmlElementString(currentOperation.getName());
            // RPC has a level of element for the entire operation.
            // we might have some schema to model this, but the following seems
            // sufficient.
            utils.appendString("<" + operationXmlElement + ">");
        }
        int px = 0;
        // the JavaScript programmer is stuck with the situation).
        for (ParticleInfo ean : unwrappedElementsAndNames) {
            String savedjsName = ean.getJavascriptName();
            try {
                ean.setJavascriptName("args[" + px + "]");
                utils.generateCodeToSerializeElement(ean, "", xmlSchemaCollection);
                px++;
            } finally {
                ean.setJavascriptName(savedjsName);
            }
        }
        if (isRPC) {
            utils.appendString("</" + operationXmlElement + ">");
        }
    }
    utils.appendLine("xml = xml + cxfjsutils.endSoap11Message();");
    utils.appendLine("return xml;");
    code.append("}\n\n");
    code.append(currentInterfaceClassName).append(".prototype.").append(serializerFunctionPropertyName).append(" = ").append(serializerFunctionGlobalName).append(";\n\n");
}
Also used : SoapVersion(org.apache.cxf.binding.soap.SoapVersion) ParticleInfo(org.apache.cxf.javascript.ParticleInfo) MessageInfo(org.apache.cxf.service.model.MessageInfo)

Example 34 with MessageInfo

use of org.apache.cxf.service.model.MessageInfo in project cxf by apache.

the class ResponseWrapperTest method testBuildFields.

@Test
public void testBuildFields() {
    // Test String[]
    Class<?> testingClass = GreeterArray.class;
    OperationInfo opInfo = getOperation(testingClass, "sayStringArray");
    assertNotNull(opInfo);
    ResponseWrapper responseWrapper = new ResponseWrapper();
    MessageInfo message = opInfo.getUnwrappedOperation().getOutput();
    Method method = (Method) opInfo.getProperty("operation.method");
    JavaField field = responseWrapper.buildFields(method, message).get(0);
    assertEquals("_return", field.getParaName());
    assertEquals("String[]", field.getType());
    // Test int[]
    opInfo = getOperation(testingClass, "sayIntArray");
    assertNotNull(opInfo);
    message = opInfo.getUnwrappedOperation().getOutput();
    method = (Method) opInfo.getProperty("operation.method");
    field = responseWrapper.buildFields(method, message).get(0);
    assertEquals("_return", field.getParaName());
    assertEquals("int[]", field.getType());
    // Test TestDataBean[]
    opInfo = getOperation(testingClass, "sayTestDataBeanArray");
    assertNotNull(opInfo);
    message = opInfo.getUnwrappedOperation().getOutput();
    method = (Method) opInfo.getProperty("operation.method");
    field = responseWrapper.buildFields(method, message).get(0);
    assertEquals("_return", field.getParaName());
    assertEquals("org.apache.cxf.tools.fortest.withannotation.doc.TestDataBean[]", field.getType());
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) JavaField(org.apache.cxf.tools.common.model.JavaField) GreeterArray(org.apache.cxf.tools.fortest.withannotation.doc.GreeterArray) Method(java.lang.reflect.Method) MessageInfo(org.apache.cxf.service.model.MessageInfo) Test(org.junit.Test)

Example 35 with MessageInfo

use of org.apache.cxf.service.model.MessageInfo in project cxf by apache.

the class MethodMapperTest method testMapOneWayOperation.

@Test
public void testMapOneWayOperation() throws Exception {
    OperationInfo operation = getOperation();
    MessageInfo inputMessage = operation.createMessage(new QName("urn:test:ns", "testInputMessage"), MessageInfo.Type.INPUT);
    operation.setInput("input", inputMessage);
    JavaMethod method = new MethodMapper().map(operation);
    assertNotNull(method);
    assertTrue(method.isOneWay());
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) QName(javax.xml.namespace.QName) JavaMethod(org.apache.cxf.tools.common.model.JavaMethod) MessageInfo(org.apache.cxf.service.model.MessageInfo) Test(org.junit.Test)

Aggregations

MessageInfo (org.apache.cxf.service.model.MessageInfo)73 QName (javax.xml.namespace.QName)42 OperationInfo (org.apache.cxf.service.model.OperationInfo)42 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)38 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)36 BindingMessageInfo (org.apache.cxf.service.model.BindingMessageInfo)19 SoapOperationInfo (org.apache.cxf.binding.soap.model.SoapOperationInfo)15 Test (org.junit.Test)15 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)14 Endpoint (org.apache.cxf.endpoint.Endpoint)13 Method (java.lang.reflect.Method)11 ArrayList (java.util.ArrayList)10 Service (org.apache.cxf.service.Service)9 MessageContentsList (org.apache.cxf.message.MessageContentsList)8 Fault (org.apache.cxf.interceptor.Fault)7 Exchange (org.apache.cxf.message.Exchange)7 Message (org.apache.cxf.message.Message)7 BindingInfo (org.apache.cxf.service.model.BindingInfo)7 FaultInfo (org.apache.cxf.service.model.FaultInfo)7 UnwrappedOperationInfo (org.apache.cxf.service.model.UnwrappedOperationInfo)7