2010-02-03 Jonathan Pobst <monkey@jpobst.com>
[mono.git] / mcs / class / System.Runtime.Remoting / System.Runtime.Remoting.Channels / SoapMessageFormatter.cs
index 5fb2be17c23dd37f74495d2c58f57bafb3596931..85c71a1c0264c558a0a260a5e401901f2db11e94 100644 (file)
@@ -5,27 +5,27 @@
 // Author:     Jean-Marc Andre (jean-marc.andre@polymtl.ca)\r
 //\r
 //\r
-
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-// 
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-// 
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
+\r
+//\r
+// Permission is hereby granted, free of charge, to any person obtaining\r
+// a copy of this software and associated documentation files (the\r
+// "Software"), to deal in the Software without restriction, including\r
+// without limitation the rights to use, copy, modify, merge, publish,\r
+// distribute, sublicense, and/or sell copies of the Software, and to\r
+// permit persons to whom the Software is furnished to do so, subject to\r
+// the following conditions:\r
+// \r
+// The above copyright notice and this permission notice shall be\r
+// included in all copies or substantial portions of the Software.\r
+// \r
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+//\r
 \r
 using System;\r
 using System.Collections;\r
@@ -74,6 +74,34 @@ namespace System.Runtime.Remoting.Channels {
                        if (sf != null) {\r
                                if(_serverFaultExceptionField != null)\r
                                        e = (Exception) _serverFaultExceptionField.GetValue(sf);\r
+#if TARGET_JVM                         \r
+                               if (e == null && sf.ExceptionType != null)\r
+                               {\r
+                                       try\r
+                                       {\r
+                                               Type te = Type.GetType(sf.ExceptionType);\r
+                                               if (te != null)\r
+                                               {\r
+                                                       ConstructorInfo ce = te.GetConstructor(\r
+                                                               BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.CreateInstance,\r
+                                                               null, new Type[] {typeof(string)}, null);\r
+\r
+                                                       if (ce != null)\r
+                                                       {\r
+                                                               e = (Exception) ce.Invoke(new object[] {sf.ExceptionMessage});\r
+                                                       }\r
+                                                       else\r
+                                                       {\r
+                                                               e = (Exception) Activator.CreateInstance(te);\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                                       catch\r
+                                       {\r
+                                               e = null;\r
+                                       }\r
+                               }\r
+#endif\r
                        }\r
                        if (e == null)\r
                                e = new RemotingException (fault.FaultString);\r
@@ -194,9 +222,18 @@ namespace System.Runtime.Remoting.Channels {
                        headersList.Add(new Header("__Uri", uri));\r
                        headersList.Add(new Header("__MethodName", soapMessage.MethodName));\r
                        string typeNamespace, assemblyName;\r
-                       SoapServices.DecodeXmlNamespaceForClrTypeNamespace(soapMessage.XmlNameSpace, out typeNamespace, out assemblyName);\r
 \r
-                       _serverType = RemotingServices.GetServerTypeForUri(uri);\r
+                       if (!SoapServices.DecodeXmlNamespaceForClrTypeNamespace(soapMessage.XmlNameSpace, out typeNamespace, out assemblyName))\r
+                               throw new RemotingException ("Could not decode SoapMessage");\r
+\r
+                       // Note that we don't need to validate the type in\r
+                       // this place because MethodCall will do it anyway.\r
+\r
+                       if (assemblyName == null) // corlib\r
+                               _serverType = Type.GetType (typeNamespace, true);\r
+                       else\r
+                               _serverType = Type.GetType (typeNamespace + ", " + assemblyName, true);\r
+\r
                        headersList.Add(new Header("__TypeName", _serverType.FullName, false));\r
                        \r
                        if (soapMessage.Headers != null) {\r
@@ -215,7 +252,10 @@ namespace System.Runtime.Remoting.Channels {
                        if (signature == null)\r
                                _methodCallInfo = _serverType.GetMethod(soapMessage.MethodName, bflags); \r
                        else\r
-                               _methodCallInfo = _serverType.GetMethod(soapMessage.MethodName, bflags, null, signature, null); \r
+                               _methodCallInfo = _serverType.GetMethod(soapMessage.MethodName, bflags, null, signature, null);\r
+                               \r
+                       if (_methodCallInfo == null && (soapMessage.MethodName == "FieldSetter" || soapMessage.MethodName == "FieldGetter"))\r
+                               _methodCallInfo = typeof(object).GetMethod (soapMessage.MethodName, bflags);\r
 \r
                        // the *out* parameters aren't serialized\r
                        // have to add them here\r
@@ -292,7 +332,7 @@ namespace System.Runtime.Remoting.Channels {
                        }\r
                        else {\r
                                // an Exception was thrown while executing the function\r
-                               responseHeaders["__HttpStatusCode"] = "400";\r
+                               responseHeaders["__HttpStatusCode"] = "500";\r
                                responseHeaders["__HttpReasonPhrase"] = "Bad Request";\r
                                // fill the transport headers\r
                                responseHeaders["Content-Type"] = "text/xml; charset=\"utf-8\"";\r
@@ -349,17 +389,9 @@ namespace System.Runtime.Remoting.Channels {
                        return sf;\r
                }\r
 \r
-               internal void GetInfoFromMethodCallMessage(IMethodCallMessage mcm) {\r
+               internal void GetInfoFromMethodCallMessage (IMethodMessage mcm) {\r
                        _serverType = Type.GetType(mcm.TypeName, true);\r
-                       \r
-                       if (mcm.MethodSignature != null) \r
-                               _methodCallInfo = _serverType.GetMethod(mcm.MethodName, \r
-                                                                                                               BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, \r
-                                                                                                               null, (Type []) mcm.MethodSignature, null);\r
-                       else\r
-                               _methodCallInfo = _serverType.GetMethod(mcm.MethodName, \r
-                                                                                                               BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);\r
-\r
+                       _methodCallInfo = RemotingServices.GetMethodBaseFromMethodMessage (mcm) as MethodInfo;\r
                        _methodCallParameters = _methodCallInfo.GetParameters();\r
                }       \r
                \r
@@ -399,6 +431,12 @@ namespace System.Runtime.Remoting.Channels {
                \r
                object GetNullValue (Type paramType)\r
                {\r
+#if TARGET_JVM                 \r
+                       if (paramType.IsEnum)\r
+                       {\r
+                               return Activator.CreateInstance(paramType);\r
+                       }\r
+#endif\r
                        switch (Type.GetTypeCode (paramType))\r
                        {\r
                                case TypeCode.Boolean: return false;\r
@@ -414,8 +452,15 @@ namespace System.Runtime.Remoting.Channels {
                                case TypeCode.UInt16: return (ushort)0;\r
                                case TypeCode.UInt32: return (uint)0;\r
                                case TypeCode.UInt64: return (ulong)0;\r
-                               default: return null;\r
+                               default: \r
+#if TARGET_JVM                 \r
+                                       if (paramType.IsValueType)\r
+                                       {\r
+                                               return Activator.CreateInstance(paramType);\r
+                                       }\r
+#endif                                 \r
+                                       return null;\r
                        }\r
                }\r
        }\r
-}
+}\r