Giter Club home page Giter Club logo

camel-smbj's Introduction

Camel SMBJ Component

Build Status codecov Codacy Badge Known Vulnerabilities

This component is intended to be a drop-in replacement for camel-jcifs component. It provides access to remote file systems over the SMB networking protocol with support of SMB2.

URI format

smb2://[[[domain;]username[:password]@]server[:port]/[[share/[dir/]]]][?options]

Where share represents the share to connect to and dir is optionally any underlying directory. Can contain nested folders. You can append query options to the URI in the following format, ?option=value&option=value&... This component uses the SMBJ library for the actual SMB work.

By itself, the camel-smbj component is an extension of the File component.

camel-smbj's People

Contributors

jborza avatar snyk-bot avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

camel-smbj's Issues

Consumer routes fail with NPE when noop=true (or idempotent=true) is set

Received at line 556 in GenericFileConsumer:

// if its a file then check we have the file in the idempotent registry already
if (endpoint.isIdempotent()) {
// use absolute file path as default key, but evaluate if an expression key was configured
String key = file.getAbsoluteFilePath();
if (endpoint.getIdempotentKey() != null) {
Exchange dummy = endpoint.createExchange(file);
key = endpoint.getIdempotentKey().evaluate(dummy, String.class);
}
if (key != null && endpoint.getIdempotentRepository().contains(key)) {
log.trace("This consumer is idempotent and the file has been consumed before matching idempotentKey: {}. Will skip this file: {}", key, file);
return false;
}
}

Buffer underflow with path resolution on non-dfs shares

Receiving a buffer_underflow in smbj when performing a path resolution on non-DFS shares.
This occurs within a response to sendDfsReferralRequest, then SMB2IoctlResponse.readMessage.

Somehow the buffer gets smaller when smbj is initialized with SmbConfig.withBufferSize(510241024).

The problem goes away when using smaller buffer sizes (default 1 MB; 4 MB works as well).

EOFException thrown during tests

Travis build says java.io.EOFException are thrown from the Packet Reader thread.
Most likely a connection not being closed properly.

the Scheduler won't work

I try to build this camel component with smbj 0.10.0๏ผŒ found that the Scheduler doesn't work.
Here is the code below:
CamelContext context = new DefaultCamelContext(); context.addComponent("smb2", new SmbComponent()); context.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("smb2://public:[email protected]/public/?delay=3000").to("file:data/outbox"); } }); context.start();

When run this camel context the VM just disconnected, without camel context shutdown, just went out:
Connected to the target VM, address: '127.0.0.1:55794', transport: 'socket'
[ main] DefaultCamelContext INFO Apache Camel 2.21.0.appconnect-1.0.0-SNAPSHOT (CamelContext: camel-1) is starting
[ main] ManagedManagementStrategy INFO JMX is enabled
[ main] DefaultTypeConverter INFO Type converters loaded (core: 194, classpath: 0)
[ main] DefaultCamelContext INFO StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
[ main] Connection INFO Successfully connected to: 112.126.5.57
[ main] Connection INFO Successfully authenticated public on 112.126.5.57, session is 4284008678
[ main] Session INFO Connecting to \112.126.5.57\public on session 4284008678
[ main] Connection INFO Closed connection to 112.126.5.57
[Packet Reader for 112.126.5.57] PacketReader INFO Thread[Packet Reader for 112.126.5.57,5,main] stopped.
[ main] DefaultCamelContext INFO Route: route1 started and consuming from: smb2://public:[email protected]:139/public/?delay=3000
[ main] DefaultCamelContext INFO Total 1 routes, of which 1 are started
[ main] DefaultCamelContext INFO Apache Camel 2.21.0.appconnect-1.0.0-SNAPSHOT (CamelContext: camel-1) started in 0.932 seconds
Disconnected from the target VM, address: '127.0.0.1:55794', transport: 'socket'

Process finished with exit code 0

SmbProducer is not compatible with camel 3.8.0

The immediate problem is it references "log" in superclass GenericFileProducer. In the latest camel, the logger is names "LOG" and it's private.
I don't know what other issue may exist.
I will probably have to stop using this library if this can't be fixed. Thanks.

com.hierynomus.mssmb2.SMBApiException - STATUS_OBJECT_NAME_NOT_FOUND(3221225524/3221225524): Create failed for ConsumeFile

2018-05-01 20:33:34 INFO Connection:184 - Successfully authenticated test on .168.16., session is 123548760801333
2018-05-01 20:33:34 INFO Session:146 - Connecting to \
.168.16.\ConsumeFile on session 123548760801333
2018-05-01 20:33:34 INFO Session:208 - Logging off session 123548760801333 from host .168.16.
2018-05-01 20:33:34 WARN SmbConsumer:213 - Consumer Consumer[smb2://Domain;test@
.168.16./claim?delete=true&password=xxxxxx] failed polling endpoint: smb2://Domain;test@*.168.16./ConsumeFile?delete=true&password=xxxxxx. Will try again at next poll. Caused by: [com.hierynomus.mssmb2.SMBApiException - STATUS_OBJECT_NAME_NOT_FOUND(3221225524/3221225524): Create failed for ConsumeFile]
com.hierynomus.mssmb2.SMBApiException: STATUS_OBJECT_NAME_NOT_FOUND(3221225524/3221225524): Create failed for ConsumeFile
at com.hierynomus.smbj.share.Share.receive(Share.java:342)
at com.hierynomus.smbj.share.Share.sendReceive(Share.java:322)
at com.hierynomus.smbj.share.Share.createFile(Share.java:135)
at com.hierynomus.smbj.share.DiskShare.createFileAndResolve(DiskShare.java:79)
at com.hierynomus.smbj.share.DiskShare.open(DiskShare.java:69)
at com.hierynomus.smbj.share.DiskShare.openDirectory(DiskShare.java:126)
at com.hierynomus.smbj.share.DiskShare.list(DiskShare.java:213)
at com.hierynomus.smbj.share.DiskShare.list(DiskShare.java:186)
at com.github.jborza.camel.component.smbj.SmbShare.listFiles(SmbShare.java:175)
at com.github.jborza.camel.component.smbj.SmbClient.listFiles(SmbClient.java:39)
at com.github.jborza.camel.component.smbj.SmbOperations.listFiles(SmbOperations.java:212)
at com.github.jborza.camel.component.smbj.SmbConsumer.pollDirectory(SmbConsumer.java:48)
at org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:124)
at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:174)
at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:101)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

FileExist=Append is not implemented

When passing the parameter FileExist=Append and if the file already exists, SMB throws an exception STATUS_OBJECT_NAME_COLLISION.
Camel JCIFS used to support the file append operation. Do you have any plans to add the support for 'append'?

moveFailed fails on share.deleteFile()

In the case of using a camel route that includes move and moveFailed in the URI the default behaviour is to first delete a file of the same name if present in the target folder.

org.apache.camel.component.file.strategy.GenericFileProcessStrategySupport

protected GenericFile<T> renameFile(GenericFileOperations<T> operations, GenericFile<T> from, GenericFile<T> to) throws IOException {
        // deleting any existing files before renaming
        try {
            operations.deleteFile(to.getAbsoluteFilePath());
        } catch (GenericFileOperationFailedException e) {
            // ignore the file does not exists
        }
        //Some other unrelated stuff....
}

The provided SmbOperations then is charged with handling the deletion of the file. When it comes to the SmbShare deleteFile(String path) method it fails with STATUS_OBJECT_NAME_NOT_FOUND resulting in an SMBApiException. This is not caught and interrupts the running task. After a lot of debugging I found out that this is intended to delete a file in the provided moveFailed folder with the same name as the file to be moved.

In the case of the File component that this library is replacing a check is executed before trying to delete the file. This seems logical to me as the file is to be moved and this prevents naming conflicts but there might be nothing there.

org.apache.camel.util.FileUtil

public static boolean deleteFile(File file) {
        // do not try to delete non existing files
        if (!file.exists()) {
            return false;
        }
        //Some other stuff....
}

As far as I can see this check is not happening when using this library resulting in the STATUS_OBJECT_NAME_NOT_FOUND error due to the file not actually existing in that location (yet).

My suggestion would be to use the fileExists method already provided on the SmbShare class as a check before calling share.rm(path). Catching the SMBApiException seems too generic to me as it might relate to other issues with the share/client. What do you think? I'm currently implementing this fix for an application we use. I have to say that your library works great otherwise. Very easy to use. ๐Ÿ˜„

DFS Referral error with many routes running against DFS shares

When having a lot of routes polling against Windows DFS share,
I receive this error:
java.lang.IllegalStateException: Could not find referral cache entry for DFSPath{[server.domain.com, dfs]}
...
(at DFSPathResolver)

it's very possible the cache or the resolution is not really thread safe, so reusing the same SMBClient may not be the best idea.
Not straightforward to reproduce.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.