use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project knime-core by knime.
the class SubnodeLayoutJSONEditorPage method isJSONValid.
/**
* @return true, if current JSON layout structure is valid
*/
protected boolean isJSONValid() {
ObjectMapper mapper = JSONLayoutPage.getConfiguredObjectMapper();
ObjectReader reader = mapper.readerForUpdating(new JSONLayoutPage());
try {
String json = isWindows() ? m_textArea.getText() : m_jsonDocument;
JSONLayoutPage page = reader.readValue(json);
m_documentNodeIDs.clear();
if (page.getRows() != null) {
for (JSONLayoutRow row : page.getRows()) {
populateDocumentNodeIDs(row);
}
compareNodeIDs();
}
return true;
} catch (IOException | NumberFormatException e) {
String errorMessage;
if (e instanceof JsonProcessingException) {
JsonProcessingException jsonException = (JsonProcessingException) e;
Throwable cause = null;
Throwable newCause = jsonException.getCause();
while (newCause instanceof JsonProcessingException) {
if (cause == newCause) {
break;
}
cause = newCause;
newCause = cause.getCause();
}
if (cause instanceof JsonProcessingException) {
jsonException = (JsonProcessingException) cause;
}
errorMessage = jsonException.getOriginalMessage().split("\n")[0];
JsonLocation location = jsonException.getLocation();
if (location != null) {
errorMessage += " at line: " + (location.getLineNr() + 1) + " column: " + location.getColumnNr();
}
} else {
String message = e.getMessage();
errorMessage = message;
}
if (m_statusLine != null && !m_statusLine.isDisposed()) {
m_statusLine.setForeground(new Color(Display.getCurrent(), 255, 0, 0));
m_statusLine.setText(errorMessage);
int textWidth = isWindows() ? m_textArea.getSize().width : m_text.getSize().x;
Point newSize = m_statusLine.computeSize(textWidth, m_statusLine.getSize().y, true);
m_statusLine.setSize(newSize);
}
}
return false;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project traccar by tananaev.
the class EventForwarder method prepareJsonPayload.
protected String prepareJsonPayload(Event event, Position position, Set<Long> users) {
Map<String, Object> data = new HashMap<>();
data.put(KEY_EVENT, event);
if (position != null) {
data.put(KEY_POSITION, position);
}
Device device = Context.getIdentityManager().getById(event.getDeviceId());
if (device != null) {
data.put(KEY_DEVICE, device);
}
if (event.getGeofenceId() != 0) {
Geofence geofence = Context.getGeofenceManager().getById(event.getGeofenceId());
if (geofence != null) {
data.put(KEY_GEOFENCE, geofence);
}
}
data.put(KEY_USERS, Context.getUsersManager().getItems(users));
try {
return Context.getObjectMapper().writeValueAsString(data);
} catch (JsonProcessingException e) {
Log.warning(e);
return null;
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project traccar by tananaev.
the class CsvBuilder method addLine.
public void addLine(Object object) {
SortedSet<Method> methods = getSortedMethods(object);
for (Method method : methods) {
if (method.getName().startsWith("get") && method.getParameterTypes().length == 0) {
try {
if (method.getReturnType().equals(boolean.class)) {
builder.append(method.invoke(object));
addSeparator();
} else if (method.getReturnType().equals(int.class)) {
builder.append(method.invoke(object));
addSeparator();
} else if (method.getReturnType().equals(long.class)) {
builder.append(method.invoke(object));
addSeparator();
} else if (method.getReturnType().equals(double.class)) {
builder.append(method.invoke(object));
addSeparator();
} else if (method.getReturnType().equals(String.class)) {
builder.append((String) method.invoke(object));
addSeparator();
} else if (method.getReturnType().equals(Date.class)) {
Date value = (Date) method.invoke(object);
builder.append(DATE_FORMAT.print(new DateTime(value)));
addSeparator();
} else if (method.getReturnType().equals(Map.class)) {
Map value = (Map) method.invoke(object);
if (value != null) {
try {
String map = Context.getObjectMapper().writeValueAsString(value);
map = map.replaceAll("[\\{\\}\"]", "");
map = map.replaceAll(",", " ");
builder.append(map);
addSeparator();
} catch (JsonProcessingException e) {
Log.warning(e);
}
}
}
} catch (IllegalAccessException | InvocationTargetException error) {
Log.warning(error);
}
}
}
addLineEnding();
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project atlasmap by atlasmap.
the class GenerateInspectionsMojo method generateInspection.
private void generateInspection(List<String> artifacts, Collection<String> classNames) throws MojoFailureException, MojoExecutionException {
List<URL> urls = artifacts == null ? Collections.emptyList() : resolveClasspath(artifacts);
ClassLoader origTccl = Thread.currentThread().getContextClassLoader();
for (String className : classNames) {
Class<?> clazz = null;
JavaClass c = null;
// Not even this plugin will be available on this new URLClassLoader
try (URLClassLoader loader = new URLClassLoader(urls.toArray(new URL[urls.size()]), origTccl)) {
clazz = loader.loadClass(className);
ClassInspectionService classInspectionService = new ClassInspectionService();
classInspectionService.setConversionService(DefaultAtlasConversionService.getInstance());
c = classInspectionService.inspectClass(loader, clazz);
} catch (ClassNotFoundException | IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
try {
ObjectMapper objectMapper = Json.mapper();
File target = outputFile;
if (target == null) {
target = new File(outputDir, "atlasmap-inpection-" + className + ".json");
}
objectMapper.writeValue(target, c);
getLog().info("Created: " + target);
} catch (JsonProcessingException e) {
throw new MojoExecutionException(e.getMessage(), e);
} catch (IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project carbon-apimgt by wso2.
the class EndpointsApiServiceImpl method endpointsEndpointIdPut.
/**
* Updates an existing endpoint
*
* @param endpointId ID of the endpoint
* @param body Updated endpoint details
* @param ifMatch If-Match header value
* @param ifUnmodifiedSince If-Unmodified-Since header value
* @param request msf4j request object
* @return updated endpoint
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response endpointsEndpointIdPut(String endpointId, EndPointDTO body, String ifMatch, String ifUnmodifiedSince, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIPublisher apiPublisher = RestAPIPublisherUtil.getApiPublisher(username);
Endpoint endpoint = MappingUtil.toEndpoint(body);
Endpoint retrievedEndpoint = apiPublisher.getEndpoint(endpointId);
if (retrievedEndpoint == null) {
String msg = "Endpoint not found " + endpointId;
log.error(msg);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(ExceptionCodes.ENDPOINT_NOT_FOUND);
return Response.status(ExceptionCodes.ENDPOINT_NOT_FOUND.getHttpStatusCode()).entity(errorDTO).build();
}
String existingFingerprint = endpointsEndpointIdGetFingerprint(endpointId, null, null, request);
if (!StringUtils.isEmpty(ifMatch) && !StringUtils.isEmpty(existingFingerprint) && !ifMatch.contains(existingFingerprint)) {
return Response.status(Response.Status.PRECONDITION_FAILED).build();
}
Endpoint updatedEndpint = new Endpoint.Builder(endpoint).id(endpointId).build();
apiPublisher.updateEndpoint(updatedEndpint);
Endpoint updatedEndpoint = apiPublisher.getEndpoint(endpointId);
String newFingerprint = endpointsEndpointIdGetFingerprint(endpointId, null, null, request);
return Response.ok().header(HttpHeaders.ETAG, "\"" + newFingerprint + "\"").entity(MappingUtil.toEndPointDTO(updatedEndpoint)).build();
} catch (APIManagementException e) {
String errorMessage = "Error while getting the endpoint :" + endpointId;
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
} catch (JsonProcessingException e) {
String errorMessage = "Error while Converting Endpoint Security Details in Endpoint :" + endpointId;
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(errorMessage, 900313L, errorMessage);
log.error(errorMessage, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorDTO).build();
} catch (IOException e) {
String errorMessage = "Error while Converting Endpoint Security Details in Endpoint :" + endpointId;
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(errorMessage, 900313L, errorMessage);
log.error(errorMessage, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorDTO).build();
}
}
Aggregations