use of org.codehaus.jackson.JsonParseException in project neo4j by neo4j.
the class StatementDeserializer method fetchNextOrNull.
@Override
protected Statement fetchNextOrNull() {
try {
if (errors != null) {
return null;
}
switch(state) {
case BEFORE_OUTER_ARRAY:
if (!beginsWithCorrectTokens()) {
return null;
}
state = State.IN_BODY;
case IN_BODY:
String statement = null;
Map<String, Object> parameters = null;
List<Object> resultsDataContents = null;
boolean includeStats = false;
JsonToken tok;
while ((tok = input.nextToken()) != null && tok != END_OBJECT) {
if (tok == END_ARRAY) {
// No more statements
state = State.FINISHED;
return null;
}
input.nextValue();
String currentName = input.getCurrentName();
switch(currentName) {
case "statement":
statement = input.readValueAs(String.class);
break;
case "parameters":
parameters = readMap(input);
break;
case "resultDataContents":
resultsDataContents = readArray(input);
break;
case "includeStats":
includeStats = input.getBooleanValue();
break;
default:
discardValue(input);
}
}
if (statement == null) {
addError(new Neo4jError(Status.Request.InvalidFormat, new DeserializationException("No statement provided.")));
return null;
}
return new Statement(statement, parameters == null ? NO_PARAMETERS : parameters, includeStats, ResultDataContent.fromNames(resultsDataContents));
case FINISHED:
return null;
default:
break;
}
return null;
} catch (JsonParseException | JsonMappingException e) {
addError(new Neo4jError(Status.Request.InvalidFormat, new DeserializationException("Unable to deserialize request", e)));
return null;
} catch (IOException e) {
addError(new Neo4jError(Status.Network.CommunicationError, e));
return null;
} catch (Exception e) {
addError(new Neo4jError(Status.General.UnknownError, e));
return null;
}
}
use of org.codehaus.jackson.JsonParseException in project spring-security-oauth by spring-projects.
the class OAuth2AccessTokenJackson1Deserializer method deserialize.
@Override
public OAuth2AccessToken deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
String tokenValue = null;
String tokenType = null;
String refreshToken = null;
Long expiresIn = null;
Set<String> scope = null;
Map<String, Object> additionalInformation = new LinkedHashMap<String, Object>();
// TODO What should occur if a parameter exists twice
while (jp.nextToken() != JsonToken.END_OBJECT) {
String name = jp.getCurrentName();
jp.nextToken();
if (OAuth2AccessToken.ACCESS_TOKEN.equals(name)) {
tokenValue = jp.getText();
} else if (OAuth2AccessToken.TOKEN_TYPE.equals(name)) {
tokenType = jp.getText();
} else if (OAuth2AccessToken.REFRESH_TOKEN.equals(name)) {
refreshToken = jp.getText();
} else if (OAuth2AccessToken.EXPIRES_IN.equals(name)) {
try {
expiresIn = jp.getLongValue();
} catch (JsonParseException e) {
expiresIn = Long.valueOf(jp.getText());
}
} else if (OAuth2AccessToken.SCOPE.equals(name)) {
String text = jp.getText();
scope = OAuth2Utils.parseParameterList(text);
} else {
additionalInformation.put(name, jp.readValueAs(Object.class));
}
}
// TODO What should occur if a required parameter (tokenValue or tokenType) is missing?
DefaultOAuth2AccessToken accessToken = new DefaultOAuth2AccessToken(tokenValue);
accessToken.setTokenType(tokenType);
if (expiresIn != null) {
accessToken.setExpiration(new Date(System.currentTimeMillis() + (expiresIn * 1000)));
}
if (refreshToken != null) {
accessToken.setRefreshToken(new DefaultOAuth2RefreshToken(refreshToken));
}
accessToken.setScope(scope);
accessToken.setAdditionalInformation(additionalInformation);
return accessToken;
}
use of org.codehaus.jackson.JsonParseException in project voldemort by voldemort.
the class R2Store method parseGetResponse.
private List<Versioned<byte[]>> parseGetResponse(ByteString entity) {
List<Versioned<byte[]>> results = new ArrayList<Versioned<byte[]>>();
try {
// Build the multipart object
byte[] bytes = new byte[entity.length()];
entity.copyBytes(bytes, 0);
ByteArrayDataSource ds = new ByteArrayDataSource(bytes, "multipart/mixed");
MimeMultipart mp = new MimeMultipart(ds);
for (int i = 0; i < mp.getCount(); i++) {
MimeBodyPart part = (MimeBodyPart) mp.getBodyPart(i);
String serializedVC = part.getHeader(RestMessageHeaders.X_VOLD_VECTOR_CLOCK)[0];
int contentLength = Integer.parseInt(part.getHeader(RestMessageHeaders.CONTENT_LENGTH)[0]);
if (logger.isDebugEnabled()) {
logger.debug("Received VC : " + serializedVC);
}
VectorClockWrapper vcWrapper = mapper.readValue(serializedVC, VectorClockWrapper.class);
InputStream input = part.getInputStream();
byte[] bodyPartBytes = new byte[contentLength];
input.read(bodyPartBytes);
VectorClock clock = new VectorClock(vcWrapper.getVersions(), vcWrapper.getTimestamp());
results.add(new Versioned<byte[]>(bodyPartBytes, clock));
}
} catch (MessagingException e) {
throw new VoldemortException("Messaging exception while trying to parse GET response " + e.getMessage(), e);
} catch (JsonParseException e) {
throw new VoldemortException("JSON parsing exception while trying to parse GET response " + e.getMessage(), e);
} catch (JsonMappingException e) {
throw new VoldemortException("JSON mapping exception while trying to parse GET response " + e.getMessage(), e);
} catch (IOException e) {
throw new VoldemortException("IO exception while trying to parse GET response " + e.getMessage(), e);
}
return results;
}
use of org.codehaus.jackson.JsonParseException in project voldemort by voldemort.
the class R2Store method parseGetAllResults.
private Map<ByteArray, List<Versioned<byte[]>>> parseGetAllResults(ByteString entity) {
Map<ByteArray, List<Versioned<byte[]>>> results = new HashMap<ByteArray, List<Versioned<byte[]>>>();
try {
// Build the multipart object
byte[] bytes = new byte[entity.length()];
entity.copyBytes(bytes, 0);
// Get the outer multipart object
ByteArrayDataSource ds = new ByteArrayDataSource(bytes, "multipart/mixed");
MimeMultipart mp = new MimeMultipart(ds);
for (int i = 0; i < mp.getCount(); i++) {
// Get an individual part. This contains all the versioned
// values for a particular key referenced by content-location
MimeBodyPart part = (MimeBodyPart) mp.getBodyPart(i);
// Get the key
String contentLocation = part.getHeader("Content-Location")[0];
String base64Key = contentLocation.split("/")[2];
ByteArray key = new ByteArray(RestUtils.decodeVoldemortKey(base64Key));
if (logger.isDebugEnabled()) {
logger.debug("Content-Location : " + contentLocation);
logger.debug("Base 64 key : " + base64Key);
}
// Create an array list for holding all the (versioned values)
List<Versioned<byte[]>> valueResultList = new ArrayList<Versioned<byte[]>>();
/*
* Get the nested Multi-part object. This contains one part for each unique versioned value.
*
* GetContent method can corrupt the embedded data, for example 0x8c be converted to 0xc2, 0x8c,
* hence use getInputStream.
*
* This thread tracks this question
* http://stackoverflow.com/questions/23023583/mimebodypart-getcontent-corrupts-binary-data
*
* getInputStream() : Return a decoded input stream for this Message's "content.
*
* getRawInputStream() : Return an InputStream to the raw data with any Content-Transfer-Encoding
* intact. This method is useful if the "Content-Transfer-Encoding" header is incorrect or corrupt,
* which would prevent the getInputStream method from returning the correct data. In such a case
* the application may use this method and attempt to decode the raw data itself.
*
*/
ByteArrayDataSource nestedDS = new ByteArrayDataSource(part.getInputStream(), "multipart/mixed");
MimeMultipart valueParts = new MimeMultipart(nestedDS);
for (int valueId = 0; valueId < valueParts.getCount(); valueId++) {
MimeBodyPart valuePart = (MimeBodyPart) valueParts.getBodyPart(valueId);
String serializedVC = valuePart.getHeader(RestMessageHeaders.X_VOLD_VECTOR_CLOCK)[0];
int contentLength = Integer.parseInt(valuePart.getHeader(RestMessageHeaders.CONTENT_LENGTH)[0]);
if (logger.isDebugEnabled()) {
logger.debug("Received serialized Vector Clock : " + serializedVC);
}
VectorClockWrapper vcWrapper = mapper.readValue(serializedVC, VectorClockWrapper.class);
// get the value bytes
InputStream input = valuePart.getInputStream();
byte[] bodyPartBytes = new byte[contentLength];
input.read(bodyPartBytes);
VectorClock clock = new VectorClock(vcWrapper.getVersions(), vcWrapper.getTimestamp());
valueResultList.add(new Versioned<byte[]>(bodyPartBytes, clock));
}
results.put(key, valueResultList);
}
} catch (MessagingException e) {
throw new VoldemortException("Messaging exception while trying to parse GET response " + e.getMessage(), e);
} catch (JsonParseException e) {
throw new VoldemortException("JSON parsing exception while trying to parse GET response " + e.getMessage(), e);
} catch (JsonMappingException e) {
throw new VoldemortException("JSON mapping exception while trying to parse GET response " + e.getMessage(), e);
} catch (IOException e) {
throw new VoldemortException("IO exception while trying to parse GET response " + e.getMessage(), e);
}
return results;
}
use of org.codehaus.jackson.JsonParseException in project stanbol by apache.
the class AnalyzedTextParser method parseAnnotation.
private void parseAnnotation(Span span, String key, ObjectNode jValue) throws IOException {
JsonNode jClass = jValue.path("class");
if (!jClass.isTextual()) {
log.warn("unable to parse Annotation {} because 'class' field " + "is not set or not a stringis no JSON object (ignored, json: {}", key, jValue);
return;
}
Class<?> clazz;
try {
clazz = AnalyzedTextParser.class.getClassLoader().loadClass(jClass.getTextValue());
} catch (ClassNotFoundException e) {
log.warn("Unable to parse Annotation " + key + " because the 'class' " + jClass.getTextValue() + " of the " + "the value can not be resolved (ignored, json: " + jValue + ")", e);
return;
}
ValueTypeParser<?> parser = this.valueTypeParserRegistry.getParser(clazz);
Object value;
if (parser != null) {
value = parser.parse(jValue, span.getContext());
} else {
JsonNode valueNode = jValue.path("value");
if (valueNode.isMissingNode()) {
log.warn("unable to parse value for annotation {} because the " + "field 'value' is not present (ignored, json: {}", key, jValue);
return;
} else {
try {
value = mapper.treeToValue(valueNode, clazz);
} catch (JsonParseException e) {
log.warn("unable to parse value for annotation " + key + "because the value can" + "not be converted to the class " + clazz.getName() + "(ignored, json: " + jValue + ")", e);
return;
} catch (JsonMappingException e) {
log.warn("unable to parse value for annotation " + key + "because the value can" + "not be converted to the class " + clazz.getName() + "(ignored, json: " + jValue + ")", e);
return;
}
}
}
JsonNode jProb = jValue.path("prob");
if (!jProb.isDouble()) {
span.addValue(key, Value.value(value));
} else {
span.addValue(key, Value.value(value, jProb.getDoubleValue()));
}
}
Aggregations