Skip to content

Commit

Permalink
Reduce errors while processing plugins
Browse files Browse the repository at this point in the history
When a plugin jar file is invalid, the amount of errors logged should be dramatically reduced.
  • Loading branch information
guusdk committed Sep 19, 2024
1 parent 58cc029 commit 1f750f2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/org/jivesoftware/site/DownloadStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/jivesoftware/site/PluginManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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");

Expand Down

0 comments on commit 1f750f2

Please sign in to comment.