Package org.gcube.common.gxhttp.request
Class GXResponse
- java.lang.Object
-
- org.gcube.common.gxhttp.request.GXResponse
-
- All Implemented Interfaces:
AutoCloseable
public class GXResponse extends Object implements AutoCloseable
The response to aGXRequest: status, headers and body. The body is read in the same way whatever the status, an error included.The body is a stream on the connection: read it, or
close()the response, to give the connection back.- Author:
- Luca Frosini (ISTI-CNR)
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the body, giving the connection back.InputStreamgetBody()StringgetBodyAsString()Reads the whole body as UTF-8 text and closes it.StringgetHeader(String name)Map<String,List<String>>getHeaders()intgetStatus()URIgetURI()booleanisSuccessful()
-
-
-
Method Detail
-
getURI
public URI getURI()
- Returns:
- the URI the response comes from, the last one when the request was redirected
-
getStatus
public int getStatus()
- Returns:
- the HTTP status code
-
isSuccessful
public boolean isSuccessful()
- Returns:
- whether the status is a success (
2xx)
-
getHeaders
public Map<String,List<String>> getHeaders()
- Returns:
- every header, with case-insensitive names
-
getHeader
public String getHeader(String name)
- Parameters:
name- the header name, case-insensitive- Returns:
- the first value of the header, or
nullwhen the response does not have it
-
getBody
public InputStream getBody()
- Returns:
- the body as a stream
-
getBodyAsString
public String getBodyAsString() throws IOException
Reads the whole body as UTF-8 text and closes it.- Returns:
- the body
- Throws:
IOException- if the body cannot be read
-
close
public void close() throws IOExceptionCloses the body, giving the connection back.- Specified by:
closein interfaceAutoCloseable- Throws:
IOException- if the body cannot be closed
-
-