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

Fix relative context Uri resolution #1211

Open
wants to merge 2 commits into
base: release-7.x
Choose a base branch
from

Conversation

biaol-odata
Copy link
Contributor

@biaol-odata biaol-odata commented Jul 13, 2018

Issues

This pull request fixes issue #1208.

Description

Fix error for relative context Uri resolution using the request uri passed in from the reader settings, applying similar logic from ODL-6.x branch.

Checklist (Uncheck if it is not completed)

  • Test cases added
  • Build and test with one-click build and test script passed

Additional work necessary

If documentation update is needed, please add "Docs Needed" label to the issue and provide details about the required document change in the issue.

@biaol-odata biaol-odata self-assigned this Jul 13, 2018
}
}

private ODataResource CreateResource1(Uri id = null)
Copy link
Contributor

@AlanWong-MS AlanWong-MS Jul 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we consolidate the CreateResource# into one method? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.


In reply to: 202220090 [](ancestors = 202220090)

Uri contextUri;
if (!Uri.TryCreate(contextUriFromPayload, UriKind.Absolute, out contextUri))
if (!Uri.TryCreate(baseUri, contextUriFromPayload, out contextUri))
Copy link
Contributor

@AlanWong-MS AlanWong-MS Jul 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will happen if contextUriFromPayload is absolute? I'm reading the API here and it says that the second Uri is relative. #ByDesign

Copy link
Contributor Author

@biaol-odata biaol-odata Jul 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it might be some doc issue. The actual implementation of Uri.TryCreate(Uri, string, out Uri) first tries to convert the string to absolute uri first if possible; otherwise it tries to use the baseUri to resolve the string representing relative url to get the result. See here: https://github.com/Microsoft/referencesource/blob/master/System/net/System/UriExt.cs#L315
Added inline comment.


In reply to: 202220739 [](ancestors = 202220739)

Copy link
Contributor

@AlanWong-MS AlanWong-MS Jul 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into this! #ByDesign

Copy link
Contributor

@AlanWong-MS AlanWong-MS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some small comments.

AlanWong-MS
AlanWong-MS previously approved these changes Jul 13, 2018
/// <summary>
/// Gets or sets current request Uri.
/// </summary>
public Uri RequestUri { get; set; }
Copy link
Member

@mikepizzo mikepizzo Jul 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the relationship between the new RequestUri property and the existing BaseUri property? When does RequestUri get set? Can we just use BaseUri? #ByDesign

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BaseUri is for Atom format and may be deprecated in the future. See

/// This URI will be used in ATOM format only, it would be overridden by &lt;xml:base /&gt; element in ATOM payload.
.


In reply to: 203896122 [](ancestors = 203896122)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason it was to be deprecated was because it was only used in Atom. The reason it was only used in Atom was because we previously didn't support relative URLs in JSON. Now that we support relative URLs in JSON, it seems like we should use this (existing) property, rather than deprecate it and add a new one for the same purpose.


In reply to: 204170332 [](ancestors = 204170332,203896122)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried using BaseUrl but it fails in multiple cases when the baseurl is the $metadata url, which is common, among other failing cases.


In reply to: 205241623 [](ancestors = 205241623,204170332,203896122)

@mikepizzo
Copy link
Member

mikepizzo commented Jul 19, 2018

Does this fix the issue with OData Client? I don't see where RelativeUrl gets set in MessageWriterSettings.

Could it use BaseUri instead? #ByDesign

/// <param name="needParseFragment">Whether the fragment after $metadata should be parsed, if set to false, only MetadataDocumentUri is parsed.</param>
/// <param name="throwIfMetadataConflict">Whether to throw if a type specified in the ContextUri is not found in metadata.</param>
/// <param name="baseUri">Optional value (with default value of null) of base Uri used for resolving the context url.
/// It should be a non-null value when resolving a top-level relative context Uri.
Copy link
Member

@mikepizzo mikepizzo Jul 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a top-level [](start = 57, length = 12)

Why call out "a top level"? Shouldn't it be non-null for resolving any relative context Url? Note that relative nested context urls should be resolved using the parent absolute contextUrl as a base; is this supported? #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be any relative context url. Removed "a top level".


In reply to: 203898403 [](ancestors = 203898403)

Copy link
Member

@mikepizzo mikepizzo Jul 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But changing the comment doesn't change how this works.
If I have a contextUrl nested within another contextUrl "scope", that nested context URL needs to be resolved relative to the outer contextUrl.

For example:

{
"@context" : "http://sampleservice/$externalMetadata#employees",
"value" : [
{
"id":"00001",
"name":"Kathy Smith",
...
"company" :
{
"@context": "#company",
"name":"FirstCompany"
}
}
]
}

or

{
"@context" : "http://sampleservice/externalMetadata#company",
"name":"FirstCompany",
"employees@context": "#employees"
"value" : [
{
"id":"00001",
"name":"Kathy Smith",
...
}
]
}

It's possible (likely) that our stack doesn't support this type of nested contextUrls, but I still want to make sure that we can support relative urls if we add support for nested context Urls in the future.


In reply to: 204168642 [](ancestors = 204168642,203898403)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are not sure how exactly nested contextUrl is going to be supported, its relative url support should be part of the future task when it comes up. Right?


In reply to: 205245558 [](ancestors = 205245558,204168642,203898403)

@biaol-odata
Copy link
Contributor Author

biaol-odata commented Jul 20, 2018

I believe the the ODataJsonLightContextUriParser.Parse() is invoked when client is reading the payload using reader settings. This change is to fix the issue of reading payload with relative url by, form example, OData Client; not the writing part.
See above related to BaseUri vs. RequestUri.


In reply to: 406439921 [](ancestors = 406439921)

@mikepizzo
Copy link
Member

Sorry, I meant MessageReaderSettings.

How/where does RequestUri get set when using ODataClient to read a result with relative URLs?


In reply to: 406729387 [](ancestors = 406729387,406439921)

@mikepizzo
Copy link
Member

mikepizzo commented Jul 25, 2018

This fix appears to be specific to the contextUrl. how do we resolve relative urls in nextLinks, edit/readLinks, mediaLInks, relationshipLinks, etc.? #Resolved

@biaol-odata
Copy link
Contributor Author

See RelativeUriReaderTests.cs L249 as an example.


In reply to: 407874612 [](ancestors = 407874612,406729387,406439921)

@biaol-odata
Copy link
Contributor Author

This issue is for relative contextUrl only, not including other relative urls.


In reply to: 407879722 [](ancestors = 407879722)

@biaol-odata
Copy link
Contributor Author

biaol-odata commented Jul 25, 2018

@mikepizzo Please see replies above. Not sure why my replies to your comments seem to be dislocated on the web page. If you can open CodeFlow, you can see that they are aligned much better there. #Resolved

@biaol-odata
Copy link
Contributor Author

🕐

@xuzhg xuzhg added this to the 7.6 milestone Oct 24, 2018
@biaol-odata biaol-odata added the Ready for review Use this label if a pull request is ready to be reviewed label Nov 12, 2018
@madansr7 madansr7 removed the Ready for review Use this label if a pull request is ready to be reviewed label Dec 17, 2018
@madansr7 madansr7 modified the milestones: 7.6, vNext Dec 17, 2018
@nils
Copy link

nils commented Jun 17, 2019

I'm also affected by this issue, is there any way I can help unblocking this pull request?

@xuzhg xuzhg force-pushed the master branch 2 times, most recently from f9519fd to 14a4b12 Compare September 22, 2019 21:12
@Tiberriver256
Copy link

Anything we can help out on with this PR @mikepizzo?

@ruza-kavanka
Copy link

Hi guys, I face the same issue, is there any progress? Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants