package download_pages; import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.WebResource; import com.sun.jersey.core.util.MultivaluedMapImpl; import java.io.IOException; import java.net.MalformedURLException; import javax.ws.rs.core.MultivaluedMap; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; import org.xml.sax.SAXException; public class Query { public static Document getDetails(String[] fingerprint) { String url = "http://www.citeseeing.com/api/documents/"; if (fingerprint.length == 1) { url += "md5"; } else { url += "movingwindow"; } Client client = Client.create(); WebResource webResource = client.resource(url); final MultivaluedMap queryParams = new MultivaluedMapImpl(); for(String hash : fingerprint) { queryParams.add("hash",hash); } webResource = webResource.queryParams(queryParams); ClientResponse response = webResource.get(ClientResponse.class); try { if (response.getStatus() == 200) { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); return db.parse(response.getEntityInputStream()); } } catch (SAXException ex) { // Handle Exception } catch (ParserConfigurationException ex) { // Handle Exception } catch (MalformedURLException ex) { // Handle Exception } catch (IOException ex) { // Handle Exception } return null; } }