为什么我在android注释中的代码在日志中没有任何内容时失败

时间:2013-09-04 01:08:24

标签: android rest annotations android-annotations

我是Android注释的新手,所以也许我错过了一些东西,但我基本上是在尝试复制其他客户端https://github.com/excilys/androidannotations/wiki/Rest%20API这里

我的拦截器定义如下

@EBean(scope = Scope.Singleton)
public class RestInterceptor implements ClientHttpRequestInterceptor{

final String TAG = "rest";

@Bean
AuthStore authStore;

@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] data, ClientHttpRequestExecution execution)
        throws IOException{

    //Need to set the api key here but nothing happens code quits
//        Log.d("Rest",authStore.getSessionKey());

     HttpHeaders headers = request.getHeaders();

     headers.set("api_key",authStore.getApiKey());

     ClientHttpResponse resp = execution.execute(request, data);

     HttpStatus code = resp.getStatusCode();

     Log.d(TAG,resp.getBody().toString());

     if(code.value() == 200){
        Log.d(TAG,"success code 200"); 

     }
     else{
         Log.d(TAG,"fail code" + code.toString());
     }
     return resp;
}

}

但是当我尝试添加额外的标头时,代码才会退出。 auth商店类看起来像这样

@EBean(scope = Scope.Singleton)
 public class AuthStore {

public String apiKey,sessionKey;

public String getApiKey() {
    return apiKey;
}

public void setApiKey(String apiKey) {
    this.apiKey = apiKey;
}

public String getSessionKey() {
    return sessionKey;
}

public void setSessionKey(String sessionKey) {
    this.sessionKey = sessionKey;
}

}

休息界面

@Rest(rootUrl = "https://pathtoapi/rest/public/", converters = {     GsonHttpMessageConverter.class }, interceptors = {RestInterceptor.class })
public interface ApiClient {

@Get("force_login")
ApiSession forceLogin();

// if you need to add some configuration to the Spring RestTemplate.
RestTemplate getRestTemplate();

void setRestTemplate(RestTemplate restTemplate);

}

0 个答案:

没有答案