Search in sources :

Example 26 with Part

use of javax.wsdl.Part in project ofbiz-framework by apache.

the class ModelParam method getWSDLPart.

public Part getWSDLPart(Definition def) {
    Part part = def.createPart();
    part.setName(this.name);
    part.setTypeName(new QName(ModelService.TNS, this.java2wsdlType()));
    return part;
}
Also used : Part(javax.wsdl.Part) QName(javax.xml.namespace.QName)

Example 27 with Part

use of javax.wsdl.Part in project tomee by apache.

the class HeavyweightOperationInfoBuilder method mapParameters.

private JaxRpcParameterInfo[] mapParameters() throws OpenEJBException {
    List<MethodParamPartsMapping> paramMappings = methodMapping.getMethodParamPartsMapping();
    // 
    // Map the ParameterDesc instance in an array so they can be ordered properly
    // before they are added to the the OperationDesc.
    // 
    JaxRpcParameterInfo[] parameterInfos = new JaxRpcParameterInfo[paramMappings.size()];
    for (MethodParamPartsMapping paramMapping : paramMappings) {
        JaxRpcParameterInfo parameterInfo = mapParameter(paramMapping);
        parameterInfos[paramMapping.getParamPosition().intValue()] = parameterInfo;
    }
    // 
    for (int i = 0; i < parameterInfos.length; i++) {
        if (parameterInfos[i] == null) {
            throw new OpenEJBException("There is no mapping for parameter number " + i + " for operation " + operationName);
        }
    }
    // 
    if (bindingStyle.isWrapped()) {
        // verify that all child elements have a parameter mapping
        Part inputPart = getWrappedPart(inputMessage);
        QName wrapperName = inputPart.getElementName();
        XmlElementInfo wrapperElement = schemaInfo.elements.get(wrapperName);
        XmlTypeInfo wrapperType = schemaInfo.types.get(wrapperElement.xmlType);
        Set<String> expectedInParams = new HashSet<>();
        for (XmlElementInfo expectedInParam : wrapperType.elements.values()) {
            expectedInParams.add(expectedInParam.qname.getLocalPart());
        }
        if (!inParamNames.equals(expectedInParams)) {
            throw new OpenEJBException("Not all wrapper children were mapped for operation name" + operationName);
        }
    } else {
        // verify all input message parts are mapped
        if (!inParamNames.equals(inputMessage.getParts().keySet())) {
            throw new OpenEJBException("Not all input message parts were mapped for operation name" + operationName);
        }
    }
    return parameterInfos;
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) QName(javax.xml.namespace.QName) MethodParamPartsMapping(org.apache.openejb.jee.MethodParamPartsMapping) Part(javax.wsdl.Part) HashSet(java.util.HashSet)

Example 28 with Part

use of javax.wsdl.Part in project tomee by apache.

the class HeavyweightOperationInfoBuilder method mapFaults.

private JaxRpcFaultInfo mapFaults(Fault fault) throws OpenEJBException {
    Message message = fault.getMessage();
    ExceptionMapping exceptionMapping = mapping.getExceptionMappingMap().get(message.getQName());
    if (exceptionMapping == null) {
        throw new OpenEJBException("No exception mapping for fault " + fault.getName() + " and fault message " + message.getQName() + " for operation " + operationName);
    }
    // TODO investigate whether there are other cases in which the namespace of faultQName can be determined.
    // this is weird, but I can't figure out what it should be.
    // if part has an element rather than a type, it should be part.getElementName() (see below)
    Part part;
    if (exceptionMapping.getWsdlMessagePartName() != null) {
        // According to schema documentation, this will only be set when several headerfaults use the same message.
        String headerFaultMessagePartName = exceptionMapping.getWsdlMessagePartName();
        part = message.getPart(headerFaultMessagePartName);
    } else {
        part = (Part) message.getOrderedParts(null).iterator().next();
    }
    // Determine the fault qname and xml schema type
    QName faultQName;
    XmlTypeInfo faultTypeInfo;
    if (part.getElementName() != null) {
        XmlElementInfo elementInfo = schemaInfo.elements.get(part.getElementName());
        if (elementInfo == null) {
            throw new OpenEJBException("Can not find element: " + part.getElementName() + ", known elements: " + schemaInfo.elements.keySet());
        }
        faultTypeInfo = schemaInfo.types.get(elementInfo.xmlType);
        if (faultTypeInfo == null) {
            throw new OpenEJBException("Can not find type " + elementInfo.xmlType + " for element " + elementInfo.qname + ", known types: " + schemaInfo.types.keySet());
        }
        faultQName = part.getElementName();
    } else if (part.getTypeName() != null) {
        faultTypeInfo = schemaInfo.types.get(part.getTypeName());
        if (faultTypeInfo == null) {
            throw new OpenEJBException("Can not find type: " + part.getTypeName() + ", known elements: " + schemaInfo.types.keySet());
        }
        faultQName = new QName("", fault.getName());
    } else {
        throw new OpenEJBException("Neither type nor element name supplied for part: " + part);
    }
    // 
    // Build the fault info
    // 
    JaxRpcFaultInfo faultInfo = new JaxRpcFaultInfo();
    faultInfo.qname = faultQName;
    faultInfo.xmlType = faultTypeInfo.qname;
    faultInfo.javaType = exceptionMapping.getExceptionType();
    faultInfo.complex = faultTypeInfo.simpleBaseType == null;
    // 
    if (exceptionMapping.getConstructorParameterOrder() != null) {
        if (faultTypeInfo.simpleBaseType != null) {
            throw new OpenEJBException("ConstructorParameterOrder can only be set for complex types, not " + faultTypeInfo.qname);
        }
        Map<String, XmlElementInfo> elements = new HashMap<>();
        for (XmlElementInfo element : faultTypeInfo.elements.values()) {
            elements.put(element.qname.getLocalPart(), element);
        }
        ConstructorParameterOrder constructorParameterOrder = exceptionMapping.getConstructorParameterOrder();
        for (int i = 0; i < constructorParameterOrder.getElementName().size(); i++) {
            String paramName = constructorParameterOrder.getElementName().get(i);
            // get the parameter element
            XmlElementInfo paramElementInfo = elements.get(paramName);
            if (paramElementInfo == null) {
                throw new OpenEJBException("Can not find element " + paramName + " in fault type " + faultTypeInfo.qname + ", known elements: " + elements.keySet());
            }
            // Java Type
            String paramJavaType = null;
            XmlTypeInfo paramTypeInfo = schemaInfo.types.get(paramElementInfo.xmlType);
            if (paramTypeInfo != null) {
                if (paramTypeInfo.anonymous) {
                    paramJavaType = anonymousTypes.get(paramTypeInfo.qname.getLocalPart());
                } else {
                    paramJavaType = publicTypes.get(paramTypeInfo.qname);
                }
            }
            // if we don't have a java type yet, check the simple types
            if (paramJavaType == null) {
                paramJavaType = QNAME_TO_JAVA_TYPE.get(paramElementInfo.xmlType);
            }
            if (paramJavaType == null) {
                throw new OpenEJBException("No class mapped for element type: " + paramElementInfo.xmlType);
            }
            JaxRpcParameterInfo parameterInfo = new JaxRpcParameterInfo();
            parameterInfo.qname = paramElementInfo.qname;
            parameterInfo.mode = Mode.OUT;
            // todo could be a soap header
            parameterInfo.soapHeader = false;
            parameterInfo.xmlType = paramElementInfo.xmlType;
            parameterInfo.javaType = paramJavaType;
            faultInfo.parameters.add(parameterInfo);
        }
    }
    return faultInfo;
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) ConstructorParameterOrder(org.apache.openejb.jee.ConstructorParameterOrder) Message(javax.wsdl.Message) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) ExceptionMapping(org.apache.openejb.jee.ExceptionMapping) Part(javax.wsdl.Part)

Example 29 with Part

use of javax.wsdl.Part in project tomee by apache.

the class HeavyweightOperationInfoBuilder method mapReturnType.

private void mapReturnType() throws OpenEJBException {
    if (outputMessage == null) {
        throw new OpenEJBException("No output message, but a mapping for it for operation " + operationName);
    }
    // verify mapped return value qname matches expected output message name
    WsdlReturnValueMapping wsdlReturnValueMapping = methodMapping.getWsdlReturnValueMapping();
    if (!wsdlReturnValueMapping.getWsdlMessage().equals(outputMessage.getQName())) {
        throw new OpenEJBException("OutputMessage has QName: " + outputMessage.getQName() + " but mapping specifies: " + wsdlReturnValueMapping.getWsdlMessage() + " for operation " + operationName);
    }
    // 
    // Determind return type qname and xml schema type
    // 
    QName returnQName = null;
    QName returnXmlType = null;
    if (wsdlReturnValueMapping.getWsdlMessagePartName() != null) {
        String wsdlMessagePartName = wsdlReturnValueMapping.getWsdlMessagePartName();
        if (outParamNames.contains(wsdlMessagePartName)) {
            throw new OpenEJBException("output message part " + wsdlMessagePartName + " has both an INOUT or OUT mapping and a return value mapping for operation " + operationName);
        }
        if (bindingStyle.isWrapped()) {
            Part outPart = getWrappedPart(outputMessage);
            XmlElementInfo returnParticle = getWrapperChild(outPart, wsdlMessagePartName);
            returnQName = new QName("", returnParticle.qname.getLocalPart());
            returnXmlType = returnParticle.xmlType;
        } else if (bindingStyle.isRpc()) {
            Part part = outputMessage.getPart(wsdlMessagePartName);
            if (part == null) {
                throw new OpenEJBException("No part for wsdlMessagePartName " + wsdlMessagePartName + " in output message for operation " + operationName);
            }
            returnQName = new QName("", part.getName());
            // RPC can only use type
            returnXmlType = part.getTypeName();
        } else {
            Part part = outputMessage.getPart(wsdlMessagePartName);
            if (part == null) {
                throw new OpenEJBException("No part for wsdlMessagePartName " + wsdlMessagePartName + " in output message for operation " + operationName);
            }
            returnQName = getPartName(part);
            returnXmlType = returnQName;
        }
        outParamNames.add(wsdlMessagePartName);
    } else {
    // what does this mean????
    }
    operationInfo.returnQName = returnQName;
    operationInfo.returnXmlType = returnXmlType;
    operationInfo.returnJavaType = wsdlReturnValueMapping.getMethodReturnValue();
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) WsdlReturnValueMapping(org.apache.openejb.jee.WsdlReturnValueMapping) QName(javax.xml.namespace.QName) Part(javax.wsdl.Part)

Example 30 with Part

use of javax.wsdl.Part in project tomee by apache.

the class HeavyweightOperationInfoBuilder method buildOperationInfo.

public JaxRpcOperationInfo buildOperationInfo() throws OpenEJBException {
    if (operationInfo != null) {
        return operationInfo;
    }
    operationInfo = new JaxRpcOperationInfo();
    operationInfo.name = operationName;
    // Binding style rpc/encoded, doc/lit, wrapped, etc.
    operationInfo.bindingStyle = bindingStyle;
    // Operation style one way, request response, etc/
    operationInfo.operationStyle = operationStyle;
    // Java method name
    operationInfo.javaMethodName = methodMapping.getJavaMethodName();
    // 
    // Map the parameters
    // 
    mapParameters();
    // 
    if (methodMapping.getWsdlReturnValueMapping() != null) {
        mapReturnType();
    }
    // Validate output mapping is complete
    if (outputMessage != null && bindingStyle.isWrapped()) {
        Part inputPart = getWrappedPart(outputMessage);
        QName wrapperName = inputPart.getElementName();
        XmlElementInfo wraperElement = schemaInfo.elements.get(wrapperName);
        XmlTypeInfo wrapperType = schemaInfo.types.get(wraperElement.xmlType);
        Set<String> expectedOutParams = new HashSet<>();
        for (XmlElementInfo expectedOutParam : wrapperType.elements.values()) {
            expectedOutParams.add(expectedOutParam.qname.getLocalPart());
        }
        if (!outParamNames.equals(expectedOutParams)) {
            throw new OpenEJBException("Not all wrapper children were mapped to parameters or a return value for operation " + operationName);
        }
    } else if (null != outputMessage) {
        if (!outParamNames.equals(outputMessage.getParts().keySet())) {
            throw new OpenEJBException("Not all output message parts were mapped to parameters or a return value for operation " + operationName);
        }
    }
    // 
    for (Fault fault : faults) {
        JaxRpcFaultInfo faultInfo = mapFaults(fault);
        operationInfo.faults.add(faultInfo);
    }
    return operationInfo;
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) Part(javax.wsdl.Part) QName(javax.xml.namespace.QName) Fault(javax.wsdl.Fault) HashSet(java.util.HashSet)

Aggregations

Part (javax.wsdl.Part)49 QName (javax.xml.namespace.QName)30 Message (javax.wsdl.Message)21 Operation (javax.wsdl.Operation)11 BindingOperation (javax.wsdl.BindingOperation)9 Input (javax.wsdl.Input)9 Output (javax.wsdl.Output)7 OMElement (org.apache.axiom.om.OMElement)7 Element (org.w3c.dom.Element)7 ArrayList (java.util.ArrayList)6 Binding (javax.wsdl.Binding)6 OpenEJBException (org.apache.openejb.OpenEJBException)6 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)6 Fault (javax.wsdl.Fault)5 Port (javax.wsdl.Port)5 Service (javax.wsdl.Service)5 MIMEPart (javax.wsdl.extensions.mime.MIMEPart)5 List (java.util.List)4 BindingInput (javax.wsdl.BindingInput)4 PortType (javax.wsdl.PortType)4