Skip to content

Commit

Permalink
groovy: add missing methods from route builder / builder support
Browse files Browse the repository at this point in the history
  • Loading branch information
lburgazzoli committed Jul 8, 2019
1 parent ad8bb2e commit 0ea2447
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,22 @@
*/
package org.apache.camel.k.groovy.dsl

import org.apache.camel.CamelContext
import org.apache.camel.Exchange
import org.apache.camel.Predicate
import org.apache.camel.Processor
import org.apache.camel.builder.RouteBuilder
import org.apache.camel.k.jvm.dsl.Components
import org.apache.camel.model.ProcessorDefinition
import org.apache.camel.model.*
import org.apache.camel.spi.Registry

class IntegrationConfiguration {
final CamelContext context
class IntegrationConfiguration extends org.apache.camel.builder.BuilderSupport {
final Registry registry
final Components components
final RouteBuilder builder

IntegrationConfiguration(RouteBuilder builder) {
this.context = builder.getContext()
super(builder.context)

this.registry = this.context.registry
this.components = new Components(this.context)
this.builder = builder
Expand All @@ -50,10 +49,6 @@ class IntegrationConfiguration {
callable.call()
}

ProcessorDefinition from(String endpoint) {
return builder.from(endpoint)
}

def processor(@DelegatesTo(Exchange) Closure<?> callable) {
return new Processor() {
@Override
Expand All @@ -73,4 +68,32 @@ class IntegrationConfiguration {
}
}
}

ProcessorDefinition from(String endpoint) {
return builder.from(endpoint)
}

OnExceptionDefinition onException(Class<? extends Throwable> exception) {
return builder.onException(exception)
}

OnCompletionDefinition onCompletion() {
return builder.onCompletion()
}

InterceptDefinition intercept() {
return builder.intercept()
}

InterceptFromDefinition interceptFrom() {
return builder.interceptFrom()
}

InterceptFromDefinition interceptFrom(String uri) {
return builder.interceptFrom(uri)
}

InterceptSendToEndpointDefinition interceptSendToEndpoint(String uri) {
return builder.interceptSendToEndpoint(uri)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import org.apache.camel.component.seda.SedaComponent
import org.apache.camel.k.Runtime
import org.apache.camel.k.jvm.ApplicationRuntime
import org.apache.camel.k.listener.RoutesConfigurer
import org.apache.camel.processor.FatalFallbackErrorHandler
import org.apache.camel.processor.SendProcessor
import org.apache.camel.processor.channel.DefaultChannel
import spock.lang.Specification

import java.util.concurrent.atomic.AtomicInteger
Expand Down Expand Up @@ -86,13 +89,37 @@ class IntegrationTest extends Specification {
runtime.stop()
})

runtime.run()
runtime.run()
then:
sedaSize == 1234
sedaConsumers == 12
mySedaSize == 4321
mySedaConsumers == 21
format != null
}

def "load integration with error handler"() {
given:
def onExceptions = []
when:
def runtime = new ApplicationRuntime()
runtime.addListener(RoutesConfigurer.forRoutes('classpath:routes-with-error-handler.groovy'))
runtime.addListener(Runtime.Phase.Started, {
it.camelContext.routes?.size() == 1
it.camelContext.routes[0].routeContext.getOnException('my-on-exception') != null

onExceptions << it.camelContext.routes[0].routeContext.getOnException('my-on-exception')

runtime.stop()
})
runtime.run()
then:
sedaSize == 1234
sedaConsumers == 12
mySedaSize == 4321
mySedaConsumers == 21
format != null
onExceptions.size() == 1
onExceptions[0] instanceof FatalFallbackErrorHandler

def eh = onExceptions[0] as FatalFallbackErrorHandler
def ch = eh.processor as DefaultChannel

ch.output instanceof SendProcessor
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/

onException(IllegalArgumentException.class)
.id('my-on-exception')
.to('log:exception')

from('timer:tick')
.to('log:info')

0 comments on commit 0ea2447

Please sign in to comment.