Hi
I am writing java client for BioCatalogue Seach By Data feature.
The working code in Python is
-------------------------------
#!/usr/bin/python
# -*- coding: utf-8 -*-
import httplib
import httplib2
import urllib
import cgi
HOSTNAME='www.biocatalogue.org'
PORT=80
if __name__=="__main__":
connection=httplib.HTTPConnection(HOSTNAME,PORT)
#params=urllib.urlencode({"aaa":"ccvc","bbb":"dvsbvdc"})
data=""">embl:122114
PPPPPPPPPPPPP
ACAGATCGTAGCTAGTACG
>aaa
AAAAAAAAAAAAAAAAAAAAA"""
u_data=cgi.escape(data)
body="""<?xml version="1.0" encoding="UTF-8" ?>
<searchByData>
<data>%s</data>
<limit>%d</limit>
</searchByData>
""" %(u_data,20)
#print body
#headers = {"Content-type":
"application/x-www-form-urlencoded","Accept": "text/plain"}
headers = {"Content-type": "application/xml","Accept": "application/xml"}
connection.request("POST","/search/by_data",body,headers)
r1=connection.getresponse()
print r1.read()
--------------------------------
However when I try to recreate it in Java with
------------------------------
try {
String query=URLEncoder.encode(SEARCH_BY_DATA_BODY,"UTF-8");
InetAddress addr = InetAddress.getByName(SEARCH_BY_DATA_URL);
Socket sock = new Socket(addr, 80);
BufferedWriter wr = new BufferedWriter(new
OutputStreamWriter(sock.getOutputStream()));
wr.write("POST " + SEARCH_BY_DATA_PATH + " HTTP/1.0\r\n");
wr.write("Host: "+SEARCH_BY_DATA_URL+"\r\n");
wr.write("Content-Length: " + query.length() + "\r\n");
wr.write("Content-Type: application/xml; Accept:
application/xml\r\n");
wr.write("\r\n");
//Send data
wr.write(query);
wr.flush();
// Response
BufferedReader rd = new BufferedReader(new
InputStreamReader(sock.getInputStream()));
String line;
while((line = rd.readLine()) != null)
System.out.println(line);
} catch (UnknownHostException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
-------------------------------
I get <500 Internal Server Error>
I tried different ways (e.x. HttpURLConnection) with no result. It seems
I am not getting the header and POST data correctly.
George
------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
taverna-hackers mailing list
[email protected]
Web site: http://www.taverna.org.uk
Mailing lists: http://www.taverna.org.uk/taverna-mailing-lists/
Developers Guide: http://www.mygrid.org.uk/tools/developer-information