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