Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove support for java class loader #1052

Merged
merged 2 commits into from
Nov 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ Camel K supports multiple languages for writing integrations:
[options="header"]
|=======================
| Language | Description
| Java | Both integrations in source `.java` files or compiled `.class` file can be run.
| Java | Integrations written in plain Java DSL are supported.
| XML | Integrations written in plain XML DSL are supported (Spring XML or Blueprint not supported).
| Groovy | Groovy `.groovy` files are supported (experimental).
| JavaScript | JavaScript `.js` files are supported (experimental).
Expand Down
163 changes: 117 additions & 46 deletions docs/modules/ROOT/pages/languages/groovy.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
= Writing Integrations in Groovy

An integration written in Groovy looks very similar to a Java one except it can leverages Groovy's language enhancements over Java:
An integration written in Groovy looks very similar to a Java one except it can leverages Groovy's language enhancements over Java such as closures:

[source,groovy]
----
Expand All @@ -9,89 +9,148 @@ from('timer:tick')
.to('log:info')
----

Camel K extends the Camel Java DSL making it easier to configure the context in which the integration runs using the top level _context_ block
== Configuring the Application

[source,groovy]
----
context {
// configure the context here
}
----

At the moment the enhanced DSL provides a way to bind items to the registry, to configure the components the context creates and some improvements over the REST DSL.

== Registry Configuration

The registry is accessible using the _registry_ block inside the _context_ one:
Camel K extends the Camel Java DSL making it easier to configure Camel's behavior using the top level _camel_ block

[source,groovy]
----
context {
registry {
bind "my-cache", Caffeine.newBuilder().build() // <1>
bind "my-processor", processor { // <2>
it.in.body = 'Hello Camel K!'
}
bind "my-predicate", predicate { // <3>
it.in.body != null
}
}
camel {
// configure camel here
}
----
<1> bind a bean to the context
<2> define a custom processor to be used later in the routes by ref
<3> define a custom predicate to be used later in the routes by ref


== Components Configuration

Components can be configured within the _components_ block inside the _context_ one:
The _camel_ block allows to configure the following Camel features:

- **Components**
+
[source,groovy]
----
context {
camel {
components {
'seda' { // <1>
seda { // <1>
queueSize = 1234
concurrentConsumers = 12
}

'log' { // <2>
log { // <2>
exchangeFormatter = {
'body ==> ' + it.in.body
} as org.apache.camel.spi.ExchangeFormatter
}

mySeda(SedaComponent) { // <3>
queueSize = 4321
concurrentConsumers = 21
}
}
}
----
<1> configure the properties of the component whit name _seda_
<2> configure the properties of the component whit name _log_

<3> creates and configure a component of type `SedaComponent` whose name is _mySeda_
+
Setting the property _exchangeFormatter_ looks a little ugly as you have to declare the type of your closure. For demonstration purpose we have created a Groovy extension module that simplify configuring the _exchangeFormatter_ so you can rewrite your DSL as

+
[source,groovy]
----
context {
camel {
components {
...

'log' {
log {
formatter {
'body ==> ' + it.in.body
}
}
}
}
----

+
which is much better.

+
[TIP]
====
You can provide your custom extensions by packaging them in a dependency you declare for your integration.
====

== Rest Endpoints
- **Languages **
+
[source,groovy]
----
camel {
languages {
language("bean") { // <1>
beanType = String.class
method = "toUpperCase"
}
myBean(BeanLanguage) { // <2>
beanType = String.class
method = "toLowerCase"
}
simple { // <3>
}
}
}
----
<1> configure the properties of the language whit name _bean_
<2> creates and configure a language of type `BeanLanguage` whose name is _myBean_
<3> configure the properties of the language whit name _simple_

- **DataFormats**
+
[source,groovy]
----
camel {
dataFormats {
dataFormat("json-jackson") { // <1>
unmarshalType = Map.class
prettyPrint = true
}
myJackson(JacksonDataFormat) { // <2>
unmarshalType = String.class
prettyPrint = false
}
csv { // <3>
}
}
}
----
<1> configure the properties of the data format whit name _json-jackson_
<2> creates and configure a data format of type `JacksonDataFormat` whose name is _myJackson_
<3> configure the properties of the data format whit name _csv_


== Beans

Beans can be bound to the _registry_ using a dedicated _bean DSL_ :

[source,groovy]
----
beans {
myCache = Caffeine.newBuilder().build() // <1>

myProcessor = processor { // <2>
it.in.body = 'Hello Camel K!'
}

myPredicate = predicate { // <3>
it.in.body != null
}

dataSource(org.apache.commons.dbcp2.BasicDataSource) { //<4>
driverClassName = "org.h2.Driver"
url = "jdbc:h2:mem:camel"
username = "sa"
password = ""
}
}
----
<1> define a bean
<2> define a custom processor
<3> define a custom predicate
<3> define a custom bean with name `dataSource` and type `org.apache.commons.dbcp2.BasicDataSource`


=== Rest Support

Integrations's REST endpoints can be configured using the top level _rest_ block:

Expand All @@ -103,10 +162,22 @@ rest {
port '9192'
}

path('/my/path') { // <2>
// standard Rest DSL
path('/my/path') {
get('/get') { // <2>
consumes 'application/json'
produces 'application/json'
to 'direct:get'
}
}

post { // <3>
path '/post'
consumes 'application/json'
produces 'application/json'
to 'direct:post'
}
}
----
<1> Configure the rest engine
<2> Configure the rest endpoint for the base path '/my/path'
<2> Configure the behavior of the method GET for the path '/my/path/get' and invoke the endpoint 'direct:get'
<2> Configure the behavior of the method POST for the path '/post' and invoke the endpoint 'direct:post'
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/languages/languages.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Camel K supports multiple languages for writing integrations:
| xref:languages/groovy.adoc[Groovy] | Groovy `.groovy` files are supported.
| xref:languages/kotlin.adoc[Kotlin] | Kotlin Script `.kts` files are supported.
| xref:languages/javascript.adoc[JavaScript] | JavaScript `.js` files are supported.
| xref:languages/java.adoc[Java] | Both integrations in source `.java` files or compiled `.class` file can be run.
| xref:languages/java.adoc[Java] | Integrations written in plain Java DSL are supported.
| xref:languages/xml.adoc[XML] | Integrations written in plain XML DSL are supported (Spring XML or Blueprint not supported).
|=======================

Expand Down
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdko
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/Rican7/retry v0.1.0/go.mod h1:FgOROf8P5bebcC1DS0PdOQiqGUridaZvikzUmkFW6gg=
github.com/alecthomas/jsonschema v0.0.0-20190122210438-a6952de1bbe6 h1:xadBCbc8D9mmkaNfCsEBHbIoCjbayJXJNsY1JjPjNio=
github.com/alecthomas/jsonschema v0.0.0-20190122210438-a6952de1bbe6/go.mod h1:qpebaTNSsyUn5rPSJMsfqEtDw71TTggXM6stUDI16HA=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
Expand Down Expand Up @@ -275,6 +276,7 @@ github.com/heketi/heketi v0.0.0-20181109135656-558b29266ce0/go.mod h1:bB9ly3Rchc
github.com/heketi/rest v0.0.0-20180404230133-aa6a65207413/go.mod h1:BeS3M108VzVlmAue3lv2WcGuPAX94/KN63MUURzbYSI=
github.com/heketi/tests v0.0.0-20151005000721-f3775cbcefd6/go.mod h1:xGMAM8JLi7UkZt1i4FQeQy0R2T8GLUwQhOP5M1gBhy4=
github.com/heketi/utils v0.0.0-20170317161834-435bc5bdfa64/go.mod h1:RYlF4ghFZPPmk2TC5REt5OFwvfb6lzxFWrTWB+qs28s=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/huandu/xstrings v1.2.0/go.mod h1:DvyZB1rfVYsBIigL8HwpZgxHwXozlTgGqn63UyNX5k4=
github.com/iancoleman/strcase v0.0.0-20180726023541-3605ed457bf7/go.mod h1:SK73tn/9oHe+/Y0h39VT4UCxmurVJkR5NA7kMEAOgSE=
Expand Down Expand Up @@ -372,12 +374,14 @@ github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn
github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.8.0 h1:VkHVNpR4iVnU8XQR6DBm8BqYjN7CRzw+xKUbVVbbW9w=
github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
github.com/onsi/gomega v0.0.0-20190113212917-5533ce8a0da3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.4.2-0.20180831124310-ae19f1b56d53/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
github.com/onsi/gomega v1.4.2/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.5.0 h1:izbySO9zDPmjJ8rDjLvkA2zJHIo+HkYXHnf7eN7SSyo=
github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/opencontainers/go-digest v0.0.0-20170106003457-a6d0ee40d420/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
Expand Down Expand Up @@ -414,6 +418,7 @@ github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/sftp v0.0.0-20160930220758-4d0e916071f6/go.mod h1:NxmoDg/QLVWluQDUYG7XBZTLUpKeFa8e3aMf1BfjyHk=
github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pquerna/cachecontrol v0.0.0-20171018203845-0dec1b30a021/go.mod h1:prYjPmNq4d1NPVmpShWobRqXY3q7Vp+80DqgxxUrUIA=
github.com/pquerna/ffjson v0.0.0-20180717144149-af8b230fcd20/go.mod h1:YARuvh7BUWHNhzDq2OM5tzR2RiCcN2D7sapiKyCel/M=
Expand Down Expand Up @@ -504,6 +509,7 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v0.0.0-20151208002404-e3a8ff8ce365/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/syndtr/gocapability v0.0.0-20160928074757-e7cb7fa329f4/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
github.com/technosophos/moniker v0.0.0-20180509230615-a5dbd03a2245/go.mod h1:O1c8HleITsZqzNZDjSNzirUGsMT0oGu9LhHKoJrqO+A=
Expand Down Expand Up @@ -687,6 +693,7 @@ gopkg.in/natefinch/lumberjack.v2 v2.0.0-20170531160350-a96e63847dc3/go.mod h1:l0
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
gopkg.in/square/go-jose.v2 v2.0.0-20180411045311-89060dee6a84/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/warnings.v0 v0.1.1/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0/go.mod h1:WDnlLJ4WF5VGsH/HVa3CI79GS0ol3YnhVnKP89i0kNg=
Expand All @@ -701,6 +708,7 @@ honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
k8s.io/api v0.0.0-20190918195907-bd6ac527cfd2 h1:bkwe5LsuANqyOwsBng5Qc4S91D2Tv0JHctAztt3YTQs=
k8s.io/api v0.0.0-20190918195907-bd6ac527cfd2/go.mod h1:AOxZTnaXR/xiarlQL0JUfwQPxjmKDvVYoRp58cA7lUo=
k8s.io/apiextensions-apiserver v0.0.0-20190918201827-3de75813f604 h1:Kl/sh+wWzYK2hWFZtwvuFECup1SbE2kXfMnhGZsoO5M=
k8s.io/apiextensions-apiserver v0.0.0-20190918201827-3de75813f604/go.mod h1:7H8sjDlWQu89yWB3FhZfsLyRCRLuoXoCoY5qtwW1q6I=
k8s.io/apimachinery v0.0.0-20190817020851-f2f3a405f61d h1:7Kns6qqhMAQWvGkxYOLSLRZ5hJO0/5pcE5lPGP2fxUw=
k8s.io/apimachinery v0.0.0-20190817020851-f2f3a405f61d/go.mod h1:3jediapYqJ2w1BFw7lAZPCx7scubsTfosqHkhXCWJKw=
Expand Down Expand Up @@ -772,6 +780,7 @@ sigs.k8s.io/controller-tools v0.2.2/go.mod h1:8SNGuj163x/sMwydREj7ld5mIMJu1cDanI
sigs.k8s.io/kustomize v2.0.3+incompatible/go.mod h1:MkjgH3RdOWrievjo6c9T245dYlB5QeXV4WCbnt/PEpU=
sigs.k8s.io/structured-merge-diff v0.0.0-20190302045857-e85c7b244fd2/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI=
sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI=
sigs.k8s.io/testing_frameworks v0.1.1 h1:cP2l8fkA3O9vekpy5Ks8mmA0NW/F7yBdXf8brkWhVrs=
sigs.k8s.io/testing_frameworks v0.1.1/go.mod h1:VVBKrHmJ6Ekkfz284YKhQePcdycOzNH9qL6ht1zEr/U=
sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs=
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
Expand Down
3 changes: 0 additions & 3 deletions pkg/apis/camel/v1alpha1/integration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ type Language string
const (
// LanguageJavaSource --
LanguageJavaSource Language = "java"
// LanguageJavaClass --
LanguageJavaClass Language = "class"
// LanguageGroovy --
LanguageGroovy Language = "groovy"
// LanguageJavaScript --
Expand All @@ -136,7 +134,6 @@ const (
// Languages is the list of all supported languages
var Languages = []Language{
LanguageJavaSource,
LanguageJavaClass,
LanguageGroovy,
LanguageJavaScript,
LanguageXML,
Expand Down
1 change: 0 additions & 1 deletion pkg/apis/camel/v1alpha1/integration_types_support_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
)

func TestAllLanguages(t *testing.T) {
assert.Contains(t, Languages, LanguageJavaClass)
assert.Contains(t, Languages, LanguageJavaSource)
assert.Contains(t, Languages, LanguageJavaScript)
assert.Contains(t, Languages, LanguageGroovy)
Expand Down
2 changes: 0 additions & 2 deletions pkg/trait/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ func addDefaultRuntimeDependencies(e *Environment) {
util.StringSliceUniqueAdd(dependencies, "mvn:org.apache.camel.k/camel-k-loader-xml")
case v1alpha1.LanguageJavaScript:
util.StringSliceUniqueAdd(dependencies, "mvn:org.apache.camel.k/camel-k-loader-js")
case v1alpha1.LanguageJavaClass:
util.StringSliceUniqueAdd(dependencies, "mvn:org.apache.camel.k/camel-k-loader-java")
case v1alpha1.LanguageJavaSource:
util.StringSliceUniqueAdd(dependencies, "mvn:org.apache.camel.k/camel-k-loader-java")
}
Expand Down