Skip to content

Commit

Permalink
Improved examples
Browse files Browse the repository at this point in the history
  • Loading branch information
milux committed Nov 27, 2023
1 parent 3ff5fe1 commit 6c0daaa
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class ArtifactRequestProcessor : Processor {
LOG.debug("Constructing RejectionMessage for requested artifact: {}", rejectionReason)
}
RejectionMessageBuilder()
._correlationMessage_(artifactRequestMessage.correlationMessage)
._correlationMessage_(artifactRequestMessage.id)
._rejectionReason_(rejectionReason)
.let {
if (LOG.isDebugEnabled) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*-
* ========================LICENSE_START=================================
* camel-processors
* %%
* Copyright (C) 2023 Fraunhofer AISEC
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =========================LICENSE_END==================================
*/
package de.fhg.aisec.ids.camel.processors

import org.apache.camel.Exchange
import org.apache.camel.Processor
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component

/**
* This processor configures the shutdown timeout of the ShutdownStrategy in this context.
*/
@Component("shutdownConfigurationProcessor")
class ShutdownConfigurationProcessor : Processor {
override fun process(exchange: Exchange) {
if (LOG.isDebugEnabled) {
LOG.debug("[IN] ${this::class.java.simpleName}")
}
exchange.getProperty("timeout-seconds")?.let {
val seconds = it.toString().toLong()
if (LOG.isDebugEnabled) {
LOG.debug("Setting shutdown timeout to {} seconds...", seconds)
}
exchange.context.shutdownStrategy.timeout = seconds
} ?: LOG.warn("Property \"timeout-seconds\" not found, no change will be performed.")
}

companion object {
private val LOG = LoggerFactory.getLogger(ShutdownConfigurationProcessor::class.java)
}
}
Binary file modified examples/src/main/resources/etc/settings.mapdb
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,22 @@
</camel:sslContextParameters>

<camelContext xmlns="http://camel.apache.org/schema/spring">
<errorHandler id="infErrorHandler" type="DeadLetterChannel" deadLetterUri="log:dead?level=ERROR">
<redeliveryPolicy maximumRedeliveries="-1" redeliveryDelay="0"/>
<errorHandler id="restartErrorHandler" type="DeadLetterChannel" deadLetterUri="direct:errorHandling">
<redeliveryPolicy maximumRedeliveries="0" redeliveryDelay="0" />
</errorHandler>

<route errorHandlerRef="infErrorHandler">
<route id="errorHandlerRoute">
<from uri="direct:errorHandling"/>
<log loggingLevel="ERROR" message="Error occured, try to stop route artifactUpdate and restart route contractNegotiation..."/>
<setProperty name="timeout-seconds">
<constant>10</constant>
</setProperty>
<process ref="shutdownConfigurationProcessor"/>
<to uri="controlbus:route?routeId=artifactRequestRoute&amp;action=stop"/>
<to uri="controlbus:route?routeId=contractNegotiationRoute&amp;action=restart"/>
</route>

<route id="contractNegotiationRoute" errorHandlerRef="restartErrorHandler">
<from uri="timer://contractRequest?repeatCount=1" />
<setProperty name="artifactUri">
<constant>https://example.com/some_artifact</constant>
Expand All @@ -43,21 +54,19 @@
<to uri="controlbus:route?routeId=artifactRequestRoute&amp;action=start"/>
</when>
<otherwise>
<log loggingLevel="ERROR" message="Expected MessageProcessedNotificationMessage, but received:\n${body}\n### Header: ###\n${headers[ids-header]}"/>
<removeHeader name="ids-header" />
<setBody><simple>${null}</simple></setBody>
<log loggingLevel="ERROR" message="Expected MessageProcessedNotificationMessage, but received ${exchangeProperty.ids-type}."/>
<throwException exceptionType="java.lang.RuntimeException"/>
</otherwise>
</choice>
</when>
<otherwise>
<log loggingLevel="ERROR" message="Expected ContractResponseMessage, but received:\n${body}\n### Header: ###\n${headers[ids-header]}"/>
<removeHeader name="ids-header" />
<setBody><simple>${null}</simple></setBody>
<log loggingLevel="ERROR" message="Expected ContractResponseMessage, but received ${exchangeProperty.ids-type}."/>
<throwException exceptionType="java.lang.RuntimeException"/>
</otherwise>
</choice>
</route>

<route id="artifactRequestRoute" autoStartup="false">
<route id="artifactRequestRoute" autoStartup="false" errorHandlerRef="restartErrorHandler">
<from uri="timer://tenSecondsTimer?fixedRate=true&amp;period=10000"/>
<setProperty name="artifactUri">
<constant>https://example.com/some_artifact</constant>
Expand All @@ -72,7 +81,8 @@
<to uri="http://echo-server:80"/>
</when>
<otherwise>
<log loggingLevel="ERROR" message="Expected ArtifactResponseMessage, but received:\n${body}\n### Header: ###\n${headers[ids-header]}"/>
<log loggingLevel="ERROR" message="Expected ArtifactResponseMessage, but received ${exchangeProperty.ids-type}."/>
<throwException exceptionType="java.lang.RuntimeException"/>
</otherwise>
</choice>
</route>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
</setBody>
</when>
<otherwise>
<log message="Unhandled or forbidden artifact ${exchangeProperty.requested-artifact} requested" loggingLevel="ERROR" />
<log message="Unhandled or forbidden artifact &quot;${exchangeProperty.requested-artifact}&quot; requested" loggingLevel="ERROR" />
</otherwise>
</choice>
</when>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<camelContext xmlns="http://camel.apache.org/schema/spring">
<route id="idscp2ReceiverClient">
<from uri="idscp2client://tc-core-server:29292?sslContextParameters=#clientSslContext"/>
<from uri="idscp2client://tc-core-server:29292?sslContextParameters=#clientSslContext&amp;maxRetries=1000000000"/>
<log message="Client received: ${body} (Header: ${headers[ids-header]})"/>
<!-- Prevents the client consumer from sending the message back to the server -->
<removeHeader name="ids-header"/>
Expand Down

0 comments on commit 6c0daaa

Please sign in to comment.