private void EndReadReply(IAsyncResult asyncResult) { HessianMethodCall call = (HessianMethodCall)asyncResult.AsyncState; try { HttpWebResponse response = (HttpWebResponse)call.request.EndGetResponse(asyncResult); if (response.StatusCode != HttpStatusCode.OK) { ReadAndThrowHttpFault(response); } using (Stream stream = response.GetResponseStream()) { AbstractHessianInput hessianInput = GetHessianInput(stream); call.result = hessianInput.ReadReply(call.methodInfo.ReturnType); response.Close(); } } catch (CHessianException e) { call.result = null; call.exception = e.InnerException; } catch (Exception e) { call.result = null; call.exception = e; } EndHessianMethodCall(call); }
public override Object ReadMap(AbstractHessianInput abstractHessianInput) { String value = null; while (!abstractHessianInput.IsEnd()) { String key = abstractHessianInput.ReadString(); if (key.Equals("value")) { value = abstractHessianInput.ReadString(); } else { abstractHessianInput.ReadObject(); } } abstractHessianInput.ReadMapEnd(); Object obj = Create(value); abstractHessianInput.AddRef(obj); return(obj); }
/// <summary> /// Reads and decodes the reply. /// </summary> /// <param name="webRequest"></param> /// <returns></returns> protected object ReadReply(WebRequest webRequest, MethodInfo methodInfo, out Stream sInStream, out int totalBytesRead) { HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse(); if (webResponse.StatusCode != HttpStatusCode.OK) { ReadAndThrowHttpFault(webResponse); } sInStream = webResponse.GetResponseStream(); if (webResponse.ContentEncoding.ToLower().Contains("gzip")) { sInStream = new GZipStream(sInStream, CompressionMode.Decompress); } else if (webResponse.ContentEncoding.ToLower().Contains("deflate")) { sInStream = new DeflateStream(sInStream, CompressionMode.Decompress); } BufferedStream bStream = new BufferedStream(sInStream, 4096); AbstractHessianInput hessianInput = this.GetHessianInput(bStream); object result = hessianInput.ReadReply(methodInfo.ReturnType); totalBytesRead = ((CHessianInput)hessianInput).GetTotalBytesRead(); return(result); }
/// <summary> /// Invoke the object with the request from the input stream. /// </summary> /// <param name="inHessian">the Hessian input stream</param> /// <param name="outHessian">the Hessian output stream</param> public void invoke(AbstractHessianInput inHessian, AbstractHessianOutput outHessian) { inHessian.StartCall(); MethodInfo methodInf = getMethodInfo(inHessian.Method); //If the method doesn't exist if (methodInf == null) { outHessian.StartReply(); outHessian.WriteFault("NoSuchMethodException", "The service has no method named: " + inHessian.Method, null); outHessian.CompleteReply(); return; } ParameterInfo[] paramInfo = methodInf.GetParameters(); Object[] valuesParam = new Object[paramInfo.Length]; for (int i = 0; i < paramInfo.Length; i++) { valuesParam[i] = inHessian.ReadObject(paramInfo[i].ParameterType); } inHessian.CompleteCall(); Object result = null; try { result = methodInf.Invoke(m_Service, valuesParam); } catch (Exception e) { //TODO: Exception besser behandeln if (e.GetType() == typeof(System.Reflection.TargetInvocationException)) { if (e.InnerException != null) { e = e.InnerException; } } outHessian.StartReply(); outHessian.WriteFault("ServiceException", e.Message, e); outHessian.CompleteReply(); return; } outHessian.StartReply(); outHessian.WriteObject(result); outHessian.CompleteReply(); }
public override object ReadMap(AbstractHessianInput abstractHessianInput) { String strInitValue = null; while (!abstractHessianInput.IsEnd()) { string strKey = abstractHessianInput.ReadString(); string strValue = abstractHessianInput.ReadString(); if (strKey.Equals("value")) strInitValue = strValue; } abstractHessianInput.ReadMapEnd(); if (strInitValue == null) throw new IOException("No value found for decimal."); return Decimal.Parse(strInitValue); }
public override Object ReadObject(AbstractHessianInput abstractHessianInput, Object[] fields) { String[] fieldNames = (String[])fields; String value = null; for (int i = 0; i < fieldNames.Length; i++) { if ("value".Equals(fieldNames[i])) { value = abstractHessianInput.ReadString(); } else { abstractHessianInput.ReadObject(); } } object obj = Create(value); abstractHessianInput.AddRef(obj); return(obj); }
public override object ReadMap(AbstractHessianInput abstractHessianInput) { Hashtable fieldValueMap = new Hashtable(); string _message = null; Exception _innerException = null; while (! abstractHessianInput.IsEnd()) { object objKey = abstractHessianInput.ReadObject(); if(objKey != null) { IDictionary deserFields = GetDeserializableFields(); FieldInfo field = (FieldInfo) deserFields[objKey]; // try to convert a Java Exception in a .NET exception if(objKey.ToString() == "_message" || objKey.ToString() == "detailMessage") { if (field != null) _message = abstractHessianInput.ReadObject(field.FieldType) as string; else _message = abstractHessianInput.ReadObject().ToString(); } else if(objKey.ToString() == "_innerException" || objKey.ToString() == "cause") { try { if (field != null) _innerException = abstractHessianInput.ReadObject(field.FieldType) as Exception; else _innerException = abstractHessianInput.ReadObject(typeof(Exception)) as Exception; } catch (Exception e) { // als Cause ist bei Java gerne mal eine zirkuläre Referenz auf die Exception selbst // angegeben. Das klappt nicht, weil die Referenz noch nicht registriert ist, // weil der Typ noch nicht klar ist (s.u.) } } else { if (field != null) { object objFieldValue = abstractHessianInput.ReadObject(field.FieldType); fieldValueMap.Add(field, objFieldValue); } else // ignore (z. B. Exception Stacktrace "stackTrace" von Java) abstractHessianInput.ReadObject(); //field.SetValue(result, objFieldValue); } } } abstractHessianInput.ReadEnd(); object result = null; try { #if COMPACT_FRAMEWORK //CF TODO: tbd #else try { result = Activator.CreateInstance(this.m_type, new object[2]{_message, _innerException}); } catch(Exception) { try { result = Activator.CreateInstance(this.m_type, new object[1]{_innerException}); } catch(Exception) { try { result = Activator.CreateInstance(this.m_type, new object[1]{_message}); } catch(Exception) { result = Activator.CreateInstance(this.m_type); } } } #endif } catch(Exception) { result = new Exception(_message, _innerException); } foreach (DictionaryEntry entry in fieldValueMap) { FieldInfo fieldInfo = (FieldInfo) entry.Key; object value = entry.Value; try {fieldInfo.SetValue(result, value);} catch(Exception){} } // besser spät als gar nicht. int refer = abstractHessianInput.AddRef(result); return result; }
/// <summary> /// Invoke the object with the request from the input stream. /// </summary> /// <param name="inHessian">the Hessian input stream</param> /// <param name="outHessian">the Hessian output stream</param> public void invoke(AbstractHessianInput inHessian, AbstractHessianOutput outHessian) { inHessian.SkipOptionalCall(); // Hessian 1.0 backward compatibility String header; while ((header = inHessian.ReadHeader()) != null) { Object value = inHessian.ReadObject(); //context.addHeader(header, value); } String methodName = inHessian.ReadMethod(); int argLength = inHessian.ReadMethodArgLength(); MethodInfo methodInf = getMethodInfo(methodName + "__" + argLength); if (methodInf == null) { methodInf = getMethodInfo(methodName); } //If the method doesn't exist if (methodInf == null) { outHessian.WriteFault("NoSuchMethodException", EscapeMessage("The service has no method named: " + methodName), null); outHessian.CompleteReply(); return; } ParameterInfo[] paramInfo = methodInf.GetParameters(); Object[] valuesParam = new Object[paramInfo.Length]; if (argLength != paramInfo.Length && argLength >= 0) { outHessian.WriteFault("NoSuchMethod", EscapeMessage("method " + methodInf + " argument length mismatch, received length=" + argLength), null); outHessian.Flush(); return; } for (int i = 0; i < paramInfo.Length; i++) { valuesParam[i] = inHessian.ReadObject(paramInfo[i].ParameterType); } inHessian.CompleteCall(); Object result = null; try { result = methodInf.Invoke(m_Service, valuesParam); } catch (Exception e) { //TODO: Exception besser behandeln //if (e.GetType() == typeof(System.Reflection.TargetInvocationException)) //{ // if (e.InnerException != null) // { // e = e.InnerException; // } //} InvokeErrorCallBack?.Invoke(this, e); //多层InnerException使用GetBaseException()更好。 e = e.GetBaseException(); //outHessian.StartReply(); outHessian.WriteFault("ServiceException", e.Message, e.ToString()); outHessian.Flush(); //outHessian.CompleteReply(); return; } outHessian.StartReply(); outHessian.WriteObject(result); outHessian.CompleteReply(); }
//JAVA TO VB & C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public Object readLengthList(AbstractHessianInput in, int length) throws IOException public override object ReadLengthList(AbstractHessianInput @in, int length) { IList list = createList(); @in.AddRef(list); for (; length > 0; length--) { list.Add(@in.ReadObject()); } return list; }
//JAVA TO VB & C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public Object readList(AbstractHessianInput in, int length) throws IOException public override object ReadList(AbstractHessianInput @in, int length) { IList list = createList(); @in.AddRef(list); while (! @in.IsEnd()) { list.Add(@in.ReadObject()); } @in.ReadEnd(); return list; }