This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-4.10.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-4.10.x by this push:
new 7ec1665f96d CAMEL-22212: camel-smb - From smb to file with
streamDownload and no stream caching
7ec1665f96d is described below
commit 7ec1665f96db33264f9d2b1482952c7c8b24db76
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Jul 2 14:43:16 2025 +0200
CAMEL-22212: camel-smb - From smb to file with streamDownload and no stream
caching
---
.../camel/component/smb/SmbConverterLoader.java | 60 ++++++++++++++++++
.../services/org/apache/camel/TypeConverterLoader | 2 +
.../apache/camel/component/smb/SmbConverter.java | 48 +++++++++++++++
.../component/smb/SmbStreamDownloadFileIT.java | 71 ++++++++++++++++++++++
.../smb/SmbStreamDownloadFileStreamCachingIT.java | 71 ++++++++++++++++++++++
5 files changed, 252 insertions(+)
diff --git
a/components/camel-smb/src/generated/java/org/apache/camel/component/smb/SmbConverterLoader.java
b/components/camel-smb/src/generated/java/org/apache/camel/component/smb/SmbConverterLoader.java
new file mode 100644
index 00000000000..6a4f8260c6f
--- /dev/null
+++
b/components/camel-smb/src/generated/java/org/apache/camel/component/smb/SmbConverterLoader.java
@@ -0,0 +1,60 @@
+/* Generated by camel build tools - do NOT edit this file! */
+package org.apache.camel.component.smb;
+
+import javax.annotation.processing.Generated;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.DeferredContextBinding;
+import org.apache.camel.Exchange;
+import org.apache.camel.TypeConversionException;
+import org.apache.camel.TypeConverterLoaderException;
+import org.apache.camel.spi.TypeConverterLoader;
+import org.apache.camel.spi.TypeConverterRegistry;
+import org.apache.camel.support.SimpleTypeConverter;
+import org.apache.camel.support.TypeConverterSupport;
+import org.apache.camel.util.DoubleMap;
+
+/**
+ * Generated by camel build tools - do NOT edit this file!
+ */
+@Generated("org.apache.camel.maven.packaging.TypeConverterLoaderGeneratorMojo")
+@SuppressWarnings("unchecked")
+@DeferredContextBinding
+public final class SmbConverterLoader implements TypeConverterLoader,
CamelContextAware {
+
+ private CamelContext camelContext;
+
+ public SmbConverterLoader() {
+ }
+
+ @Override
+ public void setCamelContext(CamelContext camelContext) {
+ this.camelContext = camelContext;
+ }
+
+ @Override
+ public CamelContext getCamelContext() {
+ return camelContext;
+ }
+
+ @Override
+ public void load(TypeConverterRegistry registry) throws
TypeConverterLoaderException {
+ registerConverters(registry);
+ }
+
+ private void registerConverters(TypeConverterRegistry registry) {
+ addTypeConverter(registry, java.io.InputStream.class,
org.apache.camel.component.smb.SmbFile.class, true,
+ (type, exchange, value) -> {
+ Object answer =
org.apache.camel.component.smb.SmbConverter.smbToInputStream((org.apache.camel.component.smb.SmbFile)
value, exchange);
+ if (true && answer == null) {
+ answer = Void.class;
+ }
+ return answer;
+ });
+ }
+
+ private static void addTypeConverter(TypeConverterRegistry registry,
Class<?> toType, Class<?> fromType, boolean allowNull,
SimpleTypeConverter.ConversionMethod method) {
+ registry.addTypeConverter(toType, fromType, new
SimpleTypeConverter(allowNull, method));
+ }
+}
diff --git
a/components/camel-smb/src/generated/resources/META-INF/services/org/apache/camel/TypeConverterLoader
b/components/camel-smb/src/generated/resources/META-INF/services/org/apache/camel/TypeConverterLoader
new file mode 100644
index 00000000000..7b4a333711a
--- /dev/null
+++
b/components/camel-smb/src/generated/resources/META-INF/services/org/apache/camel/TypeConverterLoader
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+org.apache.camel.component.smb.SmbConverterLoader
diff --git
a/components/camel-smb/src/main/java/org/apache/camel/component/smb/SmbConverter.java
b/components/camel-smb/src/main/java/org/apache/camel/component/smb/SmbConverter.java
new file mode 100644
index 00000000000..75aa254367c
--- /dev/null
+++
b/components/camel-smb/src/main/java/org/apache/camel/component/smb/SmbConverter.java
@@ -0,0 +1,48 @@
+/*
+ * 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.smb;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+import org.apache.camel.Converter;
+import org.apache.camel.Exchange;
+
+@Converter(generateLoader = true)
+public class SmbConverter {
+
+ private SmbConverter() {
+ // Helper Class
+ }
+
+ @Converter(allowNull = true)
+ public static InputStream smbToInputStream(SmbFile file, Exchange
exchange) throws Exception {
+ // allow null as valid response, because camel-smb can be set to
download=false
+ Object body = file.getBody();
+ if (body == null) {
+ return null;
+ }
+ if (body instanceof InputStream is) {
+ return is;
+ } else if (body instanceof byte[] arr) {
+ return new ByteArrayInputStream(arr);
+ } else {
+ return
exchange.getContext().getTypeConverter().convertTo(InputStream.class, exchange,
body);
+ }
+ }
+
+}
diff --git
a/components/camel-smb/src/test/java/org/apache/camel/component/smb/SmbStreamDownloadFileIT.java
b/components/camel-smb/src/test/java/org/apache/camel/component/smb/SmbStreamDownloadFileIT.java
new file mode 100644
index 00000000000..0c67c731c98
--- /dev/null
+++
b/components/camel-smb/src/test/java/org/apache/camel/component/smb/SmbStreamDownloadFileIT.java
@@ -0,0 +1,71 @@
+/*
+ * 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.smb;
+
+import java.io.File;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.util.FileUtil;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.testcontainers.shaded.org.awaitility.Awaitility;
+
+public class SmbStreamDownloadFileIT extends SmbServerTestSupport {
+
+ @Override
+ public void doPostSetup() throws Exception {
+ prepareSmbServer();
+ }
+
+ protected String getSmbUrl() {
+ return String.format(
+
"smb:%s/%s/uploadstream4?username=%s&password=%s&streamDownload=true&delete=true",
+ service.address(), service.shareName(), service.userName(),
service.password());
+ }
+
+ @Test
+ public void testStreamDownloadToFile() throws Exception {
+ FileUtil.removeDir(new File("target/deleteme"));
+
+ MockEndpoint mock = getMockEndpoint("mock:input");
+ mock.expectedMessageCount(1);
+
+ mock.assertIsSatisfied();
+
+ Awaitility.await().untilAsserted(() -> {
+ File f = new File("target/deleteme/world.txt");
+ Assertions.assertTrue(f.exists());
+ });
+ }
+
+ private void prepareSmbServer() {
+ template.sendBodyAndHeader(getSmbUrl(), "World", Exchange.FILE_NAME,
"world.txt");
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ from(getSmbUrl()).streamCache("false")
+ .to("mock:input")
+ .to("file:target/deleteme");
+ }
+ };
+ }
+}
diff --git
a/components/camel-smb/src/test/java/org/apache/camel/component/smb/SmbStreamDownloadFileStreamCachingIT.java
b/components/camel-smb/src/test/java/org/apache/camel/component/smb/SmbStreamDownloadFileStreamCachingIT.java
new file mode 100644
index 00000000000..5716aad218f
--- /dev/null
+++
b/components/camel-smb/src/test/java/org/apache/camel/component/smb/SmbStreamDownloadFileStreamCachingIT.java
@@ -0,0 +1,71 @@
+/*
+ * 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.smb;
+
+import java.io.File;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.util.FileUtil;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.testcontainers.shaded.org.awaitility.Awaitility;
+
+public class SmbStreamDownloadFileStreamCachingIT extends SmbServerTestSupport
{
+
+ @Override
+ public void doPostSetup() throws Exception {
+ prepareSmbServer();
+ }
+
+ protected String getSmbUrl() {
+ return String.format(
+
"smb:%s/%s/uploadstream5?username=%s&password=%s&streamDownload=true&delete=true",
+ service.address(), service.shareName(), service.userName(),
service.password());
+ }
+
+ @Test
+ public void testStreamDownloadToFile() throws Exception {
+ FileUtil.removeDir(new File("target/deleteme"));
+
+ MockEndpoint mock = getMockEndpoint("mock:input");
+ mock.expectedMessageCount(1);
+
+ mock.assertIsSatisfied();
+
+ Awaitility.await().untilAsserted(() -> {
+ File f = new File("target/deleteme2/world.txt");
+ Assertions.assertTrue(f.exists());
+ });
+ }
+
+ private void prepareSmbServer() {
+ template.sendBodyAndHeader(getSmbUrl(), "World", Exchange.FILE_NAME,
"world.txt");
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ from(getSmbUrl()).streamCache("true")
+ .to("mock:input")
+ .to("file:target/deleteme2");
+ }
+ };
+ }
+}