Search in sources :

Example 81 with JsonProcessingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project compss by bsc-wdc.

the class Consumer method processRegularRecord.

private static void processRegularRecord(String value) throws ConsumerException {
    // Read the encoded information in the message
    JsonNode msg = null;
    try {
        msg = new ObjectMapper().readTree(value);
    } catch (JsonProcessingException jpe) {
        jpe.printStackTrace();
        throw new ConsumerException("ERROR: Cannot read regular message", jpe);
    } catch (IOException ioe) {
        ioe.printStackTrace();
        throw new ConsumerException("ERROR: Cannot read regular message", ioe);
    }
    // Retrieve the message type
    switch(msg.get(Messages.FIELD_TYPE).asText()) {
        case Messages.TYPE_MESSAGE:
            long latency = (long) ((System.nanoTime() * 1e-9 - msg.get(Messages.FIELD_T).asDouble()) * 1_000);
            Result.addValue(latency);
            break;
        case Messages.TYPE_STATS:
            // Whenever we receive a stats message we log its retrieval
            if (DEBUG) {
                System.out.println("[LOG] Stats message received");
            }
            break;
        default:
            throw new ConsumerException("ERROR: Unrecognised message type: " + msg.get(Messages.FIELD_TYPE).asText());
    }
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) ConsumerException(streams.exceptions.ConsumerException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 82 with JsonProcessingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project atlasdb by palantir.

the class SerializableErrorDecoderTest method assertCanSerializeAndDeserializeErrorWithName.

private void assertCanSerializeAndDeserializeErrorWithName(String errorName) throws JsonProcessingException {
    SerializableError serializableError = SerializableError.of(EXCEPTION_MESSAGE, errorName);
    Response response = createResponseForEntity(serializableError);
    Exception exception = decoder.decode(SOME_METHOD_KEY, response);
    assertThat(exception).isInstanceOf(AtlasDbRemoteException.class).satisfies(remoteException -> assertHasErrorName(remoteException, errorName));
}
Also used : Response(feign.Response) SerializableError(com.palantir.remoting2.errors.SerializableError) AtlasDbRemoteException(com.palantir.atlasdb.http.errors.AtlasDbRemoteException) AtlasDbRemoteException(com.palantir.atlasdb.http.errors.AtlasDbRemoteException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 83 with JsonProcessingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project joynr by bmwcarit.

the class DefaultJoynrRuntimeFactory method provisionAccessControl.

private void provisionAccessControl(Properties properties, String domain, String[] interfaceNames) {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.enableDefaultTypingAsProperty(DefaultTyping.JAVA_LANG_OBJECT, "_typeName");
    List<MasterAccessControlEntry> allEntries = new ArrayList<>();
    for (String interfaceName : interfaceNames) {
        MasterAccessControlEntry newMasterAccessControlEntry = new MasterAccessControlEntry("*", domain, interfaceName, TrustLevel.LOW, new TrustLevel[] { TrustLevel.LOW }, TrustLevel.LOW, new TrustLevel[] { TrustLevel.LOW }, "*", Permission.YES, new Permission[] { joynr.infrastructure.DacTypes.Permission.YES });
        allEntries.add(newMasterAccessControlEntry);
    }
    MasterAccessControlEntry[] provisionedAccessControlEntries = allEntries.toArray(new MasterAccessControlEntry[allEntries.size()]);
    String provisionedAccessControlEntriesAsJson;
    try {
        provisionedAccessControlEntriesAsJson = objectMapper.writeValueAsString(provisionedAccessControlEntries);
        properties.setProperty(StaticDomainAccessControlProvisioning.PROPERTY_PROVISIONED_MASTER_ACCESSCONTROLENTRIES, provisionedAccessControlEntriesAsJson);
    } catch (JsonProcessingException e) {
        LOG.error("Error parsing JSON.", e);
    }
}
Also used : MasterAccessControlEntry(joynr.infrastructure.DacTypes.MasterAccessControlEntry) ArrayList(java.util.ArrayList) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 84 with JsonProcessingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project Discord4J by Discord4J.

the class NickHolder method moveToVoiceChannel.

@Override
public void moveToVoiceChannel(IVoiceChannel channel) {
    IVoiceChannel oldChannel = getVoiceStateForGuild(channel.getGuild()).getChannel();
    if (oldChannel == null)
        throw new DiscordException("User must already be in a voice channel before they can be moved to another.");
    // client must have permission to both move members and connect to the channel.
    PermissionUtils.requirePermissions(channel, client.getOurUser(), Permissions.VOICE_MOVE_MEMBERS, Permissions.VOICE_CONNECT);
    try {
        ((DiscordClientImpl) client).REQUESTS.PATCH.makeRequest(DiscordEndpoints.GUILDS + channel.getGuild().getStringID() + "/members/" + id, DiscordUtils.MAPPER_NO_NULLS.writeValueAsString(new MemberEditRequest.Builder().channel(channel.getStringID()).build()));
    } catch (JsonProcessingException e) {
        Discord4J.LOGGER.error(LogMarkers.HANDLE, "Discord4J Internal Exception", e);
    }
}
Also used : DiscordException(sx.blah.discord.util.DiscordException) DiscordClientImpl(sx.blah.discord.api.internal.DiscordClientImpl) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 85 with JsonProcessingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project gravitee-management-rest-api by gravitee-io.

the class PlanServiceImpl method create.

@Override
public PlanEntity create(NewPlanEntity newPlan) {
    try {
        logger.debug("Create a new plan {} for API {}", newPlan.getName(), newPlan.getApi());
        Plan plan = new Plan();
        plan.setId(UUID.toString(UUID.random()));
        plan.setApis(Collections.singleton(newPlan.getApi()));
        plan.setName(newPlan.getName());
        plan.setDescription(newPlan.getDescription());
        plan.setCreatedAt(new Date());
        plan.setUpdatedAt(plan.getCreatedAt());
        plan.setType(Plan.PlanType.valueOf(newPlan.getType().name()));
        plan.setSecurity(Plan.PlanSecurityType.valueOf(newPlan.getSecurity().name()));
        plan.setSecurityDefinition(newPlan.getSecurityDefinition());
        plan.setStatus(Plan.Status.valueOf(newPlan.getStatus().name()));
        plan.setExcludedGroups(newPlan.getExcludedGroups());
        if (plan.getSecurity() == Plan.PlanSecurityType.KEY_LESS) {
            // There is no need for a validation when authentication is KEY_LESS, force to AUTO
            plan.setValidation(Plan.PlanValidationType.AUTO);
        } else {
            plan.setValidation(Plan.PlanValidationType.valueOf(newPlan.getValidation().name()));
        }
        plan.setCharacteristics(newPlan.getCharacteristics());
        String planPolicies = objectMapper.writeValueAsString(newPlan.getPaths());
        plan.setDefinition(planPolicies);
        plan = planRepository.create(plan);
        auditService.createApiAuditLog(newPlan.getApi(), Collections.singletonMap(PLAN, plan.getId()), PLAN_CREATED, plan.getCreatedAt(), null, plan);
        return convert(plan);
    } catch (TechnicalException ex) {
        logger.error("An error occurs while trying to create a plan {} for API {}", newPlan.getName(), newPlan.getApi(), ex);
        throw new TechnicalManagementException(String.format("An error occurs while trying to create a plan %s for API %s", newPlan.getName(), newPlan.getApi()), ex);
    } catch (JsonProcessingException jse) {
        logger.error("Unexpected error while generating plan definition", jse);
        throw new TechnicalManagementException(String.format("An error occurs while trying to create a plan %s for API %s", newPlan.getName(), newPlan.getApi()), jse);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Plan(io.gravitee.repository.management.model.Plan) 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