Class HttpClient


  • public class HttpClient
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static com.google.gson.Gson GSON  
      private java.lang.String host  
      private int port  
      private java.lang.String protocol  
    • Constructor Summary

      Constructors 
      Constructor Description
      HttpClient​(java.lang.String protocol, java.lang.String host, int port)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int delete​(java.lang.String path)  
      com.google.gson.JsonObject get​(java.lang.String path)  
      <T> T get​(java.lang.String path, java.lang.Class<T> clazz)  
      private java.net.HttpURLConnection getConnection​(java.lang.String path)  
      java.lang.String getPlain​(java.lang.String path)  
      int post​(java.lang.String path)  
      com.google.gson.JsonObject post​(java.lang.String path, com.google.gson.JsonObject data)  
      com.google.gson.JsonObject post​(java.lang.String path, java.lang.String name, boolean value)  
      com.google.gson.JsonObject post​(java.lang.String path, java.lang.String name, float value)  
      com.google.gson.JsonObject post​(java.lang.String path, java.lang.String name, java.lang.String value)  
      private static <T> T readAndClose​(java.io.InputStream is, java.lang.Class<T> clazz)  
      private static <T> T readResponse​(java.net.HttpURLConnection connection, java.lang.Class<T> clazz)  
      private static java.lang.String readTextAndClose​(java.io.InputStream is)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • GSON

        private static final com.google.gson.Gson GSON
      • protocol

        private final java.lang.String protocol
      • host

        private final java.lang.String host
      • port

        private final int port
    • Constructor Detail

      • HttpClient

        HttpClient​(java.lang.String protocol,
                   java.lang.String host,
                   int port)
    • Method Detail

      • post

        public com.google.gson.JsonObject post​(java.lang.String path,
                                               java.lang.String name,
                                               float value)
                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • post

        public com.google.gson.JsonObject post​(java.lang.String path,
                                               java.lang.String name,
                                               boolean value)
                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • post

        public com.google.gson.JsonObject post​(java.lang.String path,
                                               java.lang.String name,
                                               java.lang.String value)
                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • getPlain

        public java.lang.String getPlain​(java.lang.String path)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • get

        public com.google.gson.JsonObject get​(java.lang.String path)
                                       throws java.io.IOException
        Throws:
        java.io.IOException
      • get

        public <T> T get​(java.lang.String path,
                         java.lang.Class<T> clazz)
                  throws java.io.IOException
        Throws:
        java.io.IOException
      • post

        public int post​(java.lang.String path)
                 throws java.io.IOException
        Throws:
        java.io.IOException
      • post

        public com.google.gson.JsonObject post​(java.lang.String path,
                                               com.google.gson.JsonObject data)
                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • delete

        public int delete​(java.lang.String path)
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • getConnection

        private java.net.HttpURLConnection getConnection​(java.lang.String path)
                                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • readResponse

        private static <T> T readResponse​(java.net.HttpURLConnection connection,
                                          java.lang.Class<T> clazz)
                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • readAndClose

        private static <T> T readAndClose​(java.io.InputStream is,
                                          java.lang.Class<T> clazz)
                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • readTextAndClose

        private static java.lang.String readTextAndClose​(java.io.InputStream is)
                                                  throws java.io.IOException
        Throws:
        java.io.IOException