org.androidannotations.annotations
Annotation Type HttpsClient
@Retention(value=CLASS)
@Target(value=FIELD)
public @interface HttpsClient
Use this annotation to inject an HttpClient instance with the specified
KeyStore and TrustStore configured to perform an HTTPS request.
All the parameters are optional:
- trustStore: int, Resource id of your trust store file ex
R.raw.cacerts.bks
Typically your servers trusted certificates
(public key, Root Chain Authority etc)
- trustStorePwd: String, Your trust store password (default is
changeit
)
- keyStore: int, Resource id of your keystore Usually your private
key (client certificate)
- keyStorePwd: String, Your KeyStore password (default is
changeit
)
- allowAllHostnames: boolean, if true, authorizes any TLS/SSL
hostname (default
true
) If false, Hostname in certificate (DN)
must match the URL.
Note:
Prior to ICS, Android accepts [Key|Trust]store only in BKS format
(Bouncycastle Key Store)
Example :
@EBean
public class MyBean {
@HttpsClient(trustStore = R.raw.cacerts, //
trustStorePwd = "changeit", //
keyStore = R.raw.client, //
keyStorePwd = "secret", //
allowAllHostnames = false)
HttpClient httpsClient;
@AfterInject
@Background
public void securedRequest() {
try {
HttpGet httpget = new HttpGet("https://www.verisign.com/");
HttpResponse response = httpsClient.execute(httpget);
doSomethingWithResponse(response);
} catch (Exception e) {
e.printStackTrace();
}
}
@UiThread
public void doSomethingWithResponse(HttpResponse resp) {
Toast.makeText(this, "HTTP status " + resp.getStatusLine().getStatusCode(), Toast.LENGTH_LONG).show();
}
}
trustStore
public abstract int trustStore
- Default:
- -1
trustStorePwd
public abstract String trustStorePwd
- Default:
- "changeit"
keyStore
public abstract int keyStore
- Default:
- -1
keyStorePwd
public abstract String keyStorePwd
- Default:
- "changeit"
allowAllHostnames
public abstract boolean allowAllHostnames
- Default:
- true
Copyright © 2010-2014. All Rights Reserved.