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

Possibility to modify JenaModel before response is returned by JMH/JaxRsProviders #76

Open
jadelkhoury opened this issue Jan 8, 2021 · 11 comments
Labels
Status: Abandoned This doesn't seem right
Milestone

Comments

@jadelkhoury
Copy link
Contributor

Can we introduce a mechanism that allows the devleoper to manipulate the response returned by LyoCore?

This would be done by either allowing custom functionality in JenaHelper, or AbstractOslcRdfXmlProvider?

https://github.com/eclipse/lyo/blob/b5f7207f969b4d31f0dc52756bf61229110e75b3/core/oslc4j-jena-provider/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/AbstractOslcRdfXmlProvider.java#L146

@berezovskyi @jamsden! Any tips on how we can do this elegantly?

@jadelkhoury
Copy link
Contributor Author

How about the following proposal?

  1. We introduce a method "visit(model, ....)" under AbstractResource (or IExtendedResource?).
  2. At the end of the createJenaModel method (https://github.com/eclipse/lyo/blob/b5f7207f969b4d31f0dc52756bf61229110e75b3/core/oslc4j-jena-provider/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/JenaModelHelper.java#L212), JMH loops through its "objects" and calls visit(model).
  3. Resource Classes can then override the visit method to modify the final model as desired.
  4. We will need a similar method at end of fromJenaResource() as well.

@berezovskyi
Copy link
Contributor

(2) is very much not thread safe. please do not any more static stuff to that class.

(1) Visitor pattern is in my opinion not needed here and JAX-RS interceptors are a much better fit https://docs.jboss.org/resteasy/docs/4.0.0.Final/userguide/html/Interceptors.html#d4e2053

@jamsden
Copy link

jamsden commented Jan 14, 2021

I'm left with a nagging feeling about data integrity and what actually constitutes a resource representation. Are we crossing into the ETL domain? Can clients have a reasonable expectation about the provenance of the resources? Maybe I'm overthinking this.

@berezovskyi
Copy link
Contributor

Right, JAX-RS interceptors would also allow Lyo not to step into that area either. But I agree with Jad that such hacks are very much needed in the OSLC space, sadly, and Lyo should at least provide for a way to get the job done.

@berezovskyi
Copy link
Contributor

Practical advice (did not try, but that's how I would do it):

  1. Implement https://docs.oracle.com/javaee/7/api/javax/ws/rs/ext/WriterInterceptor.html
  2. Call https://docs.oracle.com/javaee/7/api/javax/ws/rs/ext/WriterInterceptorContext.html#getEntity--, cast it to an AbstractResource or its array.
  3. Do your thing, potentially calling JMH and converting objects to a Jena Model and editing it on a triple level.
  4. Call https://docs.oracle.com/javaee/7/api/javax/ws/rs/ext/WriterInterceptorContext.html#getHeaders-- and set any extra headers as needed.
  5. Call https://docs.oracle.com/javaee/7/api/javax/ws/rs/ext/WriterInterceptorContext.html#setEntity-java.lang.Object-. If you received an array of JMH POJOs and here you set a Jena Model, this should even change a MessageBodyWriter instance used.
  6. Call https://docs.oracle.com/javaee/7/api/javax/ws/rs/ext/WriterInterceptorContext.html#proceed--

@berezovskyi
Copy link
Contributor

We may want to revive https://github.com/eclipse/lyo.core/pull/76/files#diff-0f7af1eb04acfdfbffe4b21db24c1c2c0ba064f2a1d537d6a763bda00afe6166 and also add a standard writer for a Jena Model.

@jadelkhoury
Copy link
Contributor Author

I looked into JAX-RS interceptors. The problem there is that one will receive a stream, and then one will have to reconstruct the Jena model before it can be modified. I wanted to catch the return results as a Jena model.

@jim! Not sure I understood your reservation, because this is not related to client/server. Sometimes it is just not enough to rely on the annotations to tell JMH what to do. A good example is the SysmlServer, where we wanted to perform some changes to the Jena model. For example, adding a new property, or changing a value of a property.
It would be nice if these can be done more systematically.

In my new case, I want to serialize/deserialize an object in a custom way, and I can't do that using annotations.

@jadelkhoury
Copy link
Contributor Author

but point taken about concurrency. I will look into your many pointers.

@berezovskyi
Copy link
Contributor

Jad, I assume there should be a way to intercept a JAX-RS response before the streams are involved. Let's try to have a Zoom session quickly to check this.

@jadelkhoury
Copy link
Contributor Author

@berezovskyi

The Jax-RS Provider writes to the stream. so unless we modify the JenaProviders we have built, I can't see how the Jax-RS Interceptors can work to embed code in the middle of the Provider.

@berezovskyi
Copy link
Contributor

oslc-op/refimpl#27

@berezovskyi berezovskyi added this to the 5.1 milestone May 9, 2022
@berezovskyi berezovskyi added the Status: Abandoned This doesn't seem right label May 9, 2022
@berezovskyi berezovskyi modified the milestones: 5.1, 5.x May 19, 2022
@berezovskyi berezovskyi modified the milestones: 5.x, 7.x Aug 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Abandoned This doesn't seem right
Projects
None yet
Development

No branches or pull requests

3 participants