TentantContextClientInterceptor implements ClientInterceptor { @Override public boolean handleRequest(MessageContext messageContext) throws WebServiceClientException { TransportContext transportContext = TransportContextHolder.getTransportContext(); WebServiceConnection webServiceConnection = transportContext.getConnection(); final String tenant = TenantContextHolder.getContext().getTenant(); if (webServiceConnection instanceof HeadersAwareSenderWebServiceConnection) { if (StringUtils.hasText(tenant)) { try { ((HeadersAwareSenderWebServiceConnection) webServiceConnection).addRequestHeader(getHeaderName(), tenant); } catch (IOException e) { throw new WebServiceIOException("Error setting header '" + getHeaderName() + "' on connection.", e); } } } return true; }  @Override boolean handleRequest(MessageContext messageContext); @Override boolean handleResponse(MessageContext messageContext); @Override boolean handleFault(MessageContext messageContext); @Override void afterCompletion(MessageContext messageContext, Exception ex); String getHeaderName(); void setHeaderName(String headerName);  }
@Test public void whenNoTenantSetNoHeaderShouldBeSet() throws Exception { TenantContextHolder.clearContext(); this.interceptor.handleRequest(null); verify(this.connection, never()).addRequestHeader(any(String.class), any(String.class)); }
@Test public void whenTenantSetHeaderShouldBeSet() throws Exception { TenantContextTestUtil.setCurrentTenant(HEADER_VAL); this.interceptor.handleRequest(null); verify(this.connection, times(1)).addRequestHeader(DEFAULT_HEADER, HEADER_VAL); }
@Test(expected = WebServiceIOException.class) public void whenIOExceptionThrownShouldBeConverted() throws Exception { doThrow(new IOException("test")).when(this.connection).addRequestHeader(DEFAULT_HEADER, HEADER_VAL); TenantContextTestUtil.setCurrentTenant(HEADER_VAL); this.interceptor.handleRequest(null); }