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

Fixes for Quarkus Platform 2.0.0 #2720

Merged
merged 2 commits into from
Jun 4, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@
*/
package org.apache.camel.quarkus.component.jslt.it;

import java.lang.reflect.Method;

import javax.inject.Named;

import com.schibsted.spt.data.jslt.Expression;
import com.schibsted.spt.data.jslt.Function;
import com.schibsted.spt.data.jslt.JsltException;
import com.schibsted.spt.data.jslt.Parser;
import com.schibsted.spt.data.jslt.filters.JsltJsonFilter;
import com.schibsted.spt.data.jslt.impl.FunctionWrapper;
import org.apache.camel.component.jslt.JsltComponent;

import static java.util.Collections.singleton;

import static com.schibsted.spt.data.jslt.FunctionUtils.wrapStaticMethod;

public class JsltConfiguration {

@Named
Expand All @@ -50,6 +53,30 @@ JsltComponent jsltWithFunction() throws ClassNotFoundException {
return component;
}

/* A variant of com.schibsted.spt.data.jslt.FunctionUtils.wrapStaticMethod() using TCCL
* Otherwise the class is not found on Quarkus Platform where the class loading setup is a bit different.
* Workaround for https://github.com/schibsted/jslt/issues/197 */
static public Function wrapStaticMethod(String functionName,
String className,
String methodName)
throws LinkageError, ExceptionInInitializerError, ClassNotFoundException {
Class klass = Class.forName(className, true, Thread.currentThread().getContextClassLoader());
Method[] methods = klass.getMethods();
Method method = null;
for (int ix = 0; ix < methods.length; ix++) {
if (methods[ix].getName().equals(methodName)) {
if (method == null)
method = methods[ix];
else
throw new JsltException("More than one method named '" + methodName + "'");
}
}
if (method == null)
throw new JsltException("No such method: '" + methodName + "'");

return new FunctionWrapper(functionName, method);
}

public static Ping createInfiniteRecursionObject() {
Ping ping = new Ping();
Pong pong = new Pong();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@
*/
package org.apache.camel.quarkus.kafka.sasl;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;
import java.util.stream.Stream;

import com.github.dockerjava.api.command.InspectContainerResponse;
import org.apache.camel.quarkus.test.support.kafka.KafkaTestResource;
import org.apache.camel.util.CollectionHelper;
import org.apache.commons.io.FileUtils;
import org.testcontainers.containers.KafkaContainer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.images.builder.Transferable;
import org.testcontainers.shaded.org.apache.commons.io.FileUtils;
import org.testcontainers.utility.DockerImageName;
import org.testcontainers.utility.MountableFile;

Expand All @@ -41,24 +41,23 @@ public class KafkaSaslSslTestResource extends KafkaTestResource {
private static final String KAFKA_KEYSTORE_TYPE = "PKCS12";
private static final String KAFKA_SSL_CREDS_FILE = "broker-creds";
private static final String KAFKA_TRUSTSTORE_FILE = "kafka-truststore.p12";
private static final File TMP_DIR = Paths.get(System.getProperty("java.io.tmpdir"), "kafka").toFile();
private Path configDir;
private SaslSslKafkaContainer container;

@Override
public Map<String, String> start() {
// Set up the SSL key / trust store directory
try {
TMP_DIR.mkdirs();

configDir = Files.createTempDirectory("KafkaSaslSslTestResource-");
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
URL resource = classLoader.getResource("config");
File serviceBindings = new File(resource.getPath());

for (File keyStore : serviceBindings.listFiles()) {
URL serviceBindingResource = classLoader.getResource("config/" + keyStore.getName());
FileUtils.copyInputStreamToFile(serviceBindingResource.openStream(),
Paths.get(TMP_DIR.getPath(), keyStore.getName()).toFile());
}
Stream.of("kafka_server_jaas.conf", KAFKA_KEYSTORE_FILE, KAFKA_TRUSTSTORE_FILE)
.forEach(fileName -> {
try (InputStream in = classLoader.getResourceAsStream("config/" + fileName)) {
Files.copy(in, configDir.resolve(fileName));
} catch (IOException e) {
throw new RuntimeException(e);
}
});
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand All @@ -70,17 +69,16 @@ public Map<String, String> start() {
+ "username=\"alice\" "
+ "password=\"alice-secret\";";

Path keystorePath = TMP_DIR.toPath();
return CollectionHelper.mapOf(
"camel.component.kafka.brokers", container.getBootstrapServers(),
"camel.component.kafka.sasl-mechanism", "SCRAM-SHA-512",
"camel.component.kafka.sasl-jaas-config", jaasConfig,
"camel.component.kafka.security-protocol", "SASL_SSL",
"camel.component.kafka.ssl-key-password", KAFKA_KEYSTORE_PASSWORD,
"camel.component.kafka.ssl-keystore-location", keystorePath.resolve(KAFKA_KEYSTORE_FILE).toString(),
"camel.component.kafka.ssl-keystore-location", configDir.resolve(KAFKA_KEYSTORE_FILE).toString(),
"camel.component.kafka.ssl-keystore-password", KAFKA_KEYSTORE_PASSWORD,
"camel.component.kafka.ssl-keystore-type", KAFKA_KEYSTORE_TYPE,
"camel.component.kafka.ssl-truststore-location", keystorePath.resolve(KAFKA_TRUSTSTORE_FILE).toString(),
"camel.component.kafka.ssl-truststore-location", configDir.resolve(KAFKA_TRUSTSTORE_FILE).toString(),
"camel.component.kafka.ssl-truststore-password", KAFKA_KEYSTORE_PASSWORD,
"camel.component.kafka.ssl-truststore-type", KAFKA_KEYSTORE_TYPE);
}
Expand All @@ -90,7 +88,7 @@ public void stop() {
if (this.container != null) {
try {
this.container.stop();
FileUtils.deleteDirectory(TMP_DIR);
FileUtils.deleteDirectory(configDir.toFile());
} catch (Exception e) {
// Ignored
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,58 +16,61 @@
*/
package org.apache.camel.quarkus.kafka.sasl;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Paths;
import java.util.Collections;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
import java.util.stream.Stream;

import com.github.dockerjava.api.command.InspectContainerResponse;
import org.apache.camel.quarkus.test.support.kafka.KafkaTestResource;
import org.apache.camel.util.CollectionHelper;
import org.apache.commons.io.FileUtils;
import org.apache.kafka.clients.CommonClientConfigs;
import org.testcontainers.containers.KafkaContainer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.shaded.org.apache.commons.io.FileUtils;
import org.testcontainers.utility.DockerImageName;
import org.testcontainers.utility.MountableFile;

public class KafkaSaslTestResource extends KafkaTestResource {

private static final File TMP_DIR = Paths.get(System.getProperty("java.io.tmpdir"), "k8s-sb", "kafka").toFile();
private Path serviceBindingDir;
private SaslKafkaContainer container;

@Override
public Map<String, String> start() {
// Set up the service binding directory
try {
TMP_DIR.mkdirs();

serviceBindingDir = Files.createTempDirectory("KafkaSaslTestResource-");
final Path kafkaDir = serviceBindingDir.resolve("kafka");
Files.createDirectories(kafkaDir);
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
URL resource = classLoader.getResource("k8s-sb/kafka");
File serviceBindings = new File(resource.getPath());

for (File serviceBinding : serviceBindings.listFiles()) {
URL serviceBindingResource = classLoader.getResource("k8s-sb/kafka/" + serviceBinding.getName());
FileUtils.copyInputStreamToFile(serviceBindingResource.openStream(),
Paths.get(TMP_DIR.getPath(), serviceBinding.getName()).toFile());
}
Stream.of("password", "saslMechanism", "securityProtocol", "type", "user")
.forEach(fileName -> {
try (InputStream in = classLoader.getResourceAsStream("k8s-sb/kafka/" + fileName)) {
Files.copy(in, kafkaDir.resolve(fileName));
} catch (IOException e) {
throw new RuntimeException(e);
}
});
} catch (IOException e) {
throw new RuntimeException(e);
}

container = new SaslKafkaContainer(KAFKA_IMAGE_NAME);
container.start();
return Collections.singletonMap("kafka." + CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG,
container.getBootstrapServers());
return CollectionHelper.mapOf(
"kafka." + CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG, container.getBootstrapServers(),
"quarkus.kubernetes-service-binding.root", serviceBindingDir.toString());
}

@Override
public void stop() {
if (this.container != null) {
try {
this.container.stop();
FileUtils.deleteDirectory(TMP_DIR.getParentFile());
FileUtils.deleteDirectory(serviceBindingDir.toFile());
} catch (Exception e) {
// Ignored
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@
*/
package org.apache.camel.quarkus.kafka.ssl;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;
import java.util.stream.Stream;

import com.github.dockerjava.api.command.InspectContainerResponse;
import org.apache.camel.quarkus.test.support.kafka.KafkaTestResource;
import org.apache.camel.util.CollectionHelper;
import org.apache.commons.io.FileUtils;
import org.testcontainers.containers.KafkaContainer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.images.builder.Transferable;
import org.testcontainers.shaded.org.apache.commons.io.FileUtils;
import org.testcontainers.utility.DockerImageName;
import org.testcontainers.utility.MountableFile;

Expand All @@ -41,40 +41,38 @@ public class KafkaSslTestResource extends KafkaTestResource {
private static final String KAFKA_KEYSTORE_TYPE = "PKCS12";
private static final String KAFKA_SSL_CREDS_FILE = "broker-creds";
private static final String KAFKA_TRUSTSTORE_FILE = "kafka-truststore.p12";
private static final File TMP_DIR = Paths.get(System.getProperty("java.io.tmpdir"), "kafka").toFile();
private Path configDir;
private SSLKafkaContainer container;

@Override
public Map<String, String> start() {
// Set up the SSL key / trust store directory
try {
TMP_DIR.mkdirs();

configDir = Files.createTempDirectory("KafkaSaslSslTestResource-");
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
URL resource = classLoader.getResource("config");
File serviceBindings = new File(resource.getPath());

for (File keyStore : serviceBindings.listFiles()) {
URL serviceBindingResource = classLoader.getResource("config/" + keyStore.getName());
FileUtils.copyInputStreamToFile(serviceBindingResource.openStream(),
Paths.get(TMP_DIR.getPath(), keyStore.getName()).toFile());
}
Stream.of(KAFKA_KEYSTORE_FILE, KAFKA_TRUSTSTORE_FILE)
.forEach(fileName -> {
try (InputStream in = classLoader.getResourceAsStream("config/" + fileName)) {
Files.copy(in, configDir.resolve(fileName));
} catch (IOException e) {
throw new RuntimeException(e);
}
});
} catch (IOException e) {
throw new RuntimeException(e);
}

container = new SSLKafkaContainer(KAFKA_IMAGE_NAME);
container.start();

Path keystorePath = TMP_DIR.toPath();
return CollectionHelper.mapOf(
"camel.component.kafka.brokers", container.getBootstrapServers(),
"camel.component.kafka.security-protocol", "SSL",
"camel.component.kafka.ssl-key-password", KAFKA_KEYSTORE_PASSWORD,
"camel.component.kafka.ssl-keystore-location", keystorePath.resolve(KAFKA_KEYSTORE_FILE).toString(),
"camel.component.kafka.ssl-keystore-location", configDir.resolve(KAFKA_KEYSTORE_FILE).toString(),
"camel.component.kafka.ssl-keystore-password", KAFKA_KEYSTORE_PASSWORD,
"camel.component.kafka.ssl-keystore-type", KAFKA_KEYSTORE_TYPE,
"camel.component.kafka.ssl-truststore-location", keystorePath.resolve(KAFKA_TRUSTSTORE_FILE).toString(),
"camel.component.kafka.ssl-truststore-location", configDir.resolve(KAFKA_TRUSTSTORE_FILE).toString(),
"camel.component.kafka.ssl-truststore-password", KAFKA_KEYSTORE_PASSWORD,
"camel.component.kafka.ssl-truststore-type", KAFKA_KEYSTORE_TYPE);
}
Expand All @@ -84,7 +82,7 @@ public void stop() {
if (this.container != null) {
try {
this.container.stop();
FileUtils.deleteDirectory(TMP_DIR);
FileUtils.deleteDirectory(configDir.toFile());
} catch (Exception e) {
// Ignored
}
Expand Down