protected override void HandleException(Exception exception) { if (ProxyWebRequest.ProxyWebRequestTracer.IsTraceEnabled(TraceType.ErrorTrace)) { ProxyWebRequest.ProxyWebRequestTracer.TraceError <object, Exception, ProxyAuthenticator>((long)this.GetHashCode(), "{0}: Exception occurred while completing proxy web request. Exception info is {1}. Caller SIDs: {2}", TraceContext.Get(), exception, this.proxyAuthenticator); } if (this.requestType == RequestType.CrossForest || this.requestType == RequestType.FederatedCrossForest) { Exception ex = exception; if (exception is GrayException) { ex = exception.InnerException; } if (ex is UriFormatException) { RemoteServiceUriCache.Invalidate(this.url); } if (HttpWebRequestExceptionHandler.IsConnectionException(ex, ProxyWebRequest.ProxyWebRequestTracer)) { RemoteServiceUriCache.Invalidate(this.url); } } ProxyWebRequestProcessingException ex2 = this.GenerateException(exception); this.SetExceptionInResultList(ex2); Globals.AvailabilityLogger.LogEvent(InfoWorkerEventLogConstants.Tuple_ProxyWebRequestFailed, this.url, new object[] { Globals.ProcessId, this, this.proxyAuthenticator, ex2 }); this.failedCounter.Increment(); }
protected void AddWebServiceUriToCache(AutoDiscoverQueryItem queryItem, WebServiceUri webServiceUri) { int autodiscoverVersionBucket = this.Application.GetAutodiscoverVersionBucket(this.autodiscoverType); RemoteServiceUriCache.Add(queryItem.EmailAddress, webServiceUri, autodiscoverVersionBucket); if (queryItem.InitialEmailAddress != queryItem.EmailAddress) { RemoteServiceUriCache.Add(queryItem.InitialEmailAddress, webServiceUri, autodiscoverVersionBucket); } }
protected override void EndInvoke(IAsyncResult asyncResult) { try { ProxyWebRequest.FaultInjectionTracer.TraceTest(2607164733U); base.Application.EndProxyWebRequest(this, this.queryList, this.service, asyncResult); if (this.requestType == RequestType.CrossForest || this.requestType == RequestType.FederatedCrossForest) { RemoteServiceUriCache.Validate(this.url); } this.IncrementPerfCounter(); } finally { if (!base.Aborted) { this.queryList.LogLatency("PWRC", this.webServiceCallTimer.ElapsedMilliseconds); } this.TraceCompleteRequest(); } }
internal static WebServiceUri Get(EmailAddress email, int versionBucket) { string text = email.Address.ToLower(); VersionedWebServiceUri versionedWebServiceUri; lock (RemoteServiceUriCache.cacheLocker) { versionedWebServiceUri = (VersionedWebServiceUri)RemoteServiceUriCache.cache[text]; } if (versionedWebServiceUri != null) { RemoteServiceUriCache.AutoDiscoverTracer.TraceDebug <object, VersionedWebServiceUri, string>(0L, "{0}: Found service URI {1} for email {2} in the cache.", TraceContext.Get(), versionedWebServiceUri, text); WebServiceUri webServiceUri = versionedWebServiceUri.Get(versionBucket); if (webServiceUri == null) { RemoteServiceUriCache.AutoDiscoverTracer.TraceDebug <object, string, int>(0L, "{0}: Service URI for email {1} was not found in version bucket {2}.", TraceContext.Get(), text, versionBucket); } else if (webServiceUri.Expired(DateTime.UtcNow) && (LocalizedString.Empty.Equals(webServiceUri.AutodiscoverFailedExceptionString) || RemoteServiceUriCache.IsBadUri(webServiceUri))) { RemoteServiceUriCache.AutoDiscoverTracer.TraceDebug <object, WebServiceUri>(0L, "{0}: URI {1} was found to be a bad URL, resetting and returning NULL.", TraceContext.Get(), webServiceUri); lock (RemoteServiceUriCache.cacheLocker) { if (webServiceUri == versionedWebServiceUri.Get(versionBucket)) { versionedWebServiceUri.Clear(versionBucket); } } return(null); } return(webServiceUri); } RemoteServiceUriCache.AutoDiscoverTracer.TraceDebug <object, string>(0L, "{0}: Service URI for email {1} was not found in the cache.", TraceContext.Get(), text); return(null); }
public SharingInformation Read(EmailAddress emailAddress, Application application) { if (this.requester == null) { SharingReader.RequestRoutingTracer.TraceError <object, string>((long)this.GetHashCode(), "{0}: Unable to get the requestor from the client context - address {1}", TraceContext.Get(), emailAddress.Address); return(new SharingInformation(new InvalidClientSecurityContextException())); } if (this.supportsPersonalSharing) { SharingSubscriptionData userSubscription = this.SubscriptionLoader.GetUserSubscription(emailAddress); if (!this.SubscriptionLoader.IsValid) { SharingReader.RequestRoutingTracer.TraceError <object, EmailAddress, Exception>((long)this.GetHashCode(), "{0}: SubscriptionLoader cannot open mailbox {1}. Exception: {2}", TraceContext.Get(), emailAddress, this.SubscriptionLoader.HandledException); } if (userSubscription != null) { SharingReader.RequestRoutingTracer.TraceDebug <object, string>((long)this.GetHashCode(), "{0}: Found a personal relationship for {1}", TraceContext.Get(), emailAddress.Address); if (SmtpAddress.IsValidSmtpAddress(userSubscription.SubscriberIdentity) && SmtpAddress.IsValidSmtpAddress(userSubscription.SharingKey)) { Uri sharingUrl = userSubscription.SharingUrl; return(new SharingInformation(new SmtpAddress(userSubscription.SubscriberIdentity), new SmtpAddress(userSubscription.SharingKey), new TokenTarget(userSubscription.SharerIdentityFederationUri), new WebServiceUri(sharingUrl.OriginalString, sharingUrl.Scheme, UriSource.Directory, Globals.E14SP2Version), null)); } SharingReader.RequestRoutingTracer.TraceError <object, EmailAddress>((long)this.GetHashCode(), "{0}: The subscriber information in the mailbox is invalid for address {1}. Personal subscription can't be used.", TraceContext.Get(), emailAddress); } } string domain = emailAddress.Domain; OrganizationId key = (this.requester.OrganizationId == null) ? OrganizationId.ForestWideOrgId : this.requester.OrganizationId; OrganizationIdCacheValue organizationIdCacheValue = OrganizationIdCache.Singleton.Get(key); SharingReader.RequestRoutingTracer.TraceDebug <object, string>((long)this.GetHashCode(), "{0}: Looking for an Intra-Organization connector with domain {1}.", TraceContext.Get(), domain); IntraOrganizationConnector intraOrganizationConnector = organizationIdCacheValue.GetIntraOrganizationConnector(domain); WebServiceUri targetSharingEpr; if (intraOrganizationConnector != null && intraOrganizationConnector.Enabled) { Uri discoveryEndpoint = intraOrganizationConnector.DiscoveryEndpoint; int autodiscoverVersionBucket = application.GetAutodiscoverVersionBucket(AutodiscoverType.External); targetSharingEpr = RemoteServiceUriCache.Get(emailAddress, autodiscoverVersionBucket); return(new SharingInformation(this.requester.PrimarySmtpAddress, targetSharingEpr, discoveryEndpoint)); } SharingReader.RequestRoutingTracer.TraceDebug <object, string>((long)this.GetHashCode(), "{0}: Looking for an Organization Relationship with domain {1}.", TraceContext.Get(), domain); OrganizationRelationship organizationRelationship = organizationIdCacheValue.GetOrganizationRelationship(domain); if (organizationRelationship == null) { SharingReader.RequestRoutingTracer.TraceError <object, string, EmailAddress>((long)this.GetHashCode(), "{0}: Unable to find a organization Relationship with domain {1} for emailAddress {2}.", TraceContext.Get(), emailAddress.Domain, emailAddress); return(null); } if (!organizationRelationship.Enabled) { SharingReader.RequestRoutingTracer.TraceError <object, OrganizationRelationship, string>((long)this.GetHashCode(), "{0}: Organization Relationship {1} is not enabled for access to domain {2}. Ignoring this relationship.", TraceContext.Get(), organizationRelationship, emailAddress.Domain); return(null); } if (!application.EnabledInRelationship(organizationRelationship)) { SharingReader.RequestRoutingTracer.TraceError((long)this.GetHashCode(), "{0}: Organization Relationship {1} is not enabled for application {2} to domain {3}. Ignoring this relationship.", new object[] { TraceContext.Get(), organizationRelationship, application.GetType(), emailAddress.Domain }); return(null); } if (!organizationRelationship.IsValidForRequestDispatcher()) { SharingReader.RequestRoutingTracer.TraceError((long)this.GetHashCode(), "{0}: Organization Relationship is invalid for dispatching requests, TargetApplicationUri:{1}, TargetSharingEpr:{2}, AutoDiscoverEpr:{3}.", new object[] { TraceContext.Get(), organizationRelationship.TargetApplicationUri, organizationRelationship.TargetSharingEpr, organizationRelationship.TargetAutodiscoverEpr }); return(new SharingInformation(new InvalidOrganizationRelationshipForRequestDispatcherException(organizationRelationship.ToString()))); } if (DateTime.UtcNow > this.readDeadline) { return(new SharingInformation(new TimeoutExpiredException("OrganizationRelationship lookup"))); } Uri targetSharingEpr2 = organizationRelationship.TargetSharingEpr; if (targetSharingEpr2 == null) { int autodiscoverVersionBucket2 = application.GetAutodiscoverVersionBucket(AutodiscoverType.External); targetSharingEpr = RemoteServiceUriCache.Get(emailAddress, autodiscoverVersionBucket2); } else { targetSharingEpr = new WebServiceUri(targetSharingEpr2.OriginalString, targetSharingEpr2.Scheme, UriSource.Directory, Globals.E14SP2Version); } return(new SharingInformation(this.requester.PrimarySmtpAddress, SmtpAddress.Empty, organizationRelationship.GetTokenTarget(), targetSharingEpr, organizationRelationship.TargetAutodiscoverEpr)); }