@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:
R.raw.cacerts.bks
Typically your servers trusted certificates
(public key, Root Chain Authority etc)changeit
)changeit
)true
) If false, Hostname in certificate (DN)
must match the URL.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(); } }
Modifier and Type | Fields and Description |
---|---|
static String |
DEFAULT_PASSWD
The default value of
trustStorePwd() and keyStorePwd() . |
Modifier and Type | Optional Element and Description |
---|---|
boolean |
allowAllHostnames
Whether to authorizes any TLS/SSL hostname.
|
int |
keyStore
The R.id.* field id which refers to the key store file.
|
String |
keyStorePwd
The key store password.
|
String |
keyStoreResName
The resource name which refers to the key store file.
|
int |
trustStore
The R.id.* field id which refers to the trust store file.
|
String |
trustStorePwd
The trust store password.
|
String |
trustStoreResName
The resource name which refers to the trust store file.
|
public static final String DEFAULT_PASSWD
trustStorePwd()
and keyStorePwd()
.public abstract int trustStore
public abstract String trustStoreResName
public abstract String trustStorePwd
public abstract int keyStore
public abstract String keyStoreResName
public abstract String keyStorePwd
Copyright © 2010-2015. All Rights Reserved.