use of com.ibm.cloud.sdk.core.security.IamAuthenticator in project java-sdk by watson-developer-cloud.
the class LanguageTranslatorExample method main.
public static void main(String[] args) {
Authenticator authenticator = new IamAuthenticator("<iam_api_key>");
LanguageTranslator service = new LanguageTranslator("2018-05-01", authenticator);
TranslateOptions translateOptions = new TranslateOptions.Builder().addText("text").modelId("en-es").build();
TranslationResult translationResult = service.translate(translateOptions).execute().getResult();
System.out.println(translationResult);
}
use of com.ibm.cloud.sdk.core.security.IamAuthenticator in project java-sdk by watson-developer-cloud.
the class LanguageTranslatorIT method setUp.
/**
* Sets up the tests.
*
* @throws Exception the exception
*/
/*
* (non-Javadoc)
* @see com.ibm.watson.developercloud.WatsonServiceTest#setUp()
*/
@Override
@Before
public void setUp() throws Exception {
super.setUp();
String iamApiKey = System.getenv("LANGUAGE_TRANSLATOR_APIKEY");
String serviceUrl = System.getenv("LANGUAGE_TRANSLATOR_URL");
if (iamApiKey == null) {
iamApiKey = getProperty("language_translator.apikey");
serviceUrl = getProperty("language_translator.url");
}
assertNotNull("LANGUAGE_TRANSLATOR_APIKEY is not defined and config.properties doesn't have valid credentials.", iamApiKey);
Authenticator authenticator = new IamAuthenticator(iamApiKey);
service = new LanguageTranslator("2018-05-01", authenticator);
service.setServiceUrl(serviceUrl);
// issue currently where document translation fails with learning opt-out
Map<String, String> headers = new HashMap<>();
headers.put(WatsonHttpHeaders.X_WATSON_TEST, "1");
service.setDefaultHeaders(headers);
}
use of com.ibm.cloud.sdk.core.security.IamAuthenticator in project java-sdk by watson-developer-cloud.
the class AssistantServiceTest method setUp.
/**
* Sets up the tests.
*
* @throws Exception the exception
*/
/*
* (non-Javadoc)
* @see com.ibm.watson.common.WatsonServiceTest#setUp()
*/
@Override
@Before
public void setUp() throws Exception {
super.setUp();
String apiKey = System.getenv("ASSISTANT_APIKEY");
workspaceId = System.getenv("ASSISTANT_WORKSPACE_ID");
String serviceUrl = System.getenv("ASSISTANT_URL");
if (apiKey == null) {
apiKey = getProperty("assistant.apikey");
workspaceId = getProperty("assistant.workspace_id");
serviceUrl = getProperty("assistant.url");
}
Assume.assumeFalse("ASSISTANT_APIKEY is not defined and config.properties doesn't have valid credentials.", apiKey == null);
Authenticator authenticator = new IamAuthenticator(apiKey);
service = new Assistant("2019-02-28", authenticator);
service.setServiceUrl(serviceUrl);
service.setDefaultHeaders(getDefaultHeaders());
}
use of com.ibm.cloud.sdk.core.security.IamAuthenticator in project java-sdk by watson-developer-cloud.
the class AssistantServiceTest method setUp.
/**
* Sets up the tests.
*
* @throws Exception the exception
*/
/*
* (non-Javadoc)
* @see com.ibm.watson.common.WatsonServiceTest#setUp()
*/
@Override
@Before
public void setUp() throws Exception {
super.setUp();
String apiKey = System.getenv("ASSISTANT_APIKEY");
assistantId = System.getenv("ASSISTANT_ASSISTANT_ID");
String serviceUrl = System.getenv("ASSISTANT_URL");
if (apiKey == null) {
apiKey = getProperty("assistant.apikey");
assistantId = getProperty("assistant.assistant_id");
serviceUrl = getProperty("assistant.url");
}
Assume.assumeFalse("ASSISTANT_APIKEY is not defined and config.properties doesn't have valid credentials.", apiKey == null);
Authenticator authenticator = new IamAuthenticator(apiKey);
service = new Assistant("2019-02-28", authenticator);
service.setServiceUrl(serviceUrl);
service.setDefaultHeaders(getDefaultHeaders());
}
use of com.ibm.cloud.sdk.core.security.IamAuthenticator in project java-sdk by watson-developer-cloud.
the class DiscoveryIT method setUp.
/**
* Sets up the tests.
*
* @throws Exception the exception
*/
/*
* (non-Javadoc)
*
* @see com.ibm.watson.common.WatsonServiceTest#setUp()
*/
@Override
@Before
public void setUp() throws Exception {
super.setUp();
String apiKey = System.getenv("DISCOVERY_V2_APIKEY");
String serviceUrl = System.getenv("DISCOVERY_V2_URL");
if (apiKey == null) {
apiKey = getProperty("discovery_v2.apikey");
serviceUrl = getProperty("discovery_v2.url");
}
assertNotNull("DISCOVERY_V2_APIKEY is not defined and config.properties doesn't have valid credentials.", apiKey);
Authenticator authenticator = new IamAuthenticator(apiKey);
service = new Discovery(VERSION, authenticator);
service.setDefaultHeaders(getDefaultHeaders());
service.setServiceUrl(serviceUrl);
HttpConfigOptions configOptions = new HttpConfigOptions.Builder().disableSslVerification(true).build();
service.configureClient(configOptions);
}
Aggregations