Search in sources :

Example 31 with Message

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

the class WSDL11SOAPOperationExtractor method getSoapInputParameterModel.

/**
 * Gets swagger input parameter model for a given soap operation
 *
 * @param bindingOperation soap operation
 * @return list of swagger models for the parameters
 * @throws APIMgtWSDLException
 */
private List<ModelImpl> getSoapInputParameterModel(BindingOperation bindingOperation) throws APIMgtWSDLException {
    List<ModelImpl> inputParameterModelList = new ArrayList<>();
    Operation operation = bindingOperation.getOperation();
    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) {
                            inputParameterModelList.add(parameterModelMap.get(part.getElementName().getLocalPart()));
                        } else {
                            if (part.getTypeName() != null && parameterModelMap.containsKey(part.getTypeName().getLocalPart())) {
                                inputParameterModelList.add(parameterModelMap.get(part.getTypeName().getLocalPart()));
                            } else if (part.getTypeName() != null && parameterModelMap.containsKey(message.getQName().getLocalPart())) {
                                ModelImpl model = parameterModelMap.get(message.getQName().getLocalPart());
                                model.addProperty(part.getName(), getPropertyFromDataType(part.getTypeName().getLocalPart()));
                                parameterModelMap.put(model.getName(), model);
                                inputParameterModelList.add(model);
                            } else {
                                ModelImpl model;
                                if (parameterModelMap.get(message.getQName().getLocalPart()) != null) {
                                    model = parameterModelMap.get(message.getQName().getLocalPart());
                                } else {
                                    model = new ModelImpl();
                                    model.setType(ObjectProperty.TYPE);
                                    model.setName(message.getQName().getLocalPart());
                                }
                                if (getPropertyFromDataType(part.getTypeName().getLocalPart()) instanceof RefProperty) {
                                    RefProperty property = (RefProperty) getPropertyFromDataType(part.getTypeName().getLocalPart());
                                    property.set$ref(SOAPToRESTConstants.Swagger.DEFINITIONS_ROOT + part.getTypeName().getLocalPart());
                                    model.addProperty(part.getName(), property);
                                } else {
                                    model.addProperty(part.getName(), getPropertyFromDataType(part.getTypeName().getLocalPart()));
                                }
                                parameterModelMap.put(model.getName(), model);
                                inputParameterModelList.add(model);
                            }
                        }
                    }
                }
            }
        }
    }
    return inputParameterModelList;
}
Also used : Input(javax.wsdl.Input) Message(javax.wsdl.Message) Part(javax.wsdl.Part) ArrayList(java.util.ArrayList) 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) ModelImpl(io.swagger.models.ModelImpl) Map(java.util.Map) HashMap(java.util.HashMap) NamedNodeMap(org.w3c.dom.NamedNodeMap) RefProperty(io.swagger.models.properties.RefProperty)

Example 32 with Message

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

the class WSDLServiceBuilder method buildServices.

private List<ServiceInfo> buildServices(Definition def, Service serv, QName endpointName, DescriptionInfo d) {
    Map<QName, ServiceInfo> services = new LinkedHashMap<>();
    DescriptionInfo description = d;
    if (null == description) {
        description = new DescriptionInfo();
        if (recordOriginal) {
            description.setProperty(WSDL_DEFINITION, def);
        }
        description.setName(def.getQName());
        description.setBaseURI(def.getDocumentBaseURI());
        copyExtensors(description, def.getExtensibilityElements());
        copyExtensionAttributes(description, def);
        Set<Definition> done = new HashSet<>();
        done.add(def);
        Collection<List<Import>> values = CastUtils.cast(def.getImports().values());
        for (List<Import> imports : values) {
            for (Import imp : imports) {
                if (!done.contains(imp.getDefinition())) {
                    done.add(imp.getDefinition());
                    copyExtensors(description, imp.getExtensibilityElements());
                    copyExtensionAttributes(description, imp);
                    copyExtensors(description, imp.getDefinition().getExtensibilityElements());
                    copyExtensionAttributes(description, imp.getDefinition());
                }
            }
        }
    }
    for (Port port : cast(serv.getPorts().values(), Port.class)) {
        if (endpointName != null && !endpointName.getLocalPart().equals(port.getName())) {
            continue;
        }
        Binding binding = port.getBinding();
        PortType bindingPt = binding.getPortType();
        if (bindingPt == null) {
            org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message("BINDING_MISSING_TYPE", LOG, binding.getQName());
            throw new WSDLRuntimeException(msg);
        }
        // TODO: wsdl4j's bug. if there is recursive import,
        // wsdl4j can not get operation input message
        PortType pt = def.getPortType(bindingPt.getQName());
        if (pt == null) {
            pt = bindingPt;
        }
        ServiceInfo service = services.get(pt.getQName());
        if (service == null) {
            service = new ServiceInfo();
            service.setDescription(description);
            description.getDescribed().add(service);
            if (recordOriginal) {
                service.setProperty(WSDL_DEFINITION, def);
                service.setProperty(WSDL_SERVICE, serv);
            }
            getSchemas(def, service);
            copyDocumentation(service, serv);
            service.setProperty(WSDL_SCHEMA_ELEMENT_LIST, this.schemaList);
            service.setTargetNamespace(def.getTargetNamespace());
            service.setName(serv.getQName());
            copyExtensors(service, serv.getExtensibilityElements());
            copyExtensionAttributes(service, serv);
            buildInterface(service, pt);
            services.put(pt.getQName(), service);
        }
        BindingInfo bi = service.getBinding(binding.getQName());
        if (bi == null) {
            bi = buildBinding(service, binding);
        }
        buildEndpoint(service, bi, port);
    }
    return new ArrayList<>(services.values());
}
Also used : Import(javax.wsdl.Import) Message(javax.wsdl.Message) Port(javax.wsdl.Port) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) BindingInfo(org.apache.cxf.service.model.BindingInfo) List(java.util.List) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SOAPBinding(javax.wsdl.extensions.soap.SOAPBinding) SOAP12Binding(javax.wsdl.extensions.soap12.SOAP12Binding) Binding(javax.wsdl.Binding) QName(javax.xml.namespace.QName) Definition(javax.wsdl.Definition) DescriptionInfo(org.apache.cxf.service.model.DescriptionInfo) PortType(javax.wsdl.PortType)

Example 33 with Message

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

the class ExceptionVisitor method createFaultMessage.

private void createFaultMessage(QName qname) {
    String exceptionName = qname.getLocalPart();
    // messages
    Message faultMsg = definition.createMessage();
    faultMsg.setQName(new QName(definition.getTargetNamespace(), exceptionName));
    faultMsg.setUndefined(false);
    // message - part
    Part part = definition.createPart();
    part.setName("exception");
    part.setElementName(qname);
    faultMsg.addPart(part);
    // add the fault element namespace to the definition
    String nsURI = qname.getNamespaceURI();
    manager.addWSDLDefinitionNamespace(definition, mapper.mapNSToPrefix(nsURI), nsURI);
    definition.addMessage(faultMsg);
}
Also used : Message(javax.wsdl.Message) QName(javax.xml.namespace.QName) Part(javax.wsdl.Part)

Example 34 with Message

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

the class OperationVisitor method generateInputMessage.

public Message generateInputMessage(Operation operation, BindingOperation bindingOperation) {
    Message msg = definition.createMessage();
    QName msgName;
    if (!mapper.isDefaultMapping()) {
        // mangle the message name
        // REVISIT, do we put in the entire scope for mangling
        msgName = new QName(definition.getTargetNamespace(), getScope().tail() + "." + operation.getName());
    } else {
        msgName = new QName(definition.getTargetNamespace(), operation.getName());
    }
    msg.setQName(msgName);
    msg.setUndefined(false);
    String inputName = operation.getName() + REQUEST_SUFFIX;
    Input input = definition.createInput();
    input.setName(inputName);
    input.setMessage(msg);
    BindingInput bindingInput = definition.createBindingInput();
    bindingInput.setName(inputName);
    bindingOperation.setBindingInput(bindingInput);
    operation.setInput(input);
    definition.addMessage(msg);
    return msg;
}
Also used : BindingInput(javax.wsdl.BindingInput) Input(javax.wsdl.Input) Message(javax.wsdl.Message) QName(javax.xml.namespace.QName) BindingInput(javax.wsdl.BindingInput)

Example 35 with Message

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

the class UniqueBodyPartsValidator method isValid.

public boolean isValid() {
    Collection<Binding> bindings = CastUtils.cast(def.getAllBindings().values());
    for (Binding binding : bindings) {
        uniqueBodyPartsMap = new HashMap<>();
        List<BindingOperation> ops = CastUtils.cast(binding.getBindingOperations());
        for (BindingOperation op : ops) {
            Operation operation = op.getOperation();
            if (operation != null && operation.getInput() != null) {
                Message inMessage = operation.getInput().getMessage();
                BindingInput bin = op.getBindingInput();
                Set<String> headers = new HashSet<>();
                if (bin != null) {
                    List<ExtensibilityElement> lst = CastUtils.cast(bin.getExtensibilityElements());
                    for (ExtensibilityElement ext : lst) {
                        if (!(ext instanceof SOAPHeader)) {
                            continue;
                        }
                        SOAPHeader header = (SOAPHeader) ext;
                        if (!header.getMessage().equals(inMessage.getQName())) {
                            continue;
                        }
                        headers.add(header.getPart());
                    }
                }
                if (inMessage != null && !isUniqueBodyPart(operation.getName(), inMessage, headers, binding.getQName())) {
                    return false;
                }
            }
        }
    }
    return true;
}
Also used : Binding(javax.wsdl.Binding) Message(javax.wsdl.Message) Operation(javax.wsdl.Operation) BindingOperation(javax.wsdl.BindingOperation) BindingInput(javax.wsdl.BindingInput) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) BindingOperation(javax.wsdl.BindingOperation) SOAPHeader(javax.wsdl.extensions.soap.SOAPHeader) HashSet(java.util.HashSet)

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