use of com.fasterxml.jackson.databind.JsonMappingException in project cas by apereo.
the class X509CertificateCredentialJsonSerializer method serializeWithType.
@Override
public void serializeWithType(final X509CertificateCredential value, final JsonGenerator generator, final SerializerProvider serializers, final TypeSerializer typeSer) throws IOException {
try {
typeSer.writeTypePrefixForObject(value, generator);
serialize(value, generator, serializers);
typeSer.writeTypeSuffixForObject(value, generator);
} catch (final Exception e) {
throw new JsonMappingException("Unable to serialize X509 certificate", e);
}
}
use of com.fasterxml.jackson.databind.JsonMappingException in project uPortal by Jasig.
the class AnalyticsIncorporationComponent method serializePageData.
protected String serializePageData(HttpServletRequest request, long startTime) {
final Map<String, Object> pageData = new HashMap<>();
pageData.put("executionTimeNano", System.nanoTime() - startTime);
final IPortalRequestInfo portalRequestInfo = urlSyntaxProvider.getPortalRequestInfo(request);
pageData.put("urlState", portalRequestInfo.getUrlState());
final String targetedLayoutNodeId = portalRequestInfo.getTargetedLayoutNodeId();
if (targetedLayoutNodeId != null) {
final AggregatedTabMapping mappedTabForLayoutId = aggregatedTabLookupDao.getMappedTabForLayoutId(targetedLayoutNodeId);
pageData.put("tab", mappedTabForLayoutId);
}
try {
return mapper.writeValueAsString(pageData);
} catch (JsonParseException e) {
logger.warn("Failed to convert this request's page data to JSON, no page level analytics will be included", e);
} catch (JsonMappingException e) {
logger.warn("Failed to convert this request's page data to JSON, no page level analytics will be included", e);
} catch (IOException e) {
logger.warn("Failed to convert this request's page data to JSON, no page level analytics will be included", e);
}
return "{}";
}
use of com.fasterxml.jackson.databind.JsonMappingException in project dhis2-core by dhis2.
the class GeoUtils method parseCoordinates.
public static Coordinates parseCoordinates(String coordinatesString, CoordinateOrder from) {
Coordinates coordinates = new Coordinates();
try {
List<?> list = new ObjectMapper().readValue(coordinatesString, List.class);
if (!list.isEmpty() && from == CoordinateOrder.COORDINATE_LATLNG) {
coordinates.lat = convertToDouble(list.get(0));
coordinates.lng = convertToDouble(list.get(1));
} else if (!list.isEmpty() && from == CoordinateOrder.COORDINATE_LNGLAT) {
coordinates.lat = convertToDouble(list.get(1));
coordinates.lng = convertToDouble(list.get(0));
}
} catch (JsonMappingException ignored) {
} catch (JsonParseException ignored) {
} catch (IOException ignored) {
}
return coordinates;
}
use of com.fasterxml.jackson.databind.JsonMappingException in project dhis2-core by dhis2.
the class DefaultAppManager method installApp.
@Override
public AppStatus installApp(File file, String fileName) {
try {
// -----------------------------------------------------------------
// Parse ZIP file and it's manifest.webapp file.
// -----------------------------------------------------------------
ZipFile zip = new ZipFile(file);
ZipEntry entry = zip.getEntry(MANIFEST_FILENAME);
InputStream inputStream = zip.getInputStream(entry);
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
App app = mapper.readValue(inputStream, App.class);
// -----------------------------------------------------------------
// Check for namespace and if it's already taken by another app
// -----------------------------------------------------------------
String namespace = app.getActivities().getDhis().getNamespace();
if (namespace != null && (this.appNamespaces.containsKey(namespace) && !app.equals(appNamespaces.get(namespace)))) {
zip.close();
return AppStatus.NAMESPACE_TAKEN;
}
// -----------------------------------------------------------------
// Delete if app is already installed, assuming app update so no
// data is deleted
// -----------------------------------------------------------------
deleteApp(app.getName(), false);
// -----------------------------------------------------------------
// Unzip the app
// -----------------------------------------------------------------
log.info("Installing app, namespace: " + namespace);
String dest = getAppFolderPath() + File.separator + fileName.substring(0, fileName.lastIndexOf('.'));
Unzip unzip = new Unzip();
unzip.setSrc(file);
unzip.setDest(new File(dest));
unzip.execute();
log.info("Installed app: " + app);
// -----------------------------------------------------------------
// Installation complete. Closing zip, reloading apps and return OK
// -----------------------------------------------------------------
zip.close();
reloadApps();
return AppStatus.OK;
} catch (ZipException e) {
return AppStatus.INVALID_ZIP_FORMAT;
} catch (JsonParseException e) {
return AppStatus.INVALID_MANIFEST_JSON;
} catch (JsonMappingException e) {
return AppStatus.INVALID_MANIFEST_JSON;
} catch (IOException e) {
return AppStatus.INSTALLATION_FAILED;
}
}
use of com.fasterxml.jackson.databind.JsonMappingException in project blueocean-plugin by jenkinsci.
the class HttpRequest method to.
public <T> T to(Class<T> type) throws IOException {
HttpURLConnection connection = connect();
if (methodNeedsBody()) {
if (body == null) {
GithubScm.om.writeValue(connection.getOutputStream(), Collections.emptyMap());
} else {
GithubScm.om.writeValue(connection.getOutputStream(), body);
}
}
InputStreamReader r = null;
try {
int status = connection.getResponseCode();
if (status == 304) {
return null;
}
if (status == 204 && type != null && type.isArray()) {
return type.cast(Array.newInstance(type.getComponentType(), 0));
}
if (status == 401 || status == 403) {
throw new ServiceException.ForbiddenException("Invalid accessToken");
}
if (status == 404) {
throw new ServiceException.NotFoundException("Not Found. Remote server sent code " + getErrorResponse(connection));
}
if (status > 399) {
throw new ServiceException.BadRequestException(String.format("%s %s returned error: %s. Error message: %s.", method, url, status, getErrorResponse(connection)));
}
if (!method.equals("HEAD")) {
r = new InputStreamReader(wrapStream(connection.getInputStream(), connection.getContentEncoding()), "UTF-8");
String data = IOUtils.toString(r);
if (type != null) {
try {
return GithubScm.om.readValue(data, type);
} catch (JsonMappingException e) {
throw new IOException("Failed to deserialize: " + e.getMessage() + "\n" + data, e);
}
}
}
} finally {
IOUtils.closeQuietly(r);
}
return null;
}
Aggregations