public class HttpSender extends java.lang.Object implements ReportSender
The ReportSender
used by ACRA when ReportsCrashes.formUri()
has been defined in order to post crash data to a custom server-side data
collection script. It sends all data in a POST request with parameters named
with easy to understand names (basically a string conversion of
ReportField
enum values) or based on your own conversion Map from
ReportField
values to String.
To use specific POST parameter names, you can provide your own report fields mapping scheme:
Just create and declare aReportSenderFactory
that constructs a mapping from eachReportField
to another name.
Modifier and Type | Class and Description |
---|---|
static class |
HttpSender.Method
Available HTTP methods to send data.
|
static class |
HttpSender.Type
Type of report data encoding, currently supports Html Form encoding and
JSON.
|
Constructor and Description |
---|
HttpSender(ACRAConfiguration config,
HttpSender.Method method,
HttpSender.Type type)
Create a new HttpSender instance with its destination taken from the supplied config.
|
HttpSender(ACRAConfiguration config,
HttpSender.Method method,
HttpSender.Type type,
java.util.Map<ReportField,java.lang.String> mapping)
Create a new HttpSender instance with its destination taken from the supplied config.
|
HttpSender(ACRAConfiguration config,
HttpSender.Method method,
HttpSender.Type type,
java.lang.String formUri,
java.util.Map<ReportField,java.lang.String> mapping)
Create a new HttpPostSender instance with a fixed destination provided as
a parameter.
|
Modifier and Type | Method and Description |
---|---|
protected java.util.Map<java.lang.String,java.lang.String> |
convertToForm(CrashReportData report)
Convert a report to a form-prepared map
|
protected org.json.JSONObject |
convertToJson(CrashReportData report)
Convert a report to json
|
protected void |
postMultipart(ACRAConfiguration configuration,
android.content.Context context,
HttpSender.Type type,
java.lang.String login,
java.lang.String password,
int connectionTimeOut,
int socketTimeOut,
java.util.Map<java.lang.String,java.lang.String> headers,
java.lang.String content,
java.net.URL url,
java.util.List<android.net.Uri> attachments) |
protected void |
putAttachment(ACRAConfiguration configuration,
android.content.Context context,
java.lang.String login,
java.lang.String password,
int connectionTimeOut,
int socketTimeOut,
java.util.Map<java.lang.String,java.lang.String> headers,
java.net.URL url,
android.net.Uri attachment) |
void |
send(android.content.Context context,
CrashReportData report)
Send crash report data.
|
protected void |
sendHttpRequests(ACRAConfiguration configuration,
android.content.Context context,
HttpSender.Method method,
HttpSender.Type type,
java.lang.String login,
java.lang.String password,
int connectionTimeOut,
int socketTimeOut,
java.util.Map<java.lang.String,java.lang.String> headers,
java.lang.String content,
java.net.URL url,
java.util.List<android.net.Uri> attachments) |
protected void |
sendWithoutAttachments(ACRAConfiguration configuration,
android.content.Context context,
HttpSender.Method method,
HttpSender.Type type,
java.lang.String login,
java.lang.String password,
int connectionTimeOut,
int socketTimeOut,
java.util.Map<java.lang.String,java.lang.String> headers,
java.lang.String content,
java.net.URL url) |
void |
setBasicAuth(java.lang.String username,
java.lang.String password)
Set credentials for this HttpSender that override (if present) the ones
set globally.
|
public HttpSender(@NonNull ACRAConfiguration config, @NonNull HttpSender.Method method, @NonNull HttpSender.Type type)
Create a new HttpSender instance with its destination taken from the supplied config.
Uses ReportField
values converted to String with .toString() as form parameters.
config
- AcraConfig declaring themethod
- HTTP HttpSender.Method
to be used to send data. Currently only
HttpSender.Method.POST
and HttpSender.Method.PUT
are available. If
HttpSender.Method.PUT
is used, the ReportField.REPORT_ID
is appended to the formUri to be compliant with RESTful APIs.type
- HttpSender.Type
of encoding used to send the report body.
HttpSender.Type.FORM
is a simple Key/Value pairs list as defined
by the application/x-www-form-urlencoded mime type.public HttpSender(@NonNull ACRAConfiguration config, @NonNull HttpSender.Method method, @NonNull HttpSender.Type type, @Nullable java.util.Map<ReportField,java.lang.String> mapping)
Create a new HttpSender instance with its destination taken from the supplied config.
config
- AcraConfig declaring themethod
- HTTP HttpSender.Method
to be used to send data. Currently only
HttpSender.Method.POST
and HttpSender.Method.PUT
are available. If
HttpSender.Method.PUT
is used, the ReportField.REPORT_ID
is appended to the formUri to be compliant with RESTful APIs.type
- HttpSender.Type
of encoding used to send the report body.
HttpSender.Type.FORM
is a simple Key/Value pairs list as defined
by the application/x-www-form-urlencoded mime type.mapping
- Applies only to HttpSender.Method.POST
method parameter. If null,
POST parameters will be named with ReportField
values
converted to String with .toString(). If not null, POST
parameters will be named with the result of
mapping.get(ReportField.SOME_FIELD);public HttpSender(@NonNull ACRAConfiguration config, @NonNull HttpSender.Method method, @NonNull HttpSender.Type type, @Nullable java.lang.String formUri, @Nullable java.util.Map<ReportField,java.lang.String> mapping)
Create a new HttpPostSender instance with a fixed destination provided as a parameter. Configuration changes to the formUri are not applied.
config
- AcraConfig declaring themethod
- HTTP HttpSender.Method
to be used to send data. Currently only
HttpSender.Method.POST
and HttpSender.Method.PUT
are available. If
HttpSender.Method.PUT
is used, the ReportField.REPORT_ID
is appended to the formUri to be compliant with RESTful APIs.type
- HttpSender.Type
of encoding used to send the report body.
HttpSender.Type.FORM
is a simple Key/Value pairs list as defined
by the application/x-www-form-urlencoded mime type.formUri
- The URL of your server-side crash report collection script.mapping
- Applies only to HttpSender.Method.POST
method parameter. If null,
POST parameters will be named with ReportField
values
converted to String with .toString(). If not null, POST
parameters will be named with the result of
mapping.get(ReportField.SOME_FIELD);public void setBasicAuth(@Nullable java.lang.String username, @Nullable java.lang.String password)
Set credentials for this HttpSender that override (if present) the ones set globally.
username
- The username to set for HTTP Basic Auth.password
- The password to set for HTTP Basic Auth.public void send(@NonNull android.content.Context context, @NonNull CrashReportData report) throws ReportSenderException
ReportSender
SenderService
.send
in interface ReportSender
context
- Android Context in which to send the crash report.report
- Stores key/value pairs for each report field.
A report field is identified by a ReportField
enum value.ReportSenderException
- If anything goes fatally wrong during the handling of crash
data, you can (should) throw a ReportSenderException
with a custom message.protected void sendHttpRequests(@NonNull ACRAConfiguration configuration, @NonNull android.content.Context context, @NonNull HttpSender.Method method, @NonNull HttpSender.Type type, @Nullable java.lang.String login, @Nullable java.lang.String password, int connectionTimeOut, int socketTimeOut, @Nullable java.util.Map<java.lang.String,java.lang.String> headers, @NonNull java.lang.String content, @NonNull java.net.URL url, @NonNull java.util.List<android.net.Uri> attachments) throws java.io.IOException
java.io.IOException
protected void sendWithoutAttachments(@NonNull ACRAConfiguration configuration, @NonNull android.content.Context context, @NonNull HttpSender.Method method, @NonNull HttpSender.Type type, @Nullable java.lang.String login, @Nullable java.lang.String password, int connectionTimeOut, int socketTimeOut, @Nullable java.util.Map<java.lang.String,java.lang.String> headers, @NonNull java.lang.String content, @NonNull java.net.URL url) throws java.io.IOException
java.io.IOException
protected void postMultipart(@NonNull ACRAConfiguration configuration, @NonNull android.content.Context context, @NonNull HttpSender.Type type, @Nullable java.lang.String login, @Nullable java.lang.String password, int connectionTimeOut, int socketTimeOut, @Nullable java.util.Map<java.lang.String,java.lang.String> headers, @NonNull java.lang.String content, @NonNull java.net.URL url, @NonNull java.util.List<android.net.Uri> attachments) throws java.io.IOException
java.io.IOException
protected void putAttachment(@NonNull ACRAConfiguration configuration, @NonNull android.content.Context context, @Nullable java.lang.String login, @Nullable java.lang.String password, int connectionTimeOut, int socketTimeOut, @Nullable java.util.Map<java.lang.String,java.lang.String> headers, @NonNull java.net.URL url, @NonNull android.net.Uri attachment) throws java.io.IOException
java.io.IOException
protected org.json.JSONObject convertToJson(CrashReportData report)
report
- the report to convertprotected java.util.Map<java.lang.String,java.lang.String> convertToForm(CrashReportData report)
report
- the report to convert