use of com.fasterxml.jackson.core.JsonParseException in project jackson-core by FasterXML.
the class NumberCoercionTest method testToLongFailing.
@SuppressWarnings("resource")
public void testToLongFailing() throws Exception {
for (int mode : ALL_STREAMING_MODES) {
JsonParser p;
// BigInteger -> error
BigInteger big = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.TEN);
p = createParser(mode, String.valueOf(big));
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
assertEquals(NumberType.BIG_INTEGER, p.getNumberType());
assertEquals(big, p.getBigIntegerValue());
assertEquals(big, p.getNumberValue());
try {
p.getLongValue();
fail("Should not pass");
} catch (JsonParseException e) {
verifyException(e, "out of range of long");
}
BigInteger small = BigInteger.valueOf(Long.MIN_VALUE).subtract(BigInteger.TEN);
p = createParser(mode, String.valueOf(small));
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
assertEquals(small, p.getBigIntegerValue());
try {
p.getLongValue();
fail("Should not pass");
} catch (JsonParseException e) {
verifyException(e, "out of range of long");
}
}
}
use of com.fasterxml.jackson.core.JsonParseException in project asterixdb by apache.
the class QueryServiceServlet method getRequestParameters.
private RequestParameters getRequestParameters(IServletRequest request) throws IOException {
final String contentTypeParam = request.getHttpRequest().headers().get(HttpHeaderNames.CONTENT_TYPE);
int sep = contentTypeParam.indexOf(';');
final String contentType = sep < 0 ? contentTypeParam.trim() : contentTypeParam.substring(0, sep).trim();
RequestParameters param = new RequestParameters();
param.host = host(request);
param.path = servletPath(request);
if (HttpUtil.ContentType.APPLICATION_JSON.equals(contentType)) {
try {
JsonNode jsonRequest = new ObjectMapper().readTree(HttpUtil.getRequestBody(request));
param.statement = jsonRequest.get(Parameter.STATEMENT.str()).asText();
param.format = toLower(getOptText(jsonRequest, Parameter.FORMAT.str()));
param.pretty = getOptBoolean(jsonRequest, Parameter.PRETTY.str(), false);
param.mode = toLower(getOptText(jsonRequest, Parameter.MODE.str()));
param.clientContextID = getOptText(jsonRequest, Parameter.CLIENT_ID.str());
} catch (JsonParseException | JsonMappingException e) {
// if the JSON parsing fails, the statement is empty and we get an empty statement error
GlobalConfig.ASTERIX_LOGGER.log(Level.SEVERE, e.getMessage(), e);
}
} else {
param.statement = request.getParameter(Parameter.STATEMENT.str());
if (param.statement == null) {
param.statement = HttpUtil.getRequestBody(request);
}
param.format = toLower(request.getParameter(Parameter.FORMAT.str()));
param.pretty = Boolean.parseBoolean(request.getParameter(Parameter.PRETTY.str()));
param.mode = toLower(request.getParameter(Parameter.MODE.str()));
param.clientContextID = request.getParameter(Parameter.CLIENT_ID.str());
}
return param;
}
use of com.fasterxml.jackson.core.JsonParseException in project BIMserver by opensourceBIM.
the class JsonQueryObjectModelConverter method getDefineFromFile.
// TODO thread safety and cache invalidation on file updates
public Include getDefineFromFile(String includeName) throws QueryException {
Include include = CACHED_DEFINES.get(includeName);
if (include != null) {
return include;
}
String namespaceString = includeName.substring(0, includeName.indexOf(":"));
String singleIncludeName = includeName.substring(includeName.indexOf(":") + 1);
URL resource;
try {
resource = getClass().getClassLoader().loadClass("org.bimserver.database.queries.StartFrame").getResource("json/" + namespaceString + ".json");
if (resource == null) {
throw new QueryException("Could not find '" + namespaceString + "' namespace in predefined queries");
}
} catch (ClassNotFoundException e1) {
throw new QueryException("Could not find '" + namespaceString + "' namespace in predefined queries");
}
OBJECT_MAPPER.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
try {
ObjectNode predefinedQuery = OBJECT_MAPPER.readValue(resource, ObjectNode.class);
JsonQueryObjectModelConverter converter = new JsonQueryObjectModelConverter(packageMetaData);
Query query = converter.parseJson(namespaceString, predefinedQuery);
Include define = query.getDefine(singleIncludeName);
if (define == null) {
throw new QueryException("Could not find '" + singleIncludeName + "' in defines in namespace " + query.getName());
}
CACHED_DEFINES.put(includeName, define);
return define;
} catch (JsonParseException e) {
throw new QueryException(e);
} catch (JsonMappingException e) {
throw new QueryException(e);
} catch (IOException e) {
throw new QueryException(e);
}
}
use of com.fasterxml.jackson.core.JsonParseException in project BIMserver by opensourceBIM.
the class GetNrPrimitivesDatabaseAction method execute.
@Override
public Long execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException, ServerException {
Revision revision = getDatabaseSession().get(roid, OldQuery.getDefault());
PackageMetaData packageMetaData = bimServer.getMetaDataManager().getPackageMetaData(revision.getProject().getSchema());
if (packageMetaData == null) {
throw new UserException("Schema not fond");
}
try {
Query query = new Query("test", packageMetaData);
QueryPart queryPart = query.createQueryPart();
queryPart.addType(packageMetaData.getEClassIncludingDependencies("GeometryInfo"), true);
QueryObjectProvider queryObjectProvider = new QueryObjectProvider(getDatabaseSession(), bimServer, query, java.util.Collections.singleton(roid), packageMetaData);
HashMapVirtualObject next = queryObjectProvider.next();
long totalPrimitives = 0;
while (next != null) {
int nrPrimitives = (int) next.get("primitiveCount");
totalPrimitives += nrPrimitives;
next = queryObjectProvider.next();
}
return totalPrimitives;
} catch (QueryException e) {
e.printStackTrace();
} catch (JsonParseException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
use of com.fasterxml.jackson.core.JsonParseException in project uPortal by Jasig.
the class AnalyticsIncorporationComponent method serializePortletRenderExecutionEvents.
protected String serializePortletRenderExecutionEvents(final Set<PortalEvent> portalEvents) {
// Filter to include just portlet render events
final Map<String, PortletRenderExecutionEvent> renderEvents = new HashMap<>();
for (final PortalEvent portalEvent : portalEvents) {
if (portalEvent instanceof PortletRenderExecutionEvent) {
final PortletRenderExecutionEvent portletRenderEvent = (PortletRenderExecutionEvent) portalEvent;
// Don't write out info for minimized portlets
if (!WindowState.MINIMIZED.equals(portletRenderEvent.getWindowState())) {
final IPortletWindowId portletWindowId = portletRenderEvent.getPortletWindowId();
final String eventKey = portletWindowId != null ? portletWindowId.getStringId() : portletRenderEvent.getFname();
renderEvents.put(eventKey, portletRenderEvent);
}
}
}
try {
return portletEventWriter.writeValueAsString(renderEvents);
} catch (JsonParseException e) {
logger.warn("Failed to convert this request's render events to JSON, no portlet level analytics will be included", e);
} catch (JsonMappingException e) {
logger.warn("Failed to convert this request's render events to JSON, no portlet level analytics will be included", e);
} catch (IOException e) {
logger.warn("Failed to convert this request's render events to JSON, no portlet level analytics will be included", e);
}
return "{}";
}
Aggregations