2011-01-27 20 views
0

我正尝试创建一个使用CRest与REST风格的Web服务接口的Android应用程序。使用CRest的可配置端点

我遇到的问题是创建服务。在twitter示例中,EndPoint被设置为静态url(api.twitter.com),但在我的情况下,我需要它可配置,因为直到用户指定它才会知道端点。

我想什么做的是沿着此线的东西:

@EndPoint("http://%s.somedomain.com") 
@ContextPath("/admin") 

public interface ProductService { 
    @Path("/products.json") 
    InputStream getProducts(); 

    @Path("/products/{0}.json") 
    InputStream getProduct(int id); 
} 

有没有我可以在创建服务的指定方式的端点

回答

0

看一看的quick start链接,在底部,你可以找到这段代码:

Properties props = new Properties(); 
props.setProperty("service.end-point", "http://127.0.0.1:8080"); 

CRest crest = new CRestBuilder() 
         .overrideDefaultConfigWith(props) 
         .build(); 

下一个发布版本有一个更简单的方法来做到这一点,无论是通过建造或通过修道院如上所述,在注释值上使用占位符。

0

BTW占位符的实现有现在http://crest.codegist.org/annotations/api.html

@EndPoint("http://{my.interface.host}") 
public interface MyInterface { 
    ... 
} 

记录与

String myInterfaceHost = ...; 

CRest crest = CRest.placeholder("my.interface.host", myInterfaceHost).build(); 

MyInterface myInterface = crest.build(MyInterface.class); 
使用