在Restlet 2.3(SE)我试图使用媒体类型来控制版本。我当前的尝试包括在我的呼入路由注册新的扩展:Restlet使用自定义媒体类型
@Override
public Restlet createInboundRoot() {
...
getTunnelService().setExtensionsTunnel(true);
getMetadataService().addExtension("vnd.myapp.v1", MediaType.valueOf("application/vnd.myapp.v1+json"));
getMetadataService().addExtension("vnd.myapp.v2", MediaType.valueOf("application/vnd.myapp.v2+json"));
...
}
我的资源接口则设置如下:
public interface UsersResource {
@Options
void getCorsSupport();
@Get("vnd.myapp.v1")
Collection<User> representV1() throws Exception;
// Should be the default if */* is specified
@Get("json | vnd.myapp.v2")
Collection<User> representV2() throws Exception;
}
然后我试图指定如下的媒体类型:
http://localhost:8080/api/users?media=vnd.myapp.v1
这个想法是,如果有人指定媒体类型为vnd.myapp.v1
,他们得到representV1()
(JSON),如果他们指定媒体类型为vnd.myapp.v2
他们得到representV2()
(JSON)和(可选),如果他们没有要求任何具体的东西representV2()
。有了上述设置,无论要求什么,我总是会回到representV2()
。
问题修复。该修复将在2.3.3中提供。 –