I want to use third party client API. I want to create an instance of ServiceClient and use postMessage API. I created two classes, ServiceClient and ServiceClientAPI How should I bind it? Thanks a lot!
public class ServiceClient {
@Provides
@Singleton
public ServiceClient provideServiceClient() {
return new ServiceClientBuilder()
.withEndpoint()
.withClient(ClientBuilder.newClient())
.withSystem(SystemBuilder.standard().build())
.build();
}
public class ServiceClientAPI {
private static final Logger LOGGER = LoggerFactory.getLogger(ServiceClientAPI.class);
@Inject
private ServiceClient ServiceClient;
public Value postMessage(@NonNull Value value) {
LOGGER.info("Value is " + value);
try {
Response response = ServiceClient.postMessage(value);
return response;
} catch (Exception ex) {
String errMsg = String.format("Error hitting the Service");
LOGGER.error(errMsg, ex);
throw new Exception(errMsg, ex);
}
}
It doesn't work, how should I bind them?
public class ServiceModule extends AbstractModule {
@Override
protected void configure() {
bind(ServiceClient.class).to(ServiceClientAPI.class);
}
}