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

Stack traces with aws-gateway-cdi #9

Closed
dasniko opened this issue Apr 24, 2017 · 6 comments
Closed

Stack traces with aws-gateway-cdi #9

dasniko opened this issue Apr 24, 2017 · 6 comments

Comments

@dasniko
Copy link

dasniko commented Apr 24, 2017

Hi,

first of all - jrestless is a nice project! Thanks for doing this. :-)

I tried to run the aws-gateway-cdi example in my AWS account, but I'm getting a huge log output and lots of stack traces. Locally it's no problem, everything works as expected.
I'm encountering similar behaviour when running another Jersey impl. (https://github.com/serverlessbuch/lambda-jaxrs-cdi) with Weld on Lambda. However, I'm a bit of stuck...

Did you get your example running?
Are there some special configs I need to set?

@dasniko
Copy link
Author

dasniko commented Apr 24, 2017

WTF is going on here?
Seems like I opened the issue too early, sorry.

When building and packaging with maven, this aweful logs and stack traces occur and the lambda responds with an internal error.
When building with gradle, everything works like expected...
So, wtf?

Anyway, do you have some ideas why this occurs?

@bbilger
Copy link
Owner

bbilger commented Apr 24, 2017

Hi @dasniko ,
Thanks for your feedback and sorry but I mainly use gradle.
Creating an uber-jar with maven is kind of tricky for Jersey, CDI/Weld, etc. :/ already had some fun with that (bbilger/jrestless#14)
After quite some testing and researching I think the issue can be solved by adding

<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" bean-discovery-mode="annotated" version="1.1"/>

to src/main/resources/META-INF/beans.xml
To me it looks like Weld discovers non-annotated classes as beans in the uber-jar created with the maven shade plugin - most likely some internal weld classes. The Weld documentation is talking about it, too: http://weld.cdi-spec.org/documentation/#5 but just excluding "org.jboss.weld.**" didn't work for whatever reason.

Let me know if this works. Will commit the fix shortly.

@dasniko
Copy link
Author

dasniko commented Apr 24, 2017

Thanks for quick anwering, @bbilger ,
but no, doesn't work :-(
Additionally my tests are failing now during build.
Will investigate further and will give you feedback as soon I find a solution!
(However, I'm glad to know that it work with Gradle)

@bbilger
Copy link
Owner

bbilger commented Apr 24, 2017

Hi @dasniko
when adjusting the beans.xml as suggested, you have to annotate your BooksController with @javax.enterprise.context.RequestScoped or ApplicationScoped (which is recommended, anyways and ensures that it's managed by the CDI container) and add

<transformers>
  <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
</transformers>

to the maven shade plugin's configuration section (see https://github.com/bbilger/jrestless-examples/blob/master/pom.xml#L56)

Hope this helps

BTW: serverlessbuch sounds interesting. Will the focus be on Java?

@dasniko
Copy link
Author

dasniko commented Apr 25, 2017

Hey, this does the trick!
Thank you very, very much for your help.

So, we have

  • beans.xml with above mentioned content
  • @RequestScoped or @ApplicationScoped annotations at controller classes
  • extend the maven-shade-pluginconfiguration with the above mentionedtransformers` section.

serverlessbuch.de (german language) will focus on serverless in general, based on AWS Lambda/API Gateway/DynamoDB with examples in Java and JavaScript. Hopefully, it will be published in autumn.
If it's ok for you, I'll mention your jrestless project!?

@bbilger
Copy link
Owner

bbilger commented Apr 25, 2017

Hi @dasniko ,
Glad to hear that it works, now!

Sure, I would be pleased to see JRestless being mentioned in your book.

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

No branches or pull requests

2 participants