use of com.loopj.android.http.sample.util.SampleJSON in project android-async-http by loopj.
the class CustomCASample method getResponseHandler.
@Override
public ResponseHandlerInterface getResponseHandler() {
return new BaseJsonHttpResponseHandler<SampleJSON>() {
@Override
public void onStart() {
clearOutputs();
}
@Override
public void onSuccess(int statusCode, Header[] headers, String rawJsonResponse, SampleJSON response) {
debugHeaders(LOG_TAG, headers);
debugStatusCode(LOG_TAG, statusCode);
if (response != null) {
debugResponse(LOG_TAG, rawJsonResponse);
}
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable throwable, String rawJsonData, SampleJSON errorResponse) {
debugHeaders(LOG_TAG, headers);
debugStatusCode(LOG_TAG, statusCode);
debugThrowable(LOG_TAG, throwable);
if (errorResponse != null) {
debugResponse(LOG_TAG, rawJsonData);
}
}
@Override
protected SampleJSON parseResponse(String rawJsonData, boolean isFailure) throws Throwable {
return new ObjectMapper().readValues(new JsonFactory().createParser(rawJsonData), SampleJSON.class).next();
}
};
}
use of com.loopj.android.http.sample.util.SampleJSON in project android-async-http by loopj.
the class Http401AuthSample method getResponseHandler.
@Override
public ResponseHandlerInterface getResponseHandler() {
return new BaseJsonHttpResponseHandler<SampleJSON>() {
@Override
public void onStart() {
clearOutputs();
}
@Override
public void onSuccess(int statusCode, Header[] headers, String rawJsonResponse, SampleJSON response) {
debugHeaders(LOG_TAG, headers);
debugStatusCode(LOG_TAG, statusCode);
if (response != null) {
debugResponse(LOG_TAG, rawJsonResponse);
}
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable throwable, String rawJsonData, SampleJSON errorResponse) {
debugHeaders(LOG_TAG, headers);
debugStatusCode(LOG_TAG, statusCode);
debugThrowable(LOG_TAG, throwable);
// Ask the user for credentials if required by the server.
if (statusCode == 401) {
String realm = "Protected Page";
String authType = null;
// Cycle through the headers and look for the WWW-Authenticate header.
for (Header header : headers) {
String headerName = header.getName();
if (HEADER_WWW_AUTHENTICATE.equalsIgnoreCase(headerName)) {
String headerValue = header.getValue().trim();
String headerValueLowerCase = headerValue.toLowerCase(Locale.US);
// Get the type of auth requested.
int charPos = headerValueLowerCase.indexOf(' ');
if (0 < charPos) {
authType = headerValueLowerCase.substring(0, charPos);
// The second part should begin with a "realm=" prefix.
if (headerValueLowerCase.substring(1 + charPos).startsWith(HEADER_REALM_PREFIX)) {
// The new realm value, including any possible wrapping quotation.
realm = headerValue.substring(1 + charPos + HEADER_REALM_PREFIX.length());
// If realm starts with a quote, remove surrounding quotes.
if (realm.charAt(0) == '"' || realm.charAt(0) == '\'') {
realm = realm.substring(1, realm.length() - 1);
}
}
}
}
}
// We will support basic auth in this sample.
if (authType != null && HEADER_BASIC.equals(authType)) {
// Show a dialog for the user and request user/pass.
Log.d(LOG_TAG, HEADER_REALM_PREFIX + realm);
// Present the dialog.
postRunnable(new DialogRunnable(realm));
}
}
}
@Override
protected SampleJSON parseResponse(String rawJsonData, boolean isFailure) throws Throwable {
return new ObjectMapper().readValues(new JsonFactory().createParser(rawJsonData), SampleJSON.class).next();
}
};
}
use of com.loopj.android.http.sample.util.SampleJSON in project android-async-http by loopj.
the class JsonSample method getResponseHandler.
@Override
public ResponseHandlerInterface getResponseHandler() {
return new BaseJsonHttpResponseHandler<SampleJSON>() {
@Override
public void onStart() {
clearOutputs();
}
@Override
public void onSuccess(int statusCode, Header[] headers, String rawJsonResponse, SampleJSON response) {
debugHeaders(LOG_TAG, headers);
debugStatusCode(LOG_TAG, statusCode);
if (response != null) {
debugResponse(LOG_TAG, rawJsonResponse);
}
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable throwable, String rawJsonData, SampleJSON errorResponse) {
debugHeaders(LOG_TAG, headers);
debugStatusCode(LOG_TAG, statusCode);
debugThrowable(LOG_TAG, throwable);
if (errorResponse != null) {
debugResponse(LOG_TAG, rawJsonData);
}
}
@Override
protected SampleJSON parseResponse(String rawJsonData, boolean isFailure) throws Throwable {
return new ObjectMapper().readValues(new JsonFactory().createParser(rawJsonData), SampleJSON.class).next();
}
};
}
use of com.loopj.android.http.sample.util.SampleJSON in project android-async-http by loopj.
the class PersistentCookiesSample method getResponseHandler.
@Override
public ResponseHandlerInterface getResponseHandler() {
return new BaseJsonHttpResponseHandler<SampleJSON>() {
@Override
public void onStart() {
clearOutputs();
}
@Override
public void onSuccess(int statusCode, Header[] headers, String rawJsonResponse, SampleJSON response) {
debugHeaders(LOG_TAG, headers);
debugStatusCode(LOG_TAG, statusCode);
if (response != null) {
debugResponse(LOG_TAG, rawJsonResponse);
}
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable throwable, String rawJsonData, SampleJSON errorResponse) {
debugHeaders(LOG_TAG, headers);
debugStatusCode(LOG_TAG, statusCode);
debugThrowable(LOG_TAG, throwable);
if (errorResponse != null) {
debugResponse(LOG_TAG, rawJsonData);
}
}
@Override
protected SampleJSON parseResponse(String rawJsonData, boolean isFailure) throws Throwable {
return new ObjectMapper().readValues(new JsonFactory().createParser(rawJsonData), SampleJSON.class).next();
}
};
}
Aggregations