Merge branch 'eugenp:master' into master

This commit is contained in:
Bhabani Prasad Patel
2021-05-26 16:54:20 +05:30
85 changed files with 1625 additions and 18 deletions
@@ -0,0 +1,8 @@
package com.baeldung.exceptions.illegalaccesserror;
public class Class1 {
public void bar() {
System.out.println("SUCCESS");
}
}
@@ -0,0 +1,10 @@
package com.baeldung.exceptions.illegalaccesserror;
public class Class2 {
public void foo() {
Class1 c1 = new Class1();
c1.bar();
}
}
@@ -0,0 +1,20 @@
package com.baeldung.exceptions.illegalaccesserror;
public class IllegalAccessErrorExample {
interface Baeldung {
public default void foobar() {
System.out.println("This is a default method.");
}
}
class Super {
private void foobar() {
System.out.println("SuperClass method foobar");
}
}
class MySubClass extends Super implements Baeldung {
}
}
@@ -0,0 +1,20 @@
package com.baeldung.exceptions.illegalaccesserror;
public class IllegalAccessErrorSolved {
interface BaeldungSolved {
public default void foobar() {
System.out.println("This is a default method.");
}
}
class SuperSolved {
public void foobar() {
System.out.println("SuperClass method foobar");
}
}
class MySubClassSolved extends SuperSolved implements BaeldungSolved {
}
}
@@ -0,0 +1,21 @@
package com.baeldung.exceptions.illegalaccesserror;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class IllegalAccessErrorExampleUnitTest {
@Test()
public void givenInterfaceDefaultMethOverriddenPrivateAccess_whenInvoked_thenIllegalAccessError() {
Assertions.assertThrows(IllegalAccessError.class, () -> {
new IllegalAccessErrorExample().new MySubClass().foobar();
});
}
@Test()
public void givenClass1Class2_whenSameClassDefintion_thenNoIllegalAccessError() {
Assertions.assertDoesNotThrow(() -> {
new Class2().foo();
});
}
}
@@ -0,0 +1,14 @@
package com.baeldung.exceptions.illegalaccesserror;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class IllegalAccessErrorSolvedUnitTest {
@Test()
public void givenInterfaceDefaultMethOverriddenNonPrivateAccess_whenInvoked_thenNoIllegalAccessError() {
Assertions.assertDoesNotThrow(() -> {
new IllegalAccessErrorSolved().new MySubClassSolved().foobar();
});
}
}
@@ -0,0 +1,28 @@
package com.baeldung.deserialization.vulnerabilities;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.lang.reflect.Method;
public class BadThing implements Serializable {
private static final long serialVersionUID = 0L;
Object looselyDefinedThing;
String methodName;
private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
ois.defaultReadObject();
try {
Method method = looselyDefinedThing.getClass().getMethod(methodName);
method.invoke(looselyDefinedThing);
} catch (Exception e) {
// handle error...
}
}
private void writeObject(ObjectOutputStream oos) throws IOException {
oos.defaultWriteObject();
}
}
@@ -0,0 +1,14 @@
package com.baeldung.deserialization.vulnerabilities;
import java.io.IOException;
import java.io.Serializable;
public class MyCustomAttackObject implements Serializable {
public static void methodThatTriggersAttack() {
try {
Runtime.getRuntime().exec("echo \"Oh, no! I've been hacked\"");
} catch (IOException e) {
// handle error...
}
}
}
@@ -0,0 +1,40 @@
package com.baeldung.deserialization.vulnerabilities;
import org.junit.Test;
import org.junit.jupiter.api.DisplayName;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
public class BadThingUnitTest {
@Test
@DisplayName("When a BadThing object is deserialized, then code execution in MyCustomAttackObject is run.")
public void givenABadThingObject_whenItsDeserialized_thenExecutionIsRun() throws Exception {
BadThing bt = new BadThing();
bt.looselyDefinedThing = new MyCustomAttackObject();
bt.methodName = "methodThatTriggersAttack";
byte[] serializedObject = serialize(bt);
try (InputStream bis = new ByteArrayInputStream(serializedObject);
ObjectInputStream ois = new ObjectInputStream(bis)) {
ois.readObject(); // malicious code is run
}
}
private static byte[] serialize(Object object) throws Exception {
try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos)) {
oos.writeObject(object);
oos.flush();
return bos.toByteArray();
}
}
}
@@ -57,6 +57,7 @@
<properties>
<assertj.version>3.6.1</assertj.version>
<icu4j.version>61.1</icu4j.version>
<maven.compiler.release>15</maven.compiler.release>
</properties>
</project>
@@ -64,4 +64,11 @@ public class MultiLineString {
return new String(Files.readAllBytes(Paths.get("src/main/resources/stephenking.txt")));
}
public String textBlocks() {
return """
Get busy living
or
get busy dying.
--Stephen King""";
}
}
@@ -16,6 +16,7 @@ public class MultiLineStringUnitTest {
assertEquals(ms.stringJoin(), ms.stringBuilder());
assertEquals(ms.stringBuilder(), ms.guavaJoiner());
assertEquals(ms.guavaJoiner(), ms.loadFromFile());
assertEquals(ms.loadFromFile(), ms.textBlocks());
}
}
-1
View File
@@ -111,7 +111,6 @@
<module>core-java-string-operations</module>
<module>core-java-string-operations-2</module>
<module>core-java-string-operations-3</module>
<module>core-java-strings</module>
<module>core-java-sun</module>
<module>core-java-regex</module>
<module>pre-jpms</module>
-2
View File
@@ -73,8 +73,6 @@
</build>
<properties>
<!-- lombok: https://projectlombok.org/changelog.html -->
<lombok.version>1.18.10</lombok.version>
<!-- various -->
<hibernate-jpa-2.1-api.version>1.0.0.Final</hibernate-jpa-2.1-api.version>
<!-- delombok maven plugin -->
@@ -0,0 +1,238 @@
<?xml version="1.0" encoding="Cp1252"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung</groupId>
<artifactId>maven-pom-types</artifactId>
<version>1.0-SNAPSHOT</version>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
</pluginRepository>
</pluginRepositories>
<build>
<sourceDirectory>C:\Users\emicu\Desktop\tutorials\maven-modules\maven-pom-types\src\main\java</sourceDirectory>
<scriptSourceDirectory>C:\Users\emicu\Desktop\tutorials\maven-modules\maven-pom-types\src\main\scripts
</scriptSourceDirectory>
<testSourceDirectory>C:\Users\emicu\Desktop\tutorials\maven-modules\maven-pom-types\src\test\java
</testSourceDirectory>
<outputDirectory>C:\Users\emicu\Desktop\tutorials\maven-modules\maven-pom-types\customTarget\classes
</outputDirectory>
<testOutputDirectory>C:\Users\emicu\Desktop\tutorials\maven-modules\maven-pom-types\customTarget\test-classes
</testOutputDirectory>
<resources>
<resource>
<directory>C:\Users\emicu\Desktop\tutorials\maven-modules\maven-pom-types\src\main\resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>C:\Users\emicu\Desktop\tutorials\maven-modules\maven-pom-types\src\test\resources</directory>
</testResource>
</testResources>
<directory>C:\Users\emicu\Desktop\tutorials\maven-modules\maven-pom-types\customTarget</directory>
<finalName>simplestPOM-1.0-SNAPSHOT</finalName>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>default-clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>default-testResources</id>
<phase>process-test-resources</phase>
<goals>
<goal>testResources</goal>
</goals>
</execution>
<execution>
<id>default-resources</id>
<phase>process-resources</phase>
<goals>
<goal>resources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>default-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<executions>
<execution>
<id>default-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>default-testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<executions>
<execution>
<id>default-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>default-install</id>
<phase>install</phase>
<goals>
<goal>install</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
<executions>
<execution>
<id>default-site</id>
<phase>site</phase>
<goals>
<goal>site</goal>
</goals>
<configuration>
<outputDirectory>
C:\Users\emicu\Desktop\tutorials\maven-modules\maven-pom-types\customTarget\site
</outputDirectory>
<reportPlugins>
<reportPlugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</reportPlugin>
</reportPlugins>
</configuration>
</execution>
<execution>
<id>default-deploy</id>
<phase>site-deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<outputDirectory>
C:\Users\emicu\Desktop\tutorials\maven-modules\maven-pom-types\customTarget\site
</outputDirectory>
<reportPlugins>
<reportPlugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</reportPlugin>
</reportPlugins>
</configuration>
</execution>
</executions>
<configuration>
<outputDirectory>C:\Users\emicu\Desktop\tutorials\maven-modules\maven-pom-types\customTarget\site
</outputDirectory>
<reportPlugins>
<reportPlugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</reportPlugin>
</reportPlugins>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<outputDirectory>C:\Users\emicu\Desktop\tutorials\maven-modules\maven-pom-types\customTarget\site
</outputDirectory>
</reporting>
</project>
+148
View File
@@ -0,0 +1,148 @@
<?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. -->
<!-- START SNIPPET: superpom -->
<project>
<modelVersion>4.0.0</modelVersion>
<repositories>
<repository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
</pluginRepository>
</pluginRepositories>
<build>
<directory>${project.basedir}/target</directory>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
<finalName>${project.artifactId}-${project.version}</finalName>
<testOutputDirectory>${project.build.directory}/test-classes
</testOutputDirectory>
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
<scriptSourceDirectory>${project.basedir}/src/main/scripts
</scriptSourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/java
</testSourceDirectory>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
</testResource>
</testResources>
<pluginManagement>
<!-- NOTE: These plugins will be removed from future versions of the super
POM -->
<!-- They are kept for the moment as they are very unlikely to conflict
with lifecycle mappings (MNG-4453) -->
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<reporting>
<outputDirectory>${project.build.directory}/site</outputDirectory>
</reporting>
<profiles>
<!-- NOTE: The release profile will be removed from future versions of
the super POM -->
<profile>
<id>release-profile</id>
<activation>
<property>
<name>performRelease</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<inherited>true</inherited>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<inherited>true</inherited>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<inherited>true</inherited>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<updateReleaseInfo>true</updateReleaseInfo>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
<!-- END SNIPPET: superpom -->
+9
View File
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung</groupId>
<artifactId>maven-pom-types</artifactId>
<version>1.0-SNAPSHOT</version>
</project>
@@ -0,0 +1,7 @@
## Maven Printing Plugins
This module contains articles about printing from Maven plugins.
### Relevant Articles
- [How to Display a Message in Maven](https://www.baeldung.com/maven-print-message-during-execution)
+1
View File
@@ -0,0 +1 @@
/product-service/
+62
View File
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>patterns</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>enterprise-patterns</artifactId>
<packaging>pom</packaging>
<properties>
<camel.version>3.7.4</camel.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-activemq-starter</artifactId>
</dependency>
<!-- Test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.2.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-spring-junit5</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-spring-boot-dependencies</artifactId>
<version>${camel.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,34 @@
# Wire Tap Pattern
The application shows you how to use a Wire Tap to monitor, debug or troubleshoot messages flowing through the system, without permanently consuming them off, or making any changes to the expected message in the output channel.
This example shows how to implement this with a simple Apache Camel application using Spring Boot and Apache ActiveMq.
For convenience, we are using in-memory activeMq.
### Configuring and using the Connection Factory
1. Create CamelContext.
2. Connect to embedded (or remote) ActiveMQ JMS broker.
3. Add JMS queue to CamelContext.
4. Load file orders (xml/csv) from src/data into the JMS queue.
5. Based on the extension of the incoming file message, route to the respective queues.
6. Test that the destination route is working.
7. Audit the received file (order) from the wire tap queue.
### How to run the example:
mvn spring-boot:run
The Wire Tap processor, by default, makes a shallow copy of the Camel Exchange instance. The copy of the exchange is sent to the endpoint specified in the wireTap statement. The body of the wire tapped message contains the same object as that in the original message which means any change to the internal state of that object during the wire tap route may also end up changing the main message’s body.
To solve this, we need to create a deep copy of the object before passing it to the wire tap destination. Wire Tap EIP provides us with a mechanism to perform a “deep” copy of the message, by implementing the org.apache.camel.Processor class. This needs to be be called using onPrepare statement right after wireTap.
For more details, check out the AmqApplicationUnitTest.class.
### Relevant Articles:
- [Wire tap (Enterprise Integration Pattern)](https://drafts.baeldung.com/?p=103346&preview=true)
- [Intro to Apache camel](https://www.baeldung.com/apache-camel-intro)
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>wire-tap</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<parent>
<artifactId>enterprise-patterns</artifactId>
<groupId>com.baeldung</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<dependencies>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<order name="motor" amount="1" customer="honda"/>
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<order name="motor" amount="1" customer="honda"/>
@@ -0,0 +1,70 @@
package com.baeldung;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.camel.CamelContext;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.RoutesBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.jms.JmsComponent;
import org.apache.camel.impl.DefaultCamelContext;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class AmqApplication {
public static void main(String[] args) throws Exception {
SpringApplication.run(AmqApplication.class, args);
try (CamelContext context = new DefaultCamelContext()) {
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
"vm://localhost?broker.persistent=false");
connectionFactory.setTrustAllPackages(true);
context.addComponent("direct", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
addRoute(context);
try (ProducerTemplate template = context.createProducerTemplate()) {
context.start();
MyPayload payload = new MyPayload("One");
template.sendBody("direct:source", payload);
Thread.sleep(10000);
} finally {
context.stop();
}
}
}
private static void addRoute(CamelContext context) throws Exception {
context.addRoutes(newExchangeRoute());
}
static RoutesBuilder traditionalWireTapRoute() {
return new RouteBuilder() {
public void configure() {
from("direct:source").log("Main route: Send '${body}' to tap router").wireTap("direct:tap").delay(1000)
.log("Main route: Add 'two' to '${body}'").bean(MyBean.class, "addTwo").to("direct:destination")
.log("Main route: Output '${body}'");
from("direct:tap").log("Tap Wire route: received '${body}'")
.log("Tap Wire route: Add 'three' to '${body}'").bean(MyBean.class, "addThree")
.log("Tap Wire route: Output '${body}'");
from("direct:destination").log("Output at destination: '${body}'");
}
};
}
static RoutesBuilder newExchangeRoute() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
from("direct:source").wireTap("direct:tap").onPrepare(new MyPayloadClonePrepare()).end().delay(1000);
from("direct:tap").bean(MyBean.class, "addThree");
}
};
}
}
@@ -0,0 +1,14 @@
package com.baeldung;
public class MyBean {
public MyPayload addTwo(MyPayload body) {
body.setValue(body.getValue() + " and two");
return body;
}
public MyPayload addThree(MyPayload body) {
body.setValue(body.getValue() + " and three");
return body;
}
}
@@ -0,0 +1,31 @@
package com.baeldung;
import java.io.Serializable;
public class MyPayload implements Serializable {
private static final long serialVersionUID = 1L;
private String value;
public MyPayload(String value) {
this.value = value;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String toString() {
return value;
}
public MyPayload deepClone() {
MyPayload myPayload = new MyPayload(value);
return myPayload;
}
}
@@ -0,0 +1,15 @@
package com.baeldung;
import java.util.Date;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
public class MyPayloadClonePrepare implements Processor {
public void process(Exchange exchange) throws Exception {
MyPayload myPayload = exchange.getIn().getBody(MyPayload.class);
exchange.getIn().setBody(myPayload.deepClone());
exchange.getIn().setHeader("date", new Date());
}
}
@@ -0,0 +1,9 @@
# to keep the JVM running
camel.springboot.main-run-controller = true
#configure the URL of the remote ActiveMQ broker
#camel.component.activemq.broker-url=tcp://localhost:61616
#spring.activemq.broker-url=tcp://localhost:61616
spring.activemq.in-memory=true
spring.activemq.pool.enabled=false
@@ -0,0 +1,16 @@
# Root logger option
log4j.rootLogger=INFO, file, console
log4j.logger.com.javarticles=INFO, file
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=javarticles.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d | %p | %F %L | %m%n
# Direct log messages to stdout
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.Target=System.out
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{HH:mm}| %p | %F %L | %m%n

Some files were not shown because too many files have changed in this diff Show More