Search in sources :

Example 26 with Message

use of javax.wsdl.Message 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 27 with Message

use of javax.wsdl.Message in project gravitee-management-rest-api by gravitee-io.

the class SoapHeadersBuilder method generateHeader.

private void generateHeader(HeaderDef header) {
    Message msg = wsdlDef.getMessage(header.getMessage());
    Part part = msg.getPart(header.getPart());
    xmlCursor.beginElement(version.getHeaderQName());
    if (header.useEncoded()) {
        xmlCursor.insertAttributeWithValue(SampleXmlUtil.XSI_TYPE, formatQName(version.getHeaderQName()));
    }
    xmlCursor.toFirstChild();
    xmlCursor.beginElement(new QName(part.getName()));
    QName mustUnderstandQName = version.buildAttribute("mustUnderstand");
    Object mustUnderstand = part.getExtensionAttribute(mustUnderstandQName);
    if (mustUnderstand != null && mustUnderstand instanceof String) {
        xmlCursor.insertAttributeWithValue(mustUnderstandQName, (String) mustUnderstand);
    }
    QName actorQName = version.buildAttribute("actor");
    Object actor = part.getExtensionAttribute(actorQName);
    if (actor != null && actor instanceof String) {
        xmlCursor.insertAttributeWithValue(actorQName, (String) actor);
    }
    generateXml(part, xmlCursor, header.useEncoded());
    xmlCursor.toParent();
    xmlCursor.toParent();
}
Also used : Message(javax.wsdl.Message) Part(javax.wsdl.Part) QName(javax.xml.namespace.QName) WSDLUtils.formatQName(io.gravitee.rest.api.spec.converter.wsdl.WSDLUtils.formatQName)

Example 28 with Message

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

the class ModelService method getWSDL.

public void getWSDL(Definition def, String locationURI) throws WSDLException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = null;
    Document document = null;
    try {
        builder = factory.newDocumentBuilder();
        document = builder.newDocument();
    } catch (Exception e) {
        throw new WSDLException("can not create WSDL", module);
    }
    def.setTypes(this.getTypes(document, def));
    // set the IN parameters
    Input input = def.createInput();
    Set<String> inParam = this.getInParamNames();
    Message inMessage = def.createMessage();
    inMessage.setQName(new QName(TNS, this.name + "Request"));
    inMessage.setUndefined(false);
    Part parametersPart = def.createPart();
    parametersPart.setName("map-Map");
    parametersPart.setTypeName(new QName(TNS, "map-Map"));
    inMessage.addPart(parametersPart);
    Element documentation = document.createElement("wsdl:documentation");
    for (String paramName : inParam) {
        ModelParam param = this.getParam(paramName);
        if (!param.internal) {
            Part part = param.getWSDLPart(def);
            Element attribute = document.createElement("attribute");
            attribute.setAttribute("name", paramName);
            attribute.setAttribute("type", part.getTypeName().getLocalPart());
            attribute.setAttribute("namespace", part.getTypeName().getNamespaceURI());
            attribute.setAttribute("java-class", param.type);
            attribute.setAttribute("optional", Boolean.toString(param.optional));
            documentation.appendChild(attribute);
        }
    }
    Element usernameAttr = document.createElement("attribute");
    usernameAttr.setAttribute("name", "login.username");
    usernameAttr.setAttribute("type", "std-String");
    usernameAttr.setAttribute("namespace", TNS);
    usernameAttr.setAttribute("java-class", String.class.getName());
    usernameAttr.setAttribute("optional", Boolean.toString(!this.auth));
    documentation.appendChild(usernameAttr);
    Element passwordAttr = document.createElement("attribute");
    passwordAttr.setAttribute("name", "login.password");
    passwordAttr.setAttribute("type", "std-String");
    passwordAttr.setAttribute("namespace", TNS);
    passwordAttr.setAttribute("java-class", String.class.getName());
    passwordAttr.setAttribute("optional", Boolean.toString(!this.auth));
    documentation.appendChild(passwordAttr);
    parametersPart.setDocumentationElement(documentation);
    def.addMessage(inMessage);
    input.setMessage(inMessage);
    // set the OUT parameters
    Output output = def.createOutput();
    Set<String> outParam = this.getOutParamNames();
    Message outMessage = def.createMessage();
    outMessage.setQName(new QName(TNS, this.name + "Response"));
    outMessage.setUndefined(false);
    Part resultsPart = def.createPart();
    resultsPart.setName("map-Map");
    resultsPart.setTypeName(new QName(TNS, "map-Map"));
    outMessage.addPart(resultsPart);
    documentation = document.createElement("wsdl:documentation");
    for (String paramName : outParam) {
        ModelParam param = this.getParam(paramName);
        if (!param.internal) {
            Part part = param.getWSDLPart(def);
            Element attribute = document.createElement("attribute");
            attribute.setAttribute("name", paramName);
            attribute.setAttribute("type", part.getTypeName().getLocalPart());
            attribute.setAttribute("namespace", part.getTypeName().getNamespaceURI());
            attribute.setAttribute("java-class", param.type);
            attribute.setAttribute("optional", Boolean.toString(param.optional));
            documentation.appendChild(attribute);
        }
    }
    resultsPart.setDocumentationElement(documentation);
    def.addMessage(outMessage);
    output.setMessage(outMessage);
    // set port type
    Operation operation = def.createOperation();
    operation.setName(this.name);
    operation.setUndefined(false);
    operation.setOutput(output);
    operation.setInput(input);
    PortType portType = def.createPortType();
    portType.setQName(new QName(TNS, this.name + "PortType"));
    portType.addOperation(operation);
    portType.setUndefined(false);
    def.addPortType(portType);
    // SOAP binding
    SOAPBinding soapBinding = new SOAPBindingImpl();
    soapBinding.setStyle("rpc");
    soapBinding.setTransportURI("http://schemas.xmlsoap.org/soap/http");
    Binding binding = def.createBinding();
    binding.setQName(new QName(TNS, this.name + "SoapBinding"));
    binding.setPortType(portType);
    binding.setUndefined(false);
    binding.addExtensibilityElement(soapBinding);
    BindingOperation bindingOperation = def.createBindingOperation();
    bindingOperation.setName(operation.getName());
    bindingOperation.setOperation(operation);
    SOAPBody soapBody = new SOAPBodyImpl();
    soapBody.setUse("literal");
    soapBody.setNamespaceURI(TNS);
    soapBody.setEncodingStyles(UtilMisc.toList("http://schemas.xmlsoap.org/soap/encoding/"));
    BindingOutput bindingOutput = def.createBindingOutput();
    bindingOutput.addExtensibilityElement(soapBody);
    bindingOperation.setBindingOutput(bindingOutput);
    BindingInput bindingInput = def.createBindingInput();
    bindingInput.addExtensibilityElement(soapBody);
    bindingOperation.setBindingInput(bindingInput);
    SOAPOperation soapOperation = new SOAPOperationImpl();
    // soapAction should be set to the location of the SOAP URI, or Visual Studio won't construct the correct SOAP message
    soapOperation.setSoapActionURI(locationURI);
    // this is the RPC/literal style.  See http://www.ibm.com/developerworks/webservices/library/ws-whichwsdl/
    // this parameter is necessary or Apache Synapse won't recognize the WSDL
    soapOperation.setStyle("rpc");
    bindingOperation.addExtensibilityElement(soapOperation);
    binding.addBindingOperation(bindingOperation);
    def.addBinding(binding);
    // Service port
    Port port = def.createPort();
    port.setBinding(binding);
    port.setName(this.name + "Port");
    if (locationURI != null) {
        SOAPAddress soapAddress = new SOAPAddressImpl();
        soapAddress.setLocationURI(locationURI);
        port.addExtensibilityElement(soapAddress);
    }
    Service service = def.createService();
    service.setQName(new QName(TNS, this.name));
    service.addPort(port);
    def.addService(service);
}
Also used : SOAPAddressImpl(com.ibm.wsdl.extensions.soap.SOAPAddressImpl) BindingOutput(javax.wsdl.BindingOutput) SOAPOperation(javax.wsdl.extensions.soap.SOAPOperation) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Message(javax.wsdl.Message) Element(org.w3c.dom.Element) Port(javax.wsdl.Port) Operation(javax.wsdl.Operation) BindingOperation(javax.wsdl.BindingOperation) SOAPOperation(javax.wsdl.extensions.soap.SOAPOperation) SOAPBodyImpl(com.ibm.wsdl.extensions.soap.SOAPBodyImpl) Document(org.w3c.dom.Document) BindingInput(javax.wsdl.BindingInput) Input(javax.wsdl.Input) BindingInput(javax.wsdl.BindingInput) BindingOperation(javax.wsdl.BindingOperation) BindingOutput(javax.wsdl.BindingOutput) Output(javax.wsdl.Output) SOAPBinding(javax.wsdl.extensions.soap.SOAPBinding) Binding(javax.wsdl.Binding) WSDLException(javax.wsdl.WSDLException) QName(javax.xml.namespace.QName) SOAPBinding(javax.wsdl.extensions.soap.SOAPBinding) Service(javax.wsdl.Service) SOAPOperationImpl(com.ibm.wsdl.extensions.soap.SOAPOperationImpl) GeneralException(org.apache.ofbiz.base.util.GeneralException) NoSuchElementException(java.util.NoSuchElementException) WSDLException(javax.wsdl.WSDLException) SOAPBody(javax.wsdl.extensions.soap.SOAPBody) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Part(javax.wsdl.Part) SOAPAddress(javax.wsdl.extensions.soap.SOAPAddress) SOAPBindingImpl(com.ibm.wsdl.extensions.soap.SOAPBindingImpl) PortType(javax.wsdl.PortType)

Example 29 with Message

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

the class WsdlVisitor method walkTree.

public void walkTree() {
    begin();
    try {
        visit(definition);
        for (Iterator iterator = definition.getImports().entrySet().iterator(); iterator.hasNext(); ) {
            Map.Entry entry = (Map.Entry) iterator.next();
            String namespaceURI = (String) entry.getKey();
            List importsForNamespace = (List) entry.getValue();
            for (Iterator iterator1 = importsForNamespace.iterator(); iterator1.hasNext(); ) {
                Import anImport = (Import) iterator1.next();
                visit(anImport);
            }
        }
        visit(definition.getTypes());
        Collection messages = definition.getMessages().values();
        for (Iterator iterator = messages.iterator(); iterator.hasNext(); ) {
            Message message = (Message) iterator.next();
            visit(message);
            Collection parts = message.getParts().values();
            for (Iterator iterator2 = parts.iterator(); iterator2.hasNext(); ) {
                Part part = (Part) iterator2.next();
                visit(part);
            }
        }
        Collection services = definition.getServices().values();
        for (Iterator iterator = services.iterator(); iterator.hasNext(); ) {
            Service service = (Service) iterator.next();
            visit(service);
            Collection ports = service.getPorts().values();
            for (Iterator iterator1 = ports.iterator(); iterator1.hasNext(); ) {
                Port port = (Port) iterator1.next();
                visit(port);
                Binding binding = port.getBinding();
                visit(binding);
                List bindingOperations = binding.getBindingOperations();
                for (int i = 0; i < bindingOperations.size(); i++) {
                    BindingOperation bindingOperation = (BindingOperation) bindingOperations.get(i);
                    visit(bindingOperation);
                    visit(bindingOperation.getBindingInput());
                    visit(bindingOperation.getBindingOutput());
                    Collection bindingFaults = bindingOperation.getBindingFaults().values();
                    for (Iterator iterator2 = bindingFaults.iterator(); iterator2.hasNext(); ) {
                        BindingFault bindingFault = (BindingFault) iterator2.next();
                        visit(bindingFault);
                    }
                }
                PortType portType = binding.getPortType();
                visit(portType);
                List operations = portType.getOperations();
                for (int i = 0; i < operations.size(); i++) {
                    Operation operation = (Operation) operations.get(i);
                    visit(operation);
                    {
                        Input input = operation.getInput();
                        visit(input);
                    }
                    {
                        Output output = operation.getOutput();
                        visit(output);
                    }
                    Collection faults = operation.getFaults().values();
                    for (Iterator iterator2 = faults.iterator(); iterator2.hasNext(); ) {
                        Fault fault = (Fault) iterator2.next();
                        visit(fault);
                    }
                }
            }
        }
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
    } finally {
        end();
    }
}
Also used : SOAPBinding(javax.wsdl.extensions.soap.SOAPBinding) Binding(javax.wsdl.Binding) Import(javax.wsdl.Import) Message(javax.wsdl.Message) BindingFault(javax.wsdl.BindingFault) Port(javax.wsdl.Port) Service(javax.wsdl.Service) BindingFault(javax.wsdl.BindingFault) Fault(javax.wsdl.Fault) Operation(javax.wsdl.Operation) BindingOperation(javax.wsdl.BindingOperation) BindingOperation(javax.wsdl.BindingOperation) BindingInput(javax.wsdl.BindingInput) Input(javax.wsdl.Input) Part(javax.wsdl.Part) BindingOutput(javax.wsdl.BindingOutput) Output(javax.wsdl.Output) Iterator(java.util.Iterator) Collection(java.util.Collection) List(java.util.List) Map(java.util.Map) PortType(javax.wsdl.PortType)

Example 30 with Message

use of javax.wsdl.Message in project carbon-apimgt by wso2.

the class WSDL11SOAPOperationExtractor method getSoapMessageType.

/**
 * Gets message type for a given soap operation
 *
 * @param bindingOperation soap operation
 * @return String for message type
 * @throws APIMgtWSDLException
 */
private String getSoapMessageType(BindingOperation bindingOperation) throws APIMgtWSDLException {
    Operation operation = bindingOperation.getOperation();
    String messageType = "";
    boolean hasRPCMessages = false;
    if (operation != null) {
        Input input = operation.getInput();
        if (input != null) {
            Message message = input.getMessage();
            if (message != null) {
                Map map = message.getParts();
                for (Object obj : map.entrySet()) {
                    Map.Entry entry = (Map.Entry) obj;
                    Part part = (Part) entry.getValue();
                    if (part != null) {
                        if (part.getElementName() != null) {
                            messageType = "document";
                        } else if (part.getTypeName() != null) {
                            messageType = "rpc";
                            hasRPCMessages = true;
                        }
                    }
                }
            }
        }
    }
    if (hasRPCMessages) {
        return "rpc";
    } else {
        return messageType;
    }
}
Also used : Input(javax.wsdl.Input) Message(javax.wsdl.Message) Part(javax.wsdl.Part) Operation(javax.wsdl.Operation) SOAP12Operation(javax.wsdl.extensions.soap12.SOAP12Operation) WSDLSOAPOperation(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLSOAPOperation) BindingOperation(javax.wsdl.BindingOperation) SOAPOperation(javax.wsdl.extensions.soap.SOAPOperation) WSDLOperation(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLOperation) Map(java.util.Map) HashMap(java.util.HashMap) NamedNodeMap(org.w3c.dom.NamedNodeMap)

Aggregations

Message (javax.wsdl.Message)45 Part (javax.wsdl.Part)26 QName (javax.xml.namespace.QName)25 Operation (javax.wsdl.Operation)22 Input (javax.wsdl.Input)20 BindingOperation (javax.wsdl.BindingOperation)18 Output (javax.wsdl.Output)16 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)9 Map (java.util.Map)8 Binding (javax.wsdl.Binding)8 PortType (javax.wsdl.PortType)8 HashMap (java.util.HashMap)7 BindingInput (javax.wsdl.BindingInput)7 Fault (javax.wsdl.Fault)7 SOAPOperation (javax.wsdl.extensions.soap.SOAPOperation)7 ArrayList (java.util.ArrayList)6 SOAP12Operation (javax.wsdl.extensions.soap12.SOAP12Operation)6 BindingOutput (javax.wsdl.BindingOutput)5 Test (org.junit.Test)5 XmlSchemaComplexType (org.apache.ws.commons.schema.XmlSchemaComplexType)4