Java
The same concepts apply. This section covers the Java-specific install, configuration, and patterns.
Install
Maven
XML
<dependency>
<groupId>com.wexinc</groupId>
<artifactId>wex-health-sdk<artifactId>
<version>1.0.16</version>
</dependency>
<dependency>
<groupId>com.wexinc</groupId>
<artifactId>wex-health-sdk</artifactId>
<version>1.0.16</version>
</dependency>
Configure
Register ApiClient as a Spring @Bean (singleton by default). All API classes share the same instance and the same cached token:
Java
@Configuration
public class WexHealthConfig { @Value("${wex.health.base-path}")
private String basePath;
@Bean
public ApiClient wexApiClient() {
ApiClient apiClient = new ApiClient();
apiClient.setBasePath(basePath);
// OAuth2 auto-configured from WEX_OAUTH2_* environment variables
return apiClient;
}
@Bean
public ClaimsApi claimsApi(ApiClient apiClient) {
return new ClaimsApi(apiClient);
}
}YAML
# application.yml
wex:
health:
base-path: https://platform.uat.benefits.wexglobal.com
oauth2:
token-url: ${WEX_OAUTH2_TOKEN_URL}
client-id: ${WEX_OAUTH2_CLIENT_ID}
client-secret: ${WEX_OAUTH2_CLIENT_SECRET}To provide a bearer token manually when your service manages its own token lifecycle:
Java
HttpBearerAuth bearerAuth = (HttpBearerAuth) apiClient.getAuthentication("bearerAuth");
bearerAuth.setBearerToken("your-bearer-token");Call APIs
Java
// Single claim — pass a correlation ID as the third argument
ClaimDTO claim = claimsApi.getClaim(personId, claimNumber, UUID.randomUUID().toString())
.toEntity(ClaimDTO.class)
.getBody();
// Paginated claims
ClaimsDTO claims = claimsApi.getClaimsForParticipant(personId, 0, 50, "DESC", requestId)
.toEntity(ClaimsDTO.class)
.getBody();
// Health check
boolean isHealthy = new HealthApi(apiClient).getLiveness()
.toBodilessEntity().getStatusCode().is2xxSuccessful();
Handle Errors
Retry (see Retry Contract) runs automatically before any exception reaches your code.
Java
try {
return claimsApi.getClaim(personId, claimNumber, requestId)
.toEntity(ClaimDTO.class).getBody();
} catch (HttpClientErrorException e) {
// 4xx — bad request, not found, unauthorized
log.error("Client error: {} - {}", e.getStatusCode(), e.getResponseBodyAsString());
throw new BusinessException("Invalid request", e);
} catch (HttpServerErrorException e) {
// 5xx — reached here only after all retries exhausted
log.error("Server error: {} - {}", e.getStatusCode(), e.getResponseBodyAsString());
throw new ServiceException("Service unavailable", e);
}
Logging
Add an SLF4J binding (Logback recommended) and logs appear automatically — no additional configuration needed:
XML
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency> Was this section helpful?
On this page
- Java