Search in sources :

Example 1 with WsdlOpParameterList

use of org.pentaho.di.trans.steps.webservices.wsdl.WsdlOpParameterList in project pentaho-kettle by pentaho.

the class WebService method getRequestXML.

private String getRequestXML(WsdlOperation operation, boolean qualifyWSField) throws KettleException {
    WsdlOpParameterList parameters = operation.getParameters();
    String requestOperation = Const.NVL(meta.getOperationRequestName(), meta.getOperationName());
    Iterator<WsdlOpParameter> iterator = parameters.iterator();
    List<String> bodyNames = new ArrayList<String>();
    while (iterator.hasNext()) {
        WsdlOpParameter wsdlOpParameter = iterator.next();
        bodyNames.add(wsdlOpParameter.getName().getLocalPart());
    }
    List<String> headerNames = new ArrayList<String>(parameters.getHeaderNames());
    StringBuilder xml = new StringBuilder();
    // TODO We only manage one name space for all the elements. See in the
    // future how to manage multiple name spaces
    // 
    xml.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    xml.append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" " + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:" + NS_PREFIX + "=\"");
    xml.append(meta.getOperationNamespace());
    xml.append("\">\n");
    xml.append("  <soapenv:Header>\n");
    addParametersToXML(xml, headerNames, qualifyWSField);
    xml.append("  </soapenv:Header>\n");
    xml.append("  <soapenv:Body>\n");
    // OPEN request operation
    xml.append("    <" + NS_PREFIX + ":").append(requestOperation).append(">\n");
    if (meta.getInFieldContainerName() != null) {
        xml.append("      <" + NS_PREFIX + ":" + meta.getInFieldContainerName() + ">\n");
    }
    addParametersToXML(xml, bodyNames, qualifyWSField);
    if (meta.getInFieldContainerName() != null) {
        xml.append("      </" + NS_PREFIX + ":" + meta.getInFieldContainerName() + ">\n");
    }
    // CLOSE request operation
    xml.append("    </" + NS_PREFIX + ":").append(requestOperation).append(">\n");
    xml.append("  </soapenv:Body>\n");
    xml.append("</soapenv:Envelope>\n");
    return xml.toString();
}
Also used : WsdlOpParameterList(org.pentaho.di.trans.steps.webservices.wsdl.WsdlOpParameterList) ArrayList(java.util.ArrayList) WsdlOpParameter(org.pentaho.di.trans.steps.webservices.wsdl.WsdlOpParameter)

Example 2 with WsdlOpParameterList

use of org.pentaho.di.trans.steps.webservices.wsdl.WsdlOpParameterList in project pentaho-kettle by pentaho.

the class WebServiceDialog method loadOperation.

private void loadOperation(String anOperationName) throws KettleException {
    wsdlOperation = null;
    inWsdlParamContainer = null;
    outWsdlParamContainer = null;
    if (wsdl != null) {
        for (Iterator<WsdlOperation> vItOperation = wsdl.getOperations().iterator(); vItOperation.hasNext() && wsdlOperation == null; ) {
            WsdlOperation vCurrentOperation = vItOperation.next();
            if (vCurrentOperation.getOperationQName().getLocalPart().equals(anOperationName)) {
                wsdlOperation = vCurrentOperation;
            }
        }
    }
    if (wsdlOperation != null) {
        // figure out the request name
        // 
        String request = "";
        WsdlOpParameterList parameters = wsdlOperation.getParameters();
        if (parameters != null && parameters.getOperation() != null && parameters.getOperation().getInput() != null && parameters.getOperation().getInput().getName() != null) {
            request = wsdlOperation.getParameters().getOperation().getInput().getName().toString();
        }
        wOperationRequest.setText(request);
        for (int cpt = 0; cpt < wsdlOperation.getParameters().size(); cpt++) {
            WsdlOpParameter param = wsdlOperation.getParameters().get(cpt);
            if (param.isArray()) {
                // setInFieldArgumentName(param.getName().getLocalPart());
                if (param.getItemXmlType() != null) {
                    ComplexType type = param.getItemComplexType();
                    if (type != null) {
                        for (Iterator<String> itrType = type.getElementNames().iterator(); itrType.hasNext(); ) {
                            String attributeName = itrType.next();
                            QName attributeType = type.getElementType(attributeName);
                            if (!WebServiceMeta.XSD_NS_URI.equals(attributeType.getNamespaceURI())) {
                                throw new KettleStepException(BaseMessages.getString(PKG, "WebServiceDialog.ERROR0007.UnsupporteOperation.ComplexType"));
                            }
                        }
                    }
                    if (ParameterMode.IN.equals(param.getMode()) || ParameterMode.INOUT.equals(param.getMode()) || ParameterMode.UNDEFINED.equals(param.getMode())) {
                        if (inWsdlParamContainer != null) {
                            throw new KettleStepException(BaseMessages.getString(PKG, "WebServiceDialog.ERROR0006.UnsupportedOperation.MultipleArrays"));
                        } else {
                            inWsdlParamContainer = new WsdlOpParameterContainer(param);
                        }
                    } else if (ParameterMode.OUT.equals(param.getMode()) || ParameterMode.INOUT.equals(param.getMode()) || ParameterMode.UNDEFINED.equals(param.getMode())) {
                        if (outWsdlParamContainer != null) {
                            throw new KettleStepException(BaseMessages.getString(PKG, "WebServiceDialog.ERROR0006.UnsupportedOperation.MultipleArrays"));
                        } else {
                            outWsdlParamContainer = new WsdlOpParameterContainer(param);
                        }
                    }
                }
            } else {
                if (ParameterMode.IN.equals(param.getMode()) || ParameterMode.INOUT.equals(param.getMode()) || ParameterMode.UNDEFINED.equals(param.getMode())) {
                    if (inWsdlParamContainer != null && !(inWsdlParamContainer instanceof WsdlOperationContainer)) {
                        throw new KettleStepException(BaseMessages.getString(PKG, "WebServiceDialog.ERROR0008.UnsupportedOperation.IncorrectParams"));
                    } else {
                        inWsdlParamContainer = new WsdlOperationContainer(wsdlOperation, param.getMode());
                    }
                } else if (ParameterMode.OUT.equals(param.getMode()) || ParameterMode.INOUT.equals(param.getMode()) || ParameterMode.UNDEFINED.equals(param.getMode())) {
                    if (outWsdlParamContainer != null && !(outWsdlParamContainer instanceof WsdlOperationContainer)) {
                        throw new KettleStepException(BaseMessages.getString(PKG, "WebServiceDialog.ERROR0008.UnsupportedOperation.IncorrectParams"));
                    } else {
                        outWsdlParamContainer = new WsdlOperationContainer(wsdlOperation, param.getMode());
                    }
                } else {
                    System.out.println("Parameter : " + param.getName().getLocalPart() + ", mode=" + param.getMode().toString() + ", is not considered");
                }
            }
        }
        if (wsdlOperation.getReturnType() != null) {
            outWsdlParamContainer = new WsdlOpParameterContainer((WsdlOpParameter) wsdlOperation.getReturnType());
            if (wsdlOperation.getReturnType().isArray()) {
                if (wsdlOperation.getReturnType().getItemXmlType() != null) {
                    ComplexType type = wsdlOperation.getReturnType().getItemComplexType();
                    if (type != null) {
                        for (Iterator<String> itrType = type.getElementNames().iterator(); itrType.hasNext(); ) {
                            String attributeName = itrType.next();
                            QName attributeType = type.getElementType(attributeName);
                            if (!WebServiceMeta.XSD_NS_URI.equals(attributeType.getNamespaceURI())) {
                                throw new KettleStepException(BaseMessages.getString(PKG, "WebServiceDialog.ERROR0007.UnsupportedOperation.ComplexType"));
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : WsdlOperation(org.pentaho.di.trans.steps.webservices.wsdl.WsdlOperation) WsdlOpParameterContainer(org.pentaho.di.trans.steps.webservices.wsdl.WsdlOpParameterContainer) WsdlOpParameterList(org.pentaho.di.trans.steps.webservices.wsdl.WsdlOpParameterList) KettleStepException(org.pentaho.di.core.exception.KettleStepException) WsdlOperationContainer(org.pentaho.di.trans.steps.webservices.wsdl.WsdlOperationContainer) QName(javax.xml.namespace.QName) WsdlOpParameter(org.pentaho.di.trans.steps.webservices.wsdl.WsdlOpParameter) ComplexType(org.pentaho.di.trans.steps.webservices.wsdl.ComplexType)

Aggregations

WsdlOpParameter (org.pentaho.di.trans.steps.webservices.wsdl.WsdlOpParameter)2 WsdlOpParameterList (org.pentaho.di.trans.steps.webservices.wsdl.WsdlOpParameterList)2 ArrayList (java.util.ArrayList)1 QName (javax.xml.namespace.QName)1 KettleStepException (org.pentaho.di.core.exception.KettleStepException)1 ComplexType (org.pentaho.di.trans.steps.webservices.wsdl.ComplexType)1 WsdlOpParameterContainer (org.pentaho.di.trans.steps.webservices.wsdl.WsdlOpParameterContainer)1 WsdlOperation (org.pentaho.di.trans.steps.webservices.wsdl.WsdlOperation)1 WsdlOperationContainer (org.pentaho.di.trans.steps.webservices.wsdl.WsdlOperationContainer)1