Skip to content

Commit

Permalink
Merge pull request #69 from guusdk/68_compatibility-openfire-4.9.0
Browse files Browse the repository at this point in the history
Fix compatibility issue with Openfire 4.9.0
  • Loading branch information
akrherz authored Sep 11, 2024
2 parents 98cad71 + 369a06a commit 5bad871
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 59 deletions.
2 changes: 2 additions & 0 deletions changelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ <h1>

<p><b>4.5.1</b> -- tbd</p>
<ul>
<li>Now requires Openfire 4.8.0 or later.</li>
<li>[<a href="https://github.com/igniterealtime/openfire-fastpath-plugin/issues/68">#68</a>] - Fix compatibility issue with Openfire 4.9.0.</li>
</ul>

<p><b>4.5.0</b> -- November 20, 2023</p>
Expand Down
4 changes: 2 additions & 2 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<description>Support for managed queued chat requests, such as a support team might use.</description>
<author>Ignite Realtime</author>
<version>${project.version}</version>
<date>2023-11-20</date>
<minServerVersion>4.1.1</minServerVersion>
<date>2024-09-11</date>
<minServerVersion>4.8.0</minServerVersion>
<databaseKey>fastpath</databaseKey>
<databaseVersion>1</databaseVersion>

Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>plugins</artifactId>
<groupId>org.igniterealtime.openfire</groupId>
<version>4.7.1</version>
<version>4.8.0</version>
</parent>
<groupId>org.igniterealtime.openfire.plugins</groupId>
<artifactId>fastpath</artifactId>
Expand All @@ -20,8 +20,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>11</source>
<target>11</target>
<fork>true</fork>
<compilerArgument>-XDignore.symbol.file</compilerArgument>
</configuration>
Expand Down
34 changes: 11 additions & 23 deletions src/java/org/jivesoftware/openfire/fastpath/FastpathPlugin.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2004-2008 Jive Software. All rights reserved.
* Copyright (C) 2004-2008 Jive Software, 2024 Ignite Realtime Foundation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,9 @@
package org.jivesoftware.openfire.fastpath;

import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;

import org.jivesoftware.openfire.cluster.ClusterEventListener;
Expand All @@ -40,9 +42,6 @@

import org.eclipse.jetty.apache.jsp.JettyJasperInitializer;
import org.eclipse.jetty.plus.annotation.ContainerInitializer;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.servlet.*;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.webapp.WebAppContext;

import org.apache.tomcat.InstanceManager;
Expand All @@ -64,25 +63,14 @@ public class FastpathPlugin implements Plugin, ClusterEventListener {
private WebAppContext context;

public void initializePlugin(PluginManager manager, File pluginDirectory) {
// Check if we Enterprise is installed and stop loading this plugin if found
File pluginDir = new File(JiveGlobals.getHomeDirectory(), "plugins");
File[] jars = pluginDir.listFiles(new FileFilter() {
public boolean accept(File pathname) {
String fileName = pathname.getName().toLowerCase();
return (fileName.equalsIgnoreCase("enterprise.jar"));
}
});
if (jars.length > 0) {
// Do not load this plugin since Enterprise is still installed
System.out.println("Enterprise plugin found. Stopping Fastpath Plugin");
throw new IllegalStateException("This plugin cannot run next to the Enterprise plugin");
}

// Make sure that the fastpath folder exists under the home directory
File fastpathDir = new File(JiveGlobals.getHomeDirectory() +
File.separator + "fastpath");
if (!fastpathDir.exists()) {
fastpathDir.mkdirs();
Path fastpathDir = JiveGlobals.getHomePath().resolve("fastpath");
if (!Files.exists(fastpathDir)) {
try {
Files.createDirectories(fastpathDir);
} catch (IOException e) {
throw new IllegalStateException("Unable to create fastpath directory: " + fastpathDir, e);
}
}

workgroupManagerStart();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright (C) 2004-2008 Jive Software, 2024 Ignite Realtime Foundation. All rights reserved.
*
* Licensed 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.jivesoftware.xmpp.workgroup.interceptor;

import org.jivesoftware.util.StringUtils;
Expand All @@ -17,11 +32,11 @@ public class UserInterceptor implements PacketInterceptor {
/**
* A Map of banned bare JIDs.
*/
private Map<String,String> jidBanMap = new HashMap<String,String>();
private Map<String,String> jidBanMap = new HashMap<>();
/**
* A Map of banned domains.
*/
private Map<String,String> domainBanMap = new HashMap<String,String>();
private Map<String,String> domainBanMap = new HashMap<>();
private String fromEmail;
private String fromName;
private String emailSubject = "";
Expand Down Expand Up @@ -130,7 +145,7 @@ public void setEmailNotifyList(String notifyList) {
emailNotifyList = null;
}
else {
emailNotifyList = new ArrayList<String>();
emailNotifyList = new ArrayList<>();
StringTokenizer tokenizer = new StringTokenizer(notifyList, ",");
while (tokenizer.hasMoreTokens()) {
String emailAddress = tokenizer.nextToken().trim();
Expand Down Expand Up @@ -215,14 +230,14 @@ private void sendNotifications(Packet packet, String packetSender) {
return;
}
for (String toEmail : emailNotifyList) {
body = StringUtils.replace(emailBody, "{packet}", packet.toXML());
body = StringUtils.replace(body, "{sender}", packetSender);
body = emailBody.replaceAll("\\{packet}", packet.toXML());
body = body.replaceAll("\\{sender}", packetSender);
emailService.sendMessage(null, toEmail, fromName, fromEmail, emailSubject, body, null);
}
}

private static Map<String,String> getMap(String iPStr) {
Map<String,String> newMap = new HashMap<String,String>();
Map<String,String> newMap = new HashMap<>();
if (iPStr == null) {
return newMap;
}
Expand All @@ -236,7 +251,7 @@ private static Map<String,String> getMap(String iPStr) {


private static String getString(Map<String,String> map) {
if (map == null || map.size() == 0) {
if (map == null || map.isEmpty()) {
return "";
}
// Iterate through the elements in the map.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2004-2008 Jive Software. All rights reserved.
* Copyright (C) 2004-2008 Jive Software, 2024 Ignite Realtime Foundation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -334,9 +334,9 @@ else if (beforeDate == null) {
}

private String stripWildcards(String string) {
string = StringUtils.replace(string, "*", "");
string = StringUtils.replace(string, "?", "");
string = StringUtils.replace(string, "~", "");
string = string.replaceAll("\\*", "");
string = string.replaceAll("\\?", "");
string = string.replaceAll("~", "");
return string;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2004-2008 Jive Software. All rights reserved.
* Copyright (C) 2004-2008 Jive Software, 2024 Ignite Realtime Foundation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,6 +19,8 @@
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.nio.file.Files;
import java.nio.file.Path;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
Expand Down Expand Up @@ -137,7 +139,7 @@ public class ChatSearchManager implements WorkgroupEventListener {
* Holds the path to the parent folder of the folders that will store the workgroup
* index files.
*/
private static String parentFolder = JiveGlobals.getHomeDirectory() + File.separator + "index";
private static Path parentFolder = JiveGlobals.getHomePath().resolve("index");
private static final long ONE_HOUR = 60 * 60 * 1000;

/**
Expand All @@ -147,7 +149,7 @@ public class ChatSearchManager implements WorkgroupEventListener {
*/
private Workgroup workgroup;
private Analyzer indexerAnalyzer;
private String searchDirectory;
private Path searchDirectory;
private Searcher searcher = null;
private IndexReader searcherReader = null;
ReadWriteLock searcherLock = new ReentrantReadWriteLock();
Expand Down Expand Up @@ -180,9 +182,12 @@ public class ChatSearchManager implements WorkgroupEventListener {

static {
// Check if we need to create the parent folder
File dir = new File(parentFolder);
if (!dir.exists() || !dir.isDirectory()) {
dir.mkdir();
if (!Files.exists(parentFolder) || !Files.isDirectory(parentFolder)) {
try {
Files.createDirectories(parentFolder);
} catch (IOException e) {
Log.warn("Unable to create folder: " + parentFolder, e);
}
}
}

Expand Down Expand Up @@ -299,7 +304,7 @@ private static int getOptimizationFrequency() {

ChatSearchManager(Workgroup workgroup) {
this.workgroup = workgroup;
searchDirectory = parentFolder + File.separator + workgroup.getJID().getNode();
searchDirectory = parentFolder.resolve(workgroup.getJID().getNode());
loadAnalyzer();
loadLastUpdated();
WorkgroupEventDispatcher.addListener(this);
Expand Down Expand Up @@ -460,9 +465,8 @@ public synchronized void rebuildIndex() throws IOException {
* there is a problem adding a document to the index.
*/
public synchronized void updateIndex(boolean forceUpdate) throws IOException {
// Check that the index files exist
File dir = new File(searchDirectory);
boolean create = !dir.exists() || !dir.isDirectory();
// Check that the index files exist;
boolean create = !Files.exists(searchDirectory) || !Files.isDirectory(searchDirectory);
if (lastUpdated == null || create) {
// Recreate the index since it was never created or the index files disappeared
rebuildIndex();
Expand Down Expand Up @@ -511,12 +515,12 @@ public void delete() {
// Ignore.
}
// Delete index files
String[] files = new File(searchDirectory).list();
String[] files = searchDirectory.toFile().list();
for (int i = 0; i < files.length; i++) {
File file = new File(searchDirectory, files[i]);
File file = new File(searchDirectory.toFile(), files[i]);
file.delete();
}
new File(searchDirectory).delete();
searchDirectory.toFile().delete();
// Delete dates from the database
deleteDates();
// Remove this instance from the list of instances
Expand All @@ -543,8 +547,8 @@ public void delete() {
public Searcher getSearcher() throws IOException {
synchronized (indexerAnalyzer) {
if (searcherReader == null) {
if (searchDirectory != null && IndexReader.indexExists(searchDirectory)) {
searcherReader = IndexReader.open(searchDirectory);
if (searchDirectory != null && IndexReader.indexExists(searchDirectory.toFile())) {
searcherReader = IndexReader.open(searchDirectory.toFile());
searcher = new IndexSearcher(searcherReader);
}
else {
Expand All @@ -553,7 +557,7 @@ public Searcher getSearcher() throws IOException {
Log.warn("Search " +
"directory not set, you must rebuild the index.");
}
else if (!IndexReader.indexExists(searchDirectory)) {
else if (!IndexReader.indexExists(searchDirectory.toFile())) {
Log.warn("Search " +
"directory " + searchDirectory + " does not appear to " +
"be a valid search index. You must rebuild the index.");
Expand Down Expand Up @@ -945,7 +949,7 @@ private void addTranscriptToIndex(ChatInformation chat, IndexWriter writer) thro
* existing index should be used if it's found there.
*/
private IndexWriter getWriter(boolean create) throws IOException {
IndexWriter writer = new IndexWriter(searchDirectory, indexerAnalyzer, create);
IndexWriter writer = new IndexWriter(searchDirectory.toFile(), indexerAnalyzer, create);
return writer;
}

Expand Down
2 changes: 1 addition & 1 deletion src/web/agent-selectors.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"<%= descriptor.getBeanClass().getName() %>",
"<%= descriptor.getValue("version") %>",
"<%= descriptor.getValue("author") %>",
"<%= StringUtils.replace(descriptor.getShortDescription(), "\"", "\\\"") %>"
"<%= descriptor.getShortDescription().replaceAll("\"", "\\\"") %>"
)
<% if ((availableAgentSelectors.size() - i) > 1) { %>
,
Expand Down
4 changes: 2 additions & 2 deletions src/web/interceptors.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
}
private String escapeHTML(String html) {
html = StringUtils.replace(html, "\"", "&quot;");
html = html.replaceAll("\"", "&quot;");
return StringUtils.escapeHTMLTags(html);
}
%>
Expand Down Expand Up @@ -598,7 +598,7 @@ var routerInfo = new Array(
"<%= descriptor.getBeanClass().getName() %>",
"<%= descriptor.getValue("version") %>",
"<%= descriptor.getValue("author") %>",
"<%= StringUtils.replace(descriptor.getShortDescription(), "\"", "\\\"") %>"
"<%= descriptor.getShortDescription().replaceAll("\"", "\\\"") %>"
)
<% if ((interceptorManager.getAvailableInterceptors().size() - i) > 1) { %>
,
Expand Down

0 comments on commit 5bad871

Please sign in to comment.