Cache 2016.2.1 Using java library jcifs-ng for access to Windows Shares from ObjectScript

Solapas principales

Hello everybody,

My question would be, how is the recommended way to access Windows shares, also in view of future demads. Of course, I'm also happy about an explanation or code snippet of how the library, which is mentioned in the following , can be used under cache.

The classic jcifs library is easy to use, also with Cache, but as microsoft ceases support for smb1, we are currently looking for alternatives. jcifs-ng is such a library, which we took a closer look at. In java code a jcifs-ng file operation looks like this:

CIFSContext baseCtx = new BaseContext(new PropertyConfiguration(System.getProperties()));
NtlmPasswordAuthenticator creds = new NtlmPasswordAuthenticator(smbDomain,smbUser,smbPass);
CIFSContext ct = baseCtx.withCredentials(creds);
SmbResource sr = ct.get(smbConnect);

// do something with the SmbRessource which can be either a file or a directory

In contrast to the old jcifs library, interfaces are used, e.g. with CIFSContext. I don't know if this is the reason, but it seems to cause problems using the JavaGateway Wizard and the wrapper classes it creates. Creating an empty Properties hashmap and instatiating an NtlmPasswordAuthenticator works fine but when calling the method baseCtx.withCredentials(creds), which result-type is an abstract CIFSContext, the csession runs into an exception.

Thank you very much,

Martin Staudigel


What platform are you running Cache on? And what Cache version? Can't you access the Windows fileshares directly from ObjectScript without needing to call out through the Java gateway?

It's Ensemble 2016.2.1.803.0 on SLES 12 SP3

There is the possibility to mount shares into the filesystem, but if this fails, it may go unnoticed because an empty directory remains. I don't know any other way to address a Windows share from an ObjectScript class than via the Java gateway, but that doesn't mean it doesn't exist. Every hint is appreciated.

To conclude this topic I would like to present my solution for a runtime configurable SMB access. 

First step was to write a helper class in Java, which provides static methods for all needed functionality. This class encapsulates the dependencies to the Java libraries jcifs-ng-2.1.1.jar, bcprov-jdk15on-1.58.jar and slf4j-1.7.24.jar.

Some of the implemented Methods are:

public static boolean copyFileFromSmbShareToLocal( String smbHost, String smbShare, String smbUser, String smbPass, String smbAuthDomain, String smbFileName, String localDirectory, String localFileName, boolean append, boolean deleteRemote) throws, InterruptedException { ... }

public static boolean resourceExists(String smbHost, String smbShare, String smbUser, String smbPass, String smbAuthDomain, String smbFileName, boolean checkWriteability) throws jcifs.CIFSException { ... }

 public static String listResources (String smbHost, String smbShare, String smbUser, String smbPass, String smbAuthDomain, String smbFileName, String smbFileFilter) throws jcifs.CIFSException,,  { ... }

public static String getAttributes(String smbHost, String smbShare, String smbUser, String smbPass, String smbAuthDomain, String smbFileName) throws jcifs.CIFSException,, { ... }

Next I created a jar file from this class, which could be processed with the Add-In "Java Gateway Wizard" included in Studio and transferred to corresponsing cache wrapper classes.  

This made it possible to create an operation dependending on a Java gateway, by use of the created classes. By using specially created message types, the configuration of the dynamic parameters could be communicated. The operation can be set to any Windows shares by e.g. reading the configuration from a database table and sending the required information to the operation. It is also possible to read files from different sources and copy them to the destinations without having to determine beforehand on which computers the corresponding shares are set up.

If you are interested in further details on how to solve the problem, please send us a PN. Then I will gladly give further information or provide more detailed code components.


Martin Staudigel