Skip to content

Commit

Permalink
Added a Camel connector for Ethereum blockchain using Web3j library
Browse files Browse the repository at this point in the history
  • Loading branch information
bibryam committed Apr 25, 2018
1 parent ca14beb commit ef2bbb8
Show file tree
Hide file tree
Showing 48 changed files with 5,634 additions and 1 deletion.
9 changes: 9 additions & 0 deletions apache-camel/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,10 @@
<groupId>org.apache.camel</groupId>
<artifactId>camel-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-web3j</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-wordpress</artifactId>
Expand Down Expand Up @@ -2410,6 +2414,11 @@
<artifactId>camel-websocket-starter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-web3j-starter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-wordpress-starter</artifactId>
Expand Down
2 changes: 2 additions & 0 deletions apache-camel/src/main/descriptors/common-bin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@
<include>org.apache.camel:camel-vertx</include>
<include>org.apache.camel:camel-weather</include>
<include>org.apache.camel:camel-websocket</include>
<include>org.apache.camel:camel-web3j</include>
<include>org.apache.camel:camel-wordpress</include>
<include>org.apache.camel:camel-xmlbeans</include>
<include>org.apache.camel:camel-xchange</include>
Expand Down Expand Up @@ -589,6 +590,7 @@
<include>org.apache.camel:camel-vertx-starter</include>
<include>org.apache.camel:camel-weather-starter</include>
<include>org.apache.camel:camel-websocket-starter</include>
<include>org.apache.camel:camel-web3j-starter</include>
<include>org.apache.camel:camel-wordpress-starter</include>
<include>org.apache.camel:camel-xmlbeans-starter</include>
<include>org.apache.camel:camel-xchange-starter</include>
Expand Down
10 changes: 10 additions & 0 deletions bom/camel-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2678,6 +2678,16 @@
<artifactId>camel-weather-starter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-web3j</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-web3j-starter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-websocket</artifactId>
Expand Down
93 changes: 93 additions & 0 deletions components/camel-web3j/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.apache.camel</groupId>
<artifactId>components</artifactId>
<version>2.22.0-SNAPSHOT</version>
</parent>

<artifactId>camel-web3j</artifactId>
<packaging>jar</packaging>
<name>Camel :: Web3j</name>
<description>Camel Ethereum support through Web3j</description>

<properties>
<camel.osgi.export.pkg>org.apache.camel.component.web3j.*</camel.osgi.export.pkg>
<camel.osgi.export.service>org.apache.camel.spi.ComponentResolver;component=web3j</camel.osgi.export.service>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
</dependency>
<dependency>
<groupId>org.web3j</groupId>
<artifactId>core</artifactId>
<version>${web3j-version}</version>
</dependency>
<dependency>
<groupId>org.web3j</groupId>
<artifactId>geth</artifactId>
<version>${web3j-version}</version>
</dependency>
<dependency>
<groupId>org.web3j</groupId>
<artifactId>parity</artifactId>
<version>${web3j-version}</version>
</dependency>

<!-- for testing -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
97 changes: 97 additions & 0 deletions components/camel-web3j/src/main/docs/web3j-component.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
[[web3j-component]]
== web3j Component

*Available as of Camel version 2.20*

*Available as of Camel version 2.20*


The web3j component uses the
https://github.com/web3j/web3j[web3j] client
API and allows you to read/write from geth/parity compatible Ethereum nodes.

### URI Format

[source,java]
------------------------------
web3j://ethereumServerUrl[?options]
------------------------------

You can append query options to the URI in the following format,
?options=value&option2=value&...

### Web3j Options

// component options: START
The web3j component supports 2 options which are listed below.



[width="100%",cols="2,5,^1,2",options="header"]
|===
| Name | Description | Default | Type
| *configuration* (common) | Default configuration | | Web3jConfiguration
| *resolveProperty Placeholders* (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean
|===
// component options: END

// endpoint options: START
The web3j endpoint is configured using URI syntax:

----
web3j:cmsUrl
----

with the following path and query parameters:

==== Path Parameters (1 parameters):


[width="100%",cols="2,5,^1,2",options="header"]
|===
| Name | Description | Default | Type
| *web3j* | *Required* URL to the web3j repository | | Web3j
|===


==== Query Parameters (4 parameters):


[width="100%",cols="2,5,^1,2",options="header"]
|===
| Name | Description | Default | Type
| *bridgeErrorHandler* (consumer) | Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean
| *exceptionHandler* (consumer) | To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this options is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored. | | ExceptionHandler
| *exchangePattern* (consumer) | Sets the exchange pattern when the consumer creates an exchange. | | ExchangePattern
| *synchronous* (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean
|===
// endpoint options: END


### Usage


### Dependencies

Maven users will need to add the following dependency to their pom.xml.

*pom.xml*

[source,xml]
---------------------------------------
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-web3j</artifactId>
<version>${camel-version}</version>
</dependency>
---------------------------------------

where `${camel-version`} must be replaced by the actual version of Camel
(2.22 or higher).

### See Also

* Configuring Camel
* Component
* Endpoint
* Getting Started
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* 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.
*/
package org.apache.camel.component.web3j;

import java.util.Map;

import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
import org.apache.camel.impl.DefaultComponent;
import org.apache.camel.spi.Metadata;

/**
* Represents the component that manages {@link Web3jComponent}.
*/
public class Web3jComponent extends DefaultComponent {

@Metadata(description = "Default configuration")
private Web3jConfiguration configuration;

public Web3jComponent() {
}

public Web3jComponent(CamelContext camelContext) {
super(camelContext);
}

public Web3jConfiguration getConfiguration() {
return configuration;
}

public void setConfiguration(Web3jConfiguration configuration) {
this.configuration = configuration;
}

protected Endpoint createEndpoint(String uri, final String remaining, final Map<String, Object> parameters) throws Exception {
Web3jConfiguration conf = configuration != null ? configuration.copy() : new Web3jConfiguration();
setProperties(conf, parameters);
return new Web3jEndpoint(uri, remaining, this, conf);
}

}
Loading

0 comments on commit ef2bbb8

Please sign in to comment.