Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated retrieving MetaDataUrl from endpoint url #49

Merged
merged 5 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>10.8.1</Version>
<Version>10.8.2</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<Title>OData Provider</Title>
<Description>The Odata Provider lets you fetch and map data from or to any OData endpoint.</Description>
Expand Down
40 changes: 27 additions & 13 deletions src/ODataProvider.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
using Dynamicweb.Core;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text.Json;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
using Dynamicweb.Core;
using Dynamicweb.DataIntegration.EndpointManagement;
using Dynamicweb.DataIntegration.Integration;
using Dynamicweb.DataIntegration.Integration.ERPIntegration;
Expand All @@ -9,16 +20,6 @@
using Dynamicweb.Extensibility.Editors;
using Dynamicweb.Logging;
using Dynamicweb.Security.Licensing;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;

namespace Dynamicweb.DataIntegration.Providers.ODataProvider;

Expand All @@ -30,7 +31,7 @@ namespace Dynamicweb.DataIntegration.Providers.ODataProvider;
[ResponseMapping(true)]
public class ODataProvider : BaseProvider, ISource, IDestination, IParameterOptions, IODataBaseProvider, IParameterVisibility
{
internal readonly EndpointService _endpointService = new EndpointService();
internal readonly EndpointService _endpointService = new();
internal Schema _schema;
internal Endpoint _endpoint;
internal ICredentials _credentials;
Expand Down Expand Up @@ -129,6 +130,19 @@ public string DestinationEndpointId
#endregion

private string GetMetadataURL()
{
NicolajHansenPersonal marked this conversation as resolved.
Show resolved Hide resolved
if (GetEndpointResponse(ODataSourceReader.GetEndpointUrlWithTop(_endpoint.Url), out string endpointResponse, out Exception exception) == HttpStatusCode.OK && exception is null)
return GetMetadataURLFallBack();

using var responseJson = JsonDocument.Parse(endpointResponse);

if (responseJson.RootElement.ValueKind != JsonValueKind.Object)
return GetMetadataURLFallBack();

return responseJson.RootElement.EnumerateObject().FirstOrDefault(obj => obj.Name.Equals("@odata.context", StringComparison.OrdinalIgnoreCase)).Value.GetString() ?? GetMetadataURLFallBack();
}

private string GetMetadataURLFallBack()
{
if (_endpoint.Url.Contains("companies(", StringComparison.OrdinalIgnoreCase))
{
Expand Down Expand Up @@ -164,7 +178,7 @@ internal void SetCredentials()
var endpointAuthentication = _endpoint.Authentication;
if (endpointAuthentication != null)
{
var metadataUri = new Uri(GetMetadataURL());
var metadataUri = new Uri(_endpoint.Url);
var credentialCache = new CredentialCache
{
{ new Uri(metadataUri.GetLeftPart(UriPartial.Authority)), endpointAuthentication.Type.ToString(), endpointAuthentication.GetNetworkCredential() }
Expand Down
Loading