Search in sources :

Example 1 with Parameter

use of org.apache.axis.wsdl.symbolTable.Parameter 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 Parameter

use of org.apache.axis.wsdl.symbolTable.Parameter in project Lucee by lucee.

the class Axis1Client method _call.

private Object _call(PageContext pc, Config secondChanceConfig, String methodName, Struct namedArguments, Object[] arguments) throws PageException, ServiceException, RemoteException {
    ApplicationContextSupport acs = (ApplicationContextSupport) pc.getApplicationContext();
    javax.wsdl.Service service = getWSDLService();
    Service axisService = new Service(parser, service.getQName());
    axisService.setMaintainSession(acs.getWSMaintainSession());
    TypeMappingUtil.registerDefaults(axisService.getTypeMappingRegistry());
    Port port = WSUtil.getSoapPort(service);
    Binding binding = port.getBinding();
    SymbolTable symbolTable = parser.getSymbolTable();
    BindingEntry bEntry = symbolTable.getBindingEntry(binding.getQName());
    // get matching operation/method
    Iterator<Entry<Operation, Parameters>> itr = bEntry.getParameters().entrySet().iterator();
    Operation operation = null;
    Entry<Operation, Parameters> e;
    Parameters parameters = null;
    while (itr.hasNext()) {
        e = itr.next();
        if (e.getKey().getName().equalsIgnoreCase(methodName)) {
            operation = e.getKey();
            parameters = e.getValue();
            break;
        }
    }
    // no operation found!
    if (operation == null || parameters == null) {
        // get array of existing methods
        Set<Operation> set = bEntry.getParameters().keySet();
        Iterator<Operation> it = set.iterator();
        Collection.Key[] keys = new Collection.Key[set.size()];
        int index = 0;
        while (it.hasNext()) {
            keys[index++] = KeyImpl.init(it.next().getName());
        }
        throw new RPCException(ExceptionUtil.similarKeyMessage(keys, methodName, "method/operation", "methods/operations", null, true) + " Webservice: " + wsdlUrl);
    }
    org.apache.axis.client.Call call = (Call) axisService.createCall(QName.valueOf(port.getName()), QName.valueOf(operation.getName()));
    if (!StringUtil.isEmpty(username, true)) {
        call.setUsername(username);
        call.setPassword(password);
    }
    org.apache.axis.encoding.TypeMapping tm = call.getTypeMapping();
    Vector<String> inNames = new Vector<String>();
    Vector<Parameter> inTypes = new Vector<Parameter>();
    Vector<String> outNames = new Vector<String>();
    Vector<Parameter> outTypes = new Vector<Parameter>();
    Parameter p = null;
    for (int j = 0; j < parameters.list.size(); j++) {
        p = (Parameter) parameters.list.get(j);
        map(pc, symbolTable, secondChanceConfig, tm, p.getType());
        switch(p.getMode()) {
            case Parameter.IN:
                inNames.add(p.getQName().getLocalPart());
                inTypes.add(p);
                break;
            case Parameter.OUT:
                outNames.add(p.getQName().getLocalPart());
                outTypes.add(p);
                break;
            case Parameter.INOUT:
                inNames.add(p.getQName().getLocalPart());
                inTypes.add(p);
                outNames.add(p.getQName().getLocalPart());
                outTypes.add(p);
                break;
        }
    }
    // set output type
    if (parameters.returnParam != null) {
        QName rtnQName = parameters.returnParam.getQName();
        // TypeEntry rtnType = parameters.returnParam.getType();
        map(pc, symbolTable, secondChanceConfig, tm, parameters.returnParam.getType());
        outNames.add(rtnQName.getLocalPart());
        outTypes.add(parameters.returnParam);
    }
    // get timezone
    TimeZone tz;
    if (pc == null)
        tz = ThreadLocalPageContext.getTimeZone(secondChanceConfig);
    else
        tz = ThreadLocalPageContext.getTimeZone(pc);
    // check arguments
    Object[] inputs = new Object[inNames.size()];
    if (arguments != null) {
        if (inNames.size() != arguments.length)
            throw new RPCException("Invalid arguments count for operation " + methodName + " (" + arguments.length + " instead of " + inNames.size() + ")");
        for (int pos = 0; pos < inNames.size(); pos++) {
            p = inTypes.get(pos);
            inputs[pos] = getArgumentData(tm, tz, p, arguments[pos]);
        }
    } else {
        UDFUtil.argumentCollection(namedArguments);
        if (inNames.size() != namedArguments.size())
            throw new RPCException("Invalid arguments count for operation " + methodName + " (" + namedArguments.size() + " instead of " + inNames.size() + ")");
        Object arg;
        for (int pos = 0; pos < inNames.size(); pos++) {
            p = inTypes.get(pos);
            arg = namedArguments.get(KeyImpl.init(p.getName()), null);
            if (arg == null) {
                throw new RPCException("Invalid arguments for operation " + methodName, getErrorDetailForArguments(inNames.toArray(new String[inNames.size()]), CollectionUtil.keysAsString(namedArguments)));
            }
            inputs[pos] = getArgumentData(tm, tz, p, arg);
        }
    }
    Object ret = null;
    // add header
    if (headers != null && !headers.isEmpty()) {
        Iterator<SOAPHeaderElement> it = headers.iterator();
        while (it.hasNext()) {
            call.addHeader(it.next());
        }
    }
    try {
        ret = invoke(call, inputs);
    } catch (AxisFault af) {
        boolean rethrow = true;
        Throwable cause = af.getCause();
        if (cause != null) {
            /*
        		// first check if that missing type is around
        		String[] notFound=new String[]{"could not find deserializer for type","No deserializer for"};
        		int index;
        		if(msg!=null)for(int i=0; i<notFound.length;i++) {
        			if((index=msg.indexOf(notFound[i]))==-1)continue;;
        			
        			String raw=msg.substring(index+notFound[i].length()+1).trim();
        			QName qn = QName.valueOf(raw);
        			print.e(qn.getLocalPart());
        			print.e(qn.getNamespaceURI());
        			Type type = symbolTable.getType(qn);
        			if(type!=null) {
        				map(pc,secondChanceConfig,call.getTypeMapping(),type);
        				ret = invoke(call,inputs);
        				rethrow=false;
        			}
        		}*/
            // get the missing types from the SOAP Body, if possible
            String msg = cause.getMessage();
            // if(StringUtil.indexOfIgnoreCase(msg, "deserializer")!=-1) {
            try {
                InputSource is = new InputSource(new StringReader(call.getResponseMessage().getSOAPPartAsString()));
                Document doc = XMLUtil.parse(is, null, false);
                Element body = XMLUtil.getChildWithName("soapenv:Body", doc.getDocumentElement());
                Vector types = SOAPUtil.getTypes(body, symbolTable);
                map(pc, symbolTable, secondChanceConfig, (org.apache.axis.encoding.TypeMapping) (axisService.getTypeMappingRegistry().getDefaultTypeMapping()), types);
                ret = invoke(call, inputs);
                rethrow = false;
            } catch (Throwable t) {
                ExceptionUtil.rethrowIfNecessary(t);
            }
        // }
        }
        if (rethrow)
            throw af;
    }
    last = call;
    if (outNames.size() <= 1)
        return AxisCaster.toLuceeType(null, ret);
    // getParamData((org.apache.axis.client.Call)call,parameters.returnParam,ret);
    Map outputs = call.getOutputParams();
    Struct sct = new StructImpl();
    for (int pos = 0; pos < outNames.size(); pos++) {
        String name = outNames.get(pos);
        // print.ln(name);
        Object value = outputs.get(name);
        if (value == null && pos == 0) {
            sct.setEL(name, AxisCaster.toLuceeType(null, ret));
        } else {
            sct.setEL(name, AxisCaster.toLuceeType(null, value));
        }
    }
    return sct;
}
Also used : AxisFault(org.apache.axis.AxisFault) InputSource(org.xml.sax.InputSource) Port(javax.wsdl.Port) SOAPHeaderElement(org.apache.axis.message.SOAPHeaderElement) Element(org.w3c.dom.Element) Call(org.apache.axis.client.Call) Operation(javax.wsdl.Operation) Document(org.w3c.dom.Document) Struct(lucee.runtime.type.Struct) BindingEntry(org.apache.axis.wsdl.symbolTable.BindingEntry) Entry(java.util.Map.Entry) SymTabEntry(org.apache.axis.wsdl.symbolTable.SymTabEntry) TypeEntry(org.apache.axis.wsdl.symbolTable.TypeEntry) ServiceEntry(org.apache.axis.wsdl.symbolTable.ServiceEntry) RPCException(lucee.runtime.net.rpc.RPCException) StringReader(java.io.StringReader) Vector(java.util.Vector) Binding(javax.wsdl.Binding) SOAPHeaderElement(org.apache.axis.message.SOAPHeaderElement) ApplicationContextSupport(lucee.runtime.listener.ApplicationContextSupport) Call(org.apache.axis.client.Call) Parameters(org.apache.axis.wsdl.symbolTable.Parameters) QName(javax.xml.namespace.QName) Service(org.apache.axis.client.Service) SymbolTable(org.apache.axis.wsdl.symbolTable.SymbolTable) TimeZone(java.util.TimeZone) StructImpl(lucee.runtime.type.StructImpl) Parameter(org.apache.axis.wsdl.symbolTable.Parameter) TypeMapping(javax.xml.rpc.encoding.TypeMapping) BindingEntry(org.apache.axis.wsdl.symbolTable.BindingEntry) Map(java.util.Map) Key(lucee.runtime.type.Collection.Key)

Example 3 with Parameter

use of org.apache.axis.wsdl.symbolTable.Parameter in project Lucee by lucee.

the class Axis1Client method _toHTMLOperation.

private DumpData _toHTMLOperation(String title, String doc, Parameters parameters) {
    DumpTable table = new DumpTable("#99cccc", "#ccffff", "#000000");
    table.setTitle(title);
    if (doc.length() > 0)
        table.setComment(doc);
    DumpTable attributes = new DumpTable("#99cccc", "#ccffff", "#000000");
    String returns = "void";
    attributes.appendRow(3, new SimpleDumpData("name"), new SimpleDumpData("type"));
    for (int j = 0; j < parameters.list.size(); j++) {
        Parameter p = (Parameter) parameters.list.get(j);
        QName paramType = org.apache.axis.wsdl.toJava.Utils.getXSIType(p);
        String strType = paramType.getLocalPart();
        switch(p.getMode()) {
            case Parameter.IN:
                attributes.appendRow(0, new SimpleDumpData(p.getName()), new SimpleDumpData(toLuceeType(strType)));
                break;
            case Parameter.OUT:
                returns = toLuceeType(strType);
                break;
            case Parameter.INOUT:
                attributes.appendRow(0, new SimpleDumpData(p.getName()), new SimpleDumpData(toLuceeType(strType)));
                returns = toLuceeType(strType);
                break;
        }
    }
    Parameter rtn = parameters.returnParam;
    if (rtn != null) {
        QName paramType = org.apache.axis.wsdl.toJava.Utils.getXSIType(rtn);
        String strType = paramType.getLocalPart();
        returns = toLuceeType(strType);
    }
    table.appendRow(1, new SimpleDumpData("arguments"), attributes);
    table.appendRow(1, new SimpleDumpData("return type"), new SimpleDumpData(returns));
    return table;
}
Also used : DumpTable(lucee.runtime.dump.DumpTable) QName(javax.xml.namespace.QName) SimpleDumpData(lucee.runtime.dump.SimpleDumpData) Parameter(org.apache.axis.wsdl.symbolTable.Parameter)

Aggregations

QName (javax.xml.namespace.QName)3 Parameter (org.apache.axis.wsdl.symbolTable.Parameter)3 Map (java.util.Map)2 Vector (java.util.Vector)2 Binding (javax.wsdl.Binding)2 Operation (javax.wsdl.Operation)2 Port (javax.wsdl.Port)2 BindingEntry (org.apache.axis.wsdl.symbolTable.BindingEntry)2 Parameters (org.apache.axis.wsdl.symbolTable.Parameters)2 SymbolTable (org.apache.axis.wsdl.symbolTable.SymbolTable)2 StringReader (java.io.StringReader)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Entry (java.util.Map.Entry)1 TimeZone (java.util.TimeZone)1 Service (javax.wsdl.Service)1 Call (javax.xml.rpc.Call)1 TypeMapping (javax.xml.rpc.encoding.TypeMapping)1 DumpTable (lucee.runtime.dump.DumpTable)1 SimpleDumpData (lucee.runtime.dump.SimpleDumpData)1