Created
November 8, 2009 12:37
-
-
Save anonymous/229248 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%//@ page contentType="text/xml; charset=utf-8" pageEncoding="UTF-8"%> | |
<%@ page language = "java"%> | |
<%@ page import = "java.util.*"%> | |
<%@ page import = "java.io.*"%> | |
<%@ page import="java.lang.*"%> | |
<%@ page import="java.net.*"%> | |
<%@ page import="java.nio.*"%> | |
<%@ page import= "javax.xml.parsers.*" %> | |
<%@ page import= "org.w3c.dom.*" %> | |
<% | |
try | |
{ | |
Properties systemSettings = System.getProperties(); | |
systemSettings.put("http.proxyHost", "proxy.it.iitb.ac.in"); | |
systemSettings.put("http.proxyPort", "80"); | |
systemSettings.put("sun.net.client.defaultConnectTimeout", "10000"); | |
systemSettings.put("sun.net.client.defaultReadTimeout", "10000"); | |
Authenticator.setDefault(new Authenticator() | |
{ | |
protected PasswordAuthentication getPasswordAuthentication() | |
{ | |
return new PasswordAuthentication("aaqua", "aaqua123".toCharArray()); // specify ur user name password of iitb login | |
} | |
}); | |
System.setProperties(systemSettings); | |
String URLString = request.getParameter("txtURLString").trim(); | |
URL url = new URL(URLString); //url string taken from user input. | |
HttpURLConnection connection = null; | |
connection = (HttpURLConnection) url.openConnection(); | |
connection.setRequestMethod("POST"); | |
connection.setDoInput(true); | |
connection.setDoOutput(true); | |
connection.setUseCaches(false); | |
connection.setAllowUserInteraction(false); | |
connection.setRequestProperty ("Content-Type","text/xml; charset=\"utf-8\""); | |
OutputStreamWriter dosout = new OutputStreamWriter(connection.getOutputStream()); | |
BufferedReader in = new BufferedReader( new InputStreamReader( connection.getInputStream())); | |
String decodedString; | |
String tempstr = ""; | |
/*while ((decodedString = in.readLine()) != null) | |
{ | |
tempstr = tempstr + decodedString; | |
out.println(tempstr); | |
}*/ | |
Random rn = new Random(); | |
int rnval = rn.nextInt() ; | |
String fname = "file_ncbi_"+ String.valueOf(rnval) + ".xml" ; | |
//File file = new File(fname); | |
BufferedWriter bw = new BufferedWriter(new FileWriter(fname)); | |
while ((decodedString = in.readLine()) != null) | |
{ | |
tempstr = tempstr + decodedString; | |
//out.println(tempstr); | |
bw.write(decodedString); | |
if ( tempstr.indexOf("/") == -1 ) | |
{ | |
bw.newLine(); | |
} | |
} | |
bw.close(); | |
in.close(); | |
javax.servlet.http.HttpSession hs = request.getSession(); | |
hs.setAttribute("ncbifile",fname.toString()); | |
response.sendRedirect("/ProteomDb/FetchPubmedDataFromNCBI.jsp"); | |
} | |
catch(Exception ex) | |
{ | |
out.println("Exception->"+ex); | |
PrintWriter pw = response.getWriter(); | |
ex.printStackTrace(pw); | |
} | |
%> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment