0

I try to code MS Azure Java client code like below,

Configuration config = ManagementConfiguration.configure(
          new URI(uri), 
          subscriptionId, 
          keyStoreLocation,
          keyStorePassword,
         KeyStoreType.jks
       );
   
   ManagementClient mclient = ManagementService.create(config);
   
   System.out.println("Azure URI Path : " + mclient.getBaseUri()); 
   System.out.println("Azure API Version : " + mclient.getApiVersion());
   System.out.println("Azure의 Publishing ID : " + mclient.getCredentials().getSubscriptionId());
   
   LocationsListResponse lresp = mclient.getLocationsOperations().list(); **// this line throws error**
   ArrayList<Location> locations = lresp.getLocations();
   System.out.println("Azure Regions : ");
   for( int i=0; i<locations.size(); i++){
    System.out.println("\t" + locations.get(i).getName());
   }

The following error is throws

Azure URI path : https://azure.microsoft.com/
Azure API verion : 2014-10-01
Azure publishing ID : 92a65f9e-b6b6-4eaa-b5f7-e3180db19b62


    [Fatal Error] :1:747: element type "n.length" next attribute ">" 또는 "/>"가 와야 합니다.
    Exception in thread "main" com.microsoft.windowsazure.exception.ServiceException:  <html> <head><script type="text/javascript">window.NREUM||(NREUM={});NREUM.info = {"beacon":"bam.nr-data.net","errorBeacon":"bam.nr-data.net","licenseKey":"b39980acba","applicationID":"10503464,11287305","transactionName":"Y1VSYkBRWEIEWhcICVoffWBxH2VYEVwgDghAQl9aXlVEHjVYBAQ=","queueTime":0,"applicationTime":29,"ttGuid":"7E0843DBD8B8C0A","agent":""}</script><script type="text/javascript> <style>
             body {
                 background-color: #1a1a1a;
             }
    
            .tutorial-icon svg use {
                 stroke: #00abec;
             }
         </style> </head> <body> <svg class="svg-definition"><defs><symbol id="azure" viewBox="-1 -1 34 34"><path d="M19,17.4c-0.8,0-1.5,0.5-1.9,1.2H5.3v0c-2,0-3.6-1.6-3.6-3.6s1.6-3.6,3.6-3.6v0h0h0H7
    
     <div class="column medium-9"> <ul class="linkList linkList-horizontal"> <li><a href="Feedbackhttps://feedback.azure.com/forums/34192--general-feedback">Feedback</a></li> <li><a href="Trademarkshttps://go.microsoft.com/fwlink/?LinkId=222682&clcid=0x409">Trademarks</a></li> <li><a href="Privacy">https://go.microsoft.com/fwlink/?LinkId=248681&clcid=0x409">Privacy &amp; Cookies</a></li> </ul> </div> <div class="column medium-3"> <div class="footer-copyright pull-right"> <a href="https://www.microsoft.com" class="logo-microsoft">Microsoft</a> <span>&copy; 2016 Microsoft</span> </div> </div> </div> </footer> <script type="text/javascript">
             function clearTextInput() {
                 document.getElementById('search-404').reset();
    
    
          .....
         </script> </body> </html>
      at com.microsoft.windowsazure.exception.ServiceException.createFromXml(ServiceException.java:216)
      at com.microsoft.windowsazure.management.LocationOperationsImpl.list(LocationOperationsImpl.java:162)
      at com.aaa.azure.JavaClient.main(JavaClient.java:60)

Java SDK is integrated with Eclipse with Build Path.

Any idea?

halfer
  • 19,824
  • 17
  • 99
  • 186
Joseph Hwang
  • 1,337
  • 3
  • 38
  • 67
  • I generated jks file with this command, keytool.exe –importkeystore –srckeystore SampleRemoteAccessPrivate.pfx -destkeystore .\SampleRemoteAccessPrivate.jks -srcstoretype pkcs12 -deststoretype JKS . But this time the exception is thrown like this, Exception in thread "main" com.microsoft.windowsazure.exception.ServiceException: ForbiddenError: The server failed to authenticate the request. – Joseph Hwang Jun 05 '16 at 03:30

1 Answers1

0

According to the error information, it seems that you used the incorrect uri https://azure.microsoft.com/ for the ManagementConfiguration.

As I know, the URI for authenticating Azure Service Management is https://management.core.windows.net/

More details for getting started with Azure Management Libraries for Java, please see the blog https://azure.microsoft.com/en-us/blog/getting-started-with-the-azure-java-management-libraries/.

Peter Pan
  • 23,476
  • 4
  • 25
  • 43
  • Thank you for your reply. I changes the uri to https://management.core.windows.net/ as you told. But the code throws the following exception : com.microsoft.windowsazure.exception.ServiceException: ForbiddenError: The server failed to authenticate the request. Any idea? – Joseph Hwang Jun 06 '16 at 08:24
  • @JosephHwang Please see my answer for the other SO thread http://stackoverflow.com/questions/33082328/azure-java-sdk-serviceexception-forbiddenerror. Hope it helps. Any update, please feel free to let me know. – Peter Pan Jun 06 '16 at 08:49
  • I think i have to learn how to export my jks file to ms azure could setting. I try to contact to https://management.core.windows.net/ with the jks key file. but the same exception is thrown. And I have 2 msdn accounts. Do you think this can bring the trouble I have? And my another question is my java client source worked well with previous azure portal web. , but this azure portal site the codes does not work... – Joseph Hwang Jun 06 '16 at 10:13
  • I have one more question. I use eclipse ide with azure plugin. so when my azure project is build the key files are generated in the \cert folder which names SampleRemoteAccessPublic.cer and SampleRemoteAccessPrivate.pfx. But even with these files I can't connect azure cloud with azure java sdk – Joseph Hwang Jun 06 '16 at 10:19
  • I found the correct answer in Azure classic portal web. It 's 'configuration' menu of azure classic portal. In configuration menu of classic portal I upload public key(.cer) and in java client access is successful with private key(jks). But I don't know which menu of azure portal has the same configuration menu of classic configuration. I need your advice. Thanks! – Joseph Hwang Jun 11 '16 at 08:18