summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ivy.xml5
-rw-r--r--source/net/yacy/cora/document/id/MultiProtocolURL.java44
-rw-r--r--source/net/yacy/crawler/retrieval/SMBLoader.java25
-rw-r--r--test/java/net/yacy/cora/document/id/MultiProtocolURLTest.java13
4 files changed, 52 insertions, 35 deletions
diff --git a/ivy.xml b/ivy.xml
index 3d6f5d054..71c9a4a70 100644
--- a/ivy.xml
+++ b/ivy.xml
@@ -31,7 +31,7 @@
<dependency org="io.opentracing" name="opentracing-util" rev="0.33.0"/>
<dependency org="javax.servlet" name="javax.servlet-api" rev="4.0.1"/>
<dependency org="javainetlocator" name="inetaddresslocator" rev="2.18" />
- <dependency org="jcifs" name="jcifs" rev="1.3.17" conf="compile->master" />
+ <dependency org="eu.agno3.jcifs" name="jcifs-ng" rev="2.1.10" />
<dependency org="net.arnx" name="jsonic" rev="1.3.10"/>
<dependency org="net.jthink" name="jaudiotagger" rev="3.0.1"/>
<dependency org="net.sourceforge.jchardet" name="jchardet" rev="1.0"/>
@@ -44,7 +44,8 @@
<dependency org="org.apache.commons" name="commons-lang3" rev="3.20.0" />
<dependency org="org.apache.httpcomponents" name="httpclient" rev="4.5.14"/>
<dependency org="org.apache.httpcomponents" name="httpmime" rev="4.5.14"/>
- <dependency org="org.apache.james" name="apache-mime4j" rev="0.6"/>
+ <dependency org="org.apache.james" name="apache-mime4j-core" rev="0.8.14"/>
+ <dependency org="org.apache.james" name="apache-mime4j-dom" rev="0.8.14"/>
<dependency org="org.apache.lucene" name="lucene-analysis-common" rev="9.0.0"/>
<dependency org="org.apache.lucene" name="lucene-backward-codecs" rev="9.0.0" />
<dependency org="org.apache.lucene" name="lucene-classification" rev="9.0.0" />
diff --git a/source/net/yacy/cora/document/id/MultiProtocolURL.java b/source/net/yacy/cora/document/id/MultiProtocolURL.java
index 0ff750b09..1cc8a3b9e 100644
--- a/source/net/yacy/cora/document/id/MultiProtocolURL.java
+++ b/source/net/yacy/cora/document/id/MultiProtocolURL.java
@@ -52,6 +52,8 @@ import java.util.regex.Pattern;
import org.apache.http.HttpStatus;
+import jcifs.CIFSContext;
+import jcifs.context.SingletonContext;
import jcifs.smb.SmbException;
import jcifs.smb.SmbFile;
import jcifs.smb.SmbFileInputStream;
@@ -77,6 +79,7 @@ public class MultiProtocolURL implements Serializable, Comparable<MultiProtocolU
private static final long serialVersionUID = -1173233022912141884L;
private static final long SMB_TIMEOUT = 5000;
+ private static final CIFSContext SMB_CONTEXT = SingletonContext.getInstance();
public static final int TLD_any_zone_filter = 255; // from TLD zones can be filtered during search; this is the catch-all filter
private static final Pattern backPathPattern = Pattern.compile("(/[^/]+(?<!/\\.{1,2})/)[.]{2}(?=/|$)|/\\.(?=/)|/(?=/)");
@@ -2393,7 +2396,7 @@ public class MultiProtocolURL implements Serializable, Comparable<MultiProtocolU
public SmbFile getSmbFile() throws MalformedURLException {
if (!isSMB()) throw new MalformedURLException();
final String url = unescape(this.toNormalform(true));
- return new SmbFile(url);
+ return new SmbFile(url, SMB_CONTEXT);
}
// some methods that let the MultiProtocolURI look like a java.io.File object
@@ -2401,8 +2404,8 @@ public class MultiProtocolURL implements Serializable, Comparable<MultiProtocolU
public boolean exists() throws IOException {
if (isFile()) return getFSFile().exists();
- if (isSMB()) try {
- return TimeoutRequest.exists(getSmbFile(), SMB_TIMEOUT);
+ if (isSMB()) try (final SmbFile smbFile = getSmbFile()) {
+ return TimeoutRequest.exists(smbFile, SMB_TIMEOUT);
} catch (final SmbException e) {
throw new IOException("SMB.exists SmbException (" + e.getMessage() + ") for " + toNormalform(false));
} catch (final MalformedURLException e) {
@@ -2413,8 +2416,8 @@ public class MultiProtocolURL implements Serializable, Comparable<MultiProtocolU
public boolean canRead() throws IOException {
if (isFile()) return getFSFile().canRead();
- if (isSMB()) try {
- return TimeoutRequest.canRead(getSmbFile(), SMB_TIMEOUT);
+ if (isSMB()) try (final SmbFile smbFile = getSmbFile()) {
+ return TimeoutRequest.canRead(smbFile, SMB_TIMEOUT);
} catch (final SmbException e) {
throw new IOException("SMB.canRead SmbException (" + e.getMessage() + ") for " + toNormalform(false));
} catch (final MalformedURLException e) {
@@ -2425,8 +2428,8 @@ public class MultiProtocolURL implements Serializable, Comparable<MultiProtocolU
public boolean canWrite() throws IOException {
if (isFile()) return getFSFile().canWrite();
- if (isSMB()) try {
- return TimeoutRequest.canWrite(getSmbFile(), SMB_TIMEOUT);
+ if (isSMB()) try (final SmbFile smbFile = getSmbFile()) {
+ return TimeoutRequest.canWrite(smbFile, SMB_TIMEOUT);
} catch (final SmbException e) {
throw new IOException("SMB.canWrite SmbException (" + e.getMessage() + ") for " + toNormalform(false));
} catch (final MalformedURLException e) {
@@ -2437,8 +2440,8 @@ public class MultiProtocolURL implements Serializable, Comparable<MultiProtocolU
public boolean isHidden() throws IOException {
if (isFile()) return getFSFile().isHidden();
- if (isSMB()) try {
- return TimeoutRequest.isHidden(getSmbFile(), SMB_TIMEOUT);
+ if (isSMB()) try (final SmbFile smbFile = getSmbFile()) {
+ return TimeoutRequest.isHidden(smbFile, SMB_TIMEOUT);
} catch (final SmbException e) {
throw new IOException("SMB.isHidden SmbException (" + e.getMessage() + ") for " + toNormalform(false));
} catch (final MalformedURLException e) {
@@ -2449,8 +2452,8 @@ public class MultiProtocolURL implements Serializable, Comparable<MultiProtocolU
public boolean isDirectory() throws IOException {
if (isFile()) return getFSFile().isDirectory();
- if (isSMB()) try {
- return TimeoutRequest.isDirectory(getSmbFile(), SMB_TIMEOUT);
+ if (isSMB()) try (final SmbFile smbFile = getSmbFile()) {
+ return TimeoutRequest.isDirectory(smbFile, SMB_TIMEOUT);
} catch (final SmbException e) {
throw new IOException("SMB.isDirectory SmbException (" + e.getMessage() + ") for " + toNormalform(false));
} catch (final MalformedURLException e) {
@@ -2466,8 +2469,8 @@ public class MultiProtocolURL implements Serializable, Comparable<MultiProtocolU
ConcurrentLog.logException(e);
return -1;
}
- if (isSMB()) try {
- return getSmbFile().length();
+ if (isSMB()) try (final SmbFile smbFile = getSmbFile()) {
+ return smbFile.length();
//return TimeoutRequest.length(getSmbFile(), SMB_TIMEOUT); // a timeout request is a bad idea, that will create a lot of concurrent threads during crawling
} catch (final Throwable e) {
ConcurrentLog.logException(e);
@@ -2478,8 +2481,8 @@ public class MultiProtocolURL implements Serializable, Comparable<MultiProtocolU
public long lastModified() throws IOException {
if (isFile()) return getFSFile().lastModified();
- if (isSMB()) try {
- return getSmbFile().lastModified();
+ if (isSMB()) try (final SmbFile smbFile = getSmbFile()) {
+ return smbFile.lastModified();
// return TimeoutRequest.lastModified(getSmbFile(), SMB_TIMEOUT); // a timeout request is a bad idea, that will create a lot of concurrent threads during crawling
} catch (final SmbException e) {
throw new IOException("SMB.lastModified SmbException (" + e.getMessage() + ") for " + toNormalform(false));
@@ -2491,8 +2494,8 @@ public class MultiProtocolURL implements Serializable, Comparable<MultiProtocolU
public String getName() throws IOException {
if (isFile()) return getFSFile().getName();
- if (isSMB()) try {
- return getSmbFile().getName();
+ if (isSMB()) try (final SmbFile smbFile = getSmbFile()) {
+ return smbFile.getName();
} catch (final MalformedURLException e) {
throw new IOException("SMB.getName MalformedURLException (" + e.getMessage() + ") for " + toNormalform(false) );
}
@@ -2511,8 +2514,7 @@ public class MultiProtocolURL implements Serializable, Comparable<MultiProtocolU
*/
public String[] list() throws IOException {
if (isFile() && !isHidden()) return getFSFile().list();
- if (isSMB()) try {
- final SmbFile sf = getSmbFile();
+ if (isSMB()) try (final SmbFile sf = getSmbFile()) {
if (!sf.isDirectory() || sf.isHidden()) return null;
try {
return TimeoutRequest.list(sf, SMB_TIMEOUT);
@@ -2589,7 +2591,9 @@ public class MultiProtocolURL implements Serializable, Comparable<MultiProtocolU
return getFSFile().exists();
}
if (isSMB()) {
- return getSmbFile().exists();
+ try (final SmbFile smbFile = getSmbFile()) {
+ return smbFile.exists();
+ }
}
if (isFTP()) {
final FTPClient client = new FTPClient();
diff --git a/source/net/yacy/crawler/retrieval/SMBLoader.java b/source/net/yacy/crawler/retrieval/SMBLoader.java
index 6b624b33f..e8109e402 100644
--- a/source/net/yacy/crawler/retrieval/SMBLoader.java
+++ b/source/net/yacy/crawler/retrieval/SMBLoader.java
@@ -38,6 +38,8 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
+import jcifs.CIFSContext;
+import jcifs.context.SingletonContext;
import jcifs.smb.SmbException;
import jcifs.smb.SmbFile;
import jcifs.smb.SmbFileInputStream;
@@ -60,6 +62,7 @@ import net.yacy.search.Switchboard;
public class SMBLoader {
public static final long DEFAULT_MAXFILESIZE = 1024 * 1024 * 10;
+ private static final CIFSContext SMB_CONTEXT = SingletonContext.getInstance();
private final Switchboard sb;
private final ConcurrentLog log;
@@ -120,8 +123,9 @@ public class SMBLoader {
s = MultiProtocolURL.escape(s).toString();
if (!s.endsWith("/") && !s.endsWith("\\")) {
// check if this is a directory
- SmbFile sf = new SmbFile(u + s);
- if (sf.isDirectory()) s = s + "/";
+ try (final SmbFile sf = new SmbFile(u + s, SMB_CONTEXT)) {
+ if (sf.isDirectory()) s = s + "/";
+ }
}
list.add(u + s);
}
@@ -198,20 +202,17 @@ public class SMBLoader {
}
public static void main(String[] args) {
- //jcifs.Config.setProperty( "jcifs.netbios.wins", "192.168.1.220" );
- //NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("domain", "username", "password");
- SmbFileInputStream in;
- try {
- SmbFile sf = new SmbFile(args[0]);
+ try (final SmbFile sf = new SmbFile(args[0], SMB_CONTEXT)) {
if (sf.isDirectory()) {
String[] s = sf.list();
for (String t: s) System.out.println(t);
} else {
- in = new SmbFileInputStream(sf);
- byte[] b = new byte[8192];
- int n;
- while(( n = in.read( b )) > 0 ) {
- System.out.write( b, 0, n );
+ try (final SmbFileInputStream in = new SmbFileInputStream(sf)) {
+ byte[] b = new byte[8192];
+ int n;
+ while(( n = in.read( b )) > 0 ) {
+ System.out.write( b, 0, n );
+ }
}
}
} catch (final SmbException e) {
diff --git a/test/java/net/yacy/cora/document/id/MultiProtocolURLTest.java b/test/java/net/yacy/cora/document/id/MultiProtocolURLTest.java
index 4162096c9..4f50baf6d 100644
--- a/test/java/net/yacy/cora/document/id/MultiProtocolURLTest.java
+++ b/test/java/net/yacy/cora/document/id/MultiProtocolURLTest.java
@@ -1,6 +1,7 @@
package net.yacy.cora.document.id;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -15,10 +16,21 @@ import java.util.TreeSet;
import org.junit.Test;
+import jcifs.context.SingletonContext;
+import jcifs.smb.SmbFile;
+
/**
* Automated unit tests for the {@link MultiProtocolURL} class.
*/
public class MultiProtocolURLTest {
+
+ @Test
+ public void testSmbFileUsesSharedContext() throws MalformedURLException {
+ final MultiProtocolURL url = new MultiProtocolURL("smb://example.test/share/file.txt");
+ try (final SmbFile smbFile = url.getSmbFile()) {
+ assertSame(SingletonContext.getInstance(), smbFile.getContext());
+ }
+ }
@Test
public void testSessionIdRemoval() throws MalformedURLException {
@@ -511,4 +523,3 @@ public class MultiProtocolURLTest {
}
-