我使用DropWizard建立一个API在Java中。但是,对于某些资源,我还需要消耗其他的RESTful API的。这些其他的API不需要任何身份验证。
可以DropWizard被用来消耗的API?或者有一些什么其他的方式来简单地消耗在Java应用程序一个RESTful API?由于我使用DropWizard我已经有杰克逊。
因此,如果REST API是这样的:
[ {"id": "0",
"name" : "Joe"
]
我想有这样List<Foo>
对象
我想你可以使用一个DropWizard的泽西岛客户端。根据该文件,它不正是你所期待的。
http://www.dropwizard.io/1.0.3/docs/manual/client.html
即:
public class ExampleConfiguration extends Configuration {
@Valid
@NotNull
private JerseyClientConfiguration jerseyClient = new JerseyClientConfiguration();
@JsonProperty("jerseyClient")
public JerseyClientConfiguration getJerseyClientConfiguration() {
return jerseyClient;
}
}
然后,在你的服务的run方法,创建一个新的JerseyClientBuilder:
@Override
public void run(ExampleConfiguration config,
Environment environment) {
final Client client = new JerseyClientBuilder(environment).using(config.getJerseyClientConfiguration())
.build(getName());
environment.jersey().register(new ExternalServiceResource(client));
}