「java」ClientHttpRequestInterceptorを実装するサンプルコード
Javaコード
public class TokenInterceptor implements ClientHttpRequestInterceptor
{
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException
{
String chkTokenUrl = request.getURI().getPath();
int ttTime = (int) (System.currentTimeMillis() / 1000 + 1800);
String methodName = request.getMethod().name();
String requestBody = new String(body);
String token = TokenHelper.generateToken(chkTokenUrl, ttTime, methodName, requestBody);
request.getHeaders().add(“X-Auth-Token",token);
return execution.execute(request, body);
}
}