JIJ*_*Joe 2 java api glassfish jersey
我创建了一个小型 REST API,它似乎工作得很好。我想使用 Twitter API 并显示一些推文。但是当我尝试这样做时,我的服务器会抛出错误。
尝试以下 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";
}
Run Code Online (Sandbox Code Playgroud)
但是如果我在http://localhost:8080/api-mashup-api/api/v1/foo/twitter尝试我的“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();
}
Run Code Online (Sandbox Code Playgroud)
它抛出以下错误:
HTTP Status 500 - org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: org/glassfish/jersey/jackson/JacksonFeature
Run Code Online (Sandbox Code Playgroud)
实际上,它应该只打印我的不记名令牌。我尝试过导入各种 jackson jar 文件,但未能使其正常工作。我可能会补充一点,我使用 Tomcat v8 而不是 Glassfish 服务器。
您缺少一个 jar,特别是 jersey-media-json-jackson-2.XX.jar(其中 XX 是您正在使用的球衣版本)
您可以添加 Maven 依赖项,例如:
<!-- 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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5322 次 |
| 最近记录: |