[英]Configurable Endpoints using CRest
I'm trying to create an Android application that uses CRest to interface with a RESTful web service. 我正在尝试创建一个使用CRest与RESTful Web服务接口的Android应用程序。
The issue I am having is with the creation of a Service. 我遇到的问题与服务的创建有关。 In the twitter examples the EndPoint is set to a static url (api.twitter.com) but in my case I need it to be configurable since we won't know the endpoint until the user specifies it.
在Twitter示例中,EndPoint设置为静态URL(api.twitter.com),但在我的情况下,我需要将其配置为可配置的,因为直到用户指定端点,我们才知道端点。
What I would like to do is something along the lines of this: 我想做的事情与此类似:
@EndPoint("http://%s.somedomain.com")
@ContextPath("/admin")
public interface ProductService {
@Path("/products.json")
InputStream getProducts();
@Path("/products/{0}.json")
InputStream getProduct(int id);
}
Is there a way I can specify on the creation of the service where the EndPoint 有没有一种方法可以在创建服务时指定EndPoint
BTW the placeholder implementation is there and documented now http://crest.codegist.org/annotations/api.html 顺便说一句,占位符实现在那里并且现在有文档http://crest.codegist.org/annotations/api.html
@EndPoint("http://{my.interface.host}")
public interface MyInterface {
...
}
Used with 用于
String myInterfaceHost = ...;
CRest crest = CRest.placeholder("my.interface.host", myInterfaceHost).build();
MyInterface myInterface = crest.build(MyInterface.class);
Have a look at the quick start link, at the bottom you can find this piece of code: 看一下快速入门链接,在底部可以找到以下代码:
Properties props = new Properties();
props.setProperty("service.end-point", "http://127.0.0.1:8080");
CRest crest = new CRestBuilder()
.overrideDefaultConfigWith(props)
.build();
Next release will have an easier way to do it, either through the Builder or through a convention with placeholders on annotation values as you mentioned. 如您所提到的,通过Builder或通过在注释值上带有占位符的约定,下一发行版将具有更简便的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.