Project

General

Profile

« Previous | Next » 

Revision 63301

Added by Michele Artini 3 months ago

fixed a NPE

View differences:

modules/dnet-collector-plugins/branches/gtr2_michele/src/main/java/eu/dnetlib/data/collector/plugins/projects/gtr2/Gtr2Helper.java
32 32
	}
33 33

  
34 34
	public static Document loadURL(final String url) {
35
		try {
36
			final String cleanUrl = cleanURL(url);
37
			final String xml = loadURL(cleanUrl, 0);
38
			return DocumentHelper.parseText(xml);
39
		} catch (final Exception e) {
40
			log.error("Error parsing xml", e);
41
			throw new CollectorServiceRuntimeException("Error parsing xml", e);
42
		}
35
		final String cleanUrl = cleanURL(url);
36
		return loadURL(cleanUrl, 0);
43 37
	}
44 38

  
45
	private static String loadURL(final String cleanUrl, final int attempt) {
39
	private static Document loadURL(final String cleanUrl, final int attempt) {
46 40
		try {
47 41
			log.debug("  * Downloading Url: " + cleanUrl);
48 42
			final byte[] bytes = connector.getInputSource(cleanUrl).getBytes("UTF-8");
49
			return new String(bytes);
50
		} catch (final Exception e) {
51
			log.error("Error dowloading url: " + cleanUrl, e);
43
			return DocumentHelper.parseText(new String(bytes));
44
		} catch (final Throwable e) {
45
			log.error("Error dowloading url: " + cleanUrl + ", attempt = " + attempt, e);
52 46
			if (attempt < MAX_ATTEMPTS) {
47
				try {
48
					Thread.sleep(5000);
49
				} catch (final InterruptedException e1) {
50
					throw new CollectorServiceRuntimeException("Error dowloading url: " + cleanUrl, e);
51
				}
53 52
				return loadURL(cleanUrl, attempt + 1);
54 53
			} else {
55 54
				throw new CollectorServiceRuntimeException("Error dowloading url: " + cleanUrl, e);

Also available in: Unified diff