Search in sources :

Example 11 with CollectionStringBuffer

use of org.apache.camel.util.CollectionStringBuffer in project camel by apache.

the class ParameterConfiguration method toJson.

/**
     * Returns the JSON format of this parameter configuration
     */
public String toJson() {
    if (parameterType.isEnum()) {
        String typeName = "string";
        CollectionStringBuffer sb = new CollectionStringBuffer();
        for (Object value : parameterType.getEnumConstants()) {
            sb.append(doubleQuote(value.toString()));
        }
        return doubleQuote(name) + ": { \"type\": " + doubleQuote(typeName) + ", \"javaType\": \"" + parameterType.getCanonicalName() + "\"" + ", \"enum\": [ " + sb.toString() + " ] }";
    } else if (parameterType.isArray()) {
        String typeName = "array";
        return doubleQuote(name) + ": { \"type\": " + doubleQuote(typeName) + ", \"javaType\": \"" + parameterType.getCanonicalName() + "\" }";
    } else {
        String typeName = JsonSchemaHelper.getType(parameterType);
        return doubleQuote(name) + ": { \"type\": " + doubleQuote(typeName) + ", \"javaType\": \"" + parameterType.getCanonicalName() + "\" }";
    }
}
Also used : CollectionStringBuffer(org.apache.camel.util.CollectionStringBuffer)

Example 12 with CollectionStringBuffer

use of org.apache.camel.util.CollectionStringBuffer in project camel by apache.

the class ReloadStrategySupport method onReloadXml.

@Override
public void onReloadXml(CamelContext camelContext, String name, InputStream resource) {
    log.debug("Reloading routes from XML resource: {}", name);
    Document dom;
    String xml;
    try {
        xml = camelContext.getTypeConverter().mandatoryConvertTo(String.class, resource);
        // the JAXB model expects the spring namespace (even for blueprint)
        dom = XmlLineNumberParser.parseXml(new ByteArrayInputStream(xml.getBytes()), null, "camelContext,routes", "http://camel.apache.org/schema/spring");
    } catch (Exception e) {
        failed++;
        log.warn("Cannot load the resource " + name + " as XML");
        return;
    }
    ResourceState state = cache.get(name);
    if (state == null) {
        state = new ResourceState(name, dom, xml);
        cache.put(name, state);
    }
    String oldXml = state.getXml();
    List<Integer> changed = StringHelper.changedLines(oldXml, xml);
    // find all <route> which are the routes
    NodeList list = dom.getElementsByTagName("route");
    // collect which routes are updated/skipped
    List<RouteDefinition> routes = new ArrayList<>();
    if (list != null && list.getLength() > 0) {
        for (int i = 0; i < list.getLength(); i++) {
            Node node = list.item(i);
            // what line number are this within
            String lineNumber = (String) node.getUserData(XmlLineNumberParser.LINE_NUMBER);
            String lineNumberEnd = (String) node.getUserData(XmlLineNumberParser.LINE_NUMBER_END);
            if (lineNumber != null && lineNumberEnd != null && !changed.isEmpty()) {
                int start = Integer.valueOf(lineNumber);
                int end = Integer.valueOf(lineNumberEnd);
                boolean within = withinChanged(start, end, changed);
                if (within) {
                    log.debug("Updating route in lines: {}-{}", start, end);
                } else {
                    log.debug("No changes to route in lines: {}-{}", start, end);
                    continue;
                }
            }
            try {
                // load from XML -> JAXB model and store as routes to be updated
                RoutesDefinition loaded = ModelHelper.loadRoutesDefinition(camelContext, node);
                if (!loaded.getRoutes().isEmpty()) {
                    routes.addAll(loaded.getRoutes());
                }
            } catch (Exception e) {
                failed++;
                throw ObjectHelper.wrapRuntimeCamelException(e);
            }
        }
    }
    if (!routes.isEmpty()) {
        try {
            boolean unassignedRouteIds = false;
            CollectionStringBuffer csb = new CollectionStringBuffer(",");
            // collect route ids and force assign ids if not in use
            for (RouteDefinition route : routes) {
                unassignedRouteIds |= route.hasCustomIdAssigned();
                String id = route.idOrCreate(camelContext.getNodeIdFactory());
                csb.append(id);
            }
            log.debug("Reloading routes: [{}] from XML resource: {}", csb, name);
            if (unassignedRouteIds) {
                log.warn("Routes with no id's detected. Its recommended to assign id's to your routes so Camel can reload the routes correctly.");
            }
            // update the routes (add will remove and shutdown first)
            camelContext.addRouteDefinitions(routes);
            log.info("Reloaded routes: [{}] from XML resource: {}", csb, name);
        } catch (Exception e) {
            failed++;
            throw ObjectHelper.wrapRuntimeCamelException(e);
        }
    }
    // update cache
    state = new ResourceState(name, dom, xml);
    cache.put(name, state);
    succeeded++;
}
Also used : CollectionStringBuffer(org.apache.camel.util.CollectionStringBuffer) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) RouteDefinition(org.apache.camel.model.RouteDefinition) ByteArrayInputStream(java.io.ByteArrayInputStream) RoutesDefinition(org.apache.camel.model.RoutesDefinition)

Example 13 with CollectionStringBuffer

use of org.apache.camel.util.CollectionStringBuffer in project camel by apache.

the class DataFormatClause method xstream.

/**
     * Uses the xstream by permitting the java type
     *
     * @param encoding encoding to use
     * @param type the pojo class(es) xstream should use as allowed permission
     */
public T xstream(String encoding, Class<?>... type) {
    CollectionStringBuffer csb = new CollectionStringBuffer(",");
    for (Class<?> clazz : type) {
        csb.append("+");
        csb.append(clazz.getName());
    }
    return xstream(encoding, csb.toString());
}
Also used : CollectionStringBuffer(org.apache.camel.util.CollectionStringBuffer)

Example 14 with CollectionStringBuffer

use of org.apache.camel.util.CollectionStringBuffer in project camel by apache.

the class ChoiceDefinition method getLabel.

// Properties
// -------------------------------------------------------------------------
@Override
public String getLabel() {
    CollectionStringBuffer buffer = new CollectionStringBuffer("choice[");
    List<WhenDefinition> list = getWhenClauses();
    for (WhenDefinition whenType : list) {
        buffer.append(whenType.getLabel());
    }
    buffer.append("]");
    return buffer.toString();
}
Also used : CollectionStringBuffer(org.apache.camel.util.CollectionStringBuffer)

Example 15 with CollectionStringBuffer

use of org.apache.camel.util.CollectionStringBuffer in project camel by apache.

the class OnFallbackDefinition method getLabel.

@Override
public String getLabel() {
    String name = fallbackViaNetwork != null && fallbackViaNetwork ? "onFallbackViaNetwork" : "onFallback";
    CollectionStringBuffer buffer = new CollectionStringBuffer(name);
    buffer.append("[");
    List<ProcessorDefinition<?>> list = getOutputs();
    for (ProcessorDefinition<?> type : list) {
        buffer.append(type.getLabel());
    }
    buffer.append("]");
    return buffer.toString();
}
Also used : CollectionStringBuffer(org.apache.camel.util.CollectionStringBuffer)

Aggregations

CollectionStringBuffer (org.apache.camel.util.CollectionStringBuffer)21 HashMap (java.util.HashMap)5 Map (java.util.Map)5 IOException (java.io.IOException)4 LinkedHashMap (java.util.LinkedHashMap)4 TreeMap (java.util.TreeMap)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 MalformedObjectNameException (javax.management.MalformedObjectNameException)4 FailedToStartRouteException (org.apache.camel.FailedToStartRouteException)4 NoFactoryAvailableException (org.apache.camel.NoFactoryAvailableException)4 NoSuchEndpointException (org.apache.camel.NoSuchEndpointException)4 ResolveEndpointFailedException (org.apache.camel.ResolveEndpointFailedException)4 RuntimeCamelException (org.apache.camel.RuntimeCamelException)4 VetoCamelContextStartException (org.apache.camel.VetoCamelContextStartException)4 LoadPropertiesException (org.apache.camel.util.LoadPropertiesException)4 RouteDefinition (org.apache.camel.model.RouteDefinition)2 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStreamReader (java.io.InputStreamReader)1 URI (java.net.URI)1