Reputation: 31
I have created a small REST API which seems to work just fine. I wanted to use the Twitter API and display some tweets. But when I try to do that my server throws an error.
Reaching one of my old resources works just fine when trying this URL: http://localhost:8080/api-mashup-api/api/v1/foo/bar:
@GET
@Path("/bar")
@Produces(MediaType.TEXT_HTML)
public String print2() {
return "This should be printed if in foo/bar";
}
But If I try my "twitter method" at http://localhost:8080/api-mashup-api/api/v1/foo/twitter:
@GET
@Path("/twitter")
@Produces(MediaType.TEXT_HTML)
public String print5() {
//I have my real tokens here of course.
ClientIdentifier ci = new ClientIdentifier("clientID",
"ClientSecret");
OAuth2CodeGrantFlow flow = OAuth2ClientSupport
.authorizationCodeGrantFlowBuilder(ci,
"https://api.twitter.com/oauth2/token", "https://api.twitter.com/oauth2/token")
.scope("contact")
.build();
String finalAuthorizationUri = flow.start();
return "This is the bearer: " + finalAuthorizationUri.toString();
}
It throws the following error:
HTTP Status 500 - org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: org/glassfish/jersey/jackson/JacksonFeature
In reality it should just print my bearer token. I have tried importing various jackson jar files but not managed to get it working. I might add that I use Tomcat v8 and not Glassfish server.
Upvotes: 2
Views: 6218
Reputation: 2246
You are missing a jar, specifically jersey-media-json-jackson-2.XX.jar (where XX is the version of jersey that you are using)
you can add the maven dependency like:
<!-- https://mvnrepository.com/artifact/org.glassfish.jersey.media/jersey-media-json-jackson -->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.26</version>
</dependency>
Upvotes: 6