Commit 0b3caaf6 authored by Matt Tucker's avatar Matt Tucker Committed by matt

Refactoring work.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@607 b35dd754-fafc-0310-a699-88a17e54d16e
parent 85fba0ad
......@@ -213,16 +213,12 @@
<component name="libraryTable">
<library name="Messenger">
<CLASSES>
<root url="jar://$PROJECT_DIR$/build/lib/merge/jax-qname.jar!/" />
<root url="jar://$PROJECT_DIR$/build/lib/dist/mysql.jar!/" />
<root url="jar://$PROJECT_DIR$/build/lib/merge/jsr173_1.0_ri.jar!/" />
<root url="jar://$PROJECT_DIR$/build/lib/merge/jetty.jar!/" />
<root url="jar://$PROJECT_DIR$/build/lib/merge/commons-logging.jar!/" />
<root url="jar://$PROJECT_DIR$/build/lib/merge/namespace.jar!/" />
<root url="jar://$PROJECT_DIR$/build/lib/merge/dom4j.jar!/" />
<root url="jar://$PROJECT_DIR$/build/lib/dist/postgres.jar!/" />
<root url="jar://$PROJECT_DIR$/build/lib/dist/hsqldb.jar!/" />
<root url="jar://$PROJECT_DIR$/build/lib/merge/wls_stax.jar!/" />
<root url="jar://$PROJECT_DIR$/build/lib/junit.jar!/" />
<root url="jar://$PROJECT_DIR$/build/lib/jasper-compiler.jar!/" />
<root url="jar://$PROJECT_DIR$/build/lib/jasper-runtime.jar!/" />
......@@ -232,9 +228,9 @@
<root url="jar://$PROJECT_DIR$/build/lib/merge/jaxen.jar!/" />
<root url="jar://$PROJECT_DIR$/build/lib/merge/standard.jar!/" />
<root url="jar://$PROJECT_DIR$/build/lib/merge/jstl.jar!/" />
<root url="jar://$PROJECT_DIR$/build/lib/whack.jar!/" />
<root url="jar://$PROJECT_DIR$/build/lib/merge/whack.jar!/" />
<root url="jar://$PROJECT_DIR$/build/lib/merge/jdic.jar!/" />
<root url="jar://$PROJECT_DIR$/build/lib/merge/xpp3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
......
......@@ -10,7 +10,6 @@ jetty.jar | Jetty 5.0.0
jasper-compiler.jar | Jetty 5.0.0
jasper-runtime.jar | Jetty 5.0.0
servlet.jar | Jetty 5.0.0
wls_stax.jar | Downloaded 10/19/2004
dom4j.jar | 1.5.2
jaxen.jar | 1.1 beta 4 (from DOM4J 1.5.2)
junit.jar | 3.8.1
......@@ -19,4 +18,5 @@ ant-subdirtask.jar | Revision 1.4 (CVS)
jdic.jar | 0.8.6 (for windows only)
xmltask.jar | 1.10.5
jstl.jar | Jakarta standard taglib 1.1.2
standard.jar | Jakarta standard taglib 1.1.2
\ No newline at end of file
standard.jar | Jakarta standard taglib 1.1.2
xpp3.jar | XPP_3 1.1.3.4.K
\ No newline at end of file
......@@ -14,14 +14,13 @@ package org.jivesoftware.messenger;
import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.xmpp.packet.Packet;
import org.dom4j.io.XMLWriter;
import org.xmlpull.v1.XmlPullParserException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.io.Writer;
/**
* <p>Represents a connection on the server.</p>
* Represents a connection on the server.
*
* @author Iain Shigeoka
*/
......@@ -138,7 +137,6 @@ public interface Connection {
*
* @param packet The packet to deliver.
* @throws UnauthorizedException If caller doesn't have permission to access this resource
* @throws org.xmlpull.v1.XmlPullParserException if there was a problem sending the packet
*/
void deliver(Packet packet) throws UnauthorizedException, XmlPullParserException;
void deliver(Packet packet) throws UnauthorizedException;
}
......@@ -16,11 +16,11 @@ import org.jivesoftware.util.*;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.DateFormat;
import java.util.*;
import org.dom4j.Document;
import org.dom4j.io.SAXReader;
import javax.naming.InitialContext;
......@@ -861,7 +861,8 @@ class InitPropLoader {
try {
in = getClass().getResourceAsStream("/messenger_init.xml");
if (in != null) {
Document doc = XPPReader.parseDocument(new InputStreamReader(in), this.getClass());
SAXReader reader = new SAXReader();
Document doc = reader.read(in);
messengerHome = doc.getRootElement().getText();
}
}
......@@ -869,13 +870,8 @@ class InitPropLoader {
Log.error("Error loading messenger_init.xml to find messengerHome.", e);
}
finally {
try {
if (in != null) {
in.close();
}
}
catch (Exception e) {
}
try { if (in != null) { in.close(); } }
catch (Exception e) { }
}
if (messengerHome != null) {
messengerHome = messengerHome.trim();
......
......@@ -125,13 +125,15 @@ public class OfflineMessageStrategy extends BasicModule {
Message response = new Message();
response.setTo(message.getFrom());
response.setFrom(xmppServer.createJID(null, null));
response.setBody("Message could not be delivered to " + message.getTo() + ". User is offline or unreachable.");
response.setBody("Message could not be delivered to " + message.getTo() +
". User is offline or unreachable.");
Session session = sessionManager.getSession(message.getFrom());
session.getConnection().deliver(response);
Message errorResponse = message.createCopy();
errorResponse.setError(new PacketError(PacketError.Type.continue_processing, PacketError.Condition.item_not_found));
errorResponse.setError(new PacketError(PacketError.Condition.item_not_found,
PacketError.Type.continue_processing));
session.getConnection().deliver(errorResponse);
}
catch (Exception e) {
......
......@@ -13,7 +13,6 @@ package org.jivesoftware.messenger;
import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.xmpp.packet.Packet;
import org.xmlpull.v1.XmlPullParserException;
/**
* Delivers packets to locally connected streams. This is the opposite
......@@ -33,5 +32,5 @@ public interface PacketDeliverer {
* @param packet The packet to route
* @throws java.lang.NullPointerException If the packet is null or the packet could not be routed
*/
public void deliver(Packet packet) throws UnauthorizedException, PacketException, XmlPullParserException;
public void deliver(Packet packet) throws UnauthorizedException, PacketException;
}
......@@ -261,7 +261,7 @@ public class SessionManager implements ConnectionCloseListener {
*
* @param packet
*/
private void broadcast(Packet packet) throws UnauthorizedException, PacketException, XmlPullParserException {
private void broadcast(Packet packet) throws UnauthorizedException, PacketException {
Iterator entries = resources.values().iterator();
while (entries.hasNext()) {
Session session = (Session)entries.next();
......@@ -776,7 +776,7 @@ public class SessionManager implements ConnectionCloseListener {
*
* @param packet The packet to be broadcast
*/
public void userBroadcast(String username, Packet packet) throws UnauthorizedException, PacketException, XmlPullParserException {
public void userBroadcast(String username, Packet packet) throws UnauthorizedException, PacketException {
sessionLock.readLock().lock();
try {
SessionMap sessionMap = (SessionMap)sessions.get(username);
......
......@@ -26,6 +26,10 @@ import java.util.*;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.QName;
import org.xmpp.packet.Presence;
import org.xmpp.packet.JID;
import org.xmpp.packet.IQ;
import org.xmpp.packet.PacketError;
/**
* A handler for the IQ packet with namespace http://jabber.org/protocol/muc#owner. This kind of
......@@ -41,7 +45,7 @@ public class IQOwnerHandler {
private XDataFormImpl configurationForm;
private MetaDataFragment probeResult;
private Element probeResult;
public IQOwnerHandler(MUCRoomImpl chatroom, PacketRouter packetRouter) {
this.room = chatroom;
......@@ -74,8 +78,8 @@ public class IQOwnerHandler {
throw new ForbiddenException();
}
IQ reply = packet.createResult();
Element element = ((XMPPDOMFragment)packet.getChildFragment()).getRootElement();
IQ reply = IQ.createResultIQ(packet);
Element element = packet.getChildElement();
// Analyze the action to perform based on the included element
Element formElement = element.element(QName.get("x", "jabber:x:data"));
......@@ -98,17 +102,17 @@ public class IQOwnerHandler {
// configuration form
if (!element.elementIterator().hasNext()) {
refreshConfigurationFormValues();
reply.setChildFragment(probeResult);
reply.setChildElement(probeResult.createCopy());
}
// An unknown and possibly incorrect element was included in the query
// element so answer a BAD_REQUEST error
else {
reply.setError(XMPPError.Code.BAD_REQUEST);
reply.setError(PacketError.Condition.bad_request);
}
}
}
}
if (reply.getRecipient() != null) {
if (reply.getTo() != null) {
// Send a reply only if the sender of the original packet was from a real JID. (i.e. not
// a packet generated locally)
router.route(reply);
......@@ -212,13 +216,12 @@ public class IQOwnerHandler {
item = (Element)items.next();
affiliation = item.attributeValue("affiliation");
if (hasJID) {
bareJID = XMPPAddress.parseBareAddress(item.attributeValue("jid"));
bareJID = new JID(item.attributeValue("jid")).toBareJID();
}
else {
// Get the bare JID based on the requested nick
nick = item.attributeValue("nick");
bareJID = room.getOccupant(nick).getChatUser().getAddress()
.toBareStringPrep();
bareJID = room.getOccupant(nick).getChatUser().getAddress().toBareJID();
}
jids.put(bareJID, affiliation);
}
......
......@@ -17,9 +17,12 @@ import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.jivesoftware.messenger.*;
import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.xmpp.packet.JID;
import org.xmpp.packet.Packet;
import org.xmpp.packet.PacketError;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.xml.stream.XMLStreamException;
/**
* Routes packets to the appropriate transport gateway or drops the packet.
......@@ -38,9 +41,9 @@ public class TransportHandler extends BasicModule implements ChannelHandler {
transports.put(transport.getName(), transport);
}
public void process(XMPPPacket packet) throws UnauthorizedException, PacketException {
public void process(Packet packet) throws UnauthorizedException, PacketException {
boolean handled = false;
String host = packet.getRecipient().getHost();
String host = packet.getTo().getDomain();
for (Channel channel : transports.values()) {
if (channel.getName().equalsIgnoreCase(host)) {
channel.add(packet);
......@@ -48,11 +51,11 @@ public class TransportHandler extends BasicModule implements ChannelHandler {
}
}
if (!handled) {
XMPPAddress recipient = packet.getRecipient();
XMPPAddress sender = packet.getSender();
packet.setError(XMPPError.Code.REMOTE_SERVER_TIMEOUT);
packet.setSender(recipient);
packet.setRecipient(sender);
JID recipient = packet.getTo();
JID sender = packet.getFrom();
packet.setError(PacketError.Condition.remote_server_timeout);
packet.setFrom(recipient);
packet.setTo(sender);
try {
deliverer.deliver(packet);
}
......@@ -62,9 +65,6 @@ public class TransportHandler extends BasicModule implements ChannelHandler {
catch (PacketException e) {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
}
catch (XMLStreamException xse) {
Log.error(xse);
}
}
}
......
......@@ -11,7 +11,6 @@
package org.jivesoftware.messenger.user;
import org.jivesoftware.messenger.XMPPFragment;
import org.dom4j.Element;
/**
......@@ -28,7 +27,7 @@ import org.dom4j.Element;
*
* @author Iain Shigeoka
*/
public interface IQRosterItem extends XMPPFragment, RosterItem {
public interface IQRosterItem extends RosterItem {
/**
* <p>Obtain the roster item as an XML DOM element.</p>
......
......@@ -11,7 +11,6 @@
package org.jivesoftware.messenger.user;
import org.jivesoftware.messenger.XMPPAddress;
import org.xmpp.packet.JID;
/**
......
......@@ -13,7 +13,6 @@ package org.jivesoftware.messenger.user.spi;
import java.util.Iterator;
import java.util.List;
import javax.xml.stream.XMLStreamException;
import org.jivesoftware.messenger.ChannelHandler;
import org.jivesoftware.messenger.PresenceManager;
import org.jivesoftware.messenger.RoutingTable;
......@@ -218,20 +217,15 @@ public class CachedRosterImpl extends BasicRoster implements CachedRoster {
private void broadcast(IQRoster roster) throws UnauthorizedException {
try {
if (server == null) {
server = (XMPPServer)ServiceLookupFactory.getLookup().lookup(XMPPServer.class);
}
JID recipient = server.createJID(username, null);
roster.setTo(recipient);
if (sessionManager == null) {
sessionManager = SessionManager.getInstance();
}
sessionManager.userBroadcast(username, roster);
if (server == null) {
server = (XMPPServer)ServiceLookupFactory.getLookup().lookup(XMPPServer.class);
}
catch (XMLStreamException e) {
// We couldn't send to the user, no big deal
JID recipient = server.createJID(username, null);
roster.setTo(recipient);
if (sessionManager == null) {
sessionManager = SessionManager.getInstance();
}
sessionManager.userBroadcast(username, roster);
}
public int getCachedSize() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment