From 519257ef66e0bb653135e77227a16113bdecddf8 Mon Sep 17 00:00:00 2001 From: "cmzmasek@gmail.com" Date: Thu, 31 May 2012 17:24:21 +0000 Subject: [PATCH] in progress --- forester/java/src/org/forester/ws/hmmer/Test.java | 51 +++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 forester/java/src/org/forester/ws/hmmer/Test.java diff --git a/forester/java/src/org/forester/ws/hmmer/Test.java b/forester/java/src/org/forester/ws/hmmer/Test.java new file mode 100644 index 0000000..7d53e61 --- /dev/null +++ b/forester/java/src/org/forester/ws/hmmer/Test.java @@ -0,0 +1,51 @@ + +package org.forester.ws.hmmer; + +import java.io.BufferedReader; +import java.io.DataOutputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLEncoder; + +public class Test { + + public static void main( final String[] args ) { + try { + final URL url = new URL( "http://hmmer.janelia.org/search/hmmscan" ); + final HttpURLConnection connection = ( HttpURLConnection ) url.openConnection(); + connection.setDoOutput( true ); + connection.setDoInput( true ); + connection.setInstanceFollowRedirects( false ); + connection.setRequestMethod( "POST" ); + connection.setRequestProperty( "Content-Type", "application/x-www-form-urlencoded" ); + connection.setRequestProperty( "Accept", "application/json" ); + //Add the database and the sequence. Add more options as you wish! + final String urlParameters = "hmmdb=" + URLEncoder.encode( "pfam", "UTF-8" ) + "&seq=" + + ">seq\nEMGPSENDPNLFVALYDFVASGDNTLSITKGEKLRVLGYNHNGEWCEAQTKNGQGWVPSNYITPV" + + "NSLEKHSWYHGPVSRNAAEYLLSSGINGSFLVRESESSPGQRSISLRYEG" + + "RVYHYRINTASDGKLYVSSESRFNTLAELVHHHSTVADGLITTLHYPAP"; + connection.setRequestProperty( "Content-Length", "" + Integer.toString( urlParameters.getBytes().length ) ); + //Send request + final DataOutputStream wr = new DataOutputStream( connection.getOutputStream() ); + wr.writeBytes( urlParameters ); + wr.flush(); + wr.close(); + //Now get the redirect URL + final URL respUrl = new URL( connection.getHeaderField( "Location" ) ); + final HttpURLConnection connection2 = ( HttpURLConnection ) respUrl.openConnection(); + connection2.setRequestMethod( "GET" ); + connection2.setRequestProperty( "Accept", "text/x-yaml" ); + //Get the response and print it to the screen + final BufferedReader in = new BufferedReader( new InputStreamReader( connection2.getInputStream() ) ); + String inputLine; + while ( ( inputLine = in.readLine() ) != null ) { + System.out.println( inputLine ); + } + in.close(); + } + catch ( final Exception e ) { + throw new RuntimeException( e ); + } + } +} -- 1.7.10.2