From 1f750f245cd5c39c612bff9634525432926a7cc7 Mon Sep 17 00:00:00 2001 From: Guus der Kinderen Date: Thu, 19 Sep 2024 13:01:12 +0200 Subject: [PATCH] Reduce errors while processing plugins When a plugin jar file is invalid, the amount of errors logged should be dramatically reduced. --- src/main/java/org/jivesoftware/site/DownloadStats.java | 4 ++++ .../java/org/jivesoftware/site/PluginDownloadServlet.java | 4 ++++ src/main/java/org/jivesoftware/site/PluginManager.java | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/src/main/java/org/jivesoftware/site/DownloadStats.java b/src/main/java/org/jivesoftware/site/DownloadStats.java index 82860eef..d0d02696 100644 --- a/src/main/java/org/jivesoftware/site/DownloadStats.java +++ b/src/main/java/org/jivesoftware/site/DownloadStats.java @@ -279,6 +279,10 @@ public void run() { */ public static void addListingToDatabase( String ipAddress, String product, String os, int type, ServletContext context ) { + // Correct for X-Forwarded-For header value sometimes containing a list of IPs. Use the last one. + if (ipAddress != null && ipAddress.contains(",")) { + ipAddress = ipAddress.substring(ipAddress.indexOf(",")+1).trim(); + } final DbConnectionManager connectionManager = DbConnectionManager.getInstance(); Connection con = null; PreparedStatement pstmt = null; diff --git a/src/main/java/org/jivesoftware/site/PluginDownloadServlet.java b/src/main/java/org/jivesoftware/site/PluginDownloadServlet.java index c88dbd2a..30c80b4f 100644 --- a/src/main/java/org/jivesoftware/site/PluginDownloadServlet.java +++ b/src/main/java/org/jivesoftware/site/PluginDownloadServlet.java @@ -299,6 +299,10 @@ public static String getMetadataFromPlugin( ZipFile archive, String propertyPath { try ( final InputStream in = getUncompressedEntryFromArchive( archive, "plugin.xml" ) ) { + if (in == null) { + Log.info("Unable to find 'plugin.xml' in '{}", archive); + return null; + } final SAXReader saxReader = new SAXReader(); final Document doc = saxReader.read(in); final Element element = (Element)doc.selectSingleNode( propertyPath ); diff --git a/src/main/java/org/jivesoftware/site/PluginManager.java b/src/main/java/org/jivesoftware/site/PluginManager.java index 66d86911..4b6dec89 100644 --- a/src/main/java/org/jivesoftware/site/PluginManager.java +++ b/src/main/java/org/jivesoftware/site/PluginManager.java @@ -35,6 +35,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static org.jivesoftware.site.PluginDownloadServlet.getUncompressedEntryFromArchive; + public class PluginManager { private static final Logger Log = LoggerFactory.getLogger( PluginManager.class ); @@ -382,6 +384,10 @@ public Metadata( Path mavenFile ) throws IOException, DocumentException this.mavenFile = mavenFile; try ( final JarFile archive = new JarFile( mavenFile.toFile() ) ) { + if (getUncompressedEntryFromArchive(archive, "plugin.xml") == null) { + throw new IOException("Unable to find 'plugin.xml' in: " + mavenFile); + } + this.hasReadme = PluginDownloadServlet.archiveContainsEntry( archive, "readme.html"); this.hasChangelog = PluginDownloadServlet.archiveContainsEntry( archive, "changelog.html");