-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #212 from malakaganga/add_smb2
Add SMB2 support to file connector
- Loading branch information
Showing
27 changed files
with
366 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/java/org/wso2/carbon/connector/connection/SMB2FileSystemSetup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. | ||
* | ||
* WSO2 LLC. 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.wso2.carbon.connector.connection; | ||
|
||
import org.apache.commons.vfs2.FileSystemOptions; | ||
import org.wso2.carbon.connector.pojo.ConnectionConfiguration; | ||
import org.wso2.carbon.connector.utils.Const; | ||
|
||
/** | ||
* Sets up local file system. | ||
*/ | ||
public class SMB2FileSystemSetup implements ProtocolBasedFileSystemSetup { | ||
|
||
@Override | ||
public String setupFileSystemHandler(FileSystemOptions fso, ConnectionConfiguration fsConfig) { | ||
|
||
return Const.SMB2_PROTOCOL_PREFIX + constructVfsUrl(fsConfig); | ||
|
||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/main/java/org/wso2/carbon/connector/connection/SMBConnectionFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. | ||
* | ||
* WSO2 LLC. 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.wso2.carbon.connector.connection; | ||
|
||
import org.apache.commons.vfs2.FileObject; | ||
import org.apache.commons.vfs2.FileSystemManager; | ||
import org.apache.commons.vfs2.FileSystemOptions; | ||
import org.wso2.carbon.connector.core.pool.ConnectionFactory; | ||
import org.wso2.carbon.connector.pojo.ConnectionConfiguration; | ||
|
||
public class SMBConnectionFactory implements ConnectionFactory { | ||
private ConnectionConfiguration connectionConfiguration; | ||
public SMBConnectionFactory(ConnectionConfiguration connectionConfiguration) { | ||
this.connectionConfiguration = connectionConfiguration; | ||
} | ||
@Override | ||
public Object makeObject() throws Exception { | ||
FileSystemHandler fileSystemConnection = new FileSystemHandler(connectionConfiguration); | ||
return fileSystemConnection; | ||
} | ||
|
||
@Override | ||
public void destroyObject(Object connection) throws Exception { | ||
((FileSystemHandler) connection).close(); | ||
} | ||
|
||
@Override | ||
public boolean validateObject(Object connection) { | ||
try { | ||
FileSystemHandler fileSystemHandlerConnection = (FileSystemHandler) connection; | ||
String filePath = fileSystemHandlerConnection.getBaseDirectoryPath(); | ||
FileSystemManager fsManager = fileSystemHandlerConnection.getFsManager(); | ||
FileSystemOptions fso = fileSystemHandlerConnection.getFsOptions(); | ||
|
||
// Use try-with-resources statement for the FileObject to ensure it's properly closed | ||
try (FileObject fileObject = fsManager.resolveFile(filePath, fso)) { | ||
// Attempt to perform a simple operation on the root directory. | ||
// Checking for existence is a minimal, non-intrusive operation. | ||
return fileObject.exists(); // This throws an exception if the connection is not valid | ||
} | ||
} catch (Throwable e) { | ||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public void activateObject(Object o) throws Exception { | ||
// Nothing to do here | ||
} | ||
|
||
@Override | ||
public void passivateObject(Object o) throws Exception { | ||
// Nothing to do here | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/org/wso2/carbon/connector/connection/SMBFileSystemSetup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. | ||
* | ||
* WSO2 LLC. 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.wso2.carbon.connector.connection; | ||
|
||
import org.apache.commons.vfs2.FileSystemOptions; | ||
import org.wso2.carbon.connector.pojo.ConnectionConfiguration; | ||
import org.wso2.carbon.connector.utils.Const; | ||
|
||
/** | ||
* Sets up local file system. | ||
*/ | ||
public class SMBFileSystemSetup implements ProtocolBasedFileSystemSetup { | ||
|
||
@Override | ||
public String setupFileSystemHandler(FileSystemOptions fso, ConnectionConfiguration fsConfig) { | ||
|
||
return Const.SMB_PROTOCOL_PREFIX + constructVfsUrl(fsConfig); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.