Два решения:
Решения 1
так AA 3.0 (до сих пор в снимке), вы можете использовать interceptors поле на @Rest
аннотации и реализовать пользовательские ClientHttpRequestInterceptor
, которые будут устанавливать заголовки каждого запрос:
public class HeadersRequestInterceptor implements ClientHttpRequestInterceptor {
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
request.getHeaders().set("Connection", "Close");
return execution.execute(request, body);
}
}
Решение 2
С AA < = 2.7.1 вы должны создать аннотированный класс @EBean
с введенным интерфейсом Rest. Этот компонент будет заменен всем введенным интерфейсом Rest на других классах. В этом новом компоненте, создать @AfterInject
метод, который будет извлекать экземпляр RestTemplate
и настроить перехватчик раствора 1:
RestClient.java:
@Rest(...)
public interface RestClient {
@Post("base/setItem.php")
Item setItem(Protocol protocol);
RestTemplate getRestTemplate();
}
RestClientProxy.java:
@EBean
public class RestClientProxy {
@RestService
RestClient restClient;
@AfterInject
void init() {
RestTemplate restTemplate = restClient.getRestTemplate();
List<ClientHttpRequestInterceptor> interceptors = restTemplate.getInterceptors();
interceptors.add(new HeadersRequestInterceptor());
}
}