Пример #1
0
        private object InternalAfterReceiveRequest(ref Message request, RequestDetailsLogger logger)
        {
            try
            {
                Globals.UpdateErrorTracingConfiguration();
                IActivityScope             activityScope = OwaApplication.GetRequestDetailsLogger.ActivityScope;
                HttpRequestMessageProperty httpRequestMessageProperty = (HttpRequestMessageProperty)request.Properties[HttpRequestMessageProperty.Name];
                string value = httpRequestMessageProperty.Headers[OWADispatchOperationSelector.Action];
                activityScope.SetProperty(ExtensibleLoggerMetadata.EventId, value);
                string value2 = httpRequestMessageProperty.Headers["X-OWA-ClientBuildVersion"];
                if (!string.IsNullOrEmpty(value2))
                {
                    activityScope.SetProperty(OwaServerLogger.LoggerData.ClientBuildVersion, value2);
                }
                else
                {
                    activityScope.SetProperty(OwaServerLogger.LoggerData.ClientBuildVersion, "NA");
                }
                string value3 = httpRequestMessageProperty.Headers["X-EWS-TargetVersion"];
                if (!string.IsNullOrEmpty(value3))
                {
                    activityScope.SetProperty(OwaServerLogger.LoggerData.RequestVersion, value3);
                }
                else
                {
                    activityScope.SetProperty(OwaServerLogger.LoggerData.RequestVersion, "NA");
                }
                JsonMessageHeaderProcessor jsonMessageHeaderProcessor = new JsonMessageHeaderProcessor();
                string methodName = OWAMessageInspector.GetMethodName(request);
                bool   flag       = OWAMessageInspector.RequestNeedsHeaderProcessing(methodName);
                bool   flag2      = OWAMessageInspector.RequestNeedsQueryStringProcessing(methodName);
                bool   flag3      = OWAMessageInspector.RequestNeedsHttpHeaderProcessing(methodName);
                if (flag || flag2 || flag3)
                {
                    using (MessageBuffer messageBuffer = request.CreateBufferedCopy(int.MaxValue))
                    {
                        Message request2 = messageBuffer.CreateMessage();
                        if (flag)
                        {
                            jsonMessageHeaderProcessor.ProcessMessageHeaders(request2);
                            jsonMessageHeaderProcessor.ProcessEwsVersionFromHttpHeaders(request);
                        }
                        else if (flag2)
                        {
                            jsonMessageHeaderProcessor.ProcessMessageHeadersFromQueryString(request2);
                        }
                        else if (flag3)
                        {
                            jsonMessageHeaderProcessor.ProcessHttpHeaders(request, ExchangeVersion.Exchange2013);
                        }
                        request = messageBuffer.CreateMessage();
                    }
                }
                request.Properties["MessageHeaderProcessor"] = jsonMessageHeaderProcessor;
                request.Properties["ConnectionCostType"]     = 0;
                WebMethodEntry jsonWebMethodEntry;
                if (!OWAMessageInspector.MethodNameToWebMethodEntryMap.Member.TryGetValue(methodName, out jsonWebMethodEntry))
                {
                    jsonWebMethodEntry = WebMethodEntry.JsonWebMethodEntry;
                }
                request.Properties["WebMethodEntry"] = jsonWebMethodEntry;
                MessageHeaderProcessor messageHeaderProcessor = (MessageHeaderProcessor)request.Properties["MessageHeaderProcessor"];
                messageHeaderProcessor.MarkMessageHeaderAsUnderstoodIfExists(request, "RequestServerVersion", "http://schemas.microsoft.com/exchange/services/2006/types");
                RequestDetailsLogger.LogEvent(logger, OwaServerLogger.LoggerData.CallContextInitBegin);
                Message     requestRef  = request;
                CallContext callContext = OwaApplication.GetRequestDetailsLogger.TrackLatency <CallContext>(ServiceLatencyMetadata.CallContextInitLatency, () => CallContextUtilities.CreateCallContext(requestRef, messageHeaderProcessor, true, ""));
                RequestDetailsLogger.LogEvent(logger, OwaServerLogger.LoggerData.CallContextInitEnd);
                callContext.ProtocolLog.Set(OwaServerLogger.LoggerData.IsMowaClient, OfflineClientRequestUtilities.IsRequestFromMOWAClient(callContext.HttpContext.Request, callContext.HttpContext.Request.UserAgent) ? 1 : 0);
                bool?flag4 = new bool?(OfflineClientRequestUtilities.IsRequestFromOfflineClient(callContext.HttpContext.Request));
                if (flag4 != null)
                {
                    callContext.ProtocolLog.Set(OwaServerLogger.LoggerData.IsOfflineEnabled, flag4.Value ? 1 : 0);
                }
                callContext.OwaExplicitLogonUser = UserContextUtilities.GetExplicitLogonUser(HttpContext.Current);
                if (string.IsNullOrEmpty(callContext.OwaExplicitLogonUser))
                {
                    OWAMessageInspector.CheckThatUserProvisionedDevice(methodName, callContext);
                    OWAMessageInspector.CheckMowaRemoteWipe(methodName, callContext);
                    OWAMessageInspector.CheckClientVersion(callContext);
                    OWAMessageInspector.CheckMowaDisabled(callContext);
                    OWAMessageInspector.CheckMobileDevicePolicyIsCorrect(methodName, callContext);
                }
                OWAMessageInspector.MarkResponseNonCacheable(methodName);
                callContext.WorkloadType       = WorkloadType.Owa;
                callContext.UsingWcfDispatcher = true;
                callContext.ProtocolLog.Set(OwaServerLogger.LoggerData.UsingWcfHttpHandler, 1);
                if (ExchangeVersion.Current == ExchangeVersion.Exchange2007)
                {
                    ExchangeVersion.Current = ExchangeVersion.Exchange2013;
                }
                if (OWAMessageInspector.ShouldCreateUserContext(callContext))
                {
                    UserContext userContext = UserContextManager.GetMailboxContext(callContext.HttpContext, callContext.EffectiveCaller, true) as UserContext;
                    if (userContext != null)
                    {
                        callContext.OwaCulture = userContext.UserCulture;
                        if (userContext.FeaturesManager != null)
                        {
                            callContext.FeaturesManager = userContext.FeaturesManager;
                            if (userContext.FeaturesManager.ServerSettings.OwaMailboxSessionCloning.Enabled)
                            {
                                callContext.OwaUserContextKey = userContext.Key.ToString();
                            }
                        }
                    }
                }
            }
            catch (LocalizedException ex)
            {
                Microsoft.Exchange.Diagnostics.Components.Services.ExTraceGlobals.CommonAlgorithmTracer.TraceError <string, string>((long)this.GetHashCode(), "[OWAMessageInspector::AfterReceiveRequest] Caught localized exception trying to create callcontext.  Class: {0}, Message: {1}", ex.GetType().FullName, ex.Message);
                OwaServerTraceLogger.AppendToLog(new TraceLogEvent("OWAMessageInspector", null, "InternalAfterReceiveRequest", string.Format("OwaServiceFaultException_InnerException - {0}", ex)));
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeLogRequestException(OwaApplication.GetRequestDetailsLogger, ex, "OwaServiceFaultException_InnerException");

                throw OwaFaultExceptionUtilities.CreateFault(ex);
            }
            return(null);
        }
Пример #2
0
 public static FaultException CreateFault(LocalizedException exception)
 {
     return(new OwaServiceFaultException(OwaFaultExceptionUtilities.GetServiceError(exception), exception));
 }
        private void InternalAfterReceiveRequest(HttpRequest httpRequest, string methodName, object request)
        {
            try
            {
                ExTraceGlobals.CommonAlgorithmTracer.TraceDebug <string>((long)this.GetHashCode(), "[OwaServiceMessageInspector::InternalAfterReceiveRequest] called for method name: {0}", methodName);
                CallContext.ClearCallContextForCurrentThread();
                Globals.UpdateErrorTracingConfiguration();
                OwaApplication.GetRequestDetailsLogger.ActivityScope.SetProperty(ExtensibleLoggerMetadata.EventId, methodName);
                OwaServiceMessage message = new OwaServiceMessage(httpRequest, request);
                message.Headers.Action = methodName;
                message.Properties["HttpOperationName"] = methodName;
                OwaMessageHeaderProcessor messageHeaderProcessor = new OwaMessageHeaderProcessor();
                bool flag  = OWAMessageInspector.RequestNeedsHeaderProcessing(methodName);
                bool flag2 = OWAMessageInspector.RequestNeedsQueryStringProcessing(methodName);
                bool flag3 = OWAMessageInspector.RequestNeedsHttpHeaderProcessing(methodName);
                ExTraceGlobals.CommonAlgorithmTracer.TraceDebug((long)this.GetHashCode(), "[OwaServiceMessageInspector::InternalAfterReceiveRequest] processing message headers");
                if (flag || flag2 || flag3)
                {
                    if (flag)
                    {
                        messageHeaderProcessor.ProcessMessageHeaders(message);
                        messageHeaderProcessor.ProcessEwsVersionFromHttpHeaders(message);
                    }
                    else if (flag2)
                    {
                        messageHeaderProcessor.ProcessMessageHeadersFromQueryString(message);
                    }
                    else if (flag3)
                    {
                        messageHeaderProcessor.ProcessHttpHeaders(message, ExchangeVersion.Exchange2013);
                    }
                }
                message.Properties["MessageHeaderProcessor"] = messageHeaderProcessor;
                message.Properties["ConnectionCostType"]     = 0;
                WebMethodEntry jsonWebMethodEntry;
                if (!OWAMessageInspector.MethodNameToWebMethodEntryMap.Member.TryGetValue(methodName, out jsonWebMethodEntry))
                {
                    jsonWebMethodEntry = WebMethodEntry.JsonWebMethodEntry;
                }
                message.Properties["WebMethodEntry"] = jsonWebMethodEntry;
                ExTraceGlobals.CommonAlgorithmTracer.TraceDebug((long)this.GetHashCode(), "[OwaServiceMessageInspector::InternalAfterReceiveRequest] creating CallContext");
                CallContext callContext = OwaApplication.GetRequestDetailsLogger.TrackLatency <CallContext>(ServiceLatencyMetadata.CallContextInitLatency, () => CallContextUtilities.CreateCallContext(message, messageHeaderProcessor, true, ""));
                callContext.IsOwa = true;
                ExTraceGlobals.CommonAlgorithmTracer.TraceDebug((long)this.GetHashCode(), "[OwaServiceMessageInspector::InternalAfterReceiveRequest] CallContext created");
                callContext.ProtocolLog.Set(OwaServerLogger.LoggerData.IsMowaClient, OfflineClientRequestUtilities.IsRequestFromMOWAClient(callContext.HttpContext.Request, callContext.HttpContext.Request.UserAgent) ? 1 : 0);
                bool?flag4 = new bool?(OfflineClientRequestUtilities.IsRequestFromOfflineClient(callContext.HttpContext.Request));
                if (flag4 != null)
                {
                    callContext.ProtocolLog.Set(OwaServerLogger.LoggerData.IsOfflineEnabled, flag4.Value ? 1 : 0);
                }
                callContext.OwaExplicitLogonUser = UserContextUtilities.GetExplicitLogonUser(HttpContext.Current);
                if (string.IsNullOrEmpty(callContext.OwaExplicitLogonUser))
                {
                    OWAMessageInspector.CheckThatUserProvisionedDevice(methodName, callContext);
                    OWAMessageInspector.CheckMowaRemoteWipe(methodName, callContext);
                    OWAMessageInspector.CheckClientVersion(callContext);
                    OWAMessageInspector.CheckMowaDisabled(callContext);
                    OWAMessageInspector.CheckMobileDevicePolicyIsCorrect(methodName, callContext);
                }
                OWAMessageInspector.MarkResponseNonCacheable(methodName);
                callContext.WorkloadType       = WorkloadType.Owa;
                callContext.UsingWcfDispatcher = false;
                callContext.ProtocolLog.Set(OwaServerLogger.LoggerData.UsingWcfHttpHandler, 0);
                if (ExchangeVersion.Current == ExchangeVersion.Exchange2007)
                {
                    ExchangeVersion.Current = ExchangeVersion.Exchange2013;
                }
                if (OWAMessageInspector.ShouldCreateUserContext(callContext))
                {
                    UserContext userContext = UserContextManager.GetMailboxContext(callContext.HttpContext, callContext.EffectiveCaller, true) as UserContext;
                    if (userContext != null)
                    {
                        callContext.OwaCulture = userContext.UserCulture;
                        if (userContext.FeaturesManager != null)
                        {
                            callContext.FeaturesManager = userContext.FeaturesManager;
                            if (userContext.FeaturesManager.ServerSettings.OwaMailboxSessionCloning.Enabled)
                            {
                                callContext.OwaUserContextKey = userContext.Key.ToString();
                            }
                        }
                    }
                }
            }
            catch (LocalizedException ex)
            {
                ExTraceGlobals.CommonAlgorithmTracer.TraceError <string, LocalizedException>((long)this.GetHashCode(), "[OwaServiceMessageInspector::InternalAfterReceiveRequest] Caught localized exception trying to process message. Type: {0} Exception: {1}", ex.GetType().Name, ex);
                OwaServerTraceLogger.AppendToLog(new TraceLogEvent("OWAMessageInspector", null, "InternalAfterReceiveRequest", string.Format("OwaServiceFaultException_InnerException - {0}", ex)));
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeLogRequestException(OwaApplication.GetRequestDetailsLogger, ex, "OwaServiceFaultException_InnerException");

                throw OwaFaultExceptionUtilities.CreateFault(ex);
            }
            catch (Exception ex2)
            {
                ExTraceGlobals.CommonAlgorithmTracer.TraceError <string, Exception>((long)this.GetHashCode(), "[OwaServiceMessageInspector::InternalAfterReceiveRequest] Caught exception trying to process message. Type: {0} Exception: {1}", ex2.GetType().Name, ex2);
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeLogRequestException(OwaApplication.GetRequestDetailsLogger, ex2, "OwaServiceFaultException_InnerException");

                throw;
            }
            ExTraceGlobals.CommonAlgorithmTracer.TraceDebug((long)this.GetHashCode(), "[OwaServiceMessageInspector::InternalAfterReceiveRequest] completed");
        }