Search in sources :

Example 1 with TypeEntry

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

the class AxisCaster method _toPojo.

private static Pojo _toPojo(PageContext pc, Pojo pojo, TypeMapping tm, TypeEntry typeEntry, QName type, Struct sct, Set<Object> done) throws PageException {
    // print.ds();System.exit(0);
    if (pojo == null) {
        try {
            PhysicalClassLoader cl = (PhysicalClassLoader) pc.getConfig().getRPCClassLoader(false);
            pojo = (Pojo) ClassUtil.loadInstance(ComponentUtil.getStructPropertiesClass(pc, sct, cl));
        } catch (ClassException e) {
            throw Caster.toPageException(e);
        } catch (IOException e) {
            throw Caster.toPageException(e);
        }
    }
    // initialize
    List<Property> props = new ArrayList<Property>();
    Iterator<Entry<Key, Object>> it = sct.entryIterator();
    Entry<Key, Object> e;
    PropertyImpl p;
    while (it.hasNext()) {
        e = it.next();
        p = new PropertyImpl();
        p.setAccess(Component.ACCESS_PUBLIC);
        p.setName(e.getKey().getString());
        p.setType(e.getValue() == null ? "any" : Caster.toTypeName(e.getValue()));
        props.add(p);
    }
    _initPojo(pc, typeEntry, type, pojo, props.toArray(new Property[props.size()]), sct, null, tm, done);
    return pojo;
}
Also used : Entry(java.util.Map.Entry) TypeEntry(org.apache.axis.wsdl.symbolTable.TypeEntry) PhysicalClassLoader(lucee.commons.lang.PhysicalClassLoader) ArrayList(java.util.ArrayList) ClassException(lucee.commons.lang.ClassException) PropertyImpl(lucee.runtime.component.PropertyImpl) IOException(java.io.IOException) Property(lucee.runtime.component.Property) Key(lucee.runtime.type.Collection.Key)

Example 2 with TypeEntry

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

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

the class Axis1Client method _mapComplex.

private Class _mapComplex(PageContext pc, SymbolTable symbolTable, Config secondChanceConfig, org.apache.axis.encoding.TypeMapping tm, TypeEntry type) throws PageException {
    // extension
    Class ex = null;
    if (type instanceof DefinedType) {
        DefinedType dt = (DefinedType) type;
        TypeEntry exType = dt.getComplexTypeExtensionBase(symbolTable);
        if (exType != null)
            ex = map(pc, symbolTable, secondChanceConfig, tm, exType);
    }
    Vector children = type.getContainedElements();
    ArrayList<ASMPropertyImpl> properties = new ArrayList<ASMPropertyImpl>();
    if (children != null) {
        Iterator it = children.iterator();
        ElementDecl el;
        Class clazz;
        TypeEntry t;
        String name;
        while (it.hasNext()) {
            clazz = null;
            el = (ElementDecl) it.next();
            t = el.getType();
            Vector els = t.getContainedElements();
            // again handle children
            if (els != null) {
                clazz = mapComplex(pc, symbolTable, secondChanceConfig, tm, t);
            }
            name = lucee.runtime.type.util.ListUtil.last(el.getQName().getLocalPart(), '>');
            if (clazz == null)
                clazz = tm.getClassForQName(t.getQName());
            if (clazz == null)
                clazz = Object.class;
            properties.add(new ASMPropertyImpl(clazz, name));
        }
    }
    ASMProperty[] props = properties.toArray(new ASMProperty[properties.size()]);
    String clientClassName = getClientClassName(type, props);
    Class pojo;
    if (pc == null)
        pojo = ComponentUtil.getComponentPropertiesClass(secondChanceConfig, clientClassName, props, ex);
    else
        pojo = ComponentUtil.getClientComponentPropertiesClass(pc, clientClassName, props, ex);
    TypeMappingUtil.registerBeanTypeMapping(tm, pojo, type.getQName());
    return pojo;
}
Also used : ArrayList(java.util.ArrayList) DefinedType(org.apache.axis.wsdl.symbolTable.DefinedType) ElementDecl(org.apache.axis.wsdl.symbolTable.ElementDecl) TypeEntry(org.apache.axis.wsdl.symbolTable.TypeEntry) ASMProperty(lucee.transformer.bytecode.util.ASMProperty) ASMPropertyImpl(lucee.transformer.bytecode.util.ASMPropertyImpl) KeyIterator(lucee.runtime.type.it.KeyIterator) KeyAsStringIterator(lucee.runtime.type.it.KeyAsStringIterator) ObjectsIterator(lucee.runtime.type.it.ObjectsIterator) Iterator(java.util.Iterator) ObjectsEntryIterator(lucee.runtime.type.it.ObjectsEntryIterator) Vector(java.util.Vector)

Example 4 with TypeEntry

use of org.apache.axis.wsdl.symbolTable.TypeEntry in project tdi-studio-se by Talend.

the class DynamicInvoker method getParamData.

/**
     * Method getParamData
     * 
     * @param c
     * @param arg
     */
private Object getParamData(org.apache.axis.client.Call c, Parameter p, String arg) throws Exception {
    // Get the QName representing the parameter type
    QName paramType = org.apache.axis.wsdl.toJava.Utils.getXSIType(p);
    TypeEntry type = p.getType();
    if (type.isBaseType()) {
        DeserializerFactory factory = c.getTypeMapping().getDeserializer(paramType);
        Deserializer deserializer = factory.getDeserializerAs(Constants.AXIS_SAX);
        if (deserializer instanceof SimpleDeserializer) {
            return ((SimpleDeserializer) deserializer).makeValue(arg);
        }
    }
    throw new RuntimeException("not know how to convert '" + arg + "' into " + c);
}
Also used : ElementDeserializerFactory(org.apache.axis.encoding.ser.ElementDeserializerFactory) DeserializerFactory(javax.xml.rpc.encoding.DeserializerFactory) QName(javax.xml.namespace.QName) ElementDeserializer(org.apache.axis.encoding.ser.ElementDeserializer) SimpleDeserializer(org.apache.axis.encoding.ser.SimpleDeserializer) Deserializer(javax.xml.rpc.encoding.Deserializer) TypeEntry(org.apache.axis.wsdl.symbolTable.TypeEntry) SimpleDeserializer(org.apache.axis.encoding.ser.SimpleDeserializer)

Example 5 with TypeEntry

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

the class AxisCaster method toArray.

private static Object toArray(TypeMapping tm, TypeEntry typeEntry, QName type, Object value, Set<Object> done) throws PageException {
    if (type == null || !type.getLocalPart().startsWith("ArrayOf"))
        throw new ApplicationException("invalid call of the functionn toArray");
    // get component Type
    String tmp = type.getLocalPart().substring(7);
    QName componentType = null;
    // no arrayOf embeded anymore
    if (tmp.indexOf("ArrayOf") == -1 && typeEntry != null) {
        TypeEntry ref = typeEntry.getRefType();
        componentType = ref.getQName();
    }
    if (componentType == null) {
        if (tmp.startsWith("_tns1_"))
            tmp = tmp.substring(6);
        componentType = new QName(type.getNamespaceURI(), tmp);
    }
    Object[] objs = Caster.toNativeArray(value);
    Object[] rtns;
    List<Object> list = new ArrayList<Object>();
    Class componentClass = null;
    Object v;
    for (int i = 0; i < objs.length; i++) {
        v = _toAxisType(tm, null, typeEntry, componentType, null, objs[i], done);
        list.add(v);
        if (i == 0) {
            if (v != null)
                componentClass = v.getClass();
        } else {
            if (v == null || v.getClass() != componentClass)
                componentClass = null;
        }
    }
    if (componentClass != null) {
        componentClass = toAxisTypeClass(componentClass);
        rtns = (Object[]) java.lang.reflect.Array.newInstance(componentClass, objs.length);
    } else
        rtns = new Object[objs.length];
    return list.toArray(rtns);
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) TypeEntry(org.apache.axis.wsdl.symbolTable.TypeEntry)

Aggregations

TypeEntry (org.apache.axis.wsdl.symbolTable.TypeEntry)8 QName (javax.xml.namespace.QName)4 ArrayList (java.util.ArrayList)3 Key (lucee.runtime.type.Collection.Key)3 Entry (java.util.Map.Entry)2 Vector (java.util.Vector)2 Property (lucee.runtime.component.Property)2 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 TimeZone (java.util.TimeZone)1 Binding (javax.wsdl.Binding)1 Operation (javax.wsdl.Operation)1 Port (javax.wsdl.Port)1 Deserializer (javax.xml.rpc.encoding.Deserializer)1 DeserializerFactory (javax.xml.rpc.encoding.DeserializerFactory)1 TypeMapping (javax.xml.rpc.encoding.TypeMapping)1 ClassException (lucee.commons.lang.ClassException)1 PhysicalClassLoader (lucee.commons.lang.PhysicalClassLoader)1