Here you are: this makes the same problems
public static final String SEARCH_BY_DATA_URL="www.biocatalogue.org";
public static final String SEARCH_BY_DATA_PATH="/search/by_data";
public static final String SEARCH_BY_DATA_CONTENT_TYPE="application/xml";
public static final String SEARCH_BY_DATA_ACCEPT="application/xml";
public static final String SEARCH_BY_DATA_BODY="" +
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"+
"<searchByData>\n"+
" <data>embl:122114</data>\n"+
" <limit>10</limit>\n"+
"</searchByData>";
.......
HttpURLConnection connection=null;
try {
String query=URLEncoder.encode(SEARCH_BY_DATA_BODY,"UTF-8");
//Create connection
URL url =new URL(SEARCH_BY_DATA_URL+SEARCH_BY_DATA_PATH);
connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/xml");
connection.setRequestProperty("Accept", "application/xml");
connection.setRequestProperty("Content-Length",
String.valueOf(query.length()));
connection.setUseCaches (false);
connection.setDoInput(true);
connection.setDoOutput(true);
//Send request
DataOutputStream wr = new DataOutputStream (
connection.getOutputStream ());
wr.writeBytes (URLEncoder.encode(SEARCH_BY_DATA_BODY,"UTF-8"));
wr.flush ();
wr.close ();
//Get Response
InputStream is = connection.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
String line;
StringBuffer response = new StringBuffer();
while((line = rd.readLine()) != null) {
response.append(line);
response.append("\n");
}
rd.close();
System.out.print(response.toString());
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
if(connection != null) {
connection.disconnect();
}
}
}
Egon Willighagen wrote:
> Dear Jerzy,
>
> On Tue, Feb 2, 2010 at 7:41 PM, Jerzy Orlowski <[email protected]> wrote:
>> I am writing java client for BioCatalogue Seach By Data feature.
>
> That sounds interesting... are you going to Open Source it?
>
> Looking at your code, it looks pretty low level stuff you are doing...
> have you considered using java.net.URLConnection with code like that
> one:
>
> http://www.exampledepot.com/egs/java.net/Post.html?l=rel
>
> Alternatively, perhaps a dedicated library like:
>
> http://hc.apache.org/httpclient-3.x/
>
> I think the code will get much better readable, making it easier to
> detect problems...
>
> Egon
>
------------------------------------------------------------------------------
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