I am trying to call the Data Conversion service from a Java program: http://document-conversion-demo.mybluemix.net I tried using my bluemix credentials but this is not working or correct. What is the correct process to obtain valid credentials to use this service?
This is my trap using bluemix valid credentials
Sep 21, 2015 10:46:54 AM com.ibm.watson.developer_cloud.service.WatsonService execute SEVERE: HTTP Status: 401, message: null Exception in thread "main" com.ibm.watson.developer_cloud.service.UnauthorizedException: Unauthorized: Access is denied due to invalid credentials at com.ibm.watson.developer_cloud.service.WatsonService.execute(WatsonService.java:198) at com.ibm.watson.developer_cloud.document_conversion.v1.DocumentConversion.execute(DocumentConversion.java:254) at com.ibm.watson.developer_cloud.document_conversion.v1.helpers.ConvertDocumentHelper.convertDocument(ConvertDocumentHelper.java:122) at com.ibm.watson.developer_cloud.document_conversion.v1.helpers.ConvertDocumentHelper.convertDocument(ConvertDocumentHelper.java:88) at com.ibm.watson.developer_cloud.document_conversion.v1.helpers.ConvertDocumentHelper.convertDocumentToAnswer(ConvertDocumentHelper.java:70) at com.ibm.watson.developer_cloud.document_conversion.v1.DocumentConversion.convertDocumentToAnswer(DocumentConversion.java:193)
Answer by Leo Kenji (428) | Sep 21, 2015 at 01:52 PM
You must first add the service to your bluemix application.
After that, your code will get the credentials dynamically from the system environment variable called VCAP_SERVICES
System.getenv("VCAP_SERVICES");
VCAP_SERVICES is a string in the JSON format that contains an entry for each service bound to your application, for example
{
"document_conversion": [
{
"name": "docConv",
"label": "document_conversion",
"plan": "experimental",
"credentials": {
"url": "https://gateway.watsonplatform.net/document-conversion-experimental/api",
"username": "****",
"password": "****"
}
}
]
}
so you have to parse this JSON and extract your credentials from there.
In my case, for example, I use flexjson, but could be any other JSON library (GSON, Jackson, whatever)
private static final JSONDeserializer<Map<String, List<Map<String, Map<String, String>>>>> json = new JSONDeserializer<>();
String username = dto.setUsername(map.get("document_conversion").get(0).get("credentials")
.get("username"));
String password = dto.setUsername(map.get("document_conversion").get(0).get("credentials")
.get("password"));
An then you can use the excellent java-wrappers library (as it seems you're already using)
import com.ibm.watson.developer_cloud.document_conversion.v1.DocumentConversion;
import com.ibm.watson.developer_cloud.document_conversion.v1.model.DocumentCollection;
import java.util.HashMap;
import java.util.Map;
DocumentConversion service = new DocumentConversion();
service.setUsernameAndPassword(username, password);
Map<String, Object> docListParams = new HashMap<String, Object>();
docListParams.put(DocumentConversion.LIMIT, 10);
DocumentCollection documentCollection = service.getDocumentCollection(docListParams);
System.out.println(documentCollection);
Notice that, if I am not wrong, password are periodicaly rotated in bluemix, so you must avoid using hardcoded ones.
Answer by William_von_Hagen (626) | Sep 21, 2015 at 08:50 PM
The WDC docs contain a getting started section (Docs -> Getting Started) that we typically link to from service docs or excerpt from as the first step of our tutorials. It looks as though we didn't do that for the Doc Conversion tutorial and docs. Thanks for pointing that out - we will fix that. It contains sections on obtaining Bluemix credentials, discusses the VCAP_SERVICES environment variable, and also explains how to get and examine credentials within the Bluemix web interface. Comments welcome, and sorry that this information was hard to find in this case.
Why are we seeing CSQX541E for a client connection using data conversion ? 1 Answer
what is reason and why qmgr certificate should be received not be added me mq ssl? 1 Answer
why qmgr certificate should be received not to be added in mq ssl what is the reason behind it? 1 Answer
CSQX014E listener exceeded channel limit, TRPTYPE=TCP,INDISP=disposition 1 Answer