-
Notifications
You must be signed in to change notification settings - Fork 888
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
[RESTEASY-1695] Add GRAMMARS into RESTEasy WADL #1649
Conversation
work in progress |
Sample included schema output: The usage should be simple: contextBuilder.getDeployment().getActualResourceClasses().add(ResteasyWadlExtendedResource.class); ResteasyWadlGrammar.includeGrammars("application-grammars.xml"); As shown above, the included grammars should be put into classpath and set via |
Now the schema generation is working: It will scan the resource methods and its parameters(also return types), and collect all To use the generation function, just enable it: ResteasyWadlGrammar.enableSchemaGeneration(); And it will be automatically included in |
The next step is to cleanup the code and add the tests. Then I'll move this PR for review. |
804654d
to
3f193ad
Compare
Just scanned the PR a bit, no deep dive.
|
@rsvoboda thanks for checking! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@liweinan , thanks for the PR. Now, besides for the minor comment below, I think that my main concern is with the lifecycle and and visibility of the new ResteasyWadlGrammar class. Is there a reason for having such a singleton? Can't we simply keep track of the relevant data in each deployment/classloader?
private static AtomicBoolean generateSchema = new AtomicBoolean(false); | ||
|
||
|
||
public static boolean hasGrammars() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this hasGrammar() be syncronized too (under the current design)?
@liweinan , as for the resteasy-wadl new module, yes, that will have to be added |
thanks for reviewing everyone! Let me do the refactor work. |
3f193ad
to
71dced8
Compare
71dced8
to
05f22c7
Compare
Refactor
Besides, hard coded port numbers are cleaned up in tests. Usage BecomesAdd contextBuilder.getDeployment().getActualResourceClasses().add(ResteasyWadlDefaultResource.class); contextBuilder.getDeployment().getActualResourceClasses().add(ResteasyWadlExtendedResource.class); Actually the usages of To use grammar support, it's necessary to create an instance of ResteasyWadlWriter.ResteasyWadlGrammar wadlGrammar = new ResteasyWadlWriter.ResteasyWadlGrammar();
// if you want to use your own handwritten grammar file:
wadlGrammar.includeGrammars("application-grammars.xml");
// if you'd like to enable automatic schema generation:
wadlGrammar.enableSchemaGeneration(); Put it into ResteasyWadlResourceHelper.getApiWriter().setWadlGrammar(wadlGrammar); Then |
96c7f67
to
35a0813
Compare
Relative PRs:
@asoldano I have created separated JIRA tasks to work on jboss-module / wildfly integration of WADL. So this PR is complete now. Could you please help to review it? Thanks! |
@liweinan please start by rebasing to resolve the conflicts and then removing the "requires rebase" label ;-) |
@liweinan nevermind, the PR now shows no conflicts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@liweinan I've checked the changes again. Honestly, I don't understand what has really changed wrt my previous comment. We have a single instance of ResteasyWadlWriter which relies on the latest and globally set grammar object. Is that really ok? what if 2 deployments runs in parallel? May be I really need to see an integration test using Arquillian to understand this. Can you clarify a bit?
Besides this, there're a couple of other things to solve, see comments below. Thanks!
import org.jboss.resteasy.wadl.jaxb.Resource; | ||
import org.jboss.resteasy.wadl.jaxb.Resources; | ||
import org.jboss.resteasy.wadl.jaxb.Response; | ||
import org.jboss.resteasy.wadl.jaxb.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not use * imports
} catch (JAXBException e) { | ||
e.printStackTrace(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we do something better for exception handling here? (at least use proper logging)
@asoldano Thanks for checking! Let me:
|
@liweinan I think the main item is to provide details and explanation for this:
|
@rsvoboda Yeah that's a problem. Let me redesign this part. |
0289bf8
to
9c90339
Compare
Changes
|
@asoldano The refactor is done. Could you please help to review it? Thanks! |
976358f
to
0866173
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @liweinan , this looks better. I have a question and a minor change requirement, please see the other comments. Thanks.
testsuite/integration-tests/src/test/java/org/jboss/resteasy/test/wadl/WadlTestApplication.java
Show resolved
Hide resolved
// .setAsyncSupported(false) | ||
// .setLoadOnStartup(1) | ||
// .addMapping("/application.xml"); | ||
// di.addServlet(resteasyWadlServlet); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we please get rid of this and other commented out stuff in this PR please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes sir!
0866173
to
7e8ae6f
Compare
7e8ae6f
to
3e63056
Compare
Hi Alessio, I have added comments and removed the outdated code. Could you please help to review? Thanks!
testsuite/integration-tests/src/test/java/org/jboss/resteasy/test/wadl/WadlTestApplication.java
Show resolved
Hide resolved
resteasy-wadl/src/main/java/org/jboss/resteasy/wadl/ResteasyWadlServlet.java
Show resolved
Hide resolved
contextBuilder.bind(httpServer); | ||
ResteasyWadlDefaultResource.getServices().put("/", ResteasyWadlGenerator.generateServiceRegistry(contextBuilder.getDeployment())); | ||
// defaultResource.getServices().put("/", ResteasyWadlGenerator.generateServiceRegistry(contextBuilder.getDeployment())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also remove the commented out lines here above or do they have some special meaning that justify their presence?
testsuite/integration-tests/src/test/java/org/jboss/resteasy/test/wadl/DeploymentTest.java
Show resolved
Hide resolved
Hi Alessio, I have added comments about TestApplication
. Could you please help to check if it's okay? Thanks!
No description provided.