我正在尝试使用jersey客户端代理对端点进行POST,但是我发送的对象没有被编组到json中。
界面如下所示:
public interface Authentication {
@POST
@Path("principal")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
ApiPrincipal principal(@BeanParam ApiAuthenticationRequest authRequest, @HeaderParam("x-forwarded-for") String forwardedFor, @Context HttpServletRequest request) throws UserError;
}
客户端代码如下所示:
ClientConfig cc = new ClientConfig()
.register(JacksonFeature.class)
.register(new Authenticator(remoteUser, password));
Client resource = ClientBuilder.newClient(cc);
Authentication a = WebResourceFactory.newResource(Authentication.class,
resource.target(scheme + "://" + remoteHost + ":" + port + "/app/api/authentication/v-1/"));
ApiAuthenticationRequest authRequest = new ApiAuthenticationRequest();
authRequest.username = username;
authRequest.remoteIp = "localhost";
a.principal(authRequest, null, null);
如果我在wireshark中查看请求,一切看起来都很好,除了它没有正文。
我的依赖是这些(球衣版本2.22.1):
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-proxy-client</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.6.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.6.4</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-spring3</artifactId>
</dependency>