You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by dj...@apache.org on 2005/04/24 02:28:28 UTC

svn commit: r164432 - /geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder /geronimo/trunk/modules/axis/src/java/org/apache/geronimo/axis/client

Author: djencks
Date: Sat Apr 23 17:28:28 2005
New Revision: 164432

URL: http://svn.apache.org/viewcvs?rev=164432&view=rev
Log:
Fix client encoding, and correct namespace for elementFormDefault=unqualified elements

Modified:
    geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/HeavyweightTypeInfoBuilder.java
    geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/SchemaInfoBuilder.java
    geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/SchemaTypeKey.java
    geronimo/trunk/modules/axis/src/java/org/apache/geronimo/axis/client/GenericServiceEndpoint.java
    geronimo/trunk/modules/axis/src/java/org/apache/geronimo/axis/client/OperationInfo.java
    geronimo/trunk/modules/axis/src/java/org/apache/geronimo/axis/client/SEIFactoryImpl.java

Modified: geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/HeavyweightTypeInfoBuilder.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/HeavyweightTypeInfoBuilder.java?rev=164432&r1=164431&r2=164432&view=diff
==============================================================================
--- geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/HeavyweightTypeInfoBuilder.java (original)
+++ geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/HeavyweightTypeInfoBuilder.java Sat Apr 23 17:28:28 2005
@@ -67,13 +67,12 @@
         for (int j = 0; j < javaXmlTypeMappings.length; j++) {
             JavaXmlTypeMappingType javaXmlTypeMapping = javaXmlTypeMappings[j];
 
-            QName typeQName;
             SchemaTypeKey key;
             boolean isElement = javaXmlTypeMapping.getQnameScope().getStringValue().equals("element");
             boolean isSimpleType = javaXmlTypeMapping.getQnameScope().getStringValue().equals("simpleType");
             if (javaXmlTypeMapping.isSetRootTypeQname()) {
-                typeQName = javaXmlTypeMapping.getRootTypeQname().getQNameValue();
-                key = new SchemaTypeKey(typeQName, isElement, isSimpleType, false);
+                QName typeQName = javaXmlTypeMapping.getRootTypeQname().getQNameValue();
+                key = new SchemaTypeKey(typeQName, isElement, isSimpleType, false, null);
 
                 // Skip the wrapper elements.
                 if (wrapperElementQNames.contains(typeQName)) {
@@ -87,8 +86,8 @@
                 }
 
                 //this appears to be ignored...
-                typeQName = new QName(anonTypeQNameString.substring(0, pos), anonTypeQNameString.substring(pos + 1));
-                key = new SchemaTypeKey(typeQName, isElement, isSimpleType, true);
+                QName typeQName = new QName(anonTypeQNameString.substring(0, pos), anonTypeQNameString.substring(pos + 1));
+                key = new SchemaTypeKey(typeQName, isElement, isSimpleType, true, null);
 
                 // Skip the wrapper elements.
                 if (wrapperElementQNames.contains(new QName(anonTypeQNameString.substring(0, pos), anonTypeQNameString.substring(pos + 2)))) {
@@ -121,11 +120,11 @@
 
             TypeInfo.UpdatableTypeInfo internalTypeInfo = new TypeInfo.UpdatableTypeInfo();
             internalTypeInfo.setClazz(clazz);
-            internalTypeInfo.setQName(typeQName);
+
             internalTypeInfo.setSerializerClass(serializerFactoryClass);
             internalTypeInfo.setDeserializerClass(deserializerFactoryClass);
 
-            populateInternalTypeInfo(clazz, typeQName, key, javaXmlTypeMapping, internalTypeInfo);
+            populateInternalTypeInfo(clazz, key, javaXmlTypeMapping, internalTypeInfo);
 
             typeInfoList.add(internalTypeInfo.buildTypeInfo());
         }
@@ -133,7 +132,7 @@
         return typeInfoList;
     }
 
-    private void populateInternalTypeInfo(Class javaClass, QName typeQName, SchemaTypeKey key, JavaXmlTypeMappingType javaXmlTypeMapping, TypeInfo.UpdatableTypeInfo typeInfo) throws DeploymentException {
+    private void populateInternalTypeInfo(Class javaClass, SchemaTypeKey key, JavaXmlTypeMappingType javaXmlTypeMapping, TypeInfo.UpdatableTypeInfo typeInfo) throws DeploymentException {
         SchemaType schemaType = (SchemaType) schemaTypeKeyToSchemaTypeMap.get(key);
         if (schemaType == null) {
             throw new DeploymentException("Schema type key " + key + " not found in analyzed schema: " + schemaTypeKeyToSchemaTypeMap);
@@ -141,6 +140,12 @@
         String ns = key.getqName().getNamespaceURI();
         typeInfo.setCanSearchParents(schemaType.getDerivationType() == SchemaType.DT_RESTRICTION);
 
+        //figure out the name axis expects to look up under.
+        QName axisKey = key.getElementQName();
+        if (axisKey == null) {
+            axisKey = key.getqName();
+        }
+        typeInfo.setQName(axisKey);
 
         Map nameToType = new HashMap();
         if (null  == schemaType.getContentModel()) {

Modified: geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/SchemaInfoBuilder.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/SchemaInfoBuilder.java?rev=164432&r1=164431&r2=164432&view=diff
==============================================================================
--- geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/SchemaInfoBuilder.java (original)
+++ geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/SchemaInfoBuilder.java Sat Apr 23 17:28:28 2005
@@ -384,6 +384,7 @@
         //TODO is this null if element is a ref?
         QName elementName = element.getName();
         String elementNamespace = elementName.getNamespaceURI();
+        //"" namespace means local element with elementFormDefault="unqualified"
         if (elementNamespace == null || elementNamespace.equals("")) {
             elementNamespace = key.getqName().getNamespaceURI();
         }
@@ -392,14 +393,14 @@
         if (key == null) {
             //top level. rule 2.a,
             elementQNameLocalName = elementName.getLocalPart();
-            elementKey = new SchemaTypeKey(elementName, true, false, false);
+            elementKey = new SchemaTypeKey(elementName, true, false, false, elementName);
         } else {
             //not top level. rule 2.b, key will be for enclosing Type.
             QName enclosingTypeQName = key.getqName();
             String enclosingTypeLocalName = enclosingTypeQName.getLocalPart();
             elementQNameLocalName = enclosingTypeLocalName + ">" + elementName.getLocalPart();
             QName subElementName = new QName(elementNamespace, elementQNameLocalName);
-            elementKey = new SchemaTypeKey(subElementName, true, false, true);
+            elementKey = new SchemaTypeKey(subElementName, true, false, true, elementName);
         }
         SchemaType schemaType = element.getType();
         qnameMap.put(elementKey, schemaType);
@@ -419,7 +420,7 @@
     }
 
     private void addSchemaType(QName typeQName, SchemaType schemaType, boolean anonymous, Map qnameMap) {
-        SchemaTypeKey typeKey = new SchemaTypeKey(typeQName, false, schemaType.isSimpleType(), anonymous);
+        SchemaTypeKey typeKey = new SchemaTypeKey(typeQName, false, schemaType.isSimpleType(), anonymous, null);
         qnameMap.put(typeKey, schemaType);
 //        new Exception("Adding: " + typeKey.getqName().getLocalPart()).printStackTrace();
         //TODO xmlbeans recommends using summary info from getElementProperties and getAttributeProperties instead of traversing the content model by hand.
@@ -474,14 +475,14 @@
                 elementNamespace = keyName.getNamespaceURI();
             }
             QName arrayName = new QName(elementNamespace, arrayQNameLocalName);
-            SchemaTypeKey arrayKey = new SchemaTypeKey(arrayName, false, false, true);
+            SchemaTypeKey arrayKey = new SchemaTypeKey(arrayName, false, false, true, elementName);
             //TODO not clear we want the schemaType as the value
             qnameMap.put(arrayKey, elementType);
 //            new Exception("Adding: " + arrayKey.getqName().getLocalPart()).printStackTrace();
             if (minOccurs == 1) {
                 arrayQNameLocalName = keyName.getLocalPart() + "[," + maxOccurs + "]";
                 arrayName = new QName(elementNamespace, arrayQNameLocalName);
-                arrayKey = new SchemaTypeKey(arrayName, false, false, true);
+                arrayKey = new SchemaTypeKey(arrayName, false, false, true, elementName);
                 //TODO not clear we want the schemaType as the value
                 qnameMap.put(arrayKey, elementType);
             }

Modified: geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/SchemaTypeKey.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/SchemaTypeKey.java?rev=164432&r1=164431&r2=164432&view=diff
==============================================================================
--- geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/SchemaTypeKey.java (original)
+++ geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/SchemaTypeKey.java Sat Apr 23 17:28:28 2005
@@ -32,8 +32,10 @@
     private final boolean isSimpleType;
     private final boolean isAnonymous;
 
+    private final QName elementQName;
 
-    public SchemaTypeKey(QName qName, boolean element, boolean isSimpleType, boolean anonymous) {
+
+    public SchemaTypeKey(QName qName, boolean element, boolean isSimpleType, boolean anonymous, QName elementQName) {
         assert qName != null;
         this.qName = qName;
         isElement = element;
@@ -46,6 +48,7 @@
         } else {
             qNameScope = QNAME_SCOPE_COMPLEX_TYPE;
         }
+        this.elementQName = elementQName;
     }
 
     public QName getqName() {
@@ -66,6 +69,10 @@
 
     public String getqNameScope() {
         return qNameScope;
+    }
+
+    public QName getElementQName() {
+        return elementQName;
     }
 
     public int hashCode() {

Modified: geronimo/trunk/modules/axis/src/java/org/apache/geronimo/axis/client/GenericServiceEndpoint.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/axis/src/java/org/apache/geronimo/axis/client/GenericServiceEndpoint.java?rev=164432&r1=164431&r2=164432&view=diff
==============================================================================
--- geronimo/trunk/modules/axis/src/java/org/apache/geronimo/axis/client/GenericServiceEndpoint.java (original)
+++ geronimo/trunk/modules/axis/src/java/org/apache/geronimo/axis/client/GenericServiceEndpoint.java Sat Apr 23 17:28:28 2005
@@ -17,9 +17,6 @@
 package org.apache.geronimo.axis.client;
 
 import java.net.URL;
-import java.util.Iterator;
-import java.util.List;
-
 import javax.xml.namespace.QName;
 
 import org.apache.axis.AxisFault;
@@ -32,13 +29,12 @@
  */
 public class GenericServiceEndpoint extends org.apache.axis.client.Stub {
 
-    private final List typeInfo;
 
-    public GenericServiceEndpoint(QName portQName, Service service, List typeInfo, URL location) {
+    public GenericServiceEndpoint(QName portQName, Service service, URL location) {
         this.service = service;
-        this.typeInfo = typeInfo;
         cachedEndpoint = location;
         cachedPortName = portQName;
+
     }
 
     Call createCall() throws java.rmi.RemoteException {
@@ -74,18 +70,27 @@
             // the TypeMappingRegistry of the service, which
             // is the reason why registration is only needed for the first call.
             //TODO figure out if this can be done during deployment!
-            synchronized (this) {
-                if (firstCall()) {
-                    // must set encoding style before registering serializers
-                    //TODO these constants probably need to be parameters of GSE.
-                    _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
-                    _call.setEncodingStyle(org.apache.axis.Constants.URI_SOAP11_ENC);
-                    for (Iterator iterator = typeInfo.iterator(); iterator.hasNext();) {
-                        TypeInfo info = (TypeInfo) iterator.next();
-                        _call.registerTypeMapping(info.getClazz(), info.getqName(), info.getSerFactoryClass(), info.getDeserFactoryClass(), false);
-                    }
-                }
-            }
+//            synchronized (this) {
+//                if (firstCall()) {
+//                    // must set encoding style before registering serializers
+//                    //TODO these constants probably need to be parameters of GSE.
+//                    _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
+////                    _call.setEncodingStyle(org.apache.axis.Constants.URI_SOAP11_ENC);
+//                    //override unsigned long mapping
+//                    _call.registerTypeMapping(BigInteger.class,
+//                            Constants.XSD_UNSIGNEDLONG,
+//                            new SimpleSerializerFactory(BigInteger.class, Constants.XSD_UNSIGNEDLONG),
+//                            new SimpleDeserializerFactory(BigInteger.class, Constants.XSD_UNSIGNEDLONG));
+//                    _call.registerTypeMapping(URI.class,
+//                            Constants.XSD_ANYURI,
+//                            new SimpleSerializerFactory(URI.class, Constants.XSD_ANYURI),
+//                            new SimpleDeserializerFactory(URI.class, Constants.XSD_ANYURI));
+//                    for (Iterator iterator = typeInfo.iterator(); iterator.hasNext();) {
+//                        TypeInfo info = (TypeInfo) iterator.next();
+//                        _call.registerTypeMapping(info.getClazz(), info.getqName(), info.getSerFactoryClass(), info.getDeserFactoryClass(), false);
+//                    }
+//                }
+//            }
             return _call;
         } catch (java.lang.Throwable t) {
             throw new org.apache.axis.AxisFault("Failure trying to get the Call object", t);

Modified: geronimo/trunk/modules/axis/src/java/org/apache/geronimo/axis/client/OperationInfo.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/axis/src/java/org/apache/geronimo/axis/client/OperationInfo.java?rev=164432&r1=164431&r2=164432&view=diff
==============================================================================
--- geronimo/trunk/modules/axis/src/java/org/apache/geronimo/axis/client/OperationInfo.java (original)
+++ geronimo/trunk/modules/axis/src/java/org/apache/geronimo/axis/client/OperationInfo.java Sat Apr 23 17:28:28 2005
@@ -78,5 +78,8 @@
         call.setSOAPActionURI(soapActionURI);
         call.setSOAPVersion(soapVersion);
         call.setOperationName(operationName);
+        //GAH!!!
+        call.setOperationStyle(operationDesc.getStyle());
+        call.setOperationUse(operationDesc.getUse());
     }
 }

Modified: geronimo/trunk/modules/axis/src/java/org/apache/geronimo/axis/client/SEIFactoryImpl.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/axis/src/java/org/apache/geronimo/axis/client/SEIFactoryImpl.java?rev=164432&r1=164431&r2=164432&view=diff
==============================================================================
--- geronimo/trunk/modules/axis/src/java/org/apache/geronimo/axis/client/SEIFactoryImpl.java (original)
+++ geronimo/trunk/modules/axis/src/java/org/apache/geronimo/axis/client/SEIFactoryImpl.java Sat Apr 23 17:28:28 2005
@@ -22,12 +22,16 @@
 import java.lang.reflect.InvocationTargetException;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.net.URI;
 import java.rmi.Remote;
 import java.util.Iterator;
 import java.util.List;
+import java.math.BigInteger;
 
 import javax.xml.namespace.QName;
 import javax.xml.rpc.ServiceException;
+import javax.xml.rpc.encoding.SerializerFactory;
+import javax.xml.rpc.encoding.DeserializerFactory;
 import javax.xml.rpc.handler.HandlerChain;
 
 import net.sf.cglib.core.Signature;
@@ -40,6 +44,15 @@
 import org.apache.axis.client.Service;
 import org.apache.axis.description.TypeDesc;
 import org.apache.axis.handlers.HandlerInfoChainFactory;
+import org.apache.axis.AxisEngine;
+import org.apache.axis.Constants;
+import org.apache.axis.constants.Use;
+import org.apache.axis.encoding.TypeMappingRegistry;
+import org.apache.axis.encoding.TypeMapping;
+import org.apache.axis.encoding.ser.SimpleSerializerFactory;
+import org.apache.axis.encoding.ser.SimpleDeserializerFactory;
+import org.apache.axis.encoding.ser.BaseSerializerFactory;
+import org.apache.axis.encoding.ser.BaseDeserializerFactory;
 
 /**
  * @version $Rev:  $ $Date:  $
@@ -59,6 +72,7 @@
     private final String credentialsName;
     private transient HandlerInfoChainFactory handlerInfoChainFactory;
     private transient OperationInfo[] sortedOperationInfos;
+    private boolean initialized = false;
 
     public SEIFactoryImpl(QName serviceName, String portName, Class serviceEndpointClass, OperationInfo[] operationInfos, Object serviceImpl, List typeInfo, URL location, List handlerInfos, ClassLoader classLoader, String credentialsName) throws ClassNotFoundException {
         this.serviceName = serviceName;
@@ -66,7 +80,7 @@
         this.serviceEndpointClass = serviceEndpointClass;
         this.operationInfos = operationInfos;
         Class[] constructorTypes = new java.lang.Class[0];
-            constructorTypes = classLoader == null? SERVICE_ENDPOINT_CONSTRUCTOR_TYPES: new Class[] {classLoader.loadClass(GenericServiceEndpoint.class.getName())};
+        constructorTypes = classLoader == null ? SERVICE_ENDPOINT_CONSTRUCTOR_TYPES : new Class[]{classLoader.loadClass(GenericServiceEndpoint.class.getName())};
         this.constructor = FastClass.create(serviceEndpointClass).getConstructor(constructorTypes);
         this.serviceImpl = serviceImpl;
         this.typeInfo = typeInfo;
@@ -75,6 +89,10 @@
         this.credentialsName = credentialsName;
         this.handlerInfoChainFactory = new HandlerInfoChainFactory(handlerInfos);
         sortedOperationInfos = new OperationInfo[FastClass.create(serviceEndpointClass).getMaxIndex() + 1];
+    }
+
+    void initialize() {
+        String encodingStyle = "";
         for (int i = 0; i < operationInfos.length; i++) {
             OperationInfo operationInfo = operationInfos[i];
             Signature signature = operationInfo.getSignature();
@@ -84,17 +102,46 @@
             }
             int index = methodProxy.getSuperIndex();
             sortedOperationInfos[index] = operationInfo;
+            if (operationInfo.getOperationDesc().getUse() == Use.ENCODED) {
+                encodingStyle = org.apache.axis.Constants.URI_SOAP11_ENC;
+            }
         }
         //register our type descriptors
-        for (Iterator iterator = typeInfo.iterator(); iterator.hasNext();) {
-            TypeInfo info = (TypeInfo) iterator.next();
+        Service service = ((ServiceImpl) serviceImpl).getService();
+        AxisEngine axisEngine = service.getEngine();
+        TypeMappingRegistry typeMappingRegistry = axisEngine.getTypeMappingRegistry();
+        TypeMapping typeMapping = typeMappingRegistry.getOrMakeTypeMapping(encodingStyle);
+        typeMapping.register(BigInteger.class,
+                Constants.XSD_UNSIGNEDLONG,
+                new SimpleSerializerFactory(BigInteger.class, Constants.XSD_UNSIGNEDLONG),
+                new SimpleDeserializerFactory(BigInteger.class, Constants.XSD_UNSIGNEDLONG));
+        typeMapping.register(URI.class,
+                Constants.XSD_ANYURI,
+                new SimpleSerializerFactory(URI.class, Constants.XSD_ANYURI),
+                new SimpleDeserializerFactory(URI.class, Constants.XSD_ANYURI));
+
+        for (Iterator iter = typeInfo.iterator(); iter.hasNext();) {
+            TypeInfo info = (TypeInfo) iter.next();
             TypeDesc.registerTypeDescForClass(info.getClazz(), info.buildTypeDesc());
+
+            SerializerFactory sf =
+                    BaseSerializerFactory.createFactory(info.getSerFactoryClass(), info.getClazz(), info.getqName());
+            DeserializerFactory df =
+                    BaseDeserializerFactory.createFactory(info.getDeserFactoryClass(), info.getClazz(), info.getqName());
+            typeMapping.register(info.getClazz(), info.getqName(), sf, df);
         }
     }
 
     public Remote createServiceEndpoint() throws ServiceException {
-        Service service = ((ServiceImpl)serviceImpl).getService();
-        GenericServiceEndpoint serviceEndpoint = new GenericServiceEndpoint(portQName, service, typeInfo, location);
+        //TODO figure out why this can't be called in readResolve!
+        synchronized (this) {
+            if (!initialized) {
+                initialize();
+                initialized = true;
+            }
+        }
+        Service service = ((ServiceImpl) serviceImpl).getService();
+        GenericServiceEndpoint serviceEndpoint = new GenericServiceEndpoint(portQName, service, location);
         Callback callback = new ServiceEndpointMethodInterceptor(serviceEndpoint, sortedOperationInfos, credentialsName);
         Callback[] callbacks = new Callback[]{SerializableNoOp.INSTANCE, callback};
         Enhancer.registerCallbacks(serviceEndpointClass, callbacks);
@@ -113,7 +160,9 @@
 
     private Object readResolve() throws ObjectStreamException {
         try {
-            return new SEIFactoryImpl(serviceName, portQName.getLocalPart(), serviceEndpointClass, operationInfos, serviceImpl, typeInfo, location, handlerInfos, null, credentialsName);
+            SEIFactoryImpl seiFactory =  new SEIFactoryImpl(serviceName, portQName.getLocalPart(), serviceEndpointClass, operationInfos, serviceImpl, typeInfo, location, handlerInfos, null, credentialsName);
+//            seiFactory.initialize();
+            return seiFactory;
         } catch (ClassNotFoundException e) {
             throw new InvalidClassException(GenericServiceEndpoint.class.getName(), "this is impossible");
         }
@@ -133,9 +182,8 @@
 
     public URL getWSDLDocumentLocation() {
         try {
-            return new URL(location.toExternalForm()+"?wsdl");
-        }
-        catch (MalformedURLException e) {
+            return new URL(location.toExternalForm() + "?wsdl");
+        } catch (MalformedURLException e) {
             return null;
         }
     }