Search in sources :

Example 1 with Operation

use of javax.wsdl.Operation 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 Operation

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

the class ComponentBuilder method buildOperation.

private OperationInfo buildOperation(OperationInfo operationInfo, BindingOperation bindingOper) {
    Operation oper = bindingOper.getOperation();
    operationInfo.setTargetMethodName(oper.getName());
    Vector operElems = findExtensibilityElement(bindingOper.getExtensibilityElements(), "operation");
    ExtensibilityElement operElem = (ExtensibilityElement) operElems.elementAt(0);
    if (operElem != null && operElem instanceof SOAPOperation) {
        SOAPOperation soapOperation = (SOAPOperation) operElem;
        operationInfo.setSoapActionURI(soapOperation.getSoapActionURI());
    } else if (operElem != null && operElem instanceof SOAP12Operation) {
        SOAP12Operation soapOperation = (SOAP12Operation) operElem;
        operationInfo.setSoapActionURI(soapOperation.getSoapActionURI());
    }
    BindingInput bindingInput = bindingOper.getBindingInput();
    BindingOutput bindingOutput = bindingOper.getBindingOutput();
    Vector bodyElems = findExtensibilityElement(bindingInput.getExtensibilityElements(), "body");
    ExtensibilityElement bodyElem = (ExtensibilityElement) bodyElems.elementAt(0);
    if (bodyElem != null && bodyElem instanceof SOAPBody) {
        SOAPBody soapBody = (SOAPBody) bodyElem;
        List styles = soapBody.getEncodingStyles();
        String encodingStyle = null;
        if (styles != null) {
            encodingStyle = styles.get(0).toString();
        }
        if (encodingStyle == null) {
            encodingStyle = DEFAULT_SOAP_ENCODING_STYLE;
        }
        operationInfo.setEncodingStyle(encodingStyle.toString());
        operationInfo.setTargetObjectURI(soapBody.getNamespaceURI());
    } else if (bodyElem != null && bodyElem instanceof SOAP12Body) {
        SOAP12Body soapBody = (SOAP12Body) bodyElem;
        String encodingStyle = null;
        if (soapBody.getEncodingStyle() != null) {
            encodingStyle = soapBody.getEncodingStyle().toString();
        }
        if (encodingStyle == null) {
            encodingStyle = DEFAULT_SOAP_ENCODING_STYLE;
        }
        operationInfo.setEncodingStyle(encodingStyle.toString());
        operationInfo.setTargetObjectURI(soapBody.getNamespaceURI());
    }
    Input inDef = oper.getInput();
    if (inDef != null) {
        Message inMsg = inDef.getMessage();
        if (inMsg != null) {
            operationInfo.setInputMessageName(inMsg.getQName().getLocalPart());
            getParameterFromMessage(operationInfo, inMsg, 1);
            operationInfo.setInmessage(inMsg);
        }
    }
    Output outDef = oper.getOutput();
    if (outDef != null) {
        Message outMsg = outDef.getMessage();
        if (outMsg != null) {
            operationInfo.setOutputMessageName(outMsg.getQName().getLocalPart());
            getParameterFromMessage(operationInfo, outMsg, 2);
            operationInfo.setOutmessage(outMsg);
        }
    }
    return operationInfo;
}
Also used : SOAPOperation(javax.wsdl.extensions.soap.SOAPOperation) BindingOutput(javax.wsdl.BindingOutput) SOAP12Body(javax.wsdl.extensions.soap12.SOAP12Body) Message(javax.wsdl.Message) Operation(javax.wsdl.Operation) SOAP12Operation(javax.wsdl.extensions.soap12.SOAP12Operation) BindingOperation(javax.wsdl.BindingOperation) SOAPOperation(javax.wsdl.extensions.soap.SOAPOperation) BindingInput(javax.wsdl.BindingInput) UnknownExtensibilityElement(javax.wsdl.extensions.UnknownExtensibilityElement) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) SOAPBody(javax.wsdl.extensions.soap.SOAPBody) Input(javax.wsdl.Input) BindingInput(javax.wsdl.BindingInput) SOAP12Operation(javax.wsdl.extensions.soap12.SOAP12Operation) BindingOutput(javax.wsdl.BindingOutput) Output(javax.wsdl.Output) List(java.util.List) ArrayList(java.util.ArrayList) Vector(java.util.Vector)

Example 3 with Operation

use of javax.wsdl.Operation in project tesb-studio-se by Talend.

the class PublishMetadataRunnable method process.

@SuppressWarnings("unchecked")
private void process(Definition wsdlDefinition, Collection<XmlFileConnectionItem> selectTables) throws Exception, CoreException {
    File tempFile = null;
    try {
        File wsdlFile = null;
        String baseUri = wsdlDefinition.getDocumentBaseURI();
        URI uri = new URI(baseUri);
        if ("file".equals(uri.getScheme())) {
            wsdlFile = new File(uri.toURL().getFile());
        } else {
            Map<String, InputStream> load = new WSDLLoader().load(baseUri, "tempWsdl" + "%d.wsdl");
            InputStream inputStream = load.get(WSDLLoader.DEFAULT_FILENAME);
            tempFile = getTempFile(inputStream);
            wsdlFile = tempFile;
        }
        if (populationUtil == null) {
            populationUtil = new WSDLPopulationUtil();
            populationUtil.loadWSDL("file://" + wsdlFile.getAbsolutePath());
        }
        final Set<QName> portTypes = new HashSet<QName>();
        final Set<QName> alreadyCreated = new HashSet<QName>();
        for (Binding binding : (Collection<Binding>) wsdlDefinition.getAllBindings().values()) {
            final QName portType = binding.getPortType().getQName();
            if (portTypes.add(portType)) {
                for (BindingOperation operation : (Collection<BindingOperation>) binding.getBindingOperations()) {
                    Operation oper = operation.getOperation();
                    Input inDef = oper.getInput();
                    if (inDef != null) {
                        Message inMsg = inDef.getMessage();
                        if (inMsg != null) {
                            // fix for TDI-20699
                            QName parameterFromMessage = getParameterFromMessage(inMsg);
                            if (parameterFromMessage == null) {
                                continue;
                            }
                            if (alreadyCreated.add(parameterFromMessage)) {
                                XsdMetadataUtils.createMetadataFromXSD(parameterFromMessage, portType.getLocalPart(), oper.getName(), selectTables, wsdlFile, populationUtil);
                            }
                        }
                    }
                    Output outDef = oper.getOutput();
                    if (outDef != null) {
                        Message outMsg = outDef.getMessage();
                        if (outMsg != null) {
                            QName parameterFromMessage = getParameterFromMessage(outMsg);
                            if (parameterFromMessage == null) {
                                continue;
                            }
                            if (alreadyCreated.add(parameterFromMessage)) {
                                XsdMetadataUtils.createMetadataFromXSD(parameterFromMessage, portType.getLocalPart(), oper.getName(), selectTables, wsdlFile, populationUtil);
                            }
                        }
                    }
                    for (Fault fault : (Collection<Fault>) oper.getFaults().values()) {
                        Message faultMsg = fault.getMessage();
                        if (faultMsg != null) {
                            QName parameterFromMessage = getParameterFromMessage(faultMsg);
                            if (parameterFromMessage == null) {
                                continue;
                            }
                            if (alreadyCreated.add(parameterFromMessage)) {
                                XsdMetadataUtils.createMetadataFromXSD(parameterFromMessage, portType.getLocalPart(), oper.getName(), selectTables, wsdlFile, populationUtil);
                            }
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        throw e;
    } finally {
        if (tempFile != null) {
            tempFile.delete();
        }
    }
}
Also used : Binding(javax.wsdl.Binding) Message(javax.wsdl.Message) InputStream(java.io.InputStream) QName(javax.xml.namespace.QName) Fault(javax.wsdl.Fault) Operation(javax.wsdl.Operation) BindingOperation(javax.wsdl.BindingOperation) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) PersistenceException(org.talend.commons.exception.PersistenceException) BindingOperation(javax.wsdl.BindingOperation) Input(javax.wsdl.Input) WSDLPopulationUtil(org.talend.repository.services.utils.WSDLPopulationUtil) Output(javax.wsdl.Output) Collection(java.util.Collection) IFile(org.eclipse.core.resources.IFile) File(java.io.File) WSDLLoader(org.talend.utils.wsdl.WSDLLoader) HashSet(java.util.HashSet)

Example 4 with Operation

use of javax.wsdl.Operation in project tesb-studio-se by Talend.

the class LocalWSDLEditor method saveModel.

private void saveModel() throws CoreException {
    IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    Definition definition = WSDLUtils.getDefinition(serviceItem);
    // changed for TDI-18005
    Map<String, String> portNameIdMap = new HashMap<String, String>();
    Map<String, EMap<String, String>> portAdditionalMap = new HashMap<String, EMap<String, String>>();
    Map<String, String> operNameIdMap = new HashMap<String, String>();
    Map<String, String> operJobMap = new HashMap<String, String>();
    EList<ServicePort> oldServicePorts = ((ServiceConnection) serviceItem.getConnection()).getServicePort();
    // get old service port item names and operation names under them
    HashMap<String, ArrayList<String>> oldPortItemNames = new HashMap<String, ArrayList<String>>();
    for (ServicePort servicePort : oldServicePorts) {
        // keep id
        portNameIdMap.put(servicePort.getName(), servicePort.getId());
        // keep additional infos
        portAdditionalMap.put(servicePort.getId(), servicePort.getAdditionalInfo());
        EList<ServiceOperation> operations = servicePort.getServiceOperation();
        ArrayList<String> operationNames = new ArrayList<String>();
        for (ServiceOperation operation : operations) {
            operNameIdMap.put(operation.getName(), operation.getId());
            operationNames.add(operation.getLabel());
            // record assigned job
            operJobMap.put(operation.getId(), operation.getReferenceJobId());
        }
        oldPortItemNames.put(servicePort.getName(), operationNames);
    }
    ((ServiceConnection) serviceItem.getConnection()).getServicePort().clear();
    for (Object obj : definition.getAllPortTypes().values()) {
        PortType portType = (PortType) obj;
        if (portType.isUndefined()) {
            continue;
        }
        ServicePort port = ServicesFactory.eINSTANCE.createServicePort();
        String portName = portType.getQName().getLocalPart();
        port.setName(portName);
        // set port id
        String id = portNameIdMap.get(portName);
        if (id != null) {
            port.setId(id);
            // restore additional infos
            port.getAdditionalInfo().putAll(portAdditionalMap.get(id));
        } else {
            port.setId(factory.getNextId());
        }
        @SuppressWarnings("unchecked") List<Operation> list = portType.getOperations();
        for (Operation operation : list) {
            if (operation.isUndefined()) {
                // means the operation has been removed already ,why ?
                continue;
            }
            ServiceOperation serviceOperation = ServicesFactory.eINSTANCE.createServiceOperation();
            serviceOperation.setName(operation.getName());
            Iterator<String> operationIterator = operNameIdMap.keySet().iterator();
            while (operationIterator.hasNext()) {
                String oldOperationName = operationIterator.next();
                String operationId = operNameIdMap.get(oldOperationName);
                if (oldOperationName.equals(operation.getName())) {
                    serviceOperation.setId(operationId);
                    // re-assign job
                    String jobId = operJobMap.get(operationId);
                    if (jobId != null) {
                        serviceOperation.setReferenceJobId(jobId);
                    }
                }
            }
            if (serviceOperation.getId() == null || serviceOperation.getId().equals("")) {
                serviceOperation.setId(factory.getNextId());
            }
            if (operation.getDocumentationElement() != null) {
                serviceOperation.setDocumentation(operation.getDocumentationElement().getTextContent());
            }
            boolean hasAssignedjob = false;
            ArrayList<String> operationNames = oldPortItemNames.get(portName);
            String referenceJobId = serviceOperation.getReferenceJobId();
            if (operationNames != null && referenceJobId != null) {
                IRepositoryViewObject repObj = null;
                try {
                    repObj = factory.getLastVersion(referenceJobId);
                } catch (PersistenceException e) {
                    ExceptionHandler.process(e);
                }
                if (repObj != null) {
                    for (String name : operationNames) {
                        if (name.equals(operation.getName() + '-' + repObj.getLabel())) {
                            serviceOperation.setLabel(name);
                            hasAssignedjob = true;
                            break;
                        }
                    }
                }
            }
            if (!hasAssignedjob) {
                serviceOperation.setLabel(operation.getName());
            }
            serviceOperation.setInBinding(WSDLUtils.isOperationInBinding(definition, portName, operation.getName()));
            port.getServiceOperation().add(serviceOperation);
        }
        ((ServiceConnection) serviceItem.getConnection()).getServicePort().add(port);
    }
}
Also used : ServicePort(org.talend.repository.services.model.services.ServicePort) ServiceConnection(org.talend.repository.services.model.services.ServiceConnection) HashMap(java.util.HashMap) Definition(javax.wsdl.Definition) ArrayList(java.util.ArrayList) ServiceOperation(org.talend.repository.services.model.services.ServiceOperation) Operation(javax.wsdl.Operation) ServiceOperation(org.talend.repository.services.model.services.ServiceOperation) EMap(org.eclipse.emf.common.util.EMap) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) EObject(org.eclipse.emf.ecore.EObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) PortType(javax.wsdl.PortType)

Example 5 with Operation

use of javax.wsdl.Operation in project tesb-studio-se by Talend.

the class PublishMetadataRunnable method getAllPaths.

@SuppressWarnings("unchecked")
private Collection<String> getAllPaths() throws URISyntaxException {
    final Set<String> paths = new HashSet<String>();
    final Set<QName> portTypes = new HashSet<QName>();
    final Set<QName> alreadyCreated = new HashSet<QName>();
    for (Binding binding : (Collection<Binding>) wsdlDefinition.getAllBindings().values()) {
        final QName portType = binding.getPortType().getQName();
        if (portTypes.add(portType)) {
            for (BindingOperation operation : (Collection<BindingOperation>) binding.getBindingOperations()) {
                Operation oper = operation.getOperation();
                Input inDef = oper.getInput();
                if (inDef != null) {
                    Message inMsg = inDef.getMessage();
                    addParamsToPath(portType, oper, inMsg, paths, alreadyCreated);
                }
                Output outDef = oper.getOutput();
                if (outDef != null) {
                    Message outMsg = outDef.getMessage();
                    addParamsToPath(portType, oper, outMsg, paths, alreadyCreated);
                }
                for (Fault fault : (Collection<Fault>) oper.getFaults().values()) {
                    Message faultMsg = fault.getMessage();
                    addParamsToPath(portType, oper, faultMsg, paths, alreadyCreated);
                }
            }
        }
    }
    return paths;
}
Also used : Binding(javax.wsdl.Binding) Message(javax.wsdl.Message) QName(javax.xml.namespace.QName) Fault(javax.wsdl.Fault) Operation(javax.wsdl.Operation) BindingOperation(javax.wsdl.BindingOperation) BindingOperation(javax.wsdl.BindingOperation) Input(javax.wsdl.Input) Output(javax.wsdl.Output) Collection(java.util.Collection) HashSet(java.util.HashSet)

Aggregations

Operation (javax.wsdl.Operation)7 Collection (java.util.Collection)4 Binding (javax.wsdl.Binding)4 BindingOperation (javax.wsdl.BindingOperation)4 Input (javax.wsdl.Input)4 Message (javax.wsdl.Message)4 Output (javax.wsdl.Output)4 Fault (javax.wsdl.Fault)3 PortType (javax.wsdl.PortType)3 QName (javax.xml.namespace.QName)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Map (java.util.Map)2 Vector (java.util.Vector)2 BindingInput (javax.wsdl.BindingInput)2 BindingOutput (javax.wsdl.BindingOutput)2 Port (javax.wsdl.Port)2