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

Problem serializing Response when deployed to AWS Lambda #26

Closed
davidmco65 opened this issue Jan 19, 2017 · 7 comments
Closed

Problem serializing Response when deployed to AWS Lambda #26

davidmco65 opened this issue Jan 19, 2017 · 7 comments

Comments

@davidmco65
Copy link

Hi, I'm having an issue when I've deployed my Lambda to AWS and hooked it up to API Gateway.

I use the API Gateway Test functionality to test the Lambda. It makes the call, the code executes, but when I do the Response.ok()... I get the following messages in my CloudWatch log:

org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor aroundWriteTo
SEVERE: MessageBodyWriter not found for media type=application/json, type=class com...

From what I've read, there's a problem with the glassfish jersey media implementation. So I'd like to just switch over to Jackson's implementation. Is this something you've run into or done in the past?

Thanks,
David

@bbilger
Copy link
Owner

bbilger commented Jan 19, 2017

Hi @davidmco65

  1. Do you have a dependency to org.glassfish.jersey.media:jersey-media-json-jackson:2.23?
  2. Is your DTO a JAXB class (@XmlRootElement)? If so, are you sure you have a no-args constructor?
  3. If you invoke the function through APIGateway - for example using curl - does it work?

If 1. and 2. does not apply in your case: can you send me some code + dependencies, please.

@bbilger
Copy link
Owner

bbilger commented Jan 19, 2017

Also:
I quickly deployed https://github.com/bbilger/jrestless-examples/tree/master/aws/gateway/aws-gateway-usage-example, tested it through APIGW's test functionality and can't see any issues...

apigw_test

@davidmco65
Copy link
Author

davidmco65 commented Jan 20, 2017

Here are my dependencies in my pom.xml file:
<dependency> <groupId>com.jrestless.aws</groupId> <artifactId>jrestless-aws-gateway-handler</artifactId> <version>0.4.0</version> <exclusions> <exclusion> <groupId>org.glassfish.jersey.containers</groupId> <artifactId>project</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.glassfish.jersey.core</groupId> <artifactId>jersey-server</artifactId> <version>2.23</version> </dependency> <dependency> <groupId>org.glassfish.jersey.media</groupId> <artifactId>jersey-media-json-jackson</artifactId> <version>2.23</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>5.2.5.Final</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.40</version> </dependency> <dependency> <groupId>com.github.v-ladynev</groupId> <artifactId>fluent-hibernate-core</artifactId> <version>0.3.1</version> </dependency>

My DTO is a Pojo:
`
public class ContactObject implements Serializable
{

/**
 * 
 */
private static final long serialVersionUID = 4663016387257579780L;
private ContactObject.Contact contact;
private ContactObject.Address address;
private String contactType;

/**
 * 
 */
public ContactObject()
{
}

...

`

Do I really need the @XmlRootElement if I'm really only interested in Json response body?

I can test through API GW Test function, but can't through cURL.. just get "Missing Authentication Header" error.

Thanks for your help!
David

@bbilger
Copy link
Owner

bbilger commented Jan 20, 2017

Maven, I see. I remember having some issues with maven and jrestless or rather jersey in an uber-jar...

Are you configuring the maven shade plugin as follows:

<configuration>
   <createDependencyReducedPom>false</createDependencyReducedPom>
  <!-- http://stackoverflow.com/questions/29107376/jersey-problems-with-maven-shade-plugin -->
  <transformers>
    <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
    </transformers>
</configuration>

See https://github.com/bbilger/jrestless-examples/blob/master/pom.xml#L48

@bbilger
Copy link
Owner

bbilger commented Jan 20, 2017

Sorry @davidmco65, I was short on time today.
http://stackoverflow.com/questions/29107376/jersey-problems-with-maven-shade-plugin looks exactly like your issue => try to configure maven-shade as suggested above.
You also don't need to exclude org.glassfish.jersey.containers in jersestless 0.4.0, anymore (see #14)
You also don't need to use "@XmlRootElement" if you don't need XML (using it has the advantage that you can return both JSON and XML)
If you cannot access it via curl, then you probably didn't set up APIGW properly.

Let me know if it works.

@davidmco65
Copy link
Author

davidmco65 commented Jan 20, 2017 via email

@bbilger
Copy link
Owner

bbilger commented Jan 24, 2017

I am happy to help!
Good to hear it's used and valuable.

@bbilger bbilger closed this as completed Jan 24, 2017
bbilger added a commit that referenced this issue Jan 31, 2017
The filter allows you to use the very same lambda function with
different APIGW resources without changing any code. Let's say you have
one APIGW resource configured as "/v1/{proxy+}" and one configured as
"/v2/{proxy+}" and both invoke the very same lambda function. With this
filter in place, your JAX-RS resources don't need to be mapped to "/v1"
or "/v2". So they are agnostic to it. Note: In general this filter makes
sense only if you map one endpoint to a lambda function.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants