public IEndpoint CreateEndpoint(Uri requestedUri) { string scheme = requestedUri.Scheme.ToLowerInvariant(); if (_transportFactories.Has(scheme)) { ITransportFactory transportFactory = _transportFactories[scheme]; try { IEndpointAddress address = transportFactory.GetAddress(requestedUri, _defaults.RequireTransactional || (_defaults.CreateMissingQueues && _defaults.CreateTransactionalQueues)); var uriPath = new Uri(address.Uri.GetLeftPart(UriPartial.Path)); EndpointBuilder builder = _endpointBuilders.Get(uriPath, key => { var configurator = new EndpointConfiguratorImpl(address, _defaults); return(configurator.CreateBuilder()); }); return(builder.CreateEndpoint(transportFactory)); } catch (Exception ex) { throw new EndpointException(requestedUri, "Failed to create endpoint", ex); } } throw new ConfigurationException( "The {0} scheme was not handled by any registered transport.".FormatWith(requestedUri.Scheme)); }
public IEndpoint CreateEndpoint(Uri uri) { string scheme = uri.Scheme.ToLowerInvariant(); ITransportFactory transportFactory; if (_transportFactories.TryGetValue(scheme, out transportFactory)) { try { EndpointBuilder builder = _endpointBuilders.Retrieve(uri, () => { var configurator = new EndpointConfiguratorImpl(uri, _defaults); return(configurator.CreateBuilder()); }); return(builder.CreateEndpoint(transportFactory)); } catch (Exception ex) { throw new EndpointException(uri, "Failed to create endpoint", ex); } } throw new ConfigurationException("The {0} scheme was not handled by any registered transport.".FormatWith(uri.Scheme)); }
/// <summary> /// Creates a default endpoint URL for the given service in the given region. /// <br/> /// Note, the regionId is not validated against known regions, this just creates /// a URL that follows the default format. /// </summary> /// <param name="service">The service.</param> /// <param name="regionId">The region.</param> /// <returns>The endpoint constructed from the service and region.</returns> public static string FormatDefaultRegionEndpoint(Service service, string regionId) { // Try to get a real region first. Region region = FromRegionId(regionId); if (region != null) { return(FormatDefaultRegionEndpoint(service, region)); } else { // Else we need to fall back to OC1 SLD. logger.Debug($"Unknown regionId '{regionId}', will assume it's in Realm OC1"); return(EndpointBuilder.CreateEndpoint(service, regionId, Realm.OC1)); } }
// Detects the region in which the instance is present and forms the endpoint for the Auth Service protected void AutoDetectEndpointUsingMetadataUrl() { logger.Info("Detecting federation endpoint"); if (String.IsNullOrEmpty(this.federationEndpoint)) { var url = METADATA_SERVICE_BASE_URL + Constants.INSTANCE_REGION; var httpRequestMsg = new HttpRequestMessage(HttpMethod.Get, new Uri(url)); httpRequestMsg.Headers.Add(Constants.ACCEPT_HEADER, Constants.ACCEPT_TYPE); httpRequestMsg.Headers.Add(Constants.AUTHORIZATION_HEADER, AUTHORIZATION_HEADER_VALUE); HttpResponseMessage response = null; using (var httpClient = new HttpClient()) { response = httpClient.SendAsync(httpRequestMsg).Result; } if (response == null || !response.IsSuccessStatusCode) { logger.Debug("Received non successful response while trying to get the region of the instance"); ResponseHelper.HandleNonSuccessfulResponse(response); } // regionStr can be a shortCode or regionId var regionStr = response.Content.ReadAsStringAsync().Result; try { this.Region = Region.FromRegionCodeOrId(regionStr); } catch (ArgumentException e) { logger.Warn($"Received exception: {e}, Region not supported by this version of the SDK, registering region {regionStr} under OC1 realm"); this.Region = Region.Register(regionStr, Realm.OC1); } try { this.federationEndpoint = EndpointBuilder.CreateEndpoint(SERVICE, this.Region.RegionId, this.Region.Realm); logger.Info($"federation endpoint is {this.federationEndpoint}"); } catch (ArgumentNullException e) { throw new ArgumentNullException($"Either the service, regionId, realm, template, regionId, endpointPrefix, or secondLevelDomain value is empty", e); } } }
/// <summary> /// Creates a default endpoint URL for the given service in the given region. /// <br/> /// Note, the region is not validated against known regions, this just creates /// a URL that follows the default format. /// </summary> /// <param name="service">The service.</param> /// <param name="region">The region.</param> /// <returns>The endpoint constructed from the service and region.</returns> public static string FormatDefaultRegionEndpoint(Service service, Region region) { return(EndpointBuilder.CreateEndpoint(service, region)); }