2011-01-27 19 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); 
使用