public class Request extends EmittingCallbackFn<String,Response> implements Callable<Response>
Modifier and Type | Class and Description |
---|---|
static class |
Request.Milestone
Enum for the steps in the HTTPRequest.call() method, used for error-tracking...
|
EmittingCallbackFn.NOP<IN>
Callback.ProducesMore<IN,OUT,MORE>, Callback.ProducesMultiple<IN,OUT>
Modifier and Type | Field and Description |
---|---|
protected Request.Milestone |
attempting |
protected String |
baseUrl |
static String |
FORM_DATA |
protected HTTPMultiMap |
formDataMMap |
static String |
HEADER_DATA |
protected HTTPMultiMap |
headersMMap |
protected int |
maxRetries |
protected HTTPMethod |
method |
protected boolean |
methodMustUpload |
protected HashWrapper.Linked |
options |
protected InputStream |
pipeIn |
protected OutputStream |
pipeOut |
protected OutputStream |
pipeTo |
static String |
QUERY_DATA |
protected HTTPMultiMap |
queryMMap
Three possible multimaps used for the query, header, and formData
|
protected Response |
response401 |
protected Object |
uploadMe |
protected boolean |
useStrictRFC3986 |
nextCallback
allowDuplicates, idMap, maxListeners
Constructor and Description |
---|
Request() |
Request(String urlOrOptions) |
Request(String baseUrl,
HTTPMethod method) |
Request(String baseUrl,
HTTPMethod method,
Map<String,Object> options)
Full constructor
|
Request(String baseUrl,
Map<String,Object> options) |
Modifier and Type | Method and Description |
---|---|
Request |
acceptCharset(String charset) |
Request |
auth(String user,
String pass,
boolean sendImmediately) |
Response |
call() |
Response |
call1() |
Response |
callback(Exception ex,
String urlOrOptions,
Object... more)
The callback method
|
protected void |
checkMethodMustUpload() |
protected long |
copy(InputStream input,
OutputStream output,
boolean emit) |
protected void |
doAuth(HttpURLConnection conn) |
protected String |
doAWS(Map awsMap) |
protected String |
doSubstituteMultiMapData(String upload)
Useful for POST - replaces $FORMDATA, $HEADERS or $QUERY in the upload string
with the corresponding contents of the respective MultiMaps.
|
protected void |
doUpload(OutputStream outputStream) |
Request |
form(Map<String,Object> map)
Adds form data from a map
|
Request |
form(Object... fieldValuePairs)
Adds form data
|
Request |
form(String jsonString)
Adds form data from a JSON String
|
protected String |
fullURL()
Split off for testing, but a subclass may want to override
|
protected URLEncoding |
getEncoding() |
Request |
headers(Map<String,Object> map)
Adds header data from a Map
|
Request |
headers(Object... fieldValuePairs)
Adds header data
|
Request |
headers(String jsonString)
Adds header data from a JSON String
|
Map<String,Object> |
JSONtoMap(String jsonString)
Converts JSON String to a Map.
|
Request |
method(HTTPMethod method) |
protected void |
noteMilestone(Request.Milestone attempting)
Subclasses who wish to log or send progress can override this
|
Request |
oauth(String jsonString) |
protected String |
objectToStringForUpload(Object object)
Converts Object to a String for uploading
Subclasses might want to override and do JSON, XML, etc...
|
protected HttpURLConnection |
openConnection()
Split off for testing, but a subclass may want to override
|
Request |
options(Map<String,Object> optionMap)
Set all options from a Map.
|
Request |
options(String jsonString)
Set all options based on a JSON String
|
Request |
pipe(InputStream in)
Sets an input stream for uploading data
|
Request |
pipe(OutputStream out)
Sets an outputstream for downloading
|
protected HttpURLConnection |
prepareConnection(HttpURLConnection conn) |
Request |
query(Map<String,Object> map) |
Request |
query(Object... fieldValuePairs)
Adds field value pairs to the query
|
Request |
query(String jsonString)
Adds query data from a JSON String
|
Request |
setForm(Object... fieldValuePairs)
Sets form data, replacing any previous data for th field
|
Request |
setHeaders(Object... fieldValuePairs)
Replaces all previous header data for the given key value pairs
|
Request |
setQuery(Object... fieldValuePairs)
Replaces all previous query data for the given key value pairs
|
Request |
upload(Object toBeUploaded)
Sets data to be uploaded: a File or InputStream,
a Map which will get converted to JSON
or anything else will be sent as a String
|
Request |
uploadSubstitution(boolean b)
If uploadSubstitution is activated, text like ${FORM_DATA} in the upload data
will be replaced with values from the FORM
|
Request |
useStrictRFC3986(boolean b) |
failFast, failSlow, fn1, fn2, getNextCallback, handleEvent, handleException, setNextCallback
addListener, createListenerList, emit, emit, fireEvent, getListenerList, listenerCount, listeners, on, once, removeAllListeners, removeListener, setMaxListeners
public static final String FORM_DATA
public static final String HEADER_DATA
public static final String QUERY_DATA
protected boolean useStrictRFC3986
protected boolean methodMustUpload
protected int maxRetries
protected HashWrapper.Linked options
protected final HTTPMultiMap queryMMap
form(Object...)
,
headers(Object...)
,
query(Object...)
protected final HTTPMultiMap headersMMap
protected final HTTPMultiMap formDataMMap
protected String baseUrl
protected HTTPMethod method
protected OutputStream pipeOut
protected InputStream pipeIn
protected Object uploadMe
protected OutputStream pipeTo
protected volatile Request.Milestone attempting
protected Response response401
public Request(String baseUrl, HTTPMethod method, Map<String,Object> options)
baseUrl
- may include a query part but you have to encode it yourselfmethod
- options
- may be nullpublic Request(String baseUrl, HTTPMethod method)
public Request(String urlOrOptions)
public Request()
public Response callback(Exception ex, String urlOrOptions, Object... more) throws Exception
Callback
callback
in interface Callback<String,Response>
callback
in class EmittingCallbackFn<String,Response>
ex
- null, or an Exception thrown from an earlier callback. You should test for this!urlOrOptions
- input data, probably coming from a previous callbackmore
- additional input data (rarely used)Exception
public Request options(Map<String,Object> optionMap)
optionMap
- if null nothing happenspublic Request options(String jsonString)
jsonString
- if null or empty nothing happenspublic Request form(Object... fieldValuePairs)
fieldValuePairs
- should be an even number of field/value pairspublic Request form(Map<String,Object> map)
map
- may be null or emptypublic Request form(String jsonString)
jsonString
- if null or empty nothing happenspublic Request setForm(Object... fieldValuePairs)
fieldValuePairs
- if null or [], deletes all previous form datapublic Request headers(Object... fieldValuePairs)
fieldValuePairs
- public Request headers(Map<String,Object> map)
map
- non-null, may be emptypublic Request headers(String jsonString)
jsonString
- if null or empty nothing happenspublic Request setHeaders(Object... fieldValuePairs)
fieldValuePairs
- if empty, clears all headers for all keyspublic Request method(HTTPMethod method)
public Request pipe(InputStream in)
in
- public Request pipe(OutputStream out)
out
- public Request query(Object... fieldValuePairs)
fieldValuePairs
- public Request query(String jsonString)
jsonString
- if null or empty nothing happenspublic Request setQuery(Object... fieldValuePairs)
fieldValuePairs
- if empty, clears all query data for all keyspublic Request upload(Object toBeUploaded)
toBeUploaded
- public Request uploadSubstitution(boolean b)
b
- public Request useStrictRFC3986(boolean b)
public Response call1()
public Map<String,Object> JSONtoMap(String jsonString)
jsonString
- if null or empty return empty mapprotected String objectToStringForUpload(Object object)
protected long copy(InputStream input, OutputStream output, boolean emit) throws IOException
IOException
protected String doSubstituteMultiMapData(String upload)
uploadSubstitution(boolean)
,
FORM_DATA
,
HEADER_DATA
,
QUERY_DATA
protected URLEncoding getEncoding()
protected void noteMilestone(Request.Milestone attempting)
attempting
- protected HttpURLConnection openConnection() throws IOException
IOException
protected String fullURL() throws IOException
IOException
protected HttpURLConnection prepareConnection(HttpURLConnection conn)
protected void doAuth(HttpURLConnection conn)
protected String doAWS(Map awsMap) throws IOException
IOException
protected void checkMethodMustUpload()
protected void doUpload(OutputStream outputStream) throws IOException
IOException