incubator-yoko-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dmidd...@apache.org
Subject svn commit: r424419 - in /incubator/yoko/trunk/bindings/src: main/java/org/apache/yoko/bindings/corba/ test/java/org/apache/yoko/bindings/corba/
Date Fri, 21 Jul 2006 18:51:44 GMT
Author: dmiddlem
Date: Fri Jul 21 11:51:43 2006
New Revision: 424419

URL: http://svn.apache.org/viewvc?rev=424419&view=rev
Log:
Updates to corba binding (YOKO-40):
    - proper handling of Corba exceptions within a Yoko client
    - misc. corrections to method name spelling

Added:
    incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaExceptionHandler.java
Modified:
    incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaBindingImpl.java
    incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaClientBinding.java
    incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaDSIServant.java
    incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectHolder.java
    incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectReader.java
    incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectWriter.java
    incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaUtils.java
    incubator/yoko/trunk/bindings/src/test/java/org/apache/yoko/bindings/corba/CorbaObjectHolderTest.java

Modified: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaBindingImpl.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaBindingImpl.java?rev=424419&r1=424418&r2=424419&view=diff
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaBindingImpl.java
(original)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaBindingImpl.java
Fri Jul 21 11:51:43 2006
@@ -21,6 +21,8 @@
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Iterator;
@@ -376,38 +378,53 @@
 
     public void unmarshalFault(MessageContext mc, ObjectMessageContext objContext,
                                DataBindingCallback callback) {
-//        CorbaMessageContext corbaCtx = (CorbaMessageContext) mc;
+        CorbaMessageContext corbaCtx = (CorbaMessageContext) mc;
 
         try {
-//            This won't work for faults since we can not tell a DataReader using XMLEventReaders
to 
-//            read fault information.  They can only be used to read parameters and return
values. 
-//
-//            DataReader<XMLEventReader> reader = callback.createReader(XMLEventReader.class);
-//            if (reader == null) {
-//                throw new CorbaBindingException("Unable to create data reader");
-//            }
-//            
-//            XMLInputFactory inputFactory = XMLInputFactory.newInstance();
-//            XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
-//            outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
-//
-//            CorbaStreamable exStreamable = corbaCtx.getMessage().getStreamableException();
-//            ByteArrayOutputStream outStream = new ByteArrayOutputStream();
-//            XMLEventWriter evtWriter = outputFactory.createXMLEventWriter(outStream);
-//            writeCorbaObject(exStreamable.getObject(), evtWriter, null);
-//            evtWriter.flush();
-//     
-//            ByteArrayInputStream inStream = new ByteArrayInputStream(outStream.toByteArray());
-//            XMLEventReader evtReader = inputFactory.createXMLEventReader(inStream);
-//            Object obj = reader.read(new QName("exception"), -1, evtReader);
-//            
+            Method currentMethod = (Method)objContext.get(ObjectMessageContext.METHOD_OBJ);
+            Class<?>[] methodExs = currentMethod.getExceptionTypes();
+
+            CorbaMessage message = corbaCtx.getMessage();
+            CorbaStreamable streamableEx = message.getStreamableException();
+            CorbaObjectHolder exObject = streamableEx.getObject();
+            String name = exObject.getName().getLocalPart();
             
-            // TODO: Implement once we have support for exceptions
-            throw new CorbaBindingException("Method unmarshalFault not implemented");
+            Class exWrapperCls = null;
+            for (int i = 0; i < methodExs.length; ++i) {
+                // Right now, this assumes that all exceptions will have unique simple names.
 REVISIT.
+                if (name.equals(methodExs[i].getSimpleName())) {
+                    exWrapperCls = methodExs[i];
+                    break;
+                }
+            }
+
+            if (exWrapperCls == null) {
+                throw new CorbaBindingException("Unable to locate exception type in " 
+                                                + "declared exception list");
+            }
+
+            try {
+                Field exField = exWrapperCls.getDeclaredField("exception");
+                Class<?> exCls = exField.getType();
+                Object yokoEx = exCls.newInstance();
+
+                CorbaExceptionHandler.unmarshalCorbaException(exObject, yokoEx);
+                
+                Constructor exWrapperCtr = exWrapperCls.getConstructor(String.class, exCls);
+                Object exWrapper = exWrapperCtr.newInstance("", yokoEx);
+
+                // the wrapper should always be an instance of throwable
+                objContext.setException((Throwable)exWrapper);    
+
+                
+            } catch (java.lang.Exception ex) {
+                // rethrow to be caught below
+                throw ex;
+            }
+
         } catch (java.lang.Exception ex) {
             LOG.log(Level.SEVERE, "CORBA unmarshalFault exception", ex);
-            // TODO: Throw a exception proper exception once implemented
-            throw new CorbaBindingException("Method unmarshalFault not implemented");
+            throw new CorbaBindingException("CORBA unmarshalFault exception", ex);
         }
     }
 
@@ -692,7 +709,7 @@
             // not simply write character data to the event writer. Instead, they need 
             // to structure the data in the form of additional XML events and 
             // character data.
-            NamedType objType = obj.getTypeDefintion();
+            NamedType objType = obj.getTypeDefinition();
             if (objType instanceof Struct 
                 || objType instanceof Exception 
                 || objType instanceof Union
@@ -714,4 +731,4 @@
             throw new CorbaBindingException("writeCorbaObject exception", ex);
         }
     }
-}
\ No newline at end of file
+}

Modified: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaClientBinding.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaClientBinding.java?rev=424419&r1=424418&r2=424419&view=diff
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaClientBinding.java
(original)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaClientBinding.java
Fri Jul 21 11:51:43 2006
@@ -31,6 +31,7 @@
 import javax.wsdl.Port;
 import javax.wsdl.WSDLException;
 import javax.xml.namespace.QName;
+import javax.xml.ws.WebServiceException;
 
 import org.apache.schemas.yoko.bindings.corba.AddressType;
 import org.apache.schemas.yoko.bindings.corba.Exception;
@@ -222,19 +223,15 @@
                 }
                 corbaBinding.unmarshal(mc, objectCtx, callback);
             } else if (ex instanceof UnknownUserException) {
-                objectCtx.setException(ex);
+                UnknownUserException userEx = (UnknownUserException)ex;
+                Any exAny = userEx.except;
+                RaisesType raisesExType = exceptions.get(exAny.type());
                 
-                // TODO: Revisit.  This is only a temporary way around the exception handling.
-                // We need to address the issue with converting a corba exception into a
celtix
-                // fault to implement this properly.
-                
-                //UnknownUserException userEx = (UnknownUserException)ex;
-                //Any exAny = userEx.except;
-                //RaisesType raisesExType = exceptions.get(exAny.type());
-                //
-                //CorbaStreamable streamableEx = createStreamableException(exAny, raisesExType);
-                //mc.getMessage().setStreamableException(streamableEx);
-                //corbaBinding.unmarshalFault(mc, objectCtx, callback);
+                CorbaStreamable streamableEx = createStreamableException(exAny, raisesExType);
+                mc.getMessage().setStreamableException(streamableEx);
+                corbaBinding.unmarshalFault(mc, objectCtx, callback);
+            } else {
+                objectCtx.setException(new WebServiceException("Unknown CORBA return value"));
             }
         } catch (java.lang.Exception ex) {
             throw new CorbaBindingException("Exception during invoke", ex);
@@ -371,4 +368,4 @@
         
         return exStreamable;
     }
-}
\ No newline at end of file
+}

Modified: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaDSIServant.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaDSIServant.java?rev=424419&r1=424418&r2=424419&view=diff
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaDSIServant.java
(original)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaDSIServant.java
Fri Jul 21 11:51:43 2006
@@ -64,7 +64,7 @@
     private List<String> interfaces;
 
     public CorbaDSIServant(ORB theOrb, POA poa, CorbaServerBinding binding,
-            ServerBindingEndpointCallback epCallback) {
+                           ServerBindingEndpointCallback epCallback) {
         orb = theOrb;
         servantPOA = poa;
         serverBinding = binding;

Added: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaExceptionHandler.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaExceptionHandler.java?rev=424419&view=auto
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaExceptionHandler.java
(added)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaExceptionHandler.java
Fri Jul 21 11:51:43 2006
@@ -0,0 +1,133 @@
+package org.apache.yoko.bindings.corba;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Iterator;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.schemas.yoko.bindings.corba.Exception;
+
+import org.objectweb.celtix.common.logging.LogUtils;
+
+import org.omg.CORBA.TCKind;
+
+// This class exists to allow for the conversion of a Corba UserException into an
+// exception that a Yoko client/server can use.  The big issue with this conversion
+// occurs when going from a Corba UserException to a Yoko exception.  Currently, the
+// data readers/writers that we use to marshal and unmarshal regular data will
+// not support the marshalling/unmarshalling of exceptions when we use XML Events.
+// This class allows us to unmarshal the data correctly into an appropriate Yoko
+// exception object.
+
+public class CorbaExceptionHandler {
+
+    private static final Logger LOG = LogUtils.getL7dLogger(CorbaExceptionHandler.class);
+    
+    public static void unmarshalCorbaException(CorbaObjectHolder corbaEx, Object yokoEx)
+        throws CorbaBindingException {
+        try {
+            LOG.log(Level.INFO, "Preparing to unmarshal a CORBA exception");
+
+            Exception ex = (Exception)corbaEx.getTypeDefinition();
+            List<CorbaObjectHolder> exMembers = corbaEx.getNestedObjects();
+
+            for (Iterator i = exMembers.iterator(); i.hasNext();) {
+                CorbaObjectHolder member = (CorbaObjectHolder)i.next();
+                String memberName = member.getName().getLocalPart();
+                LOG.log(Level.INFO, "Setting field " + memberName);
+
+                Field field = yokoEx.getClass().getDeclaredField(memberName);
+                Method setMethod = getFieldSetMethod(memberName, yokoEx.getClass(), field);
+                setExceptionFieldValue(member, field, setMethod, yokoEx);
+            }
+        } catch (java.lang.Exception ex) {
+            LOG.log(Level.SEVERE, "Error during CORBA unmarshal exception: " + ex.getMessage());
+            throw new CorbaBindingException("Unable to unmarshal CORBA exception: " + ex.getMessage(),
ex);
+        }
+    }   
+
+    private static void setExceptionFieldValue(CorbaObjectHolder obj, Field field, 
+                                               Method setMethod, Object objInstance) 
+        throws CorbaBindingException {
+       
+        // These are special cases where the wrapper for the primitive type doesn't match
the 
+        // type used by the wsdl2java tool.  Make accomodations for these.  Otherwise, just

+        // invoke the setMethod with the object stored in the holder.  REVISIT: we may want

+        // to change the way the binding handles the data internally to make this step 
+        // unnecessary.
+        try {
+            switch (obj.getType().kind().value()) {
+            case TCKind._tk_boolean:
+                setMethod.invoke(objInstance, obj.getValue());
+                break;
+            case TCKind._tk_char:
+                setMethod.invoke(objInstance, Byte.valueOf((byte)((Character)obj.getValue()).charValue()));
+                break;
+            case TCKind._tk_wchar:
+                setMethod.invoke(objInstance, ((Character)obj.getValue()).toString());
+                break;
+            case TCKind._tk_octet:
+                setMethod.invoke(objInstance, Short.valueOf((Byte)obj.getValue()).shortValue());
+                break;
+            case TCKind._tk_short:
+            case TCKind._tk_ushort:
+                setMethod.invoke(objInstance, obj.getValue());
+                break;
+            case TCKind._tk_long:
+                setMethod.invoke(objInstance, Integer.valueOf(((Long)obj.getValue()).intValue()));
+                break;
+            case TCKind._tk_ulong:
+            case TCKind._tk_longlong:
+                setMethod.invoke(objInstance, Long.valueOf(((BigInteger)obj.getValue()).longValue()));
+                break;
+            case TCKind._tk_ulonglong:
+                setMethod.invoke(objInstance, obj.getValue());
+                break;
+            case TCKind._tk_float:
+                setMethod.invoke(objInstance, obj.getValue());
+                break;
+            case TCKind._tk_double:
+                setMethod.invoke(objInstance, obj.getValue());
+                break;
+            case TCKind._tk_string:
+            case TCKind._tk_wstring:
+                setMethod.invoke(objInstance, obj.getValue());
+                break;
+            case TCKind._tk_fixed:
+                setMethod.invoke(objInstance, new BigDecimal((String)obj.getValue()));
+                break;
+            //case TCKind._tk_enum:
+            default:
+                setMethod.invoke(objInstance, createExceptionField(obj, field.getClass()));
+                break;
+            }
+        } catch (java.lang.Exception ex) {
+            throw new CorbaBindingException("Unable to set the exception field " 
+                                            + obj.getName().getLocalPart(), ex);
+        }
+    }
+    
+    private static Object createExceptionField(CorbaObjectHolder obj, Class cls) 
+        throws CorbaBindingException {
+        // This method will allow for the creation of nested complex types within the exception.
+        // TODO: Provide implementation
+        throw new CorbaBindingException("Non-primitive exception fields not implemented yet.");
+    }
+
+    private static Method getFieldSetMethod(String fieldName, Class cls, Field field) 
+        throws CorbaBindingException {
+        Method setMethod = null;
+        String methodName = "set" + (char)(fieldName.charAt(0) - 'a' + 'A') + fieldName.substring(1);
+        try {
+            setMethod = cls.getMethod(methodName, field.getType());
+        } catch (java.lang.Exception ex) {
+            throw new CorbaBindingException("Unable to locate the 'set' method " + methodName,
ex);
+        }
+
+        return setMethod;
+    }
+}

Modified: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectHolder.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectHolder.java?rev=424419&r1=424418&r2=424419&view=diff
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectHolder.java
(original)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectHolder.java
Fri Jul 21 11:51:43 2006
@@ -62,7 +62,7 @@
         return idlType;
     }
 
-    public NamedType getTypeDefintion() {
+    public NamedType getTypeDefinition() {
         return typeDefinition;
     }
 

Modified: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectReader.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectReader.java?rev=424419&r1=424418&r2=424419&view=diff
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectReader.java
(original)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectReader.java
Fri Jul 21 11:51:43 2006
@@ -286,7 +286,7 @@
 
     public void readEnum(CorbaObjectHolder obj) throws CorbaBindingException {
         int enumIndex = stream.read_long();
-        Enum enumType = (Enum) obj.getTypeDefintion();
+        Enum enumType = (Enum) obj.getTypeDefinition();
         List<Enumerator> enumerators = enumType.getEnumerator();
 
         obj.setObjectValueFromData(enumerators.get(enumIndex).getValue());
@@ -320,7 +320,7 @@
 
     public void readFixed(CorbaObjectHolder obj) throws CorbaBindingException {
         // TODO: Update so we don't have to use toString here.
-        Fixed fixedType = (Fixed)obj.getTypeDefintion();
+        Fixed fixedType = (Fixed)obj.getTypeDefinition();
         long scale = fixedType.getScale();
         
         java.math.BigDecimal fixedValue = stream.read_fixed().movePointLeft((int)scale);
@@ -362,7 +362,7 @@
                 CorbaObjectHolder nestedObj = new CorbaObjectHolder(template.getName(),
                                                                     template.getIdlType(),
                                                                     template.getType(),
-                                                                    template.getTypeDefintion());
+                                                                    template.getTypeDefinition());
                 this.read(nestedObj);
                 obj.addNestedObject(nestedObj);
             }

Modified: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectWriter.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectWriter.java?rev=424419&r1=424418&r2=424419&view=diff
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectWriter.java
(original)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectWriter.java
Fri Jul 21 11:51:43 2006
@@ -179,7 +179,7 @@
     }
 
     public void writeEnum(CorbaObjectHolder type) throws CorbaBindingException {
-        Enum enumType = (Enum)type.getTypeDefintion();
+        Enum enumType = (Enum)type.getTypeDefinition();
         String enumLabel = type.getValueData();
         List<Enumerator> enumerators = enumType.getEnumerator();
         
@@ -207,7 +207,7 @@
     }
 
     public void writeException(CorbaObjectHolder type) throws CorbaBindingException {
-        Exception exType = (Exception)type.getTypeDefintion();
+        Exception exType = (Exception)type.getTypeDefinition();
         List<CorbaObjectHolder> exMembers = type.getNestedObjects();
     
         stream.write_string(exType.getRepositoryID());
@@ -217,7 +217,7 @@
     }
 
     public void writeFixed(CorbaObjectHolder type) throws CorbaBindingException {
-        Fixed fixedType = (Fixed)type.getTypeDefintion();
+        Fixed fixedType = (Fixed)type.getTypeDefinition();
         long scale = fixedType.getScale();
         
         java.math.BigDecimal fixedValue = new java.math.BigDecimal(type.getValueData());
@@ -262,4 +262,4 @@
         // TODO: Provide complete implementation
         return false; 
     }
-}
\ No newline at end of file
+}

Modified: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaUtils.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaUtils.java?rev=424419&r1=424418&r2=424419&view=diff
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaUtils.java
(original)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaUtils.java
Fri Jul 21 11:51:43 2006
@@ -348,7 +348,7 @@
         try {
             Port wsdlPort = EndpointReferenceUtils.getPort(bus.getWSDLManager(), endpointRef);
             Binding wsdlBinding = wsdlPort.getBinding();
-
+            
             List extElements = wsdlBinding.getExtensibilityElements();
             for (int i = 0; i < extElements.size(); ++i) {
                 Object e = extElements.get(i);

Modified: incubator/yoko/trunk/bindings/src/test/java/org/apache/yoko/bindings/corba/CorbaObjectHolderTest.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/test/java/org/apache/yoko/bindings/corba/CorbaObjectHolderTest.java?rev=424419&r1=424418&r2=424419&view=diff
==============================================================================
--- incubator/yoko/trunk/bindings/src/test/java/org/apache/yoko/bindings/corba/CorbaObjectHolderTest.java
(original)
+++ incubator/yoko/trunk/bindings/src/test/java/org/apache/yoko/bindings/corba/CorbaObjectHolderTest.java
Fri Jul 21 11:51:43 2006
@@ -84,7 +84,7 @@
         assertNotNull(tc);
         assertTrue(tc.kind().value() == objTypeCode.kind().value());
         
-        Object objDef = obj.getTypeDefintion();
+        Object objDef = obj.getTypeDefinition();
         assertNull(objDef);
     }
     



Mime
View raw message