diff --git a/.github/workflows/manual-update-version.yml b/.github/workflows/manual-update-version.yml index 43f62ef2..db26ec4d 100644 --- a/.github/workflows/manual-update-version.yml +++ b/.github/workflows/manual-update-version.yml @@ -14,10 +14,6 @@ on: description: '4.0.0' required: true default: '4.0.0' - - push: - branches: - - 'update-development-version' jobs: update_version: @@ -28,11 +24,11 @@ jobs: - name: Checkout the code uses: actions/checkout@v3 with: - ref: 'develop' + ref: ${{ inputs.BRANCH }} - name: Update POM Version env: - VERSION: '4.0.0-SNAPSHOT' + VERSION: ${{ inputs.VERSION }} run: | echo "Updating to version: $VERSION" mvn versions:set -DnewVersion=$VERSION diff --git a/.github/workflows/new-release.yml b/.github/workflows/new-release.yml new file mode 100644 index 00000000..df5e14b5 --- /dev/null +++ b/.github/workflows/new-release.yml @@ -0,0 +1,70 @@ +name: New Release Workflow + +on: + + release: + types: [ released ] + +jobs: + + publish_prod_packages: + + name: Publish Snapshot Packages + runs-on: ubuntu-latest + steps: + + - name: Checkout code + uses: actions/checkout@v3 + with: + ref: 'master' + + - name: Setup Java + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + + - name: Update to snapshot version + env: + VERSION: ${{ github.ref_name }} + run: | + echo "Updating to version: ${VERSION}" + mvn versions:set -DgenerateBackupPoms=false -DnewVersion=${VERSION} + mvn versions:set-property -Dproperty=assimbly.version -DnewVersion=${VERSION} + + - name: Publish package + run: mvn --batch-mode deploy + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + publish_snapshot_packages: + + name: Publish Snapshot Packages + runs-on: ubuntu-latest + steps: + + - name: Checkout code + uses: actions/checkout@v3 + with: + ref: 'develop' + + - name: Setup Java + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + + - name: Update to snapshot version + env: + SNAPSHOT_VERSION: ${{ github.ref_name }}-SNAPSHOT + run: | + echo "Updating to version: ${SNAPSHOT_VERSION}" + mvn versions:set -DgenerateBackupPoms=false -DnewVersion=${SNAPSHOT_VERSION} + mvn versions:set-property -Dproperty=assimbly.version -DnewVersion=${SNAPSHOT_VERSION} + + - name: Publish package + run: mvn --batch-mode deploy + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + diff --git a/.github/workflows/release-publish.yml b/.github/workflows/release-publish.yml deleted file mode 100644 index 09225ae3..00000000 --- a/.github/workflows/release-publish.yml +++ /dev/null @@ -1,60 +0,0 @@ -name: Publish packages to GitHub Packages - -on: - release: - types: [ released ] - push: - branches: - - 'release-publish' - - -jobs: - update_version: - runs-on: ubuntu-latest - - steps: - - - name: Checkout the code - uses: actions/checkout@v3 - - - name: Update POM Version - run: | - echo "Updating to version: $(jq -r '.pull_request.milestone.title' $GITHUB_EVENT_PATH)" - mvn versions:set -DnewVersion=$(jq -r '.pull_request.milestone.title' $GITHUB_EVENT_PATH) - mvn versions:set-property -Dproperty=assimbly.version -DnewVersion=$(jq -r '.pull_request.milestone.title' $GITHUB_EVENT_PATH) - - - name: Diff check - run: git diff - - - name: Add & Commit - uses: EndBug/add-and-commit@v9.1.1 - with: - add: '.' - default_author: github_actions - push: origin HEAD:develop --force - - publish_packages: - needs: [update_version] - - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - - steps: - - - name: Checkout the code - uses: actions/checkout@v3 - with: - ref: 'master' - - - name: Setup JDK 11 - uses: actions/setup-java@v3 - with: - java-version: '11' - distribution: 'temurin' - - - name: Publish package - run: mvn --batch-mode deploy - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/broker/pom.xml b/broker/pom.xml index d804daa2..de7dfe50 100644 --- a/broker/pom.xml +++ b/broker/pom.xml @@ -6,7 +6,7 @@ runtime org.assimbly - 4.0.0 + 4.0.1 broker diff --git a/brokerRest/pom.xml b/brokerRest/pom.xml index 2f63ab37..7d49b060 100644 --- a/brokerRest/pom.xml +++ b/brokerRest/pom.xml @@ -6,7 +6,7 @@ runtime org.assimbly - 4.0.0 + 4.0.1 broker-rest diff --git a/dil/pom.xml b/dil/pom.xml index c92a91f6..7fcd9b24 100644 --- a/dil/pom.xml +++ b/dil/pom.xml @@ -4,7 +4,7 @@ runtime org.assimbly - 4.0.0 + 4.0.1 dil diff --git a/dil/src/main/java/org/assimbly/dil/blocks/beans/AggregateStrategy.java b/dil/src/main/java/org/assimbly/dil/blocks/beans/AggregateStrategy.java index 54928c17..0321b762 100644 --- a/dil/src/main/java/org/assimbly/dil/blocks/beans/AggregateStrategy.java +++ b/dil/src/main/java/org/assimbly/dil/blocks/beans/AggregateStrategy.java @@ -9,8 +9,6 @@ public class AggregateStrategy implements AggregationStrategy { - protected Logger log = LoggerFactory.getLogger(getClass()); - private AggregationStrategy aggregateStrategy; @Override diff --git a/dil/src/main/java/org/assimbly/dil/blocks/beans/enrich/EnrichStrategy.java b/dil/src/main/java/org/assimbly/dil/blocks/beans/enrich/EnrichStrategy.java index eb47bc49..8539125f 100644 --- a/dil/src/main/java/org/assimbly/dil/blocks/beans/enrich/EnrichStrategy.java +++ b/dil/src/main/java/org/assimbly/dil/blocks/beans/enrich/EnrichStrategy.java @@ -12,8 +12,6 @@ public class EnrichStrategy implements AggregationStrategy { - protected Logger log = LoggerFactory.getLogger(getClass()); - private AggregationStrategy enrichStrategy; @Override diff --git a/dil/src/main/java/org/assimbly/dil/blocks/beans/enrich/attachment/AttachmentEnrichStrategy.java b/dil/src/main/java/org/assimbly/dil/blocks/beans/enrich/attachment/AttachmentEnrichStrategy.java index 16d5bd65..7a450c7e 100644 --- a/dil/src/main/java/org/assimbly/dil/blocks/beans/enrich/attachment/AttachmentEnrichStrategy.java +++ b/dil/src/main/java/org/assimbly/dil/blocks/beans/enrich/attachment/AttachmentEnrichStrategy.java @@ -26,7 +26,7 @@ public Exchange aggregate(Exchange original, Exchange resource) { Message resourceMessage; - if(resource == null){ + if(resource != null){ resourceMessage = resource.getIn(); }else{ log.error("Could not get a response from your requested resource."); diff --git a/dil/src/main/java/org/assimbly/dil/blocks/beans/enrich/json/JsonEnrichStrategy.java b/dil/src/main/java/org/assimbly/dil/blocks/beans/enrich/json/JsonEnrichStrategy.java index 74718572..e5466cc7 100644 --- a/dil/src/main/java/org/assimbly/dil/blocks/beans/enrich/json/JsonEnrichStrategy.java +++ b/dil/src/main/java/org/assimbly/dil/blocks/beans/enrich/json/JsonEnrichStrategy.java @@ -10,8 +10,6 @@ public class JsonEnrichStrategy implements AggregationStrategy { - protected Logger log = LoggerFactory.getLogger(getClass()); - @Override public Exchange aggregate(Exchange original, Exchange resource) { diff --git a/dil/src/main/java/org/assimbly/dil/blocks/beans/enrich/override/OverrideEnrichStrategy.java b/dil/src/main/java/org/assimbly/dil/blocks/beans/enrich/override/OverrideEnrichStrategy.java index 99ec4855..14913278 100644 --- a/dil/src/main/java/org/assimbly/dil/blocks/beans/enrich/override/OverrideEnrichStrategy.java +++ b/dil/src/main/java/org/assimbly/dil/blocks/beans/enrich/override/OverrideEnrichStrategy.java @@ -10,8 +10,6 @@ public class OverrideEnrichStrategy implements AggregationStrategy { - protected Logger log = LoggerFactory.getLogger(getClass()); - @Override public Exchange aggregate(Exchange original, Exchange resource) { diff --git a/dil/src/main/java/org/assimbly/dil/blocks/beans/json/JsonAggregateStrategy.java b/dil/src/main/java/org/assimbly/dil/blocks/beans/json/JsonAggregateStrategy.java index 035c6c79..16209046 100644 --- a/dil/src/main/java/org/assimbly/dil/blocks/beans/json/JsonAggregateStrategy.java +++ b/dil/src/main/java/org/assimbly/dil/blocks/beans/json/JsonAggregateStrategy.java @@ -9,8 +9,6 @@ public class JsonAggregateStrategy implements AggregationStrategy { - protected Logger log = LoggerFactory.getLogger(getClass()); - @Override public Exchange aggregate(Exchange oldExchange, Exchange newExchange) { diff --git a/dil/src/main/java/org/assimbly/dil/blocks/connections/Connection.java b/dil/src/main/java/org/assimbly/dil/blocks/connections/Connection.java index 5d77b724..10d0a848 100644 --- a/dil/src/main/java/org/assimbly/dil/blocks/connections/Connection.java +++ b/dil/src/main/java/org/assimbly/dil/blocks/connections/Connection.java @@ -25,8 +25,8 @@ public class Connection { private CamelContext context; private String stepType; private Object stepId; - private String connectionType; + private static final Random RANDOM = new Random(); public Connection(CamelContext context, TreeMap properties, String key) { this.context = context; @@ -65,7 +65,7 @@ private void startConnection() throws Exception{ new ActiveMQConnection(context, decryptedProperties, connectionId, "amazonmq").start(); break; case "SonicMQ": - String connectId = stepType + connectionIdValue + new Random().nextInt(1000000); + String connectId = stepType + connectionIdValue + RANDOM.nextInt(1000000); new SonicMQConnection(context, decryptedProperties, connectionId, "sonicmq").start(flowId, connectId, connectionIdValue); uri = uri.replace("sonicmq:", "sonicmq." + flowId + connectId + ":"); properties.put(stepType + "." + stepId + ".uri", uri); diff --git a/dil/src/main/java/org/assimbly/dil/blocks/connections/broker/AMQPConnection.java b/dil/src/main/java/org/assimbly/dil/blocks/connections/broker/AMQPConnection.java index 7a94f811..f545ace1 100644 --- a/dil/src/main/java/org/assimbly/dil/blocks/connections/broker/AMQPConnection.java +++ b/dil/src/main/java/org/assimbly/dil/blocks/connections/broker/AMQPConnection.java @@ -87,13 +87,13 @@ private String createSSLEnabledUrl(String url) { String modifiedUrl = ""; String multipleUrls; - if (url.indexOf(",") == -1) { + if (url.indexOf(',') == -1) { log.info("SSLEnabled Normal Url: "); modifiedUrl = addSSLParameterToUrl(url); }else{ log.info("SSLEnabled Failover Url: "); - if (url.indexOf("(") != -1) { + if (url.indexOf('(') != -1) { multipleUrls = StringUtils.substringBetween(url,"(",")"); }else{ multipleUrls = url; @@ -110,7 +110,7 @@ private String createSSLEnabledUrl(String url) { } } - if (url.indexOf("(") != -1) { + if (url.indexOf('(') != -1) { modifiedUrl = "failover:(" + modifiedUrl + ")"; } @@ -131,7 +131,7 @@ private String addSSLParameterToUrl(String url){ String baseDirURI = baseDir.replace("\\", "/"); String sslUrl = url; - if (url.indexOf("?") == -1) { + if (url.indexOf('?') == -1) { sslUrl = url + "?transport.verifyHost=false&transport.trustAll=true&transport.trustStoreLocation=" + baseDirURI + "/security/truststore.jks" + "&transport.trustStorePassword=supersecret"; } else { String[] urlSplitted = url.split("/?"); diff --git a/dil/src/main/java/org/assimbly/dil/blocks/processors/FailureProcessor.java b/dil/src/main/java/org/assimbly/dil/blocks/processors/FailureProcessor.java index 60e5eb26..79023286 100644 --- a/dil/src/main/java/org/assimbly/dil/blocks/processors/FailureProcessor.java +++ b/dil/src/main/java/org/assimbly/dil/blocks/processors/FailureProcessor.java @@ -45,6 +45,8 @@ public void process(Exchange exchange) throws Exception { .filter(map -> map.getKey().startsWith("message." + stepId)) .collect(Collectors.toMap(map -> map.getKey(), map -> map.getValue())); + XPathFactory fac = new net.sf.saxon.xpath.XPathFactoryImpl(); + for (Map.Entry entry : headers.entrySet()) { String language = StringUtils.substringBetween(entry.getKey(), stepId + ".", "."); @@ -57,7 +59,6 @@ public void process(Exchange exchange) throws Exception { } else if (language.equalsIgnoreCase("constant")) { result = value; } else if (language.equalsIgnoreCase("xpath")) { - XPathFactory fac = new net.sf.saxon.xpath.XPathFactoryImpl(); result = XPathBuilder.xpath(value).factory(fac).evaluate(exchange, String.class); } else { Language resolvedLanguage = exchange.getContext().resolveLanguage(language); diff --git a/dil/src/main/java/org/assimbly/dil/blocks/processors/SetHeadersProcessor.java b/dil/src/main/java/org/assimbly/dil/blocks/processors/SetHeadersProcessor.java index f0a53bcf..145243ff 100644 --- a/dil/src/main/java/org/assimbly/dil/blocks/processors/SetHeadersProcessor.java +++ b/dil/src/main/java/org/assimbly/dil/blocks/processors/SetHeadersProcessor.java @@ -29,7 +29,8 @@ public void process(Exchange exchange) throws Exception { String language; String type; - + XPathFactory fac = new net.sf.saxon.xpath.XPathFactoryImpl(); + if (node.getNodeType() == Node.ELEMENT_NODE) { String headerKey = node.getNodeName(); String headerValue = node.getTextContent(); @@ -43,7 +44,6 @@ public void process(Exchange exchange) throws Exception { if (language.equalsIgnoreCase("constant")) { result = headerValue; } else if (language.equalsIgnoreCase("xpath")) { - XPathFactory fac = new net.sf.saxon.xpath.XPathFactoryImpl(); result = XPathBuilder.xpath(headerValue).factory(fac).evaluate(exchange, String.class); } else { Language resolvedLanguage = exchange.getContext().resolveLanguage(language); diff --git a/dil/src/main/java/org/assimbly/dil/event/EventConfigurer.java b/dil/src/main/java/org/assimbly/dil/event/EventConfigurer.java index c072df28..ff909b45 100644 --- a/dil/src/main/java/org/assimbly/dil/event/EventConfigurer.java +++ b/dil/src/main/java/org/assimbly/dil/event/EventConfigurer.java @@ -33,37 +33,6 @@ public EventConfigurer(String collectorId, CamelContext context) { this.context = context; } - public String checkConfiguration() { - - if(configuration == null){ - return "Invalid event format (json)"; - } - - type = configuration.getType(); - - if(type==null){ - return "The type of collector is missing. Valid types are: message,log or step."; - }else if(!type.equals("log") && !type.equals("message") && !type.equals("step")){ - return "Invalid event collector: " + type + ". Valid types are message,log or step."; - } - - String id = configuration.getId(); - - if(!this.collectorId.equals(id)){ - return "CollectorId of endpoint and configuration don't match. CollectorId endpoint=" + collectorId + " and CollectorID configuration=" + id; - } - - //remove if configuration already exists - if(isConfigured()){ - remove(collectorId); - } - - log.info("Event collector configuration is valid"); - - return "ok"; - - } - public String add(String jsonConfiguration) { log.info("Check event collector configuration:\n\n" + jsonConfiguration); @@ -90,8 +59,6 @@ public String add(Collection configuration) { } - - public String remove(String collectorId) { log.info("Removing collector with id=" + collectorId); @@ -117,6 +84,46 @@ public String remove(String collectorId) { return "removed"; } + public String checkConfiguration() { + + if(configuration == null){ + return "Invalid event format (json)"; + } + + type = configuration.getType(); + + if(type==null){ + return "The type of collector is missing. Valid types are: message,log or step."; + }else if(!type.equals("log") && !type.equals("message") && !type.equals("step")){ + return "Invalid event collector: " + type + ". Valid types are message,log or step."; + } + + String id = configuration.getId(); + + if(!this.collectorId.equals(id)){ + return "CollectorId of endpoint and configuration don't match. CollectorId endpoint=" + collectorId + " and CollectorID configuration=" + id; + } + + //remove if configuration already exists + if(isConfigured()){ + remove(collectorId); + } + + log.info("Event collector configuration is valid"); + + return "ok"; + + } + + public boolean isConfigured(){ + Object collector = context.getRegistry().lookupByName(collectorId); + if(collector==null){ + return false; + }else{ + return true; + } + } + public String configureCollector(){ String checkMessage = checkConfiguration(); @@ -150,16 +157,6 @@ public String configureCollector(){ } - public boolean isConfigured(){ - Object collector = context.getRegistry().lookupByName(collectorId); - if(collector==null){ - return false; - }else{ - return true; - } - } - - public void configureStepCollector() { log.info("Configure collection of step events"); diff --git a/dil/src/main/java/org/assimbly/dil/event/collect/MessageCollector.java b/dil/src/main/java/org/assimbly/dil/event/collect/MessageCollector.java index f736743e..585182da 100644 --- a/dil/src/main/java/org/assimbly/dil/event/collect/MessageCollector.java +++ b/dil/src/main/java/org/assimbly/dil/event/collect/MessageCollector.java @@ -5,12 +5,14 @@ import org.apache.camel.builder.ExpressionBuilder; import org.apache.camel.spi.CamelEvent; import org.apache.camel.support.EventNotifierSupport; +import org.apache.commons.lang3.StringUtils; import org.assimbly.dil.event.domain.Filter; import org.assimbly.dil.event.domain.Store; import org.assimbly.dil.event.store.StoreManager; import org.assimbly.dil.event.util.EventUtil; import org.assimbly.dil.event.domain.MessageEvent; +import java.nio.charset.StandardCharsets; import java.time.Clock; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; @@ -25,8 +27,10 @@ public class MessageCollector extends EventNotifierSupport { private final String expiryInHours; private final ArrayList filters; private final ArrayList events; + private final String collectorId; public MessageCollector(String collectorId, ArrayList events, ArrayList filters, ArrayList stores) { + this.collectorId = collectorId; this.events = events; this.filters = filters; this.storeManager = new StoreManager(collectorId, stores); @@ -58,16 +62,16 @@ public void notify(CamelEvent event) throws Exception { //process and store the exchange if(stepId!=null && filters==null){ - processEvent(exchange, stepId); + processEvent(exchange, collectorId, stepId); }else if(stepId!=null && EventUtil.isFiltered(filters, stepId)){ - processEvent(exchange, stepId); + processEvent(exchange, collectorId, stepId); } } } - private void processEvent(Exchange exchange, String stepId){ + private void processEvent(Exchange exchange, String flowId, String stepId){ //set fields Message message = exchange.getMessage(); @@ -77,7 +81,7 @@ private void processEvent(Exchange exchange, String stepId){ String timestamp = EventUtil.getTimestamp(); //create json - MessageEvent messageEvent = new MessageEvent(timestamp, messageId, stepId, "0", stepId, headers, body, expiryInHours); + MessageEvent messageEvent = new MessageEvent(timestamp, messageId, flowId, "0", stepId, headers, body, expiryInHours); String json = messageEvent.toJson(); //store the event @@ -98,9 +102,9 @@ public String getBody(Message message) { String typeName = message.getBody().getClass().getTypeName(); return "<" + typeName + ">"; }else if (body.length > 250000) { - return new String(Arrays.copyOfRange(body, 0, 250000)); + return new String(Arrays.copyOfRange(body, 0, 250000), StandardCharsets.UTF_8); }else{ - return new String (body); + return new String (body, StandardCharsets.UTF_8); } } catch (Exception e) { diff --git a/dil/src/main/java/org/assimbly/dil/event/domain/MessageEvent.java b/dil/src/main/java/org/assimbly/dil/event/domain/MessageEvent.java index 7ee8b704..fdcd6911 100644 --- a/dil/src/main/java/org/assimbly/dil/event/domain/MessageEvent.java +++ b/dil/src/main/java/org/assimbly/dil/event/domain/MessageEvent.java @@ -26,21 +26,21 @@ public class MessageEvent { private static final String JMS_PREFIX = "JMS"; private final String id; - private final String stepId; + private final String flowId; private final String flowVersion; - private final String step; + private final String stepId; private final String timestamp; private final String expiryDate; private final Map headers; private final String body; - public MessageEvent(String timestamp, String id, String stepId, String flowVersion, String step, Map headers, String body, String expiryDate) { + public MessageEvent(String timestamp, String id, String flowId, String flowVersion, String stepId, Map headers, String body, String expiryDate) { this.timestamp = timestamp; this.id = id; - this.stepId = stepId; + this.flowId = flowId; this.flowVersion = flowVersion; - this.step = step; + this.stepId = stepId; this.headers = headers; this.body = body; this.expiryDate = expiryDate; @@ -57,8 +57,8 @@ public String getId() { } @JsonProperty("bundleId") - public String getStepId() { - return stepId; + public String getFlowId() { + return flowId; } @JsonProperty("flowVersion") @@ -68,7 +68,7 @@ public String getFlowVersion() { @JsonProperty("component") public String getStep() { - return step; + return stepId; } /** diff --git a/dil/src/main/java/org/assimbly/dil/event/store/impl/FileStore.java b/dil/src/main/java/org/assimbly/dil/event/store/impl/FileStore.java index 6917e437..1f0f1691 100644 --- a/dil/src/main/java/org/assimbly/dil/event/store/impl/FileStore.java +++ b/dil/src/main/java/org/assimbly/dil/event/store/impl/FileStore.java @@ -23,7 +23,7 @@ public FileStore(String collectorId, org.assimbly.dil.event.domain.Store store) this.store = store; if(file==null){ - createFile(collectorId, store); + createFile(this.collectorId, this.store); } } diff --git a/dil/src/main/java/org/assimbly/dil/loader/FlowLoader.java b/dil/src/main/java/org/assimbly/dil/loader/FlowLoader.java index 00272bea..2f4f6b2f 100644 --- a/dil/src/main/java/org/assimbly/dil/loader/FlowLoader.java +++ b/dil/src/main/java/org/assimbly/dil/loader/FlowLoader.java @@ -1,10 +1,8 @@ package org.assimbly.dil.loader; -import java.util.List; import java.util.TreeMap; import org.apache.camel.*; import org.apache.camel.builder.*; -import org.apache.camel.spi.Resource; import org.apache.camel.spi.RoutesLoader; import org.apache.commons.lang3.StringUtils; import org.assimbly.dil.blocks.errorhandler.ErrorHandler; @@ -29,13 +27,13 @@ public class FlowLoader extends RouteBuilder { private boolean isFlowLoaded = true; private FlowLoaderReport flowLoaderReport; - public FlowLoader(final TreeMap props){ + public FlowLoader() { super(); - this.props = props; } - public FlowLoader() { + public FlowLoader(final TreeMap props){ super(); + this.props = props; } public interface FailureProcessorListener { @@ -47,7 +45,7 @@ public void configure() throws Exception { init(); - loadFlowSteps(); + load(); finish(); } @@ -67,6 +65,21 @@ private void init(){ } + private void load() throws Exception { + + setErrorHandlers(); + + setRouteConfigurations(); + + defineRouteTemplates(); + + setRouteTemplates(); + + setRoutes(); + + } + + private void finish() { flowLoaderReport.logResult(flowId,flowName,flowEvent); @@ -81,24 +94,8 @@ private void finish() { private void setExtendedCamelContext() { context = getContext(); extendedCamelContext = context.adapt(ExtendedCamelContext.class); + loader = extendedCamelContext.getRoutesLoader(); } - - - - private void loadFlowSteps() throws Exception { - - setErrorHandlers(); - - setRouteConfigurations(); - - defineRouteTemplates(); - - setRouteTemplates(); - - setRoutes(); - - } - private void setErrorHandlers() throws Exception{ for(String prop : props.keySet()){ @@ -123,7 +120,7 @@ private void setRouteConfigurations() throws Exception{ if(routeConfiguration!=null && !routeConfiguration.isEmpty()){ context.removeRoute(id); - loadOrUpdateStep(routeConfiguration, "routeconfiguration", id, null); + loadStep(routeConfiguration, "routeconfiguration", id, null); } } } @@ -138,7 +135,7 @@ private void defineRouteTemplates() throws Exception{ String id = props.get(prop + ".id"); if(routeTemplate!=null && !routeTemplate.isEmpty()){ - loadOrUpdateStep(routeTemplate, "routeTemplate definition", id, null); + loadStep(routeTemplate, "routeTemplate definition", id, null); } } @@ -156,7 +153,7 @@ private void setRouteTemplates() throws Exception{ String uri = props.get(basePath + "uri"); if(routeTemplate!=null && !routeTemplate.isEmpty()){ - loadOrUpdateStep(routeTemplate, "routeTemplate", id, uri); + loadStep(routeTemplate, "routeTemplate", id, uri); } } @@ -170,75 +167,23 @@ private void setRoutes() throws Exception{ String route = props.get(prop); String id = props.get(prop + ".id"); - if(prop.startsWith("route")){ - loadOrUpdateStep(route, "route",id, null); - }else{ - loadOrUpdateStep(route, "route", id, null); - } + loadStep(route, "route",id, null); } } } - - - private void loadOrUpdateStep(String route, String type, String id, String uri) throws Exception { - - loader = extendedCamelContext.getRoutesLoader(); - - Resource resource = IntegrationUtil.setResource(route); - - if(isStepLoaded(id)) { - updateStep(resource,route, type, id, uri); - }else{ - loadStep(resource,route, type, id, uri); - } - - } - - private void loadStep(Resource resource, String route, String type, String id, String uri){ + private void loadStep(String route, String type, String id, String uri){ try { log.info(logMessage("Loading step", id, type, route)); - - loader.loadRoutes(List.of(resource)); - - flowEvent = "start"; - flowLoaderReport.setStep(id, uri, type, "success", null); - }catch (Exception e){ - e.printStackTrace(); - try { - String errorMessage = e.getMessage(); - - if(errorMessage.contains("duplicate id detected")) { - updateStep(resource, route, type, id, uri); - }else if(errorMessage.contains("Route configuration already exists with id")){ - updateStep(resource, route, type, id, uri); - }else{ - log.error("Failed loading step | stepid=" + id); - isFlowLoaded = false; - flowEvent = "error"; - flowLoaderReport.setStep(id, uri, type,"error",errorMessage); - } - }catch (Exception e2){ - log.error("Failed updating step | stepid=" + id); - isFlowLoaded = false; - flowEvent = "error"; - flowLoaderReport.setStep(id,uri, type,"error",e2.getMessage()); - } - } - } - - private void updateStep(Resource resource, String route, String type, String id, String uri){ - try { - log.info(logMessage("Updating step", id, type, route)); - loader.updateRoutes(List.of(resource)); + loader.loadRoutes(IntegrationUtil.setResource(route)); //context flowLoaderReport.setStep(id, uri, type, "success", null); flowEvent = "start"; }catch (Exception e) { String errorMessage = e.getMessage(); - log.error("Failed updating step | stepid=" + id); + log.error("Failed loading step | stepid=" + id); flowLoaderReport.setStep(id, uri, type, "error", errorMessage); flowEvent = "error"; isFlowLoaded = false; @@ -248,33 +193,21 @@ private void updateStep(Resource resource, String route, String type, String id, private void setErrorHandler(String id, String errorUri) throws Exception { if (errorUri!=null && !errorUri.isEmpty()) { - routeErrorHandler = new DeadLetterChannelBuilder(); - routeErrorHandler = deadLetterChannel(errorUri); + routeErrorHandler = new DeadLetterChannelBuilder(errorUri); }else{ routeErrorHandler = deadLetterChannel("log:org.assimbly.integration.routes.ESBRoute?level=ERROR"); } ErrorHandler errorHandler = new ErrorHandler(routeErrorHandler, props); - routeErrorHandler = errorHandler.configure(); + DeadLetterChannelBuilder updatedErrorHandler = errorHandler.configure(); - extendedCamelContext.setErrorHandlerFactory(routeErrorHandler); + extendedCamelContext.setErrorHandlerFactory(updatedErrorHandler); flowLoaderReport.setStep(id, errorUri, "error", "success", null); } - public boolean isStepLoaded(String id){ - - Route route = context.getRoute(id); - - if(route != null && route.getUptimeMillis()>0){ - return true; - } - - return false; - } - public boolean isFlowLoaded(){ return isFlowLoaded; } diff --git a/dil/src/main/java/org/assimbly/dil/transpiler/XMLFileConfiguration.java b/dil/src/main/java/org/assimbly/dil/transpiler/XMLFileConfiguration.java index 1d1141f4..4e33c53d 100644 --- a/dil/src/main/java/org/assimbly/dil/transpiler/XMLFileConfiguration.java +++ b/dil/src/main/java/org/assimbly/dil/transpiler/XMLFileConfiguration.java @@ -27,6 +27,7 @@ import org.apache.commons.configuration2.builder.fluent.Parameters; import org.apache.commons.configuration2.io.FileHandler; import org.apache.commons.configuration2.tree.xpath.XPathExpressionEngine; +import org.apache.commons.lang3.time.StopWatch; import org.assimbly.dil.transpiler.marshalling.Marshall; import org.assimbly.dil.transpiler.marshalling.Unmarshall; import org.assimbly.dil.transpiler.transform.Transform; @@ -101,10 +102,6 @@ public TreeMap getFlowConfiguration(String flowId, String xml) t dilXml = Transform.transformToDil(xml); } - log.info("---------------------------- DIL START----------------------------"); - log.info(dilXml); - log.info("---------------------------- DIL END----------------------------"); - DocumentBuilder docBuilder = setDocumentBuilder("dil.xsd"); conf = new BasicConfigurationBuilder<>(XMLConfiguration.class).configure(new Parameters().xml() @@ -117,7 +114,7 @@ public TreeMap getFlowConfiguration(String flowId, String xml) t FileHandler fh = new FileHandler(conf); fh.load(DocConverter.convertStringToStream(dilXml)); - + properties = new Unmarshall().getProperties(conf,flowId); //IntegrationUtil.printTreemap(properties); diff --git a/dil/src/main/java/org/assimbly/dil/transpiler/marshalling/Marshall.java b/dil/src/main/java/org/assimbly/dil/transpiler/marshalling/Marshall.java index 9d3044ee..5d7ba077 100644 --- a/dil/src/main/java/org/assimbly/dil/transpiler/marshalling/Marshall.java +++ b/dil/src/main/java/org/assimbly/dil/transpiler/marshalling/Marshall.java @@ -6,6 +6,7 @@ import org.w3c.dom.Node; import java.io.ByteArrayInputStream; +import java.nio.charset.StandardCharsets; import java.util.*; import java.util.stream.Collectors; @@ -347,7 +348,7 @@ private Document getDocument(String xml) throws Exception { DocumentBuilderFactory dbFactory = javax.xml.parsers.DocumentBuilderFactory.newInstance(); DocumentBuilder builder = dbFactory.newDocumentBuilder(); - Document document = builder.parse(new ByteArrayInputStream(xml.getBytes())); + Document document = builder.parse(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8))); return document; diff --git a/dil/src/main/java/org/assimbly/dil/transpiler/marshalling/Unmarshall.java b/dil/src/main/java/org/assimbly/dil/transpiler/marshalling/Unmarshall.java index 1319f048..63f3d4e7 100644 --- a/dil/src/main/java/org/assimbly/dil/transpiler/marshalling/Unmarshall.java +++ b/dil/src/main/java/org/assimbly/dil/transpiler/marshalling/Unmarshall.java @@ -3,10 +3,14 @@ import org.apache.commons.configuration2.XMLConfiguration; import org.apache.commons.configuration2.ex.ConfigurationException; import org.apache.commons.lang3.StringUtils; +import org.apache.xpath.CachedXPathAPI; +import org.apache.xpath.objects.XObject; import org.assimbly.dil.transpiler.marshalling.core.*; import org.assimbly.util.DependencyUtil; import org.assimbly.util.IntegrationUtil; import org.w3c.dom.Document; + +import javax.xml.transform.TransformerException; import javax.xml.xpath.*; import java.util.*; import java.util.stream.Collectors; @@ -42,6 +46,8 @@ public class Unmarshall { private String flowParallelProcessing; private String stepId; + CachedXPathAPI cachedXPathAPI = new CachedXPathAPI(); + public TreeMap getProperties(XMLConfiguration configuration, String flowId) throws Exception{ //create a Treemap for the configuration @@ -74,11 +80,9 @@ private void setFlows() throws Exception{ private String setFlowSelector() throws Exception{ - XPath xPath = XPathFactory.newInstance().newXPath(); - String selector = "1"; - Integer numberOfFlows = Integer.parseInt(xPath.evaluate("count(//flows/flow)",doc)); + Integer numberOfFlows = Integer.parseInt(evaluateXpath("count(//flows/flow)")); if(numberOfFlows > 1){ @@ -86,7 +90,7 @@ private String setFlowSelector() throws Exception{ String originalFlowId = flowId; selector = "id='" + originalFlowId + "'"; - flowId = xPath.evaluate("//flows/flow[" + selector + "]/id",doc); + flowId = evaluateXpath("//flows/flow[" + selector + "]/id"); if(!originalFlowId.equals(flowId)) { ConfigurationException configurationException = new ConfigurationException("The flow ID " + originalFlowId + " doesn't exists in XML Configuration"); @@ -94,7 +98,7 @@ private String setFlowSelector() throws Exception{ throw configurationException; } }else{ - flowId = xPath.evaluate("//flows/flow[" + selector + "]/id",doc); + flowId = evaluateXpath("//flows/flow[" + selector + "]/id"); } return selector; @@ -130,19 +134,16 @@ public void setFlowDefaults(){ } - public void setFlowProperties(String flowSelector) throws XPathExpressionException { - - XPath xPath = XPathFactory.newInstance().newXPath(); - - flowName = xPath.evaluate("//flows/flow[" + flowSelector + "]/name",doc); - flowType = xPath.evaluate("//flows/flow[" + flowSelector + "]/type",doc); + public void setFlowProperties(String flowSelector) throws Exception { - flowVersion = xPath.evaluate("//flows/flow[" + flowSelector + "]/version", doc); + flowName = evaluateXpath("//flows/flow[" + flowSelector + "]/name"); + flowType = evaluateXpath("//flows/flow[" + flowSelector + "]/type"); + flowVersion = evaluateXpath("//flows/flow[" + flowSelector + "]/version"); - flowMaximumRedeliveries = xPath.evaluate("//flows/flow[" + flowSelector + "]/options/maximumRedeliveries",doc); - flowRedeliveryDelay = xPath.evaluate("//flows/flow[" + flowSelector + "]/options/redeliveryDelay",doc); - flowLogLevel = xPath.evaluate("//flows/flow[" + flowSelector + "]/options/logLevel",doc); - flowParallelProcessing = xPath.evaluate("//flows/flow[" + flowSelector + "]/options/parallelProcessing",doc); + flowMaximumRedeliveries = evaluateXpath("//flows/flow[" + flowSelector + "]/options/maximumRedeliveries"); + flowRedeliveryDelay = evaluateXpath("//flows/flow[" + flowSelector + "]/options/redeliveryDelay"); + flowLogLevel = evaluateXpath("//flows/flow[" + flowSelector + "]/options/logLevel"); + flowParallelProcessing = evaluateXpath("//flows/flow[" + flowSelector + "]/options/parallelProcessing"); integrationXPath = "integrations/integration/flows/flow[" + flowSelector + "]"; @@ -154,9 +155,11 @@ public void setFlowProperties(String flowSelector) throws XPathExpressionExcepti } } - String environment = xPath.evaluate("//integrations/integration[1]/options/environment",doc); + integrationXPath = "integrations/integration/flows/flow[" + flowSelector + "]"; + + String environment = evaluateXpath("//integrations/integration[1]/options/environment"); - String frontend = xPath.evaluate("//integrations/integration[1]/options/frontend",doc); + String frontend = evaluateXpath("//integrations/integration[1]/options/frontend"); String dependenciesXpath = "integrations/integration/flows/flow[" + flowSelector + "]/dependencies/dependency"; @@ -379,4 +382,10 @@ private String createOptions(List optionProperties){ return options; } + private String evaluateXpath(String xpath) throws TransformerException { + XObject xObject = cachedXPathAPI.eval(doc, xpath); + return xObject.xstr(cachedXPathAPI.getXPathContext()).toString(); + } + + } \ No newline at end of file diff --git a/dil/src/main/java/org/assimbly/dil/transpiler/marshalling/core/Route.java b/dil/src/main/java/org/assimbly/dil/transpiler/marshalling/core/Route.java index bd600e06..19331d73 100644 --- a/dil/src/main/java/org/assimbly/dil/transpiler/marshalling/core/Route.java +++ b/dil/src/main/java/org/assimbly/dil/transpiler/marshalling/core/Route.java @@ -54,10 +54,11 @@ private String createRoute(String flowId, String routeId) throws Exception { private String createDataFormat(String route) throws Exception { + String dataFormatAsString = null; if (route.contains("", ""); dataFormatAsString = StringUtils.substringBetween(dataFormatAsString, ""); if(dataFormatAsString!=null) { @@ -70,7 +71,9 @@ private String createDataFormat(String route) throws Exception { if (route.contains("", ""); @@ -86,7 +89,9 @@ private String createDataFormat(String route) throws Exception { if (route.contains("", ""); @@ -103,5 +108,4 @@ private String createDataFormat(String route) throws Exception { } - } \ No newline at end of file diff --git a/dil/src/main/java/org/assimbly/dil/transpiler/marshalling/core/RouteConfiguration.java b/dil/src/main/java/org/assimbly/dil/transpiler/marshalling/core/RouteConfiguration.java index 38f834ba..6568f589 100644 --- a/dil/src/main/java/org/assimbly/dil/transpiler/marshalling/core/RouteConfiguration.java +++ b/dil/src/main/java/org/assimbly/dil/transpiler/marshalling/core/RouteConfiguration.java @@ -21,10 +21,14 @@ public TreeMap setRouteConfiguration(String type, String stepId, Node node = IntegrationUtil.getNode(conf,"/dil/core/routeConfigurations/routeConfiguration[@id='" + routeConfigurationId + "']"); - String routeAsString = DocConverter.convertNodeToString(node); + if(node!=null){ - properties.put(type + "." + stepId + ".routeconfiguration.id", routeConfigurationId); - properties.put(type + "." + stepId + ".routeconfiguration", routeAsString); + String routeAsString = DocConverter.convertNodeToString(node); + + properties.put(type + "." + stepId + ".routeconfiguration.id", routeConfigurationId); + properties.put(type + "." + stepId + ".routeconfiguration", routeAsString); + + } return properties; } diff --git a/dil/src/main/java/org/assimbly/dil/transpiler/marshalling/core/RouteTemplate.java b/dil/src/main/java/org/assimbly/dil/transpiler/marshalling/core/RouteTemplate.java index 40d5d2ef..72adeeee 100644 --- a/dil/src/main/java/org/assimbly/dil/transpiler/marshalling/core/RouteTemplate.java +++ b/dil/src/main/java/org/assimbly/dil/transpiler/marshalling/core/RouteTemplate.java @@ -2,6 +2,7 @@ import org.apache.commons.configuration2.XMLConfiguration; import org.apache.commons.lang3.StringUtils; +import org.apache.xerces.dom.DocumentImpl; import org.assimbly.docconverter.DocConverter; import org.assimbly.util.DependencyUtil; import org.assimbly.util.IntegrationUtil; @@ -11,10 +12,6 @@ import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.TransformerException; import javax.xml.xpath.*; import java.sql.Timestamp; @@ -63,7 +60,7 @@ public TreeMap setRouteTemplate(String type, String flowId, Stri this.baseUri = baseUri; - templateDoc = createNewDocument(); + templateDoc = new DocumentImpl(); routeId = flowId + "-" + stepId; this.options = options; @@ -73,7 +70,7 @@ public TreeMap setRouteTemplate(String type, String flowId, Stri createTemplateId(baseUri, type); if(baseUri.equalsIgnoreCase("content") && type.equalsIgnoreCase("router") ) { - contentRouteDoc = createNewDocument(); + contentRouteDoc = new DocumentImpl(); createContentRouter(links, stepXPath, type, flowId, stepId); }else if(!predefinedStep && baseUri.startsWith("block")){ createCustomStep(optionProperties, links, type, stepXPath, flowId, stepId); @@ -85,7 +82,7 @@ public TreeMap setRouteTemplate(String type, String flowId, Stri } - private void createContentRouter(String[] links, String stepXPath, String type, String flowId, String stepId){ + private void createContentRouter(String[] links, String stepXPath, String type, String flowId, String stepId) throws Exception { createContentRoute(links, stepXPath); @@ -234,7 +231,7 @@ public Element createOtherwise(String[] links, String stepXPath, Element choice) return choice; } - private void createStep(List optionProperties, String[] links, String stepXPath, String type, String flowId, String stepId){ + private void createStep(List optionProperties, String[] links, String stepXPath, String type, String flowId, String stepId) throws Exception { createTemplatedRoute(optionProperties, links, stepXPath, type, flowId); @@ -327,18 +324,6 @@ private void createCustomStep(List optionProperties, String[] links, Str } - - - private Document createNewDocument() throws ParserConfigurationException { - DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); - - // root elements - Document doc = docBuilder.newDocument(); - - return doc; - } - private void createTemplateId(String uri,String type){ if(uri==null || uri.isEmpty()){ @@ -638,7 +623,7 @@ public String createLinkEndpoint(String xpath, String transport, String id){ String endpoint; - Objects.toString(conf.getProperty(xpath + "options"), null); + //Objects.toString(conf.getProperty(xpath + "options"), null); if (options == null || options.isEmpty()) { endpoint = transport + ":" + id; diff --git a/dil/src/main/java/org/assimbly/dil/transpiler/ssl/SSLConfiguration.java b/dil/src/main/java/org/assimbly/dil/transpiler/ssl/SSLConfiguration.java index 9cb8e11f..84ce614d 100644 --- a/dil/src/main/java/org/assimbly/dil/transpiler/ssl/SSLConfiguration.java +++ b/dil/src/main/java/org/assimbly/dil/transpiler/ssl/SSLConfiguration.java @@ -82,12 +82,15 @@ public void createKeystore(String keystorePath){ if(!file.exists()){ try { - file.createNewFile(); + boolean newFile = file.createNewFile(); + + if(newFile){ + ClassLoader classloader = Thread.currentThread().getContextClassLoader(); + InputStream is = classloader.getResourceAsStream("keystore.jks"); + Files.copy(is, path, StandardCopyOption.REPLACE_EXISTING); + is.close(); + } - ClassLoader classloader = Thread.currentThread().getContextClassLoader(); - InputStream is = classloader.getResourceAsStream("keystore.jks"); - Files.copy(is, path, StandardCopyOption.REPLACE_EXISTING); - is.close(); } catch (IOException e) { log.error("Create keystore for certificates failed (ssl/tls)",e); } diff --git a/dil/src/main/java/org/assimbly/dil/transpiler/transform/Transform.java b/dil/src/main/java/org/assimbly/dil/transpiler/transform/Transform.java index 5735fb8e..e8eb0f7e 100644 --- a/dil/src/main/java/org/assimbly/dil/transpiler/transform/Transform.java +++ b/dil/src/main/java/org/assimbly/dil/transpiler/transform/Transform.java @@ -1,5 +1,6 @@ package org.assimbly.dil.transpiler.transform; +import org.apache.commons.lang3.time.StopWatch; import org.assimbly.util.TransformUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/dil/src/main/java/org/assimbly/dil/validation/FtpValidator.java b/dil/src/main/java/org/assimbly/dil/validation/FtpValidator.java index 4df71ba4..300dc54f 100644 --- a/dil/src/main/java/org/assimbly/dil/validation/FtpValidator.java +++ b/dil/src/main/java/org/assimbly/dil/validation/FtpValidator.java @@ -16,6 +16,9 @@ import java.io.IOException; import java.net.ConnectException; import java.net.UnknownHostException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; public class FtpValidator { @@ -56,7 +59,7 @@ private ValidationErrorMessage checkSFtpConnection(String userName, String passw if (privateKeyFileData != null && !privateKeyFileData.isEmpty()) { tempFile = File.createTempFile("temp", ""); - try (BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile))){ + try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(tempFile.toURI()), StandardCharsets.UTF_8)){ writer.write(privateKeyFileData); } jsch.addIdentity(tempFile.getAbsolutePath()); diff --git a/dil/src/main/java/org/assimbly/dil/validation/HttpsCertificateValidator.java b/dil/src/main/java/org/assimbly/dil/validation/HttpsCertificateValidator.java index 0f2a1538..e328f87a 100755 --- a/dil/src/main/java/org/assimbly/dil/validation/HttpsCertificateValidator.java +++ b/dil/src/main/java/org/assimbly/dil/validation/HttpsCertificateValidator.java @@ -15,9 +15,9 @@ public class HttpsCertificateValidator implements CertificateRetriever { - static private List trustStores = new ArrayList<>(); - static private FileBasedTrustStore customTrustStore; - static private HttpClient httpClient; + private List trustStores = new ArrayList<>(); + private FileBasedTrustStore customTrustStore; + private static HttpClient httpClient; /** * Checks if the certificate of the given HTTPS url is valid or not. @@ -44,7 +44,7 @@ public ValidationResult validate(String httpsUrlString) { req.setConfig(reqConfig); try { - HttpResponse response = httpClient.execute(req); + httpClient.execute(req); } catch (SSLException e) { return new ValidationResult(ValidationResultStatus.INVALID, getRootCause(e).getMessage()); } catch (IOException e) { @@ -99,7 +99,7 @@ public enum ValidationResultStatus { VALID, INVALID, UNKNOWN } - public class ValidationResult { + public static class ValidationResult { private final ValidationResultStatus validationResultStatus; private final String message; diff --git a/dil/src/main/java/org/assimbly/dil/validation/XsltValidator.java b/dil/src/main/java/org/assimbly/dil/validation/XsltValidator.java index 0111117f..5b76a652 100755 --- a/dil/src/main/java/org/assimbly/dil/validation/XsltValidator.java +++ b/dil/src/main/java/org/assimbly/dil/validation/XsltValidator.java @@ -53,7 +53,7 @@ private Source getXsltSource(String url, String xsltBody) throws TransformerExce } } - private class ValidationErrorListener implements ErrorListener { + private static class ValidationErrorListener implements ErrorListener { protected final List errors = new ArrayList<>(); diff --git a/dil/src/main/java/org/assimbly/dil/validation/expressions/JsonPathValidator.java b/dil/src/main/java/org/assimbly/dil/validation/expressions/JsonPathValidator.java index 2e7e1ed0..69534dba 100644 --- a/dil/src/main/java/org/assimbly/dil/validation/expressions/JsonPathValidator.java +++ b/dil/src/main/java/org/assimbly/dil/validation/expressions/JsonPathValidator.java @@ -11,7 +11,7 @@ public class JsonPathValidator implements Validator { @Override public ValidationErrorMessage validate(Expression expression){ try { - JsonPath path = JsonPath.compile(expression.getExpression()); + JsonPath.compile(expression.getExpression()); } catch(InvalidPathException e) { if(expression.getName() == null) { return new ValidationErrorMessage(e.getMessage()); diff --git a/dil/src/main/java/org/assimbly/dil/validation/https/CompositeTrustManager.java b/dil/src/main/java/org/assimbly/dil/validation/https/CompositeTrustManager.java index a888597b..70acef0d 100755 --- a/dil/src/main/java/org/assimbly/dil/validation/https/CompositeTrustManager.java +++ b/dil/src/main/java/org/assimbly/dil/validation/https/CompositeTrustManager.java @@ -77,6 +77,6 @@ public X509Certificate[] getAcceptedIssuers() { acceptedIssuers.addAll(Arrays.asList(trustManager.getAcceptedIssuers())); } - return acceptedIssuers.toArray(new X509Certificate[acceptedIssuers.size()]); + return acceptedIssuers.toArray(new X509Certificate[0]); } } diff --git a/dil/src/main/java/org/assimbly/dil/validation/https/FileBasedTrustStore.java b/dil/src/main/java/org/assimbly/dil/validation/https/FileBasedTrustStore.java index dd73eb44..3560ca0b 100755 --- a/dil/src/main/java/org/assimbly/dil/validation/https/FileBasedTrustStore.java +++ b/dil/src/main/java/org/assimbly/dil/validation/https/FileBasedTrustStore.java @@ -10,6 +10,8 @@ import java.io.FileOutputStream; import java.io.IOException; import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Paths; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.SecureRandom; @@ -37,7 +39,7 @@ public void setPassword(String password) { public KeyStore loadTrustStore() throws KeyStoreException, IOException { try { KeyStore trustStore = KeyStore.getInstance(type); - trustStore.load(new FileInputStream(path), password.toCharArray()); + trustStore.load(Files.newInputStream(Paths.get(path)), password.toCharArray()); return trustStore; } catch (IOException e) { @@ -53,7 +55,7 @@ public void addCertificateEntry(String alias, Certificate certificate) throws Ke try { synchronized (this) { - trustStore.store(new FileOutputStream(path), password.toCharArray()); + trustStore.store(Files.newOutputStream(Paths.get(path)), password.toCharArray()); } } catch (IOException e) { throw e; diff --git a/dil/src/main/resources/transform-to-dil.xsl b/dil/src/main/resources/transform-to-dil.xsl index b68e27b5..d789bc80 100644 --- a/dil/src/main/resources/transform-to-dil.xsl +++ b/dil/src/main/resources/transform-to-dil.xsl @@ -175,7 +175,6 @@ - diff --git a/integration/pom.xml b/integration/pom.xml index 4ce19b6e..3885eb6b 100644 --- a/integration/pom.xml +++ b/integration/pom.xml @@ -4,7 +4,7 @@ runtime org.assimbly - 4.0.0 + 4.0.1 integration diff --git a/integration/src/main/java/org/assimbly/integration/impl/BaseIntegration.java b/integration/src/main/java/org/assimbly/integration/impl/BaseIntegration.java index 11ac6e4d..c1ff3b9b 100644 --- a/integration/src/main/java/org/assimbly/integration/impl/BaseIntegration.java +++ b/integration/src/main/java/org/assimbly/integration/impl/BaseIntegration.java @@ -34,12 +34,8 @@ public abstract class BaseIntegration implements Integration { private List> properties = new ArrayList<>(); private TreeMap flowProperties; - private List> connections = new ArrayList<>(); - private TreeMap configuredFlows = new TreeMap<>(); - //configuration are strings - private String configuration; private String flowConfiguration; private Properties encryptionProperties; diff --git a/integration/src/main/java/org/assimbly/integration/impl/CamelIntegration.java b/integration/src/main/java/org/assimbly/integration/impl/CamelIntegration.java index 113ad946..16797a66 100644 --- a/integration/src/main/java/org/assimbly/integration/impl/CamelIntegration.java +++ b/integration/src/main/java/org/assimbly/integration/impl/CamelIntegration.java @@ -99,14 +99,12 @@ public class CamelIntegration extends BaseIntegration { - protected Logger log = LoggerFactory.getLogger(getClass()); - private static String BROKER_HOST = "ASSIMBLY_BROKER_HOST"; private static String BROKER_PORT = "ASSIMBLY_BROKER_PORT"; private CamelContext context; - private static boolean started = false; - private final int stopTimeout = 10; + private boolean started; + private final static int stopTimeout = 10; private ServiceStatus status; private String flowStatus; private final MetricRegistry metricRegistry = new MetricRegistry(); @@ -116,7 +114,7 @@ public class CamelIntegration extends BaseIntegration { private RouteController routeController; private ManagedCamelContext managed; private Properties encryptionProperties; - private boolean watchDeployDirectoryInitialized = false; + private boolean watchDeployDirectoryInitialized; private TreeMap props; private TreeMap confFiles = new TreeMap(); private String loadReport; @@ -138,8 +136,15 @@ public final void init(boolean useDefaultSettings) throws Exception { //setting tracing standby to true, so it can be enabled during runtime context.setTracingStandby(true); + //load settings into a separate thread if(useDefaultSettings){ - setDefaultSettings(); + new Thread(() -> { + try { + setDefaultSettings(); + } catch (Exception e) { + throw new RuntimeException(e); + } + }).start(); } //set management tasks @@ -331,7 +336,7 @@ private List getKamelets() throws IOException { classpathNames = scanResult.getAllResources().getPaths(); } - if(classpathNames != null || classpathNames.isEmpty()){ + if(classpathNames != null && !classpathNames.isEmpty()){ kamelets.addAll(classpathNames); } @@ -713,7 +718,7 @@ public String setFlowId(String filename, String configuration) throws Exception String flowId = null; - String configurationUTF8 = new String(configuration.getBytes("UTF-8")); + String configurationUTF8 = new String(configuration.getBytes(StandardCharsets.UTF_8),StandardCharsets.UTF_8); if(IntegrationUtil.isXML(configurationUTF8)) { Document doc = DocConverter.convertStringToDoc(configurationUTF8); @@ -838,7 +843,16 @@ public String addFlow(TreeMap props) { //create connections & install dependencies if needed createConnections(props); - return loadFlow(props); + FlowLoader flow = new FlowLoader(props); + + flow.addRoutesToCamelContext(context); + loadReport = flow.getReport(); + + if(!flow.isFlowLoaded()){ + return "error"; + } + + return "started"; }catch (Exception e){ log.error("add flow failed: ", e); @@ -905,21 +919,6 @@ public void createConnections(TreeMap props) throws Exception { } } - public String loadFlow(final TreeMap props) throws Exception { - - FlowLoader flow = new FlowLoader(props); - flow.updateRoutesToCamelContext(context); - - loadReport = flow.getReport(); - - if(!flow.isFlowLoaded()){ - return "error"; - } - - return "started"; - - } - public void addEventNotifier(EventNotifier eventNotifier) throws Exception { context.getManagementStrategy().addEventNotifier(eventNotifier); } @@ -1093,7 +1092,7 @@ public String routesFlow(String flowId, String mediaType, String configuration) props.put("flow.type","esb"); props.put("route.1.route", configuration); - loadFlow(props); + addFlow(props); String status = startFlow(flowId); @@ -1153,7 +1152,7 @@ public String startFlow(String id) { status = startStep(step); } - if (status.isStarted()) { + if (status!= null && status.isStarted()) { finishFlowActionReport(id, "start","Started flow successfully","info"); }else{ finishFlowActionReport(id, "error","Failed starting flow","error"); @@ -1692,8 +1691,6 @@ public String getStepMessages(String flowId, String stepId, String mediaType) th JSONObject json = new JSONObject(); JSONObject step = new JSONObject(); - List routes = getRoutesByFlowId(flowId); - step.put("id",flowId); step.put("total",totalMessages); step.put("completed",completedMessages); @@ -1807,8 +1804,12 @@ public String getCamelRouteConfiguration(String id, String mediaType) throws Exc return camelRouteConfiguration; } + + //to do public String getAllCamelRoutesConfiguration(String mediaType) throws Exception { + //if used this path needs to be updated + /* File directory = new File("C:/messages/templates"); java.util.Collection files = FileUtils.listFiles(directory, null, false); @@ -1844,6 +1845,8 @@ public String getAllCamelRoutesConfiguration(String mediaType) throws Exception } + */ + /* ManagedCamelContextMBean managedCamelContext = managed.getManagedCamelContext(); @@ -1861,7 +1864,7 @@ public String getAllCamelRoutesConfiguration(String mediaType) throws Exception camelRoutesConfiguration = DocConverter.convertXmlToYaml(camelRoutesConfiguration); }*/ - String camelRoutesConfiguration = "{x}"; + String camelRoutesConfiguration = "{not available yet}"; return camelRoutesConfiguration; @@ -2848,7 +2851,10 @@ private void setSSLContext() throws Exception { File securityPath = new File(baseDir + "/security"); if (!securityPath.exists()) { - securityPath.mkdirs(); + boolean securityPathCreated = securityPath.mkdirs(); + if(!securityPathCreated){ + throw new Exception("Directory: " + securityPath.getAbsolutePath() + " cannot be create to store keystore files"); + } } String keyStorePath = baseDir2 + "/security/keystore.jks"; @@ -2872,7 +2878,7 @@ private void setSSLContext() throws Exception { try { SSLContext sslContext = sslContextParameters.createSSLContext(context); - SSLEngine engine = sslContext.createSSLEngine(); + sslContext.createSSLEngine(); }catch (Exception e){ log.error("Can't set SSL context for certificate keystore. TLS/SSL certificates are not available. Reason: " + e.getMessage()); } diff --git a/integrationRest/pom.xml b/integrationRest/pom.xml index a67d1336..1ea8bc34 100644 --- a/integrationRest/pom.xml +++ b/integrationRest/pom.xml @@ -6,7 +6,7 @@ runtime org.assimbly - 4.0.0 + 4.0.1 integration-rest diff --git a/integrationRest/src/main/java/org/assimbly/integrationrest/CertificateManagerRuntime.java b/integrationRest/src/main/java/org/assimbly/integrationrest/CertificateManagerRuntime.java index d321e3af..6a29ac6c 100644 --- a/integrationRest/src/main/java/org/assimbly/integrationrest/CertificateManagerRuntime.java +++ b/integrationRest/src/main/java/org/assimbly/integrationrest/CertificateManagerRuntime.java @@ -16,6 +16,7 @@ import java.io.ByteArrayInputStream; import java.io.InputStream; import java.net.URISyntaxException; +import java.nio.charset.StandardCharsets; import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.SecureRandom; @@ -123,7 +124,7 @@ public ResponseEntity uploadCertificate(@Parameter(hidden = true) @Reque }else{ //create certificate from String CertificateFactory cf = CertificateFactory.getInstance("X.509"); - InputStream certificateStream = new ByteArrayInputStream(certificate.getBytes()); + InputStream certificateStream = new ByteArrayInputStream(certificate.getBytes(StandardCharsets.UTF_8)); cert = cf.generateCertificate(certificateStream); } diff --git a/integrationRest/src/main/java/org/assimbly/integrationrest/IntegrationRuntime.java b/integrationRest/src/main/java/org/assimbly/integrationrest/IntegrationRuntime.java index 70029172..7092877b 100644 --- a/integrationRest/src/main/java/org/assimbly/integrationrest/IntegrationRuntime.java +++ b/integrationRest/src/main/java/org/assimbly/integrationrest/IntegrationRuntime.java @@ -340,6 +340,8 @@ public ResponseEntity addCollectorConfigurations(@Parameter(hidden = tru log.info("Add collectors"); + log.info("Collectors configuration: \n\n" + configuration + "\n"); + try { String result = integration.addCollectorsConfiguration(mediaType, configuration); if(!result.equalsIgnoreCase("configured")){ diff --git a/integrationRest/src/main/java/org/assimbly/integrationrest/ValidationRuntime.java b/integrationRest/src/main/java/org/assimbly/integrationrest/ValidationRuntime.java index f67a72e6..56110f88 100644 --- a/integrationRest/src/main/java/org/assimbly/integrationrest/ValidationRuntime.java +++ b/integrationRest/src/main/java/org/assimbly/integrationrest/ValidationRuntime.java @@ -23,6 +23,7 @@ import javax.print.attribute.standard.Media; import java.io.ByteArrayOutputStream; +import java.nio.charset.StandardCharsets; import java.util.AbstractMap; import java.util.HashMap; import java.util.List; @@ -67,7 +68,7 @@ public ResponseEntity validateCron( final ByteArrayOutputStream out = new ByteArrayOutputStream(); final ObjectMapper mapper = new ObjectMapper(); mapper.writeValue(out, cronResp); - return ResponseUtil.createSuccessResponse(integrationId, mediaType, "/validation/{integrationId}/cron", out.toString(), plainResponse); + return ResponseUtil.createSuccessResponse(integrationId, mediaType, "/validation/{integrationId}/cron", out.toString(StandardCharsets.UTF_8), plainResponse); } else { return ResponseUtil.createNoContentResponse(integrationId, mediaType); } @@ -99,7 +100,7 @@ public ResponseEntity validateCertificate( final ByteArrayOutputStream out = new ByteArrayOutputStream(); final ObjectMapper mapper = new ObjectMapper(); mapper.writeValue(out, certificateResp); - return ResponseUtil.createSuccessResponse(integrationId, mediaType, "/validation/{integrationId}/certificate", out.toString(), plainResponse); + return ResponseUtil.createSuccessResponse(integrationId, mediaType, "/validation/{integrationId}/certificate", out.toString(StandardCharsets.UTF_8), plainResponse); } else { return ResponseUtil.createSuccessResponse(integrationId, mediaType, "/validation/{integrationId}/certificate", "", plainResponse); } @@ -130,7 +131,7 @@ public ResponseEntity validateUrl( final ByteArrayOutputStream out = new ByteArrayOutputStream(); final ObjectMapper mapper = new ObjectMapper(); mapper.writeValue(out, urlResp); - return ResponseUtil.createSuccessResponse(integrationId, mediaType, "/validation/{integrationId}/url", out.toString(), plainResponse); + return ResponseUtil.createSuccessResponse(integrationId, mediaType, "/validation/{integrationId}/url", out.toString(StandardCharsets.UTF_8), plainResponse); } else { return ResponseUtil.createNoContentResponse(integrationId, mediaType); } @@ -168,7 +169,7 @@ public ResponseEntity validateExpression( final ByteArrayOutputStream out = new ByteArrayOutputStream(); final ObjectMapper mapper = new ObjectMapper(); mapper.writeValue(out, expressionResp); - return ResponseUtil.createSuccessResponse(integrationId, mediaType, "/validation/{integrationId}/expression", out.toString(), plainResponse); + return ResponseUtil.createSuccessResponse(integrationId, mediaType, "/validation/{integrationId}/expression", out.toString(StandardCharsets.UTF_8), plainResponse); } else { return ResponseUtil.createNoContentResponse(integrationId, mediaType); } @@ -207,7 +208,7 @@ public ResponseEntity validateFtp( final ByteArrayOutputStream out = new ByteArrayOutputStream(); final ObjectMapper mapper = new ObjectMapper(); mapper.writeValue(out, ftpResp); - return ResponseUtil.createSuccessResponse(integrationId, mediaType, "/validation/{integrationId}/ftp", out.toString(), plainResponse); + return ResponseUtil.createSuccessResponse(integrationId, mediaType, "/validation/{integrationId}/ftp", out.toString(StandardCharsets.UTF_8), plainResponse); } else { return ResponseUtil.createNoContentResponse(integrationId, mediaType); } @@ -289,10 +290,10 @@ public ResponseEntity validateScript( final ObjectMapper mapper = new ObjectMapper(); if(scriptResp.getCode() == 1) { mapper.writeValue(out, scriptResp); - return ResponseUtil.createSuccessResponse(integrationId, mediaType, "/validation/{integrationId}/script", out.toString(), plainResponse); + return ResponseUtil.createSuccessResponse(integrationId, mediaType, "/validation/{integrationId}/script", out.toString(StandardCharsets.UTF_8), plainResponse); } else { mapper.writeValue(out, new BadRequestResponse(scriptResp.getResult())); - return ResponseUtil.createFailureResponse(integrationId, mediaType, "/validation/{integrationId}/script", out.toString(), plainResponse); + return ResponseUtil.createFailureResponse(integrationId, mediaType, "/validation/{integrationId}/script", out.toString(StandardCharsets.UTF_8), plainResponse); } } else { return ResponseUtil.createFailureResponse(integrationId, mediaType, "/validation/{integrationId}/script", "", plainResponse); @@ -330,29 +331,32 @@ public ResponseEntity validateXslt( @RequestBody String body ) throws Exception { - plainResponse = true; - try { + + plainResponse = true; + HashMap paramList = null; + if(body!=null){ paramList = new ObjectMapper().readValue(body, new TypeReference>(){}); - } - integration = integrationRuntime.getIntegration(); - List expressionResp = integration.validateXslt( - paramList.get("xsltUrl"), - paramList.get("xsltBody") - ); + integration = integrationRuntime.getIntegration(); + List expressionResp = integration.validateXslt( + paramList.get("xsltUrl"), + paramList.get("xsltBody") + ); + + if(expressionResp!=null) { + final ByteArrayOutputStream out = new ByteArrayOutputStream(); + final ObjectMapper mapper = new ObjectMapper(); + mapper.writeValue(out, expressionResp); + return ResponseUtil.createSuccessResponse(integrationId, mediaType, "/validation/{integrationId}/xslt", out.toString(StandardCharsets.UTF_8), plainResponse); + } - if(expressionResp!=null) { - final ByteArrayOutputStream out = new ByteArrayOutputStream(); - final ObjectMapper mapper = new ObjectMapper(); - mapper.writeValue(out, expressionResp); - return ResponseUtil.createSuccessResponse(integrationId, mediaType, "/validation/{integrationId}/xslt", out.toString(), plainResponse); - } else { - return ResponseUtil.createNoContentResponse(integrationId, mediaType); } + return ResponseUtil.createNoContentResponse(integrationId, mediaType); + } catch (Exception e) { log.error("Error",e); return ResponseUtil.createFailureResponse(integrationId, mediaType, "/validation/{integrationId}/xslt", e.getMessage(), plainResponse); diff --git a/integrationRest/src/main/java/org/assimbly/integrationrest/event/FailureCollector.java b/integrationRest/src/main/java/org/assimbly/integrationrest/event/FailureCollector.java index 25d727bb..f3cf4fd7 100644 --- a/integrationRest/src/main/java/org/assimbly/integrationrest/event/FailureCollector.java +++ b/integrationRest/src/main/java/org/assimbly/integrationrest/event/FailureCollector.java @@ -50,7 +50,7 @@ public void notify(CamelEvent event) throws Exception { ExchangeFailureHandledEvent exchangeFailedEvent = (ExchangeFailureHandledEvent) event; flowId = exchangeFailedEvent.getExchange().getFromRouteId(); - int flowIdPart = flowId.indexOf("-"); //this finds the first occurrence of "." + int flowIdPart = flowId.indexOf('-'); //this finds the first occurrence of "." if (flowIdPart != -1) { @@ -68,7 +68,7 @@ public void notify(CamelEvent event) throws Exception { ExchangeFailedEvent exchangeFailedEvent = (ExchangeFailedEvent) event; flowId = exchangeFailedEvent.getExchange().getFromRouteId(); - int flowIdPart = flowId.indexOf("-"); //this finds the first occurrence of "." + int flowIdPart = flowId.indexOf('-'); //this finds the first occurrence of "." if (flowIdPart != -1) { diff --git a/integrationRest/src/test/java/org/assimbly/integrationrest/utils/CamelContextUtil.java b/integrationRest/src/test/java/org/assimbly/integrationrest/utils/CamelContextUtil.java index 1e9a3ff0..aa2ff298 100644 --- a/integrationRest/src/test/java/org/assimbly/integrationrest/utils/CamelContextUtil.java +++ b/integrationRest/src/test/java/org/assimbly/integrationrest/utils/CamelContextUtil.java @@ -17,29 +17,29 @@ static public Properties buildExample() { UUID randomContextPath = UUID.randomUUID(); StringBuffer camelContextBuf = new StringBuffer(); - camelContextBuf.append(""); - camelContextBuf.append(""); - camelContextBuf.append(""); - camelContextBuf.append(""); - camelContextBuf.append(""); - camelContextBuf.append(""); - camelContextBuf.append("java.lang.Exception"); - camelContextBuf.append(""); - camelContextBuf.append(""); - camelContextBuf.append(""); - camelContextBuf.append(""); - camelContextBuf.append(""); - camelContextBuf.append(""); - camelContextBuf.append(""); - camelContextBuf.append(""); - camelContextBuf.append(""); - camelContextBuf.append(""); - camelContextBuf.append(""); - camelContextBuf.append("sdfgsdfgdsfg"); - camelContextBuf.append(""); - camelContextBuf.append(""); - camelContextBuf.append(""); - camelContextBuf.append(""); + camelContextBuf.append("") + .append("") + .append("") + .append("") + .append("") + .append("") + .append("java.lang.Exception") + .append("") + .append("") + .append("") + .append("") + .append("") + .append("") + .append("") + .append("") + .append("") + .append("") + .append("") + .append("sdfgsdfgdsfg") + .append("") + .append("") + .append("") + .append(""); props.setProperty(Field.id.name(), "ID_63ee34e25827222b3d000022"); props.setProperty(Field.routeId1.name(), "0bc12100-ae01-11ed-8f2a-c39ccdb17c7e"); diff --git a/integrationRest/src/test/java/org/assimbly/integrationrest/utils/MavenUtil.java b/integrationRest/src/test/java/org/assimbly/integrationrest/utils/MavenUtil.java index c46b000b..936a47ad 100644 --- a/integrationRest/src/test/java/org/assimbly/integrationrest/utils/MavenUtil.java +++ b/integrationRest/src/test/java/org/assimbly/integrationrest/utils/MavenUtil.java @@ -4,16 +4,20 @@ import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; +import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; public class MavenUtil { public static String getModelVersion() throws Exception { String version = null; File pomFile = new File("pom.xml"); - try (FileReader reader = new FileReader(pomFile)) { + try (BufferedReader reader = Files.newBufferedReader(Paths.get(pomFile.toURI()), StandardCharsets.UTF_8)) { MavenXpp3Reader xpp3Reader = new MavenXpp3Reader(); Model model = xpp3Reader.read(reader); version = model.getModelVersion(); diff --git a/pom.xml b/pom.xml index 6eabc110..087dd179 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ org.assimbly runtime - 4.0.0 + 4.0.1 broker @@ -24,7 +24,7 @@ 11 UTF-8 ${project.basedir} - 4.0.0 + 4.0.1 2.2 2.7.12 3.9.2