VMware {code} Community
kem5451
Enthusiast
Enthusiast

VI Java API2.0 Sample code issues!

Hi,

I have dowloaded the VIJava2b120090307src.jar for the replacement of VI JAVA SDK. With this, I was just trying to execute the sample code given RestAppDemo.java. and getting exception in the below specified line

Line no 60 - System.out.println("Name : " + si.getPropertyAsString("content.about.fullName);

Exception:-

:1:63: White spaces are required between publicId and systemId.

Exception in thread "main" org.xml.sax.SAXParseException: White spaces are requi

red between publicId and systemId.

at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.

java:264)

at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Doc

umentBuilderImpl.java:292)

at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.evaluate(XPathImpl.j

ava:468)

at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.evaluate(XPathImpl.j

ava:515)

at com.vmware.vim.rest.RestManagedObject.getPropertyAsString(RestManaged

Object.java:91)

at RestAppDemo.runMOLevel(RestAppDemo.java:60)

at RestAppDemo.main(RestAppDemo.java:52)

-


linked to -


javax.xml.xpath.XPathExpressionException

at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.evaluate(XPathImpl.j

ava:473)

at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.evaluate(XPathImpl.j

ava:515)

at com.vmware.vim.rest.RestManagedObject.getPropertyAsString(RestManaged

Object.java:91)

at RestAppDemo.runMOLevel(RestAppDemo.java:60)

at RestAppDemo.main(RestAppDemo.java:52)

Caused by: org.xml.sax.SAXParseException: White spaces are required between publ

icId and systemId.

at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.

java:264)

at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Doc

umentBuilderImpl.java:292)

at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.evaluate(XPathImpl.j

ava:468)

... 4 more

Can anyone explain the reason for this problem?. Thanks in advance.

-JV

0 Kudos
14 Replies
admin
Immortal
Immortal

I am afraid you might download the wrong package to use.

Vi SDK for Java should be download from here: http://communities.vmware.com/community/developer/java_toolkit

core API and toolkits team

0 Kudos
JV5451
Contributor
Contributor

Am not looking for VI SDK which is using Axis code base. This is related to VI JAVA API Beta 1 which was recently released without using Axis code base. Please look at the below link for more info.

http://communities.vmware.com/message/1195150#1195150

If this is not the correct community, please re-direct me to the correct one.

Thanks.

0 Kudos
admin
Immortal
Immortal

VI SDK for Java is a VMware supported project.

Vi Java API is an open source project, there is no specific VMware comunity for this project, but you can find it here:

core API and toolkits team

0 Kudos
admin
Immortal
Immortal

We are not using axis1.4 anymore,

the VI SDK for Java is based on the new Axis2 which is much faster than Axis1.4.

The following are the reasons why we choose Axis as our SOAP stack:

1. It is a mature and stable product in the Java community and there is no reason to re-invert the wheel.

2. high performance. We did the performance testing and found Axis2 is faster than the home-grown SOAP stack used by VI Java API 2.0 (http://vijava.sourceforge.net/)

3. It has best WSDL spec coverage which will work with our future VI SDK SOAP server when we add more features.

4. All methods in VI API is tested by Vmware QA using Axis and they gurantees to work.

core API and toolkits team

0 Kudos
Steve_Jin
Expert
Expert

Hi Kem5451,

I just ran the code in my environment after changing the IP, username, password, and it worked fine. Did you change the IP... to your setting?

It seems to me there is an issue with the connection. Pleaese file a bug at vijava.sf.net and let's get from there.

BTW, the REST API is not based on VI SDK web services. It's a unique feature of VI Java API which allows you to develop super light applications.

Steve JIN, VMware Engineering

Creator of VMware Infrastructure Java API. VI Java API 2.0 --- 15 times faster than AXIS in loading, 4+ faster in deserialization; only 1/4 of the size required by AXIS. More importantly, the freedom to redistribute your applications. (Download, Samples, DocWiki, RSS Feed)

Get Connected with Other Developers in the Community?

Steve JIN Author of VMware VI and vSphere SDK; Creator of open source VI Java API (http://vijava.sf.net); Blogger at http://www.doublecloud.org
0 Kudos
kem5451
Enthusiast
Enthusiast

Yes. I tried after changing my IP, connection created and got xml info also. while parsing with XPATH with your code gets an excepiton.

Please find sample code attached.

public class RestAppDemo

{

public static void main(String[] args) throws Exception

{

RestClient rc = new RestClient("https://192.168.10.136", "healthinfo", "healthinfo");

// runRestLevel(rc);

runMOLevel(rc);

}

public static void runMOLevel(RestClient rc) throws Exception

{

RestManagedObject si = new RestManagedObject(rc, "ServiceInstance");

System.out.println("name:" + si.getPropertyAsString("content.about.fullName"));

-

-

-

-

-

public String RestManagedObject.getPropertyAsString(String path) throws IOException, XPathExpressionException

{

String propName = null;

String doName = "";

int last = path.lastIndexOf(".");

if(last!=-1)

{

doName = path.substring(0, last);

propName = path.substring(last+1);

} else

{

propName = path;

}

String doXml = getPropertyDO(doName);

System.out.println("doXml = " + doXml); //Generated XML prints here

xpath.reset();

return xpath.evaluate( propName, new InputSource(new StringReader(doXml))); //throwing exception here.

}

-JV

0 Kudos
Steve_Jin
Expert
Expert

It seems related to the XPath. Can you please show the value of doXml and propName? Thanks!

Steve JIN, VMware Engineering

Creator of VMware Infrastructure Java API. VI Java API 2.0 --- 15 times faster than AXIS in loading, 4+ faster in deserialization; only 1/4 of the size required by AXIS. More importantly, the freedom to redistribute your applications. (Download, Samples, DocWiki, RSS Feed)

Get Connected with Other Developers in the Community?

Steve JIN Author of VMware VI and vSphere SDK; Creator of open source VI Java API (http://vijava.sf.net); Blogger at http://www.doublecloud.org
0 Kudos
kem5451
Enthusiast
Enthusiast

Pls find the attached log file for the same. Thanks.

0 Kudos
kem5451
Enthusiast
Enthusiast

Please find the log file attached for the same.

runRestLevel(rc) -API call also throws same exception.

Thanks.

0 Kudos
Steve_Jin
Expert
Expert

Hi Kem5451,

Thanks for the log. I just read it and the returned page from MOB is there correctly. Somehow the code to extract the XML didn't work as expected. Just wonder if you could set a breakpoint inside the following method inside the RestClient.java

public String get(String urlStr) throws IOException

105 int start = sb.indexOf("<xml id=\"objData\">");

106 int objPos = sb.indexOf("<object>", start);

107 sb.replace(objPos, objPos+8 , "<object xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>");

108 int end = sb.indexOf("</textarea>", objPos);

It would be helpful to step through and see why the code from 105 missed the <xml id="objData">. From your log, I can see it's there...

Thanks!

Steve JIN, VMware Engineering

Creator of VMware Infrastructure Java API. VI Java API 2.0 --- 15 times faster than AXIS in loading, 4+ faster in deserialization; only 1/4 of the size required by AXIS. More importantly, the freedom to redistribute your applications. (Download, Samples, DocWiki, RSS Feed)

Get Connected with Other Developers in the Community?

Steve JIN Author of VMware VI and vSphere SDK; Creator of open source VI Java API (http://vijava.sf.net); Blogger at http://www.doublecloud.org
0 Kudos
kem5451
Enthusiast
Enthusiast

Yes.I did comment those lines.Because of ArrayIndexbounds exception on the line 107 while replacing. After uncommenting, tried now and it is working good. Still me too wondering where was the problem and what Smiley Happy

Will let you know once I reproduced that problem.

Thanks a TON for your kind update.

0 Kudos
kem5451
Enthusiast
Enthusiast

Hi Steve,

RestManagedObject si = new RestManagedObject(rc, "ServiceInstance");

si.invoke("currentTime"); //returns the following

With this code,how can we get the value of this tag?

If I hit the page via URL and click the InvokeMethod link, am able to get the "CurrentTime" Value.

Ex - https://192.168.10.136/mob/?moid=ServiceInstance&method=currentTime

Please help me out. Thanks.

-JV

0 Kudos
Steve_Jin
Expert
Expert

Hi JV,

This turned out to be a bug. I have filed a defect@ http://sourceforge.net/tracker/index.php?func=detail&aid=2685661&group_id=228007&atid=1073396.

More importantly, it's fixed and pushed into SVN. Could you please test it out? Just replace this file: http://vijava.svn.sourceforge.net/viewvc/vijava/trunk/src/com/vmware/vim/rest/ResultConverter.java. I will push it into next update release upon your confirmation. Please let me know if it works for you or not.

Moving forward, please use management API forum for discussions : http://communities.vmware.com/community/developer/managementapi

Thanks!

Steve JIN, VMware Engineering

Creator of VMware Infrastructure Java API. VI Java API 2.0 --- 15 times faster than AXIS in loading, 4+ faster in deserialization; only 1/4 of the size required by AXIS. More importantly, the freedom to redistribute your applications. (Download, Samples, DocWiki, RSS Feed)

Get Connected with Other Developers in the Community?

Steve JIN Author of VMware VI and vSphere SDK; Creator of open source VI Java API (http://vijava.sf.net); Blogger at http://www.doublecloud.org
0 Kudos