use of org.apache.flink.shaded.jackson2.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 "{}";
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParseException in project swagger-core by swagger-api.
the class SecuritySchemeDeserializer method deserialize.
@Override
public SecurityScheme deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
ObjectMapper mapper = null;
if (openapi31) {
mapper = Json31.mapper();
} else {
mapper = Json.mapper();
}
SecurityScheme result = null;
JsonNode node = jp.getCodec().readTree(jp);
JsonNode inNode = node.get("type");
if (inNode != null) {
String type = inNode.asText();
if (Arrays.stream(SecurityScheme.Type.values()).noneMatch(t -> t.toString().equals(type))) {
// wrong type, throw exception
throw new JsonParseException(jp, String.format("SecurityScheme type %s not allowed", type));
}
result = new SecurityScheme().description(getFieldText("description", node));
if ("http".equals(type)) {
result.type(SecurityScheme.Type.HTTP).scheme(getFieldText("scheme", node)).bearerFormat(getFieldText("bearerFormat", node));
} else if ("apiKey".equals(type)) {
result.type(SecurityScheme.Type.APIKEY).name(getFieldText("name", node)).in(getIn(getFieldText("in", node)));
} else if ("openIdConnect".equals(type)) {
result.type(SecurityScheme.Type.OPENIDCONNECT).openIdConnectUrl(getFieldText("openIdConnectUrl", node));
} else if ("oauth2".equals(type)) {
result.type(SecurityScheme.Type.OAUTH2).flows(mapper.convertValue(node.get("flows"), OAuthFlows.class));
} else if ("mutualTLS".equals(type)) {
result.type(SecurityScheme.Type.MUTUALTLS);
}
}
return result;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParseException in project snow-owl by b2ihealthcare.
the class ExpandParser method parse.
public static Options parse(final String expand) {
String jsonizedOptionPart = String.format("{%s}", expand.replace("(", ":{").replace(')', '}'));
try {
JsonParser parser = JSON_FACTORY.createParser(jsonizedOptionPart);
parser.setCodec(new ObjectMapper());
Map<String, Object> source = parser.<Map<String, Object>>readValueAs(new TypeReference<Map<String, Object>>() {
});
return OptionsBuilder.newBuilder().putAll(source).build();
} catch (JsonParseException e) {
throw new BadRequestException("Expansion parameter %s is malformed.", expand);
} catch (IOException e) {
throw new SnowowlRuntimeException("Caught I/O exception while reading expansion parameters.", e);
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParseException in project drools by kiegroup.
the class JsonUtils method convertFromStringToJSONNode.
/**
* This method aim is to to evaluate if any possible String is a valid json or not.
* Given a json in String format, it try to convert it in a <code>JsonNode</code>. In case of success, i.e.
* the given string is a valid json, it put the <code>JsonNode</code> in a <code>Optional</code>. An empty
* <code>Optional</code> is passed otherwise.
* @param json
* @return
*/
public static Optional<JsonNode> convertFromStringToJSONNode(String json) {
if (json == null || json.isEmpty()) {
return Optional.empty();
}
try {
ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonNode = objectMapper.readTree(json);
return Optional.of(jsonNode);
} catch (JsonParseException e) {
return Optional.empty();
} catch (IOException e) {
throw new IllegalArgumentException("Generic error during json parsing: " + json, e);
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParseException in project carbon-apimgt by wso2.
the class JSONAnalyzer method analyze.
/**
* Analyze the JSON payload against limitations.
* @param in input stream of the request payload.
* @param apiContext request api context.
* @throws APIMThreatAnalyzerException if defined limits for json payload exceeds
*/
@Override
public void analyze(InputStream in, String apiContext) throws APIMThreatAnalyzerException {
try (JsonParser parser = factory.createParser(new InputStreamReader(in))) {
int currentDepth = 0;
int currentFieldCount = 0;
JsonToken token;
while ((token = parser.nextToken()) != null) {
switch(token) {
case START_OBJECT:
currentDepth += 1;
analyzeDepth(maxJsonDepth, currentDepth, apiContext);
break;
case END_OBJECT:
currentDepth -= 1;
break;
case FIELD_NAME:
currentFieldCount += 1;
String name = parser.getCurrentName();
analyzeField(name, maxFieldCount, currentFieldCount, maxFieldLength);
break;
case VALUE_STRING:
String value = parser.getText();
analyzeString(value, maxStringLength);
break;
case START_ARRAY:
analyzeArray(parser, maxArrayElementCount, maxStringLength);
}
}
} catch (JsonParseException e) {
throw new APIMThreatAnalyzerException("Error occurred while parsing the JSON payload", e);
} catch (IOException e) {
throw new APIMThreatAnalyzerException("Error occurred while reading the JSON payload.", e);
}
}
Aggregations