Search in sources :

Example 76 with JsonProcessingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project fabric8-maven-plugin by fabric8io.

the class ApplyMojo method createRouteForService.

private Route createRouteForService(String routeDomainPostfix, String namespace, Service service) {
    Route route = null;
    String id = KubernetesHelper.getName(service);
    if (Strings.isNotBlank(id) && hasExactlyOneService(service, id)) {
        route = new Route();
        String routeId = id;
        KubernetesHelper.setName(route, namespace, routeId);
        RouteSpec routeSpec = new RouteSpec();
        RouteTargetReference objectRef = new RouteTargetReferenceBuilder().withName(id).build();
        // objectRef.setNamespace(namespace);
        routeSpec.setTo(objectRef);
        if (!Strings.isNullOrBlank(routeDomainPostfix)) {
            String host = Strings.stripSuffix(Strings.stripSuffix(id, "-service"), ".");
            routeSpec.setHost(host + "." + Strings.stripPrefix(routeDomainPostfix, "."));
        } else {
            routeSpec.setHost("");
        }
        route.setSpec(routeSpec);
        String json;
        try {
            json = KubernetesHelper.toJson(route);
        } catch (JsonProcessingException e) {
            json = e.getMessage() + ". object: " + route;
        }
        log.debug("Created route: " + json);
    }
    return route;
}
Also used : RouteTargetReference(io.fabric8.openshift.api.model.RouteTargetReference) RouteTargetReferenceBuilder(io.fabric8.openshift.api.model.RouteTargetReferenceBuilder) KubernetesHelper.createIntOrString(io.fabric8.kubernetes.api.KubernetesHelper.createIntOrString) RouteSpec(io.fabric8.openshift.api.model.RouteSpec) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Route(io.fabric8.openshift.api.model.Route)

Example 77 with JsonProcessingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project fabric8-maven-plugin by fabric8io.

the class ApplyMojo method createIngressForService.

private Ingress createIngressForService(String routeDomainPostfix, String namespace, Service service) {
    Ingress ingress = null;
    String serviceName = KubernetesHelper.getName(service);
    ServiceSpec serviceSpec = service.getSpec();
    if (serviceSpec != null && Strings.isNotBlank(serviceName) && shouldCreateExternalURLForService(service, serviceName)) {
        String ingressId = serviceName;
        String host = "";
        if (Strings.isNotBlank(routeDomainPostfix)) {
            host = serviceName + "." + namespace + "." + Strings.stripPrefix(routeDomainPostfix, ".");
        }
        List<HTTPIngressPath> paths = new ArrayList<>();
        List<ServicePort> ports = serviceSpec.getPorts();
        if (ports != null) {
            for (ServicePort port : ports) {
                Integer portNumber = port.getPort();
                if (portNumber != null) {
                    HTTPIngressPath path = new HTTPIngressPathBuilder().withNewBackend().withServiceName(serviceName).withServicePort(createIntOrString(portNumber.intValue())).endBackend().build();
                    paths.add(path);
                }
            }
        }
        if (paths.isEmpty()) {
            return ingress;
        }
        ingress = new IngressBuilder().withNewMetadata().withName(ingressId).withNamespace(namespace).endMetadata().withNewSpec().addNewRule().withHost(host).withNewHttp().withPaths(paths).endHttp().endRule().endSpec().build();
        String json;
        try {
            json = KubernetesHelper.toJson(ingress);
        } catch (JsonProcessingException e) {
            json = e.getMessage() + ". object: " + ingress;
        }
        log.debug("Created ingress: " + json);
    }
    return ingress;
}
Also used : ServicePort(io.fabric8.kubernetes.api.model.ServicePort) IngressBuilder(io.fabric8.kubernetes.api.model.extensions.IngressBuilder) ServiceSpec(io.fabric8.kubernetes.api.model.ServiceSpec) ArrayList(java.util.ArrayList) Ingress(io.fabric8.kubernetes.api.model.extensions.Ingress) HTTPIngressPathBuilder(io.fabric8.kubernetes.api.model.extensions.HTTPIngressPathBuilder) KubernetesHelper.createIntOrString(io.fabric8.kubernetes.api.KubernetesHelper.createIntOrString) HTTPIngressPath(io.fabric8.kubernetes.api.model.extensions.HTTPIngressPath) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 78 with JsonProcessingException

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

the class UpdateShippedCode method cleanJsonFile.

private static void cleanJsonFile(File packJson) {
    println("  Cleaning: " + packJson);
    ObjectMapper mapper = new ObjectMapper();
    try {
        ObjectNode root = (ObjectNode) mapper.readTree(packJson);
        Iterator<Entry<String, JsonNode>> fieldIterator = root.fields();
        List<String> removeFields = new LinkedList<>();
        while (fieldIterator.hasNext()) {
            Entry<String, JsonNode> field = fieldIterator.next();
            String name = field.getKey();
            if (name != null && name.startsWith("_")) {
                removeFields.add(name);
            }
        }
        final StringBuilder sb = new StringBuilder();
        sb.append("    removing fields: ");
        for (String fieldName : removeFields) {
            sb.append(fieldName + " ");
            root.remove(fieldName);
        }
        println(sb.toString());
        String cleanJson = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(root);
        FileWriter f2 = new FileWriter(packJson, false);
        f2.write(cleanJson);
        // note: by convention, N4JS repository uses \n as line separator (independent of OS)
        f2.write('\n');
        f2.close();
    } catch (JsonProcessingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) FileWriter(java.io.FileWriter) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) LinkedList(java.util.LinkedList) Entry(java.util.Map.Entry) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 79 with JsonProcessingException

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

the class ActorCell method saveSnapshot.

@SuppressWarnings("unchecked")
public <S extends ActorPersistenceObject> void saveSnapshot(Consumer<S> onSuccess, Consumer<Exception> onFailure, S state) {
    if (system.persistenceMode && state != null) {
        state.persistenceId = persistenceId();
        List<ActorPersistenceObject> list = new ArrayList<>();
        list.add(state);
        PersistenceTuple tuple = new PersistenceTuple((Consumer<ActorPersistenceObject>) onSuccess, onFailure, list);
        try {
            system.messageDispatcher.postPersistence(new ActorMessage<String>(new ObjectMapper().writeValueAsString(state), PersistenceServiceActor.PERSIST_STATE, id, null));
            persistenceTuples.offer(tuple);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
            onFailure.accept(e);
        }
    }
}
Also used : ActorPersistenceObject(actor4j.core.persistence.ActorPersistenceObject) ArrayList(java.util.ArrayList) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 80 with JsonProcessingException

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

the class WebDataHandler method formatRequest.

public String formatRequest(Position position) {
    Device device = Context.getIdentityManager().getById(position.getDeviceId());
    String request = url.replace("{name}", device.getName()).replace("{uniqueId}", device.getUniqueId()).replace("{status}", device.getStatus()).replace("{deviceId}", String.valueOf(position.getDeviceId())).replace("{protocol}", String.valueOf(position.getProtocol())).replace("{deviceTime}", String.valueOf(position.getDeviceTime().getTime())).replace("{fixTime}", String.valueOf(position.getFixTime().getTime())).replace("{valid}", String.valueOf(position.getValid())).replace("{latitude}", String.valueOf(position.getLatitude())).replace("{longitude}", String.valueOf(position.getLongitude())).replace("{altitude}", String.valueOf(position.getAltitude())).replace("{speed}", String.valueOf(position.getSpeed())).replace("{course}", String.valueOf(position.getCourse())).replace("{statusCode}", calculateStatus(position));
    if (position.getAddress() != null) {
        try {
            request = request.replace("{address}", URLEncoder.encode(position.getAddress(), StandardCharsets.UTF_8.name()));
        } catch (UnsupportedEncodingException error) {
            Log.warning(error);
        }
    }
    if (request.contains("{attributes}")) {
        try {
            String attributes = Context.getObjectMapper().writeValueAsString(position.getAttributes());
            request = request.replace("{attributes}", URLEncoder.encode(attributes, StandardCharsets.UTF_8.name()));
        } catch (UnsupportedEncodingException | JsonProcessingException error) {
            Log.warning(error);
        }
    }
    if (request.contains("{gprmc}")) {
        request = request.replace("{gprmc}", formatSentence(position));
    }
    return request;
}
Also used : Device(org.traccar.model.Device) UnsupportedEncodingException(java.io.UnsupportedEncodingException) 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