Search in sources :

Example 1 with Binding

use of javax.wsdl.Binding in project tdi-studio-se by Talend.

the class DynamicInvoker method invokeMethod.

/**
     * Method invokeMethod
     * 
     * @param wsdlLocation
     * @param operationName
     * @param inputName
     * @param outputName
     * @param portName
     * @param args
     * 
     * @return
     * 
     * @throws Exception
     */
public HashMap invokeMethod(String operationName, String portName, String[] args) throws Exception {
    String serviceNS = null;
    String serviceName = null;
    String operationQName = null;
    // System.out.println("Preparing Axis dynamic invocation");
    Service service = selectService(serviceNS, serviceName);
    Operation operation = null;
    org.apache.axis.client.Service dpf = new org.apache.axis.client.Service(wsdlParser, service.getQName());
    if (needWINAuth) {
        EngineConfiguration defaultConfig = EngineConfigurationFactoryFinder.newFactory().getClientEngineConfig();
        SimpleProvider config = new SimpleProvider(defaultConfig);
        config.deployTransport(HTTPTransport.DEFAULT_TRANSPORT_NAME, new CommonsHTTPSender());
        AxisClient axisClient = new AxisClient(config);
        dpf.setEngine(axisClient);
    }
    Vector inputs = new Vector();
    Port port = selectPort(service.getPorts(), portName);
    if (portName == null) {
        portName = port.getName();
    }
    Binding binding = port.getBinding();
    Call call = dpf.createCall(QName.valueOf(portName), QName.valueOf(operationName));
    ((org.apache.axis.client.Call) call).setTimeout(new Integer(timeout * 1000));
    ((org.apache.axis.client.Call) call).setProperty(ElementDeserializer.DESERIALIZE_CURRENT_ELEMENT, Boolean.TRUE);
    if (needAuth) {
        // authentication way1:
        // for calling webservice in deploy.wsdd:
        // <handler type="java:org.apache.axis.handlers.SimpleAuthorizationHandler"/>
        ((org.apache.axis.client.Call) call).setUsername(username);
        ((org.apache.axis.client.Call) call).setPassword(password);
        // authentication way2:
        // for bug:8403, in order to call webservice on "basic HTTP authentication"
        ((org.apache.axis.client.Call) call).setProperty(Stub.USERNAME_PROPERTY, username);
        ((org.apache.axis.client.Call) call).setProperty(Stub.PASSWORD_PROPERTY, password);
    }
    if (needWINAuth) {
        ((org.apache.axis.client.Call) call).setUsername(username);
        ((org.apache.axis.client.Call) call).setPassword(password);
    }
    if (useProxy) {
        AxisProperties.setProperty("http.proxyHost", proxyHost);
        AxisProperties.setProperty("http.proxyPort", proxyPort);
        AxisProperties.setProperty("http.proxyUser", proxyUser);
        AxisProperties.setProperty("http.proxyPassword", proxyPassword);
    }
    // Output types and names
    Vector outNames = new Vector();
    // Input types and names
    Vector inNames = new Vector();
    Vector inTypes = new Vector();
    SymbolTable symbolTable = wsdlParser.getSymbolTable();
    BindingEntry bEntry = symbolTable.getBindingEntry(binding.getQName());
    Parameters parameters = null;
    Iterator i = bEntry.getParameters().keySet().iterator();
    while (i.hasNext()) {
        Operation o = (Operation) i.next();
        if (o.getName().equals(operationName)) {
            operation = o;
            parameters = (Parameters) bEntry.getParameters().get(o);
            break;
        }
    }
    if ((operation == null) || (parameters == null)) {
        throw new RuntimeException(operationName + " was not found.");
    }
    // loop over paramters and set up in/out params
    for (int j = 0; j < parameters.list.size(); ++j) {
        Parameter p = (Parameter) parameters.list.get(j);
        if (p.getMode() == 1) {
            // IN
            inNames.add(p.getQName().getLocalPart());
            inTypes.add(p);
        } else if (p.getMode() == 2) {
            // OUT
            outNames.add(p.getQName().getLocalPart());
        } else if (p.getMode() == 3) {
            // INOUT
            inNames.add(p.getQName().getLocalPart());
            inTypes.add(p);
            outNames.add(p.getQName().getLocalPart());
        }
    }
    // set output type
    if (parameters.returnParam != null) {
        if (!parameters.returnParam.getType().isBaseType()) {
            ((org.apache.axis.client.Call) call).registerTypeMapping(org.w3c.dom.Element.class, parameters.returnParam.getType().getQName(), new ElementSerializerFactory(), new ElementDeserializerFactory());
        }
        // Get the QName for the return Type
        QName returnType = org.apache.axis.wsdl.toJava.Utils.getXSIType(parameters.returnParam);
        QName returnQName = parameters.returnParam.getQName();
        outNames.add(returnQName.getLocalPart());
    }
    if (inNames.size() != args.length - 2)
        throw new RuntimeException("Need " + inNames.size() + " arguments!!!");
    for (int pos = 0; pos < inNames.size(); ++pos) {
        String arg = args[pos + 2];
        Parameter p = (Parameter) inTypes.get(pos);
        inputs.add(getParamData((org.apache.axis.client.Call) call, p, arg));
    }
    // System.out.println("Executing operation " + operationName + " with parameters:");
    for (int j = 0; j < inputs.size(); j++) {
    // System.out.println(inNames.get(j) + "=" + inputs.get(j));
    }
    Object ret = call.invoke(inputs.toArray());
    Map outputs = call.getOutputParams();
    HashMap map = new HashMap();
    String name = null;
    Object value = null;
    if (outNames.size() > 0) {
        name = (String) outNames.get(0);
        value = outputs.get(name);
    }
    if ((value == null) && (ret != null)) {
        map.put(name, ret);
    } else {
        map.put(outNames, outputs);
    }
    return map;
}
Also used : HashMap(java.util.HashMap) Port(javax.wsdl.Port) Operation(javax.wsdl.Operation) AxisClient(org.apache.axis.client.AxisClient) EngineConfiguration(org.apache.axis.EngineConfiguration) Iterator(java.util.Iterator) ElementDeserializerFactory(org.apache.axis.encoding.ser.ElementDeserializerFactory) Vector(java.util.Vector) Binding(javax.wsdl.Binding) Call(javax.xml.rpc.Call) CommonsHTTPSender(org.apache.axis.transport.http.CommonsHTTPSender) Parameters(org.apache.axis.wsdl.symbolTable.Parameters) ElementSerializerFactory(org.apache.axis.encoding.ser.ElementSerializerFactory) QName(javax.xml.namespace.QName) Service(javax.wsdl.Service) SymbolTable(org.apache.axis.wsdl.symbolTable.SymbolTable) SimpleProvider(org.apache.axis.configuration.SimpleProvider) Parameter(org.apache.axis.wsdl.symbolTable.Parameter) BindingEntry(org.apache.axis.wsdl.symbolTable.BindingEntry) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with Binding

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

the class WSDLASTVisitor method getCorbaBindings.

public Binding[] getCorbaBindings() {
    List<Binding> result = new ArrayList<>();
    Map<QName, Binding> bindings = CastUtils.cast(definition.getBindings());
    for (Binding binding : bindings.values()) {
        List<ExtensibilityElement> extElements = CastUtils.cast(binding.getExtensibilityElements());
        for (int i = 0; i < extElements.size(); i++) {
            ExtensibilityElement el = extElements.get(i);
            if (el.getElementType().equals(CorbaConstants.NE_CORBA_BINDING)) {
                result.add(binding);
                break;
            }
        }
    }
    return result.toArray(new Binding[result.size()]);
}
Also used : Binding(javax.wsdl.Binding) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement)

Example 3 with Binding

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

the class WSDLASTVisitor method getPhysicalDefinition.

// Write the physical definitions to a file.
private Definition getPhysicalDefinition(Definition logicalDef, boolean schemaOnly) throws WSDLException, JAXBException {
    Definition def = null;
    if (schemaOnly) {
        def = logicalDef;
    } else {
        def = manager.createWSDLDefinition(targetNamespace);
    }
    Collection<String> namespaces = CastUtils.cast(definition.getNamespaces().values());
    for (String namespace : namespaces) {
        String prefix = definition.getPrefix(namespace);
        def.addNamespace(prefix, namespace);
    }
    Collection<Binding> bindings = CastUtils.cast(definition.getAllBindings().values());
    for (Binding binding : bindings) {
        def.addBinding(binding);
    }
    Collection<Service> services = CastUtils.cast(definition.getAllServices().values());
    for (Service service : services) {
        def.addService(service);
    }
    Collection<ExtensibilityElement> extns = CastUtils.cast(definition.getExtensibilityElements());
    for (ExtensibilityElement ext : extns) {
        def.addExtensibilityElement(ext);
    }
    def.setExtensionRegistry(definition.getExtensionRegistry());
    return def;
}
Also used : Binding(javax.wsdl.Binding) Definition(javax.wsdl.Definition) Service(javax.wsdl.Service) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement)

Example 4 with Binding

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

the class WSDLToCorbaBinding method generateCORBABinding.

private Binding generateCORBABinding(Definition definition, PortType portType) throws Exception {
    QName bqname = null;
    if (extReg == null) {
        extReg = def.getExtensionRegistry();
    }
    bindingNames = new ArrayList<>();
    String interfaceName = portType.getQName().getLocalPart();
    String bname = getMappedBindingName(interfaceName);
    String prefix = definition.getPrefix(definition.getTargetNamespace());
    if (prefix == null) {
        prefix = "";
    }
    if (bname == null && !allbindings) {
        bname = bindingName;
    }
    if (bname == null) {
        bname = mangleInterfaceName(interfaceName) + "CORBABinding";
        setBindingName(bname);
        bqname = new QName(definition.getTargetNamespace(), bname, prefix);
        int count = 0;
        StringBuilder builder = new StringBuilder(bname);
        while (WSDLToCorbaHelper.queryBinding(definition, bqname)) {
            builder.append(count);
            bqname = new QName(definition.getTargetNamespace(), builder.toString(), prefix);
        }
        bname = builder.toString();
    } else {
        bqname = new QName(definition.getTargetNamespace(), bname, prefix);
        // Check if the Binding with name already exists
        if (WSDLToCorbaHelper.queryBinding(definition, bqname)) {
            String msgStr = "Binding " + bqname.getLocalPart() + " already exists in WSDL.";
            org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message(msgStr, LOG);
            throw new Exception(msg.toString());
        }
    }
    // jwsdl model should have all other bindings in it.
    String pfx = definition.getPrefix(CorbaConstants.NU_WSDL_CORBA);
    if (pfx == null) {
        pfx = "corba";
        def.addNamespace(pfx, CorbaConstants.NU_WSDL_CORBA);
    }
    Binding binding = null;
    binding = def.createBinding();
    binding.setPortType(portType);
    binding.setQName(bqname);
    bindingNames.add(bname);
    mapBindingToInterface(portType.getQName().getLocalPart(), bname);
    BindingType bindingType = null;
    addCorbaTypeMap(def);
    try {
        bindingType = (BindingType) extReg.createExtension(Binding.class, CorbaConstants.NE_CORBA_BINDING);
        bindingType.setRepositoryID(WSDLToCorbaHelper.REPO_STRING + binding.getPortType().getQName().getLocalPart().replace('.', '/') + WSDLToCorbaHelper.IDL_VERSION);
        binding.addExtensibilityElement((ExtensibilityElement) bindingType);
    } catch (WSDLException ex) {
        ex.printStackTrace();
    }
    try {
        addBindingOperations(def, portType, binding);
        binding.setUndefined(false);
        definition.addBinding(binding);
    } catch (Exception ex) {
        binding.setUndefined(true);
    }
    cleanUpTypeMap(typeMappingType);
    return binding;
}
Also used : Binding(javax.wsdl.Binding) WSDLException(javax.wsdl.WSDLException) QName(javax.xml.namespace.QName) WSDLException(javax.wsdl.WSDLException) ToolException(org.apache.cxf.tools.common.ToolException) BindingType(org.apache.cxf.binding.corba.wsdl.BindingType)

Example 5 with Binding

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

the class WSDLToIDLAction method findBinding.

private Binding findBinding(Definition definition) {
    Binding binding = null;
    Collection<Binding> bindings = CastUtils.cast(definition.getBindings().values());
    if (bindingName != null) {
        for (Binding b : bindings) {
            binding = b;
            if (binding.getQName().getLocalPart().equals(bindingName)) {
                return binding;
            }
        }
    } else {
        if (bindings.size() >= 1) {
            binding = bindings.iterator().next();
        }
    }
    return binding;
}
Also used : Binding(javax.wsdl.Binding)

Aggregations

Binding (javax.wsdl.Binding)68 QName (javax.xml.namespace.QName)39 BindingOperation (javax.wsdl.BindingOperation)28 SOAPBinding (javax.wsdl.extensions.soap.SOAPBinding)21 Definition (javax.wsdl.Definition)18 Test (org.junit.Test)18 Port (javax.wsdl.Port)17 SOAP12Binding (javax.wsdl.extensions.soap12.SOAP12Binding)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)10 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 Part (javax.wsdl.Part)6