public class TestClient {
private static ComputeManagementClient computeManagementClient;
private static ManagementClient client;
private static URI uri;
private static String subscriptionId;
private static String keyStoreLocation;
private static String keyStorePassword;
private static KeyStoreType keyStoreType;
public static Configuration createConfiguration() throws IOException,URISyntaxException{
uri = new URI("https://management.core.windows.net/");
subscriptionId="1dd1940e-9979-476c-a5dc-79a7d31686fd";
keyStoreLocation="C:\\Program Files\\Java\\jdk1.8.0_40\\bin\\AzureKeyStore.jks";
keyStorePassword="123456";
keyStoreType= KeyStoreType.fromString("jks");
Configuration configuration = ManagementConfiguration.configure(uri, subscriptionId,
keyStoreLocation, keyStorePassword,keyStoreType);
configuration.setProperty("testprefix.com.microsoft.windowsazure.services.core.Configuration.connectTimeout","3");
configuration.setProperty("testprefix.com.microsoft.windowsazure.services.core.Configuration.readTimeout","7");
return configuration;
}
/**
* https://management.core.windows.net/1dd1940e-9979-476c-a5dc-79a7d31686fd/services/resourceextensions
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
computeManagementClient = ComputeManagementService.create(createConfiguration());
client = ManagementService.create(createConfiguration());
// get the list of regions
LocationsListResponse response = client.getLocationsOperations().list();
ArrayList<LocationsListResponse.Location> locations = response.getLocations();
// write them out
for( int i=0; i<locations.size(); i++){
System.out.println(locations.get(i).getDisplayName());
}
HostedServiceListResponse hostedServiceListResponse = computeManagementClient.getHostedServicesOperations().list();
System.out.println("statusCode:"+hostedServiceListResponse.getStatusCode());
VirtualMachineExtensionListResponse virtualMachineExtensionListResponse = computeManagementClient.getVirtualMachineExtensionsOperations().list();
System.out.println("................response........................");
System.out.println("requestId:" + virtualMachineExtensionListResponse.getRequestId());
System.out.println("statusCode:"+virtualMachineExtensionListResponse.getStatusCode());
ArrayList<VirtualMachineExtensionListResponse.ResourceExtension> list= virtualMachineExtensionListResponse.getResourceExtensions();
if( list != null && !list.isEmpty() ){
for( VirtualMachineExtensionListResponse.ResourceExtension resourceExtension : list){
System.out.println("resourceExtension:"+resourceExtension.getName());
}
}
}
}
但依然报http 403错误
This XML file does not appear to have any style information associated with it. The document tree is shown below.ForbiddenError
The server failed to authenticate the request. Verify that the certificate is valid and is associated with this subscription.