use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisApiIdPut.
/**
* Updates an API by UUID
*
* @param apiId UUID of API
* @param body Updated API details
* @param ifMatch If-Match header value
* @param ifUnmodifiedSince If-Unmodified-Since header value
* @param request msf4j request object
* @return Updated API
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response apisApiIdPut(String apiId, APIDTO body, String ifMatch, String ifUnmodifiedSince, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIPublisher apiPublisher = RestAPIPublisherUtil.getApiPublisher(username);
String existingFingerprint = apisApiIdGetFingerprint(apiId, null, null, request);
if (!StringUtils.isEmpty(ifMatch) && !StringUtils.isEmpty(existingFingerprint) && !ifMatch.contains(existingFingerprint)) {
return Response.status(Response.Status.PRECONDITION_FAILED).build();
}
API.APIBuilder api = MappingUtil.toAPI(body).id(apiId);
apiPublisher.updateAPI(api);
String newFingerprint = apisApiIdGetFingerprint(apiId, null, null, request);
APIDTO apidto = MappingUtil.toAPIDto(apiPublisher.getAPIbyUUID(apiId));
return Response.ok().header(HttpHeaders.ETAG, "\"" + newFingerprint + "\"").entity(apidto).build();
} catch (APIManagementException e) {
String errorMessage = "Error while updating API : " + apiId;
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
} catch (JsonProcessingException e) {
String errorMessage = "Error while updating API : " + apiId;
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 updating API : " + apiId;
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(errorMessage, 900313L, errorMessage);
log.error(errorMessage, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorDTO).build();
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project vorto by eclipse.
the class JsonIMTemplate method getContent.
@Override
public String getContent(InformationModel model, InvocationContext context) {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
objectMapper.setSerializationInclusion(Include.NON_NULL);
String result = "";
try {
result = objectMapper.writeValueAsString(model);
} catch (JsonProcessingException e) {
LOG.error("Could not serialize model.", e);
}
return result;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project data-transfer-project by google.
the class CosmosStore method create.
private void create(UUID id, Object instance, String query) {
PreparedStatement statement = session.prepare(query);
BoundStatement boundStatement = new BoundStatement(statement);
try {
boundStatement.setUUID(0, id);
boundStatement.setString(1, mapper.writeValueAsString(instance));
session.execute(boundStatement);
} catch (JsonProcessingException e) {
throw new MicrosoftStorageException("Error creating data: " + id, e);
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project weblogic-kubernetes-operator by oracle.
the class LoggingFormatter method format.
@Override
public String format(LogRecord record) {
String sourceClassName = "";
String sourceMethodName = "";
if (record.getSourceClassName() != null) {
sourceClassName = record.getSourceClassName();
if (record.getSourceMethodName() != null) {
sourceMethodName = record.getSourceMethodName();
}
} else {
sourceClassName = record.getLoggerName();
}
// the toString() format for the model classes is inappropriate for our logs
// so, replace with the JSON serialization
JSON j = LoggingFactory.getJSON();
if (j != null) {
Object[] parameters = record.getParameters();
if (parameters != null) {
for (int i = 0; i < parameters.length; i++) {
Object pi = parameters[i];
if (pi != null) {
if (pi.getClass().getAnnotation(ApiModel.class) != null || pi.getClass().getName().startsWith("oracle.kubernetes.weblogic.domain.")) {
// this is a model object
parameters[i] = j.serialize(pi);
}
}
}
}
}
String message = formatMessage(record);
String code = "";
Map<String, List<String>> headers = PLACEHOLDER;
String body = "";
String throwable = "";
if (record.getThrown() != null) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
pw.println();
record.getThrown().printStackTrace(pw);
pw.close();
throwable = sw.toString();
if (record.getThrown() instanceof ApiException) {
ApiException ae = (ApiException) record.getThrown();
code = String.valueOf(ae.getCode());
if (ae.getResponseHeaders() != null) {
headers = ae.getResponseHeaders();
}
String rb = ae.getResponseBody();
if (rb != null)
body = rb;
}
}
String level = record.getLevel().getLocalizedName();
Map<String, Object> map = new LinkedHashMap<>();
long rawTime = record.getMillis();
final String dateString = dateFormat.format(new Date(rawTime));
long thread = Thread.currentThread().getId();
map.put(TIMESTAMP, dateString);
map.put(THREAD, thread);
map.put(LOG_LEVEL, level);
map.put(SOURCE_CLASS, sourceClassName);
map.put(SOURCE_METHOD, sourceMethodName);
map.put(TIME_IN_MILLIS, rawTime);
// if message or throwable have new lines in them, we need to replace with JSON newline control character \n
map.put(MESSAGE, message != null ? message.replaceAll("\n", "\\\n") : "");
map.put(EXCEPTION, throwable.replaceAll("\n", "\\\n"));
map.put(RESPONSE_CODE, code);
map.put(RESPONSE_HEADERS, headers);
map.put(RESPONSE_BODY, body.replaceAll("\n", "\\\n"));
String json = "";
try {
ObjectMapper mapper = new ObjectMapper();
json = mapper.writeValueAsString(map);
} catch (JsonProcessingException e) {
String tmp = "{\"@timestamp\":%1$s,\"level\":%2$s, \"class\":%3$s, \"method\":\"format\", \"timeInMillis\":%4$d, \"@message\":\"Exception while preparing json object\",\"exception\":%5$s}\n";
return String.format(tmp, dateString, level, LoggingFormatter.class.getName(), rawTime, e.getLocalizedMessage());
}
return json + "\n";
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project microservices by pwillhan.
the class MySqlApp method nativeQuery.
private static void nativeQuery(EntityManager entityManager) {
entityManager.getTransaction().begin();
Query nativeQuery = entityManager.createNativeQuery("SELECT * FROM Customer");
List resultList = nativeQuery.getResultList();
resultList.forEach(u -> {
try {
System.out.println(MAPPER.writeValueAsString(u));
} catch (JsonProcessingException e) {
e.printStackTrace();
}
});
entityManager.getTransaction().commit();
}
Aggregations