Class HttpResource

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable
    Direct Known Subclasses:
    DeleteResource, GetResource, PostResource

    public abstract class HttpResource
    extends java.lang.Object
    implements java.io.Closeable
    Base Http resource object that will handle most of the http request information. Sub classes generally will set the type of request and possibly a couple of request-specific parameters. For instance POST will require to post body data in the request. Example Usage: URI uri = new URIBuilder("http://localhost:2020/path/to/location").build(); HttpResource post = new GetResource // get t(uri, body); //read the response post.lines().foreach(System.out.println(x)); //get status code int code = post.getStatusCode();
    • Constructor Summary

      Constructors 
      Constructor Description
      HttpResource​(java.lang.String uri)  
      HttpResource​(java.net.URI uri)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      void execute()
      If you want to execute the request, call this.
      org.apache.http.Header[] getHeader​(java.lang.String headerKey)  
      org.apache.http.client.methods.CloseableHttpResponse getResponse()  
      java.lang.String getResponseBodyAsString()  
      int getStatusCode()  
      void setAuth​(java.lang.String user, java.lang.String pass)  
      void setHeader​(java.lang.String name, java.lang.String value)  
      • Methods inherited from class java.lang.Object

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

      • HttpResource

        public HttpResource​(java.lang.String uri)
      • HttpResource

        public HttpResource​(java.net.URI uri)
    • Method Detail

      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
      • execute

        public void execute()
                     throws MapRouletteException
        If you want to execute the request, call this. All other attempts in an HttpResource will first check to see if the response object has been retrieved. This will null out the response object and execute it again.
        Throws:
        MapRouletteException - if any exceptions occur while trying to get a response
      • setAuth

        public void setAuth​(java.lang.String user,
                            java.lang.String pass)
      • setHeader

        public void setHeader​(java.lang.String name,
                              java.lang.String value)