Hi Manjula, 1. The endpoint should be "http://www.biomart.org/biomart/martservice", you are missing part of the path.
2. I would recommend the use of Jersey Client to handle interactions with REST APIs in Java. http://jersey.java.net/nonav/documentation/latest/user-guide.html#d4e617 With the Jersey Client you can either get results as a String or InputStream. Hope that helps. -jack From: Manjula Dharmawardhana <[email protected]<mailto:[email protected]>> Date: Wed, 19 Oct 2011 07:01:58 -0400 To: BioMart Users <[email protected]<mailto:[email protected]>> Subject: [BioMart Users] Accessing Mart Services Hi all, I want to access the COSMIC biomart using smart services and Java. Here is my code. import java.io.BufferedReader; import java.io.FileReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.URL; import java.net.URLConnection; public class accessDB { public static void saveDbData(String xmlName) throws Exception { try { URL url = new URL("http://www.biomart.org/martservice"); String fileContents = readFileAsString(xmlName); URLConnection urlc = url.openConnection(); urlc.setDoOutput(true); urlc.setDoInput(true); PrintWriter pw = new PrintWriter(urlc.getOutputStream()); pw.write(fileContents); pw.close(); BufferedReader in = new BufferedReader(new InputStreamReader(urlc.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) { System.out.println(inputLine); } in.close(); } catch (Exception e) { } } private static String readFileAsString(String filePath) throws java.io.IOException { StringBuilder fileData = new StringBuilder(1000); BufferedReader reader = new BufferedReader( new FileReader(filePath)); char[] buf = new char[1024]; int numRead = 0; while ((numRead = reader.read(buf)) != -1) { String readData = String.valueOf(buf, 0, numRead); fileData.append(readData); buf = new char[1024]; } reader.close(); return fileData.toString(); } } I used a XML file saved from the COSMIC Biomart site XML button. What could be the problem. I think I am correct in thinking that if I POST the XML file to the link it should work. What have I missed? Thank you very much. Regards, Manjula -- [http://www.linkedin.com/img/webpromo/btn_myprofile_160x33.png]<http://lk.linkedin.com/in/manjulapra> This communication (including any attachments) is intended for the use of the intended recipient only and may contain information that is confidential, privileged or legally protected. Any unauthorized use or dissemination of this communication is strictly prohibited. If you have received this communication in error, please immediately notify [email protected]<mailto:[email protected]> by return e-mail message and delete all copies of the original communication. Thank you for your cooperation.
_______________________________________________ Users mailing list [email protected] https://lists.biomart.org/mailman/listinfo/users
