NIH | National Cancer Institute | NCI Wiki  

Error rendering macro 'rw-search'

null

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
titleJava REST example
collapsetrue
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899importimport java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;


/**
 * Created with IntelliJ IDEA.
 * User: m029206
 * Date: 9/20/12
 * Time: 11:48 AM.
 */
public class ValueSetClient {    public


    public  void getValueSets(){        String
        String uri =                
                "http://informatics.mayo.edu/cts2/rest/valuesets";        URL
        URL url;        try {            url
        try {
            url = new URL(uri);        HttpURLConnection


        HttpURLConnection connection =                
                (HttpURLConnection) url.openConnection();            if
            if (connection.getResponseCode() != 200) {                throw
                throw new RuntimeException("Failed : The HTTP error code is : "                        + connection.getResponseCode());            }            BufferedReader br 
                        + connection.getResponseCode());
            }


            BufferedReader br = new BufferedReader(new InputStreamReader(                    
                    (connection.getInputStream())));            String


            String output;            System
            System.out.println("Output from Server .... \n");            while
            while ((output = br.readLine()) != null) {                System
                System.out.println(output);            }        connection
            }


        connection.disconnect();        


        } catch (MalformedURLException e) {            e
            e.printStackTrace();        
        } catch (ProtocolException e) {            e
            e.printStackTrace();        
        } catch (IOException e) {            e
            e.printStackTrace();        }    }    public
        }
    }


    public  void getValueSet(){        String
        String uri =                
                "http://informatics.mayo.edu/cts2/rest/valuesets?matchvalue=Sequence&format=json";        URL
        URL url;        HttpURLConnection
        HttpURLConnection connection = null;        try {            url
        try {
            url = new URL(uri);            connection




            connection = (HttpURLConnection) url.openConnection();            connection
            connection.setRequestProperty("Accept", "text/json");            if
            if (connection.getResponseCode() != 200) {                throw
                throw new RuntimeException("Failed : The HTTP error code is : "                        
                        + connection.getResponseCode());            }            BufferedReader
            }


            BufferedReader br = new BufferedReader(new InputStreamReader(                    
                    (connection.getInputStream())));            String


            String output;            System
            System.out.println("\nOutput from CTS2 Service .... \n");            while
            while ((output = br.readLine()) != null) {                System
                System.out.println(output);            }        
            }




        } catch (MalformedURLException e) {
            e.printStackTrace() {            e;
        } catch (ProtocolException e) {
            e.printStackTrace();        } catch (ProtocolException e) {            e.printStackTrace();        
        } catch (IOException e) {            e
            e.printStackTrace();        
        } finally {            if
            if(connection != null){                connection
                connection.disconnect();            }        }    }    public
            }
        }
    }


    public static void main(String[] args){        ValueSetClient


        ValueSetClient client =  new ValueSetClient();        client
        client.getValueSets();        client
        client.getValueSet();    }}






    }
}

 

The Current State of CTS2

...