@Test public void intercept() throws IOException { DTMContext dtmContext = DTMContext.getDTMContext(); int expectGlobalTxId = 100; dtmContext.setGlobalTxId(expectGlobalTxId); ClientHttpRequestExecution clientHttpRequestExecution = new ClientHttpRequestExecution() { @Override public ClientHttpResponse execute(HttpRequest request, byte[] body) throws IOException { return null; } }; HttpHeaders header = new HttpHeaders(); HttpRequest request = new HttpRequest() { @Override public String getMethodValue() { return null; } @Override public URI getURI() { return null; } @Override public HttpHeaders getHeaders() { return header; } }; clientHttpRequestInterceptor.intercept(request, null, clientHttpRequestExecution); DtmContextDTO dtmContextDTO = Json.decodeValue(header.get(DtmConstants.DTM_CONTEXT).get(0), DtmContextDTO.class); assertEquals(dtmContextDTO.getGlobalTxId(), expectGlobalTxId); }
@Override public ClientHttpResponse intercept(HttpRequest httpRequest, byte[] bytes, ClientHttpRequestExecution clientHttpRequestExecution) throws IOException { DTMContext dtmContext = DTMContext.getDTMContext(); long gid = dtmContext.getGlobalTxId(); HttpHeaders headers = httpRequest.getHeaders(); if (gid != -1) { DtmContextDTO dtmContextDTO = DtmContextDTO.fromDtmContext(dtmContext); headers.add(DtmConstants.DTM_CONTEXT, Json.encode(dtmContextDTO)); } return clientHttpRequestExecution.execute(httpRequest, bytes); }
DtmRestTemplateInterceptor implements ClientHttpRequestInterceptor { @Override public ClientHttpResponse intercept(HttpRequest httpRequest, byte[] bytes, ClientHttpRequestExecution clientHttpRequestExecution) throws IOException { DTMContext dtmContext = DTMContext.getDTMContext(); long gid = dtmContext.getGlobalTxId(); HttpHeaders headers = httpRequest.getHeaders(); if (gid != -1) { DtmContextDTO dtmContextDTO = DtmContextDTO.fromDtmContext(dtmContext); headers.add(DtmConstants.DTM_CONTEXT, Json.encode(dtmContextDTO)); } return clientHttpRequestExecution.execute(httpRequest, bytes); } }
DtmRestTemplateInterceptor implements ClientHttpRequestInterceptor { @Override public ClientHttpResponse intercept(HttpRequest httpRequest, byte[] bytes, ClientHttpRequestExecution clientHttpRequestExecution) throws IOException { DTMContext dtmContext = DTMContext.getDTMContext(); long gid = dtmContext.getGlobalTxId(); HttpHeaders headers = httpRequest.getHeaders(); if (gid != -1) { DtmContextDTO dtmContextDTO = DtmContextDTO.fromDtmContext(dtmContext); headers.add(DtmConstants.DTM_CONTEXT, Json.encode(dtmContextDTO)); } return clientHttpRequestExecution.execute(httpRequest, bytes); }  }
DtmRestTemplateInterceptor implements ClientHttpRequestInterceptor { @Override public ClientHttpResponse intercept(HttpRequest httpRequest, byte[] bytes, ClientHttpRequestExecution clientHttpRequestExecution) throws IOException { DTMContext dtmContext = DTMContext.getDTMContext(); long gid = dtmContext.getGlobalTxId(); HttpHeaders headers = httpRequest.getHeaders(); if (gid != -1) { DtmContextDTO dtmContextDTO = DtmContextDTO.fromDtmContext(dtmContext); headers.add(DtmConstants.DTM_CONTEXT, Json.encode(dtmContextDTO)); } return clientHttpRequestExecution.execute(httpRequest, bytes); }  @Override ClientHttpResponse intercept(HttpRequest httpRequest, byte[] bytes,
      ClientHttpRequestExecution clientHttpRequestExecution); }
DtmRestTemplateInterceptor implements ClientHttpRequestInterceptor { @Override public ClientHttpResponse intercept(HttpRequest httpRequest, byte[] bytes, ClientHttpRequestExecution clientHttpRequestExecution) throws IOException { DTMContext dtmContext = DTMContext.getDTMContext(); long gid = dtmContext.getGlobalTxId(); HttpHeaders headers = httpRequest.getHeaders(); if (gid != -1) { DtmContextDTO dtmContextDTO = DtmContextDTO.fromDtmContext(dtmContext); headers.add(DtmConstants.DTM_CONTEXT, Json.encode(dtmContextDTO)); } return clientHttpRequestExecution.execute(httpRequest, bytes); }  @Override ClientHttpResponse intercept(HttpRequest httpRequest, byte[] bytes,
      ClientHttpRequestExecution clientHttpRequestExecution);  }