XWiki RESTful API issue on localhost

9 messages Options
Embed this post
Permalink
Dilipkumar Jadhav

XWiki RESTful API issue on localhost

Reply Threaded More More options
Print post
Permalink
Hello folks,

The REST example at
http://platform.xwiki.org/xwiki/bin/view/Features/XWikiRESTfulAPI  seems to
be working fine to quite some extent.

I retrieved the xwiki.org Main.WebHome page in the XML format. However, the
same code returns empty result if I look for the Main.WebHome on
localhost:8080/xwiki.

Is there something that I need to enable on my localhost XWiki instance. I
see that xwiki.org has been upgraded to version 2.0.2 which is the same
version on my machine.

I am using tomcat 6.0.18 with MySql 5.

 

Also, the URL
http://www.xwiki.org/xwiki/rest/wikis/xwiki/spaces/Main/pages/WebHome
returns a well formed XML document.

However, the URL
http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/WebHome
returns an error :   XML Parsing Error: no element foundLocation:
http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/WebHome Line
Number 1, Column 1: in Mozilla FF

& the error : XML document must have a top level element. Error processing
resource 'http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/... in IE8

 

 

I am retrieving XML info through the following code:

 

import javax.xml.bind.JAXBContext;

import javax.xml.bind.JAXBContext.*;

import javax.xml.bind.JAXBException;

import javax.xml.bind.Unmarshaller;

import org.apache.commons.httpclient.*;

import org.apache.commons.httpclient.methods.GetMethod;

import java.io.IOException;

import java.io.InputStream;

 

public class Main{

 

public static void main(String[] args) throws JAXBException, IOException {

 

HttpClient httpClient = new HttpClient();

JAXBContext context = JAXBContext.newInstance("org.xwiki");

Unmarshaller un = context.createUnmarshaller();

 

GetMethod getMethod = new
GetMethod("http://xwiki.org/xwiki/rest/wikis/xwiki/spaces/Main/pages/WebHome
");

getMethod.addRequestHeader("Accept", "application/xml");

httpClient.executeMethod(getMethod);

InputStream is = getMethod.getResponseBodyAsStream();

System.out.println(getMethod.getResponseBodyAsString());

//Page page = (Page) un.unmarshal(getMethod.getResponseBodyAsStream());

    }

}

 

Any help would be greatly appreciated. Thank you.

 

Regards,

Dilipkumar Jadhav

 

_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Sergiu Dumitriu-2

Re: XWiki RESTful API issue on localhost

Reply Threaded More More options
Print post
Permalink
On 11/01/2009 01:59 AM, Dilipkumar Jadhav wrote:

> Hello folks,
>
> The REST example at
> http://platform.xwiki.org/xwiki/bin/view/Features/XWikiRESTfulAPI  seems to
> be working fine to quite some extent.
>
> I retrieved the xwiki.org Main.WebHome page in the XML format. However, the
> same code returns empty result if I look for the Main.WebHome on
> localhost:8080/xwiki.
>
> Is there something that I need to enable on my localhost XWiki instance. I
> see that xwiki.org has been upgraded to version 2.0.2 which is the same
> version on my machine.
>
> I am using tomcat 6.0.18 with MySql 5.
>
>
>
> Also, the URL
> http://www.xwiki.org/xwiki/rest/wikis/xwiki/spaces/Main/pages/WebHome
> returns a well formed XML document.
>
> However, the URL
> http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/WebHome
> returns an error :   XML Parsing Error: no element foundLocation:
> http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/WebHome Line
> Number 1, Column 1: in Mozilla FF
>
> &  the error : XML document must have a top level element. Error processing
> resource 'http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/... in IE8

Works fine on my local wiki. Can you try a different document? Maybe you
wrote some strange content in the Main.WebHome one.

--
Sergiu Dumitriu
http://purl.org/net/sergiu/
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Dilipkumar Jadhav

Re: XWiki RESTful API issue on localhost

Reply Threaded More More options
Print post
Permalink
In reply to this post by Dilipkumar Jadhav
Hi Sergiu,
Thanks for taking the time out to look into the issue.
I reinstalled the XWiki instance & now have a clean XWiki instance. I
checked the xwiki/WEB-INF/lib folder and I see that the JAXB library shipped
with XWiki is JAXB2.1 (jaxb-api-2.1, jaxb-fluent-api-2.1.8,
jaxb-impl-2.1.10,jaxb-xjc-2.1.8,jaxrpc-api-1.1 & activation-1.1).
Tried accessing the URL
http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/WebHome
directly from the browser.

Following is the java.lang.Linkage error that I get:

java.lang.LinkageError: JAXB 2.0 API is being loaded from the bootstrap
classloader, but this RI (from
jar:file:/C:/Tomcat6.0/webapps/xwiki/WEB-INF/lib/jaxb-impl-2.1.10.jar!/com/s
un/xml/bind/v2/model/impl/ModelBuilder.class) needs 2.1 API. Use the
endorsed directory mechanism to place jaxb-api.jar in the bootstrap
classloader. (See http://java.sun.com/j2se/1.5.0/docs/guide/standards/)
       
com.sun.xml.bind.v2.model.impl.ModelBuilder.<clinit>(ModelBuilder.java:173)
       
com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.j
ava:431)
       
com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:288)
       
com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBCon
textImpl.java:1111)
       
com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:154)
       
com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:121)
        sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        java.lang.reflect.Method.invoke(Unknown Source)
        javax.xml.bind.ContextFinder.newInstance(Unknown Source)
        javax.xml.bind.ContextFinder.find(Unknown Source)
        javax.xml.bind.JAXBContext.newInstance(Unknown Source)
        javax.xml.bind.JAXBContext.newInstance(Unknown Source)
       
org.restlet.ext.jaxrs.internal.provider.AbstractJaxbProvider.getJaxbContext(
AbstractJaxbProvider.java:63)
       
org.restlet.ext.jaxrs.internal.provider.AbstractJaxbProvider.marshal(Abstrac
tJaxbProvider.java:84)
       
org.restlet.ext.jaxrs.internal.provider.JaxbProvider.writeTo(JaxbProvider.ja
va:106)
       
org.restlet.ext.jaxrs.internal.wrappers.provider.SingletonProvider.writeTo(S
ingletonProvider.java:335)
       
org.restlet.ext.jaxrs.internal.util.JaxRsOutputRepresentation.write(JaxRsOut
putRepresentation.java:105)
       
com.noelios.restlet.http.HttpServerCall.writeResponseBody(HttpServerCall.jav
a:492)
       
com.noelios.restlet.http.HttpServerCall.sendResponse(HttpServerCall.java:428
)
       
com.noelios.restlet.ext.servlet.ServletCall.sendResponse(ServletCall.java:40
7)
       
com.noelios.restlet.http.HttpServerConverter.commit(HttpServerConverter.java
:391)
       
com.noelios.restlet.http.HttpServerHelper.handle(HttpServerHelper.java:148)
       
com.noelios.restlet.ext.servlet.ServerServlet.service(ServerServlet.java:881
)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        com.xpn.xwiki.web.ActionFilter.doFilter(ActionFilter.java:117)
       
com.xpn.xwiki.plugin.webdav.XWikiDavFilter.doFilter(XWikiDavFilter.java:68)
       
com.xpn.xwiki.web.SavedRequestRestorerFilter.doFilter(SavedRequestRestorerFi
lter.java:295)
       
com.xpn.xwiki.web.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFi
lter.java:112)


_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Sergiu Dumitriu-2

Re: XWiki RESTful API issue on localhost

Reply Threaded More More options
Print post
Permalink
On 11/01/2009 02:46 PM, Dilipkumar Jadhav wrote:

> Hi Sergiu,
> Thanks for taking the time out to look into the issue.
> I reinstalled the XWiki instance&  now have a clean XWiki instance. I
> checked the xwiki/WEB-INF/lib folder and I see that the JAXB library shipped
> with XWiki is JAXB2.1 (jaxb-api-2.1, jaxb-fluent-api-2.1.8,
> jaxb-impl-2.1.10,jaxb-xjc-2.1.8,jaxrpc-api-1.1&  activation-1.1).
> Tried accessing the URL
> http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/WebHome
> directly from the browser.
>
> Following is the java.lang.Linkage error that I get:
>
> java.lang.LinkageError: JAXB 2.0 API is being loaded from the bootstrap
> classloader, but this RI (from
> jar:file:/C:/Tomcat6.0/webapps/xwiki/WEB-INF/lib/jaxb-impl-2.1.10.jar!/com/s
> un/xml/bind/v2/model/impl/ModelBuilder.class) needs 2.1 API. Use the
> endorsed directory mechanism to place jaxb-api.jar in the bootstrap
> classloader. (See http://java.sun.com/j2se/1.5.0/docs/guide/standards/)

What container are you using? It looks like the container already
provides an incompatible JAXB jar.

--
Sergiu Dumitriu
http://purl.org/net/sergiu/
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Dilipkumar Jadhav

Re: XWiki RESTful API issue on localhost

Reply Threaded More More options
Print post
Permalink
In reply to this post by Dilipkumar Jadhav
Hi Sergiu,
I happen to use Tomcat 6.0.18 as the servlet container and JDK 1.6.
But I also chanced upon this article while digging for more info:

http://blog.spaceprogram.com/2007/05/how-to-fix-linkageerror-when-using-jaxb
.html
http://java.sun.com/j2se/1.5.0/docs/guide/standards/

I am trying to fix this using the endorsed library mechanism. It seems only
JDK 1.6 would have the java.lang.LinkageError and not JDK 1.5.
Will keep you posted once this is done.
Thanks Sergiu...


_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Dilipkumar Jadhav

Re: XWiki RESTful API issue on localhost

Reply Threaded More More options
Print post
Permalink
In reply to this post by Dilipkumar Jadhav
Finally, I have a working version of the code to access the Xwiki RESTful
API.
It worked smooth on a Tomcat 6.0.14 + JDK 1.5 machine. But had to make
certain changes to the bootstrap files for JDK 1.6 as I mentioned in the
previous post. I have used the Apache HTTP HTTPClient 3.1 jar files here but
soon will upgrade that to Apache HTTPClient 4.0. The only change in the code
from the one posted at
http://platform.xwiki.org/xwiki/bin/view/Features/XWikiRESTfulAPI are the
lines Unmarshaller un = context.createUnmarshaller(); and the line Page page
= (Page) ((JAXBElement)
un.unmarshal(getMethod.getResponseBodyAsStream())).getValue();
The default object that getMethod returns turned out to be a JAXBElement
rather than a Page object. Hence, had to do some class casting.
A big thanks to Fabio Mancinelli & Sergiu Dumitriu for helping me out on
this one.

Just one more request though. Do we cast the
getMethod.getResponseBodyAsStream() to Tags class (if we want to retrieve a
list of pages based on their tags) or the SearchResults class (if we want to
retrieve pages returned through a page search). Even though, I cast the
getMethod.getResponseBodyAsStream to the tags class, my compiler still
throws an error for class cast exception : org.xwiki.Pages. Could someone
please post a snippet to access pages with specific tags or any other
complex querying using classes in the org.xwiki classes. Any help on this
would be greatly appreciated friends.


/*
JDK: 1.5
Tomcat: 6.0.14 (Xwiki server)
Libraries: Apache HTTPClient 3.1, JAXB 2.1, Apache Commons Logging 1.1.1 &
Apache Commons Codec 1.4
Class File Dependencies: org.xwiki package of class files generated from the
XSD file at
http://svn.xwiki.org/svnroot/xwiki/platform/core/trunk/xwiki-rest/src/main/r
esources/xwiki.rest.model.xsd with the help of the XJC compiler available in
the JAXB 2.1 distribution
*/

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.GetMethod;
import org.xwiki.Page;

public class Main {

        public static void main(String[] args) throws JAXBException,
HttpException, IOException {

        HttpClient httpClient = new HttpClient();

        JAXBContext context = JAXBContext.newInstance("org.xwiki");

        Unmarshaller un = context.createUnmarshaller();

        GetMethod getMethod = new
GetMethod("http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/We
bHome");
        getMethod.addRequestHeader("Accept", "application/xml");
        httpClient.executeMethod(getMethod);

        Page page = (Page) ((JAXBElement)
un.unmarshal(getMethod.getResponseBodyAsStream())).getValue();

        System.out.println(page.getCreator());
        System.out.println(page.getCreated());
        System.out.println(page.getFullName());
        System.out.println(page.getXwikiAbsoluteUrl());
       

    }
}

_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Dilipkumar Jadhav

Re: XWiki RESTful API issue on localhost

Reply Threaded More More options
Print post
Permalink
In reply to this post by Dilipkumar Jadhav
Hello friends,

I am really stuck on retrieving a list of pages based on tags associated to
them using the XWiki RESTful service.

The regular page fetch works fine & so do some other API calls. However,
when I retrieve a list of pages based on tags the code returns an empty
result. But when I lookup the same URL in a browser I can see number of
pages listed for that tag.

Any Tags object is a complex type which returns Pages & PageSummary objects
as output.

Could someone please help me out with just the few crucial lines that I am
missing here. I would have to write an XML parser if this does not work out.
However, I was really hoping that I would be able to implement this in JAXB
itself. Thank you for your time guys.

 

import javax.xml.bind.JAXBContext;

import javax.xml.bind.JAXBContext.*;

import javax.xml.bind.JAXBException;

import javax.xml.bind.Unmarshaller;

import org.apache.commons.httpclient.*;

import org.apache.commons.httpclient.methods.GetMethod;

import java.io.IOException;

import javax.xml.bind.JAXBElement;

import javax.xml.transform.stream.StreamSource;

import org.xwiki.Pages;

import org.xwiki.Space;

 

public class Main{

 

public static void main(String[] args) throws JAXBException, IOException {

 

HttpClient httpClient = new HttpClient();

JAXBContext context = JAXBContext.newInstance("org.xwiki");

Unmarshaller un = context.createUnmarshaller();

 

GetMethod getMethod = new
GetMethod("http://localhost:8080/xwiki/rest/wikis/xwiki/tags/admin");

getMethod.addRequestHeader("Accept", "application/xml");

httpClient.executeMethod(getMethod);

 

 

JAXBElement<Pages> pages = un.unmarshal(new
StreamSource(getMethod.getResponseBodyAsStream()),Pages.class);

Pages pg = pages.getValue();

System.out.println(pg.getPageSummary().size());

 

    }

}

 

 

 

 

 

Regards,

Dilipkumar Jadhav

 

_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Fabio Mancinelli-4

Re: XWiki RESTful API issue on localhost

Reply Threaded More More options
Print post
Permalink

On Nov 5, 2009, at 2:35 AM, Dilipkumar Jadhav wrote:

> Hello friends,
>
> I am really stuck on retrieving a list of pages based on tags  
> associated to
> them using the XWiki RESTful service.
>
> The regular page fetch works fine & so do some other API calls.  
> However,
> when I retrieve a list of pages based on tags the code returns an  
> empty
> result. But when I lookup the same URL in a browser I can see number  
> of
> pages listed for that tag.
>
> Any Tags object is a complex type which returns Pages & PageSummary  
> objects
> as output.
>
> Could someone please help me out with just the few crucial lines  
> that I am
> missing here. I would have to write an XML parser if this does not  
> work out.
> However, I was really hoping that I would be able to implement this  
> in JAXB
> itself. Thank you for your time guys.
>
>
Your code is correct (except the method getPageSummary() which doesn't  
exist in my generated JAXB model classes, but this could be due to the  
fact that you are generating them without the simple bindings)

I think the problem is from where you get your JAXB generated model  
classes (which is not clear from the code you posted)

Anyway I tried your code and it works perfectly (modulo a renaming of  
getPageSummary() to getPageSummaries()).

Since I am not able to spot the problem from your mail, I attach to  
this reply the project I used to do the test. You can look at it and  
find where are the differences wrt what you wrote. You could also use  
it as a template for writing JAXB-clients for the XWiki RESTful API.

To execute do this:

touch pom.xml (this will ensure the re-generation of the JAXB files)
mvn install
mvn exec:java -Dexec.mainClass="org.test.App"

You will see as the output the number of pages tagged with the "admin"  
tag.

Hope this help.

-Fabio


_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Dilipkumar Jadhav

Re: XWiki RESTful API issue on localhost

Reply Threaded More More options
Print post
Permalink
In reply to this post by Dilipkumar Jadhav
Hi Fabio,
Thank you so much for your time & response. I really appreciate your gesture
of sending over the maven project files. I was able to build the xwiki rest
.jar & use it successfully in my project :)


"Your code is correct (except the method getPageSummary() which doesn't  
exist in my generated JAXB model classes, but this could be due to the  
fact that you are generating them without the simple bindings)"
I think the problem is from where you get your JAXB generated model  
classes (which is not clear from the code you posted).
Anyway I tried your code and it works perfectly (modulo a renaming of  
getPageSummary() to getPageSummaries())."

I generated the model classes from the .xsd file mentioned in the XWiki
Restful API tutorial at
http://svn.xwiki.org/svnroot/xwiki/platform/core/trunk/xwiki-rest/src/main/r
esources/xwiki.rest.model.xsd
I've used XJC which was bundled with the JAXB 2.1 distribution. Surprisingly
despite using the .xsd that you provided in your project, the XJC still
created a very small Pages.java file. It barely had one method which was the
getPageSummary() method.
However, when I checked the Pages.class file in the jar from your project,
it contained quite a few methods (including the one that I was longing to
see). The difference in technique that I see here is that the jar was built
using mvn while my class files were created using XJC through command
prompt.
Not sure if there are version differences in any of the dependencies whilst
using the two methods. Will have to look into that.



"Since I am not able to spot the problem from your mail, I attach to  
this reply the project I used to do the test. You can look at it and  
find where are the differences wrt what you wrote. You could also use  
it as a template for writing JAXB-clients for the XWiki RESTful API.
Hope this help.
-Fabio"


It is help that arrived just in time Fabio. We have an internal
trouble-ticketing application. The XWiki instance is projected to be our
knowledge base & went live just today. We wanted our application to extract
tags & pass on to XWiki which in turn would return trouble-shooting
articles. Probably, once the search feature is successful, we would like to
be able to "push" new articles/pages to XWiki from our internal application
at the click of a button.
Your work is a great starting point. This will give XWiki a lot more
portability in today's times when applications "interacting" with each other
is becoming a must.

Thanks Fabio...


_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users