Search in sources :

Example 46 with JsonProcessingException

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();
    }
}
Also used : APIDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.APIDTO) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) HashMap(java.util.HashMap) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) API(org.wso2.carbon.apimgt.core.models.API) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 47 with JsonProcessingException

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;
}
Also used : JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 48 with JsonProcessingException

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);
    }
}
Also used : PreparedStatement(com.datastax.driver.core.PreparedStatement) BoundStatement(com.datastax.driver.core.BoundStatement) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 49 with JsonProcessingException

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";
}
Also used : JSON(io.kubernetes.client.JSON) Date(java.util.Date) LinkedHashMap(java.util.LinkedHashMap) StringWriter(java.io.StringWriter) List(java.util.List) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) PrintWriter(java.io.PrintWriter) ApiException(io.kubernetes.client.ApiException)

Example 50 with JsonProcessingException

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();
}
Also used : Query(javax.persistence.Query) List(java.util.List) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)741 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)241 IOException (java.io.IOException)174 HashMap (java.util.HashMap)108 Map (java.util.Map)83 ArrayList (java.util.ArrayList)74 JsonNode (com.fasterxml.jackson.databind.JsonNode)73 Test (org.junit.Test)65 List (java.util.List)56 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)36 Collectors (java.util.stream.Collectors)30 InputStream (java.io.InputStream)26 Json (com.sequenceiq.cloudbreak.domain.json.Json)21 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)20 File (java.io.File)20 Function (java.util.function.Function)20 Logger (org.slf4j.Logger)20 Optional (java.util.Optional)19 Date (java.util.Date)18 Test (org.testng.annotations.Test)18