Search in sources :

Example 36 with Binding

use of javax.wsdl.Binding 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 37 with Binding

use of javax.wsdl.Binding 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 38 with Binding

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

the class SOAPBindingUtil method createSoapBinding.

public static SoapBinding createSoapBinding(ExtensionRegistry extReg, boolean isSOAP12) throws WSDLException {
    final ExtensibilityElement extElement;
    if (isSOAP12) {
        extElement = extReg.createExtension(Binding.class, new QName(WSDLConstants.NS_SOAP12, "binding"));
        ((SOAP12Binding) extElement).setTransportURI(WSDLConstants.NS_SOAP_HTTP_TRANSPORT);
    } else {
        extElement = extReg.createExtension(Binding.class, new QName(WSDLConstants.NS_SOAP11, "binding"));
        ((SOAPBinding) extElement).setTransportURI(WSDLConstants.NS_SOAP_HTTP_TRANSPORT);
    }
    return getSoapBinding(extElement);
}
Also used : SOAPBinding(javax.wsdl.extensions.soap.SOAPBinding) SOAP12Binding(javax.wsdl.extensions.soap12.SOAP12Binding) Binding(javax.wsdl.Binding) SoapBinding(org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding) SOAP12Binding(javax.wsdl.extensions.soap12.SOAP12Binding) QName(javax.xml.namespace.QName) SOAPBinding(javax.wsdl.extensions.soap.SOAPBinding) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement)

Example 39 with Binding

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

the class CorbaObjectReferenceHelper method populateEprInfo.

public static void populateEprInfo(EprMetaData info) {
    if (!info.isValid()) {
        return;
    }
    Binding match = info.getBinding();
    Definition wsdlDef = info.getCandidateWsdlDef();
    Collection<Service> services = CastUtils.cast(wsdlDef.getServices().values());
    for (Service serv : services) {
        Collection<Port> ports = CastUtils.cast(serv.getPorts().values());
        for (Port pt : ports) {
            if (pt.getBinding().equals(match)) {
                info.setPortName(pt.getName());
                info.setServiceQName(serv.getQName());
                break;
            }
        }
    }
    if (info.getServiceQName() == null) {
        Iterator<?> importLists = wsdlDef.getImports().values().iterator();
        while (info.getServiceQName() == null && importLists.hasNext()) {
            List<?> imports = (List<?>) importLists.next();
            for (java.lang.Object imp : imports) {
                if (imp instanceof Import) {
                    Definition importDef = ((Import) imp).getDefinition();
                    LOG.log(Level.FINE, "following wsdl import " + importDef.getDocumentBaseURI());
                    info.setCandidateWsdlDef(importDef);
                    populateEprInfo(info);
                    if (info.getServiceQName() != null) {
                        break;
                    }
                }
            }
        }
    }
}
Also used : Binding(javax.wsdl.Binding) Import(javax.wsdl.Import) Port(javax.wsdl.Port) Definition(javax.wsdl.Definition) Service(javax.wsdl.Service) List(java.util.List)

Example 40 with Binding

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

the class CorbaObjectReferenceHelper method getBindingForTypeId.

public static EprMetaData getBindingForTypeId(String repId, Definition wsdlDef) {
    LOG.log(Level.FINE, "RepositoryId " + repId + ", wsdl namespace " + wsdlDef.getTargetNamespace());
    EprMetaData ret = new EprMetaData();
    Collection<Binding> bindings = CastUtils.cast(wsdlDef.getBindings().values());
    for (Binding b : bindings) {
        List<?> extElements = b.getExtensibilityElements();
        // Get the list of all extensibility elements
        for (Iterator<?> extIter = extElements.iterator(); extIter.hasNext(); ) {
            java.lang.Object element = extIter.next();
            // Find a binding type so we can check against its repository ID
            if (element instanceof BindingType) {
                BindingType type = (BindingType) element;
                if (repId.equals(type.getRepositoryID())) {
                    ret.setCandidateWsdlDef(wsdlDef);
                    ret.setBinding(b);
                    return ret;
                }
            }
        }
    }
    if (!ret.isValid()) {
        // recursivly check imports
        Iterator<?> importLists = wsdlDef.getImports().values().iterator();
        while (importLists.hasNext()) {
            List<?> imports = (List<?>) importLists.next();
            for (java.lang.Object imp : imports) {
                if (imp instanceof Import) {
                    Definition importDef = ((Import) imp).getDefinition();
                    LOG.log(Level.INFO, "Following import " + importDef.getDocumentBaseURI());
                    ret = getBindingForTypeId(repId, importDef);
                    if (ret.isValid()) {
                        return ret;
                    }
                }
            }
        }
    }
    return ret;
}
Also used : Binding(javax.wsdl.Binding) Import(javax.wsdl.Import) BindingType(org.apache.cxf.binding.corba.wsdl.BindingType) Definition(javax.wsdl.Definition) List(java.util.List)

Aggregations

Binding (javax.wsdl.Binding)69 QName (javax.xml.namespace.QName)39 BindingOperation (javax.wsdl.BindingOperation)28 SOAPBinding (javax.wsdl.extensions.soap.SOAPBinding)22 Definition (javax.wsdl.Definition)18 SOAP12Binding (javax.wsdl.extensions.soap12.SOAP12Binding)18 Test (org.junit.Test)18 Port (javax.wsdl.Port)17 Operation (javax.wsdl.Operation)16 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)15 PortType (javax.wsdl.PortType)14 Service (javax.wsdl.Service)12 BindingType (org.apache.cxf.binding.corba.wsdl.BindingType)12 ToolException (org.apache.cxf.tools.common.ToolException)12 File (java.io.File)9 ArrayList (java.util.ArrayList)8 BindingInput (javax.wsdl.BindingInput)8 Message (javax.wsdl.Message)8 Map (java.util.Map)7 HashSet (java.util.HashSet)6