use of com.fasterxml.jackson.core.JsonFactory in project cassandra-mesos-deprecated by mesosphere.
the class AbstractApiControllerTest method fetchJson.
@NotNull
protected Tuple2<Integer, JsonNode> fetchJson(final String rel, final boolean post) throws Exception {
final JsonFactory factory = new JsonFactory();
final HttpURLConnection conn = (HttpURLConnection) resolve(rel).toURL().openConnection();
try {
conn.setRequestMethod(post ? "POST" : "GET");
conn.setRequestProperty("Accept", "application/json");
conn.connect();
final int responseCode = conn.getResponseCode();
InputStream in;
try {
in = conn.getInputStream();
} catch (final IOException e) {
in = conn.getErrorStream();
}
if (in == null) {
return Tuple2.tuple2(responseCode, (JsonNode) MissingNode.getInstance());
}
assertEquals("application/json", conn.getHeaderField("Content-Type"));
try {
final ObjectMapper om = new ObjectMapper();
return Tuple2.tuple2(responseCode, om.reader().with(factory).readTree(in));
} finally {
in.close();
}
} finally {
conn.disconnect();
}
}
use of com.fasterxml.jackson.core.JsonFactory 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.fasterxml.jackson.core.JsonFactory 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.fasterxml.jackson.core.JsonFactory 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();
}
};
}
use of com.fasterxml.jackson.core.JsonFactory in project hadoop by apache.
the class JMXJsonServlet method init.
/**
* Initialize this servlet.
*/
@Override
public void init() throws ServletException {
// Retrieve the MBean server
mBeanServer = ManagementFactory.getPlatformMBeanServer();
jsonFactory = new JsonFactory();
}
Aggregations