PluRav helped me out on my other discussion, but I decided to start a new discussion centered around server certificates. When I run this code:
Client client = ClientConfig.builder().serverUrl("https://{ip}/suite-api")
.basicAuth("user", "pass")
.useJson()
.build()
.newClient();
AdapterInstancesInfoDto adapters = client.adapterInstancesClient().list();
I get two error messages:
client.HttpClientFactory - No verification of server certificates
client.RestTemplate - Get "url" resulted in 401 unauthorized; invoking handler error
I suspect I need to tell the code to trust the self-signed certificate but I'm unsure how to do that.
Any help would be appreciated.
Give this a try, do you get any output now?
public static void main(String[] args) {
try {
Client client = ClientConfig
.builder()
.serverUrl("https://123.45.67.89/suite-api")
.basicAuth("admin", "password")
.verify("false")
.useJson()
.build()
.newClient();
//retrieve list of all adapter instances
AdapterInstancesInfoDto adapterInstances = client.adapterInstancesClient().list();
//get actual set of adapters
Set<AdapterInstanceInfoDto> adapters = adapterInstances.getAdapterInstancesInfoDto();
//iterate the set
for (AdapterInstanceInfoDto adapter : adapters) {
//print to console
System.out.println(ReflectionToStringBuilder.reflectionToString(adapter, ToStringStyle.MULTI_LINE_STYLE));
}
} catch (Exception e) {
e.printStackTrace();
}
}
From the documentation is seems I need to use HttpClientFactory.SuiteApiTrustManager package.
I just don't know how to implement the X509Certificate method here. Any help would be appreciated.
Heya, are you running exactly this code?
If yes,i'd start from checking if a user "user" exists in your vrops
Also, from what i remember the first error - "No verification..." is actually just a warning.
Of course I stripped out the credentials for this post. But yes, when I input actual valid credentials into the code that is the error I get.
Sorry, just wanted to be sure.
Do you need to validate the certificate? You might be able to skip it.
To do so:
Client client = ClientConfig.builder().serverUrl("https://{ip}/suite-api")
.basicAuth("user", "pass")
.verify("false")
.useJson()
.build()
.newClient();
Still get this error:
client.HttpClientFactory - No verification of server certificates
Then I get build succeeds. But there is no output in the console.
Hmm, strange. I don't remember having similar problems.
Can you add the whole code you're running as well as it's output?
package restapi;
import com.vmware.ops.api.client.Client;
import com.vmware.ops.api.client.Client.ClientConfig;
import com.vmware.ops.api.model.adapter.AdapterInstanceInfoDto.AdapaterInstanceInfoDto;
public class Restapi{
public static void main(string[] args) {
Client client = ClientConfig.builder().serverUrl("https://{ip}/suite-api")
.basicAuth("user", "pass")
.verify("false")
.useJson()
.build()
.newClient();
AdapterInstancesInfoDto adapters = client.adapterInstancesClient().list();
}
};
output:
run:
0 [main] DEBUG com.vmware.ops.api.client.HttpClientFactory - No verification of server certificates
Build Successful: (Run Time 6 Seconds)
Give this a try, do you get any output now?
public static void main(String[] args) {
try {
Client client = ClientConfig
.builder()
.serverUrl("https://123.45.67.89/suite-api")
.basicAuth("admin", "password")
.verify("false")
.useJson()
.build()
.newClient();
//retrieve list of all adapter instances
AdapterInstancesInfoDto adapterInstances = client.adapterInstancesClient().list();
//get actual set of adapters
Set<AdapterInstanceInfoDto> adapters = adapterInstances.getAdapterInstancesInfoDto();
//iterate the set
for (AdapterInstanceInfoDto adapter : adapters) {
//print to console
System.out.println(ReflectionToStringBuilder.reflectionToString(adapter, ToStringStyle.MULTI_LINE_STYLE));
}
} catch (Exception e) {
e.printStackTrace();
}
}
Thank You. That worked. Can't believe I didn't realize I needed an output statement. It seems I have a lot of learning left to do!