Search in sources :

Example 66 with MessagePartInfo

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

the class ParameterProcessor method buildParamModelsWithoutOrdering.

private void buildParamModelsWithoutOrdering(JavaMethod method, MessageInfo inputMessage, MessageInfo outputMessage) throws ToolException {
    boolean wrapped = method.isWrapperStyle();
    if (wrapped) {
        if (inputMessage != null) {
            List<MessagePartInfo> inputParts = inputMessage.getMessageParts();
            MessagePartInfo inputPart = !inputParts.isEmpty() ? inputParts.iterator().next() : null;
            List<QName> inputWrapElement = null;
            if (inputPart != null && inputPart.isElement()) {
                inputWrapElement = ProcessorUtil.getWrappedElementQNames(context, inputPart.getElementQName());
            }
            if (inputWrapElement != null) {
                for (QName item : inputWrapElement) {
                    String fullJavaName = dataBinding.getWrappedElementType(inputPart.getElementQName(), item);
                    if (StringUtils.isEmpty(fullJavaName)) {
                        wrapped = false;
                        break;
                    }
                }
            }
        }
        if (outputMessage != null) {
            List<MessagePartInfo> outputParts = outputMessage.getMessageParts();
            MessagePartInfo outputPart = !outputParts.isEmpty() ? outputParts.iterator().next() : null;
            List<QName> outputWrapElement = null;
            if (outputPart != null && outputPart.isElement()) {
                outputWrapElement = ProcessorUtil.getWrappedElementQNames(context, outputPart.getElementQName());
            }
            if (outputWrapElement != null) {
                for (QName item : outputWrapElement) {
                    String fullJavaName = dataBinding.getWrappedElementType(outputPart.getElementQName(), item);
                    if (StringUtils.isEmpty(fullJavaName)) {
                        wrapped = false;
                        break;
                    }
                }
            }
        }
        if (!wrapped) {
            // could not map one of the parameters to a java type, need to drop down to bare style
            method.setWrapperStyle(false);
        }
    }
    if (inputMessage != null) {
        if (method.isWrapperStyle()) {
            processWrappedInput(method, inputMessage);
        } else {
            processInput(method, inputMessage);
        }
    }
    if (outputMessage == null) {
        processReturn(method, null);
    } else {
        if (method.isWrapperStyle()) {
            processWrappedOutput(method, inputMessage, outputMessage);
        } else {
            processOutput(method, inputMessage, outputMessage);
        }
    }
}
Also used : QName(javax.xml.namespace.QName) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo)

Example 67 with MessagePartInfo

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

the class ParameterProcessor method processInput.

private void processInput(JavaMethod method, MessageInfo inputMessage) throws ToolException {
    if (requireOutOfBandHeader()) {
        try {
            Class.forName("org.apache.cxf.binding.soap.SoapBindingFactory");
        } catch (Exception e) {
            LOG.log(Level.WARNING, new Message("SOAP_MISSING", LOG).toString());
        }
    }
    JAXWSBinding mBinding = inputMessage.getOperation().getExtensor(JAXWSBinding.class);
    for (MessagePartInfo part : inputMessage.getMessageParts()) {
        if (isOutOfBandHeader(part) && !requireOutOfBandHeader()) {
            continue;
        }
        JavaParameter param = getParameterFromPart(method, part, JavaType.Style.IN);
        if (mBinding != null && mBinding.getJaxwsParas() != null) {
            for (JAXWSParameter jwp : mBinding.getJaxwsParas()) {
                if (part.getName().getLocalPart().equals(jwp.getPart())) {
                    param.setName(jwp.getName());
                }
            }
        }
        addParameter(part, method, param);
    }
}
Also used : Message(org.apache.cxf.common.i18n.Message) JAXWSParameter(org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSParameter) JavaParameter(org.apache.cxf.tools.common.model.JavaParameter) JAXWSBinding(org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) ToolException(org.apache.cxf.tools.common.ToolException)

Example 68 with MessagePartInfo

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

the class UniqueBodyValidator method isValidEndpoint.

private boolean isValidEndpoint(EndpointInfo endpoint) {
    BindingInfo binding = endpoint.getBinding();
    Map<QName, QName> uniqueNames = new HashMap<>();
    Map<QName, Set<String>> actions = new HashMap<>();
    Collection<BindingOperationInfo> bos = binding.getOperations();
    for (BindingOperationInfo bo : bos) {
        OperationInfo op = binding.getInterface().getOperation(bo.getName());
        if (op.getInput() != null && op.getInput().getMessagePartsNumber() == 1) {
            MessagePartInfo part = op.getInput().getFirstMessagePart();
            if (part.getElementQName() == null) {
                continue;
            }
            QName mName = part.getElementQName();
            String action = getWSAAction(op.getInput());
            QName opName = uniqueNames.get(mName);
            Set<String> opActions = actions.get(mName);
            if (opName != null && opActions != null && !opActions.contains(action)) {
                opName = null;
            }
            if (opName != null) {
                Message msg = new Message("NON_UNIQUE_BODY", LOG, endpoint.getName(), op.getName(), opName, mName);
                addErrorMessage(msg.toString());
                return false;
            }
            uniqueNames.put(mName, op.getName());
            if (action != null) {
                if (opActions == null) {
                    opActions = new HashSet<>();
                    actions.put(mName, opActions);
                }
                opActions.add(action);
            }
        }
        for (BindingFaultInfo fault : bo.getFaults()) {
            if (fault.getFaultInfo().getMessagePartsNumber() > 1) {
                Message msg = new Message("FAULT_WITH_MULTIPLE_PARTS", LOG, fault.getFaultInfo().getName().getLocalPart());
                addErrorMessage(msg.toString());
                return false;
            }
        }
    }
    return true;
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Set(java.util.Set) HashSet(java.util.HashSet) Message(org.apache.cxf.common.i18n.Message) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) BindingInfo(org.apache.cxf.service.model.BindingInfo) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo)

Example 69 with MessagePartInfo

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

the class WrapperStyleNameCollisionValidator method mapElementName.

private String mapElementName(OperationInfo op, MessageInfo mi, WrapperElement element) {
    MessagePartInfo mpi = mi.getMessagePart(element.getElementName());
    JAXWSBinding bind = op.getExtensor(JAXWSBinding.class);
    if (bind != null && bind.getJaxwsParas() != null) {
        for (JAXWSParameter par : bind.getJaxwsParas()) {
            if (mi.getName().getLocalPart().equals(par.getMessageName()) && mpi.getName().getLocalPart().equals(par.getElementName().getLocalPart())) {
                return par.getName();
            }
        }
    }
    return mpi.getElementQName().getLocalPart();
}
Also used : JAXWSParameter(org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSParameter) JAXWSBinding(org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo)

Example 70 with MessagePartInfo

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

the class WrapperStyleNameCollisionValidator method isValidOperation.

private boolean isValidOperation(OperationInfo operation) {
    ToolContext context = service.getProperty(ToolContext.class.getName(), ToolContext.class);
    boolean c = context.optionSet(ToolConstants.CFG_AUTORESOLVE);
    boolean valid = false;
    if (operation.getUnwrappedOperation() == null) {
        valid = true;
    }
    String operationName = operation.getName().getLocalPart();
    operationName = ProcessorUtil.mangleNameToVariableName(operationName);
    JAXWSBinding binding = operation.getExtensor(JAXWSBinding.class);
    if (binding != null) {
        if (!binding.isEnableWrapperStyle()) {
            valid = true;
        } else if (binding.getMethodName() != null) {
            operationName = binding.getMethodName();
        }
    }
    binding = operation.getInterface().getExtensor(JAXWSBinding.class);
    if (binding != null) {
        if (!binding.isEnableWrapperStyle()) {
            valid = true;
        } else if (binding.getMethodName() != null) {
            operationName = binding.getMethodName();
        }
    }
    binding = operation.getInterface().getService().getDescription().getExtensor(JAXWSBinding.class);
    if (binding != null) {
        if (!binding.isEnableWrapperStyle()) {
            valid = true;
        } else if (binding.getMethodName() != null) {
            operationName = binding.getMethodName();
        }
    }
    valid |= checkBare(context, operationName);
    if (valid) {
        return true;
    }
    MessagePartInfo input = null;
    MessagePartInfo output = null;
    if (operation.getInput() != null && operation.getInput().getMessagePartsNumber() == 1) {
        input = operation.getInput().getFirstMessagePart();
    }
    if (operation.getOutput() != null && operation.getOutput().getMessagePartsNumber() == 1) {
        output = operation.getOutput().getFirstMessagePart();
    }
    if (!c) {
        Map<String, QName> names = new HashMap<>();
        if (input != null) {
            for (WrapperElement element : ProcessorUtil.getWrappedElement(context, input.getElementQName())) {
                String mappedName = mapElementName(operation, operation.getUnwrappedOperation().getInput(), element);
                if (names.containsKey(mappedName) && (names.get(mappedName) == element.getSchemaTypeName() || names.get(mappedName).equals(element.getSchemaTypeName()))) {
                    handleErrors(names.get(mappedName), element);
                    return false;
                }
                names.put(mappedName, element.getSchemaTypeName());
            }
        }
        if (output != null) {
            List<WrapperElement> els = ProcessorUtil.getWrappedElement(context, output.getElementQName());
            if (els.size() > 1) {
                for (WrapperElement element : els) {
                    String mappedName = mapElementName(operation, operation.getUnwrappedOperation().getOutput(), element);
                    QName mn = names.get(mappedName);
                    if (names.containsKey(mappedName) && !(mn == element.getSchemaTypeName() || (mn != null && mn.equals(element.getSchemaTypeName())))) {
                        handleErrors(names.get(mappedName), element);
                        return false;
                    }
                    names.put(mappedName, element.getSchemaTypeName());
                }
            }
        }
    }
    return true;
}
Also used : WrapperElement(org.apache.cxf.tools.wsdlto.frontend.jaxws.processor.internal.WrapperElement) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) ToolContext(org.apache.cxf.tools.common.ToolContext) JAXWSBinding(org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo)

Aggregations

MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)157 QName (javax.xml.namespace.QName)97 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)60 OperationInfo (org.apache.cxf.service.model.OperationInfo)44 Test (org.junit.Test)38 MessageInfo (org.apache.cxf.service.model.MessageInfo)36 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)27 Service (org.apache.cxf.service.Service)21 BindingMessageInfo (org.apache.cxf.service.model.BindingMessageInfo)21 Fault (org.apache.cxf.interceptor.Fault)20 BindingInfo (org.apache.cxf.service.model.BindingInfo)20 ArrayList (java.util.ArrayList)18 Endpoint (org.apache.cxf.endpoint.Endpoint)18 MessageContentsList (org.apache.cxf.message.MessageContentsList)18 SoapOperationInfo (org.apache.cxf.binding.soap.model.SoapOperationInfo)16 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)15 XMLStreamReader (javax.xml.stream.XMLStreamReader)13 Exchange (org.apache.cxf.message.Exchange)13 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)12 FaultInfo (org.apache.cxf.service.model.FaultInfo)11