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

Implemented isReadable on Oslc XML/RDF Providers #228

Conversation

jhemm2
Copy link
Contributor

@jhemm2 jhemm2 commented Dec 22, 2021

Description

OslcXmlProvider(s) returned always true for isReadable. This has been changed to verify the type and annotations first.
Without this fix, XML entities have been read by the OslcXmlProvider instead of e.g. an JaxbProvider which has lead to errors.

Checklist

  • This PR adds an entry to the CHANGELOG. See https://keepachangelog.com/en/1.0.0/ for instructions. Minor edits are exempt.
  • This PR was tested on at least one Lyo OSLC server or adds unit/integration tests.
  • This PR does NOT break the API

Issues

Closes #226 ;

(use exactly this syntax to link to issues, one issue per statement only!)

@jhemm2
Copy link
Contributor Author

jhemm2 commented Dec 22, 2021

Sorry, for the formatting, I was using the .editorconfig for formatting but it seems it didn't work pretty well :/
If someone can help me out how to fix this, I will update the formatting...

@jhemm2 jhemm2 force-pushed the bugfix/#226-OslcXmlProvider_/_OslcRdfXmlProvider_always_returns_is_readable branch from 75d0ce0 to e272199 Compare December 22, 2021 09:15
@jhemm2 jhemm2 changed the title Fixed OslcXml Providers Implemented isReadable on Oslc XML/RDF Providers Dec 22, 2021
@jadelkhoury
Copy link
Contributor

Sorry, for the formatting, I was using the .editorconfig for formatting but it seems it didn't work pretty well :/ If someone can help me out how to fix this, I will update the formatting...

Not sure how .editorconfig works. But maybe you can just commit the files (or parts of) with the substantial changes?

@jhemm2
Copy link
Contributor Author

jhemm2 commented Dec 22, 2021

Sorry, for the formatting, I was using the .editorconfig for formatting but it seems it didn't work pretty well :/ If someone can help me out how to fix this, I will update the formatting...

Not sure how .editorconfig works. But maybe you can just commit the files (or parts of) with the substantial changes?

Well, the PR contains only the files changed actually. Unfortunately I can't get it done without breaking the formatting.
Changes are:

  • Added

MessageBodyReaderTest and ResourceWithoutShape

  • Modified

AbstractOslcRdfXmlProvider: Added method isReadable and isCompatible
OslcRdfXmlProvider, OslcRdfXmlArrayProvider: Modified isReadable Method

Copy link
Member

@berezovskyi berezovskyi left a comment

Choose a reason for hiding this comment

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

Thank you so much @jhemm2 for the pull request!

I asked Jad and Jim to check on the use of the OslcNotQueryResult that your code may disrupt. I also linked my old PR in the comments.

I think the list of types accepted by the isReadable method and the @Consumes (and identically for the writes) should be the same unless I am missing something.

Finally, I am trying to find some corner cases in the OSLC adaptors code I have because this part was not well tested to check for regressions. For now let's focus with you on the isReadable/@Consumes logic.

Formatting changes are OK, though in the future it would be better to only reformat the code you touch and all the other lines to only wrap code that exceeds the margin and correct whitespace. But we needed to reformat this class long time ago anyway.

Merry Christmas and happy holidays!

We will aim to merge this PR in Lyo 5.0.0.beta1 and may backport it to 4.2.x if we can establish that it doesn't break any existing code.


protected static boolean isReadable(final Class<?> type, final MediaType actualMediaType,
final MediaType... requiredMediaTypes) {
if (type.getAnnotation(OslcResourceShape.class) != null) {
Copy link
Member

Choose a reason for hiding this comment

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

@jamsden @jadelkhoury could you please remind me how do we handle OSLC Query responses? AFAIK they are NOT annotated with the OslcResourceShape annotation.

@jhemm2 this change seems correct to me but I am afraid it may be breaking for some legacy code. Let me ask around and dig some old implementations to see if I can test the effect of your change. I think this is my old PR for replacing many RDF providers with one and there I also checked for the OslcNotQueryResult annotation. Please compare the logic in our PRs if you could.

final MediaType mediaType) {
if (type.isArray()) {
return isReadable(type.getComponentType(), mediaType, OslcMediaType.APPLICATION_RDF_XML_TYPE,
OslcMediaType.APPLICATION_XML_TYPE, OslcMediaType.TEXT_XML_TYPE);
Copy link
Member

Choose a reason for hiding this comment

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

I think I am recalling a bit more about this. Doesn't @Consumes protect you from having to do this check? Or do you think it broke with the Wink to Jersey transition? Do you use Jersey, by the way? I would also say the types in this check must match the @Consumes annotation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Quite a long time ago so I cannot completely remember ..I think you are right, that the media types should match the @consumes annotation. Then we would be able to read application/rdf+xml only but not application/xml anymore.

I don't know how far it should be restricted but actually it should also be checked to have @OslcResourceShape annotation, shouldn't it?

import org.eclipse.lyo.oslc4j.provider.jena.test.resources.TestResource;
import org.junit.Test;

public class MessageBodyReaderTest {
Copy link
Member

Choose a reason for hiding this comment

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

Need to check if we can add a simple @OslcNotQueryResult test here. @jadelkhoury @jamsden do you have some code that you could find that uses that annotation to help @jhemm2 write a test? I think we annotate JAX-RS methods with it IIRC.

public void testOslcXmlProvider() {
OslcXmlProvider provider = new OslcXmlProvider();

boolean isReadable = provider.isReadable(TestResource.class, null, TestResource.class.getAnnotations(),
Copy link
Member

Choose a reason for hiding this comment

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

@jhemm2 I am not sure the 3rd argument is passed correctly:

if the message body is to be converted into a method parameter, this will be the annotations on that parameter returned by Method.getParameterAnnotations

from https://docs.oracle.com/javaee/7/api/javax/ws/rs/ext/MessageBodyReader.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure, too as it also states:
annotations an array of the annotations on the declaration of the artifact that will be initialized with the produced instance

What do you think would be correct here?

@eclipse-lyo-bot
Copy link

Can one of the admins verify this patch?

@berezovskyi
Copy link
Member

ok to test

@berezovskyi
Copy link
Member

@jhemm2 we will release Lyo 5.0 without this patch. Please reply to my comments on the PR if we are to target this PR for Lyo 5.1.

@berezovskyi
Copy link
Member

Dear @jhemm2, thank you again for your PR! For a number of reasons, we could not merge it right then but your PR brought the problem to our attention and inspired us to make thorough changes in #286 and #288. PR #288 also comes with a set of extensive unit tests.

I will thus close your PR. Please check if your issue persists on 5.0.1-SNAPSHOT and please reopen this PR or open a new issue if it's still the case.

Thank you for your input and a great effort!

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.

OslcXmlProvider / OslcRdfXmlProvider always returns true for method "isReadable"
4 participants