Package org.maproulette.client.http
Class HttpResource
- java.lang.Object
-
- org.maproulette.client.http.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.CloseableBase 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 voidclose()voidexecute()If you want to execute the request, call this.org.apache.http.Header[]getHeader(java.lang.String headerKey)org.apache.http.client.methods.CloseableHttpResponsegetResponse()java.lang.StringgetResponseBodyAsString()intgetStatusCode()voidsetAuth(java.lang.String user, java.lang.String pass)voidsetHeader(java.lang.String name, java.lang.String value)
-
-
-
Method Detail
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable
-
execute
public void execute() throws MapRouletteExceptionIf 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
-
getHeader
public org.apache.http.Header[] getHeader(java.lang.String headerKey) throws MapRouletteException- Throws:
MapRouletteException
-
getResponseBodyAsString
public java.lang.String getResponseBodyAsString() throws MapRouletteException- Throws:
MapRouletteException
-
getResponse
public org.apache.http.client.methods.CloseableHttpResponse getResponse() throws MapRouletteException- Throws:
MapRouletteException
-
getStatusCode
public int getStatusCode() throws MapRouletteException- Throws:
MapRouletteException
-
setAuth
public void setAuth(java.lang.String user, java.lang.String pass)
-
setHeader
public void setHeader(java.lang.String name, java.lang.String value)
-
-