Commit 46c0e2a4 authored by Derek DeMoro's avatar Derek DeMoro Committed by derek

Refactoring work.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@602 b35dd754-fafc-0310-a699-88a17e54d16e
parent 743692b3
...@@ -11,24 +11,23 @@ ...@@ -11,24 +11,23 @@
package org.jivesoftware.messenger.net; package org.jivesoftware.messenger.net;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.jivesoftware.messenger.PacketDeliverer;
import org.jivesoftware.messenger.PacketException;
import org.jivesoftware.messenger.Session;
import org.jivesoftware.messenger.XMPPPacket;
import org.jivesoftware.messenger.audit.Auditor;
import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.spi.BasicConnection;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.Writer; import java.io.Writer;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.Socket; import java.net.Socket;
import javax.xml.stream.XMLOutputFactory; import org.dom4j.io.XMLWriter;
import javax.xml.stream.XMLStreamException; import org.jivesoftware.messenger.PacketDeliverer;
import javax.xml.stream.XMLStreamWriter; import org.jivesoftware.messenger.PacketException;
import org.jivesoftware.messenger.Session;
import org.jivesoftware.messenger.audit.Auditor;
import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.spi.BasicConnection;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.xmlpull.v1.XmlPullParserException;
import org.xmpp.packet.Packet;
/** /**
* An object to track the state of a Jabber client-server session. * An object to track the state of a Jabber client-server session.
...@@ -68,8 +67,7 @@ public class SocketConnection extends BasicConnection { ...@@ -68,8 +67,7 @@ public class SocketConnection extends BasicConnection {
private boolean secure; private boolean secure;
private XMLStreamWriter xmlSerializer; private XMLWriter xmlSerializer;
private static XMLOutputFactory xmlFactory;
/** /**
* Create a new session using the supplied socket. * Create a new session using the supplied socket.
...@@ -80,11 +78,8 @@ public class SocketConnection extends BasicConnection { ...@@ -80,11 +78,8 @@ public class SocketConnection extends BasicConnection {
* @param isSecure True if this is a secure connection * @param isSecure True if this is a secure connection
* @throws NullPointerException If the socket is null * @throws NullPointerException If the socket is null
*/ */
public SocketConnection(PacketDeliverer deliverer, public SocketConnection(PacketDeliverer deliverer, Auditor auditor,
Auditor auditor, Socket socket, boolean isSecure) throws IOException, XmlPullParserException {
Socket socket,
boolean isSecure)
throws IOException, XMLStreamException {
if (socket == null) { if (socket == null) {
throw new NullPointerException("Socket channel must be non-null"); throw new NullPointerException("Socket channel must be non-null");
...@@ -95,10 +90,7 @@ public class SocketConnection extends BasicConnection { ...@@ -95,10 +90,7 @@ public class SocketConnection extends BasicConnection {
sock = socket; sock = socket;
writer = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream(), charset)); writer = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream(), charset));
this.deliverer = deliverer; this.deliverer = deliverer;
if (xmlFactory == null) { xmlSerializer = new XMLWriter(writer);
xmlFactory = XMLOutputFactory.newInstance();
}
xmlSerializer = xmlFactory.createXMLStreamWriter(writer);
} }
public boolean validate() { public boolean validate() {
...@@ -107,8 +99,8 @@ public class SocketConnection extends BasicConnection { ...@@ -107,8 +99,8 @@ public class SocketConnection extends BasicConnection {
} }
try { try {
synchronized (writer) { synchronized (writer) {
xmlSerializer.writeCharacters(" "); writer.write(" ");
xmlSerializer.flush(); writer.flush();
} }
} }
catch (Exception e) { catch (Exception e) {
...@@ -125,10 +117,14 @@ public class SocketConnection extends BasicConnection { ...@@ -125,10 +117,14 @@ public class SocketConnection extends BasicConnection {
return sock.getInetAddress(); return sock.getInetAddress();
} }
public XMLStreamWriter getSerializer() throws UnauthorizedException { public XMLWriter getSerializer() throws UnauthorizedException {
return xmlSerializer; return xmlSerializer;
} }
public Writer getWriter() throws UnauthorizedException {
return writer;
}
/** /**
* Retrieve the closed state of the Session. * Retrieve the closed state of the Session.
* *
...@@ -179,16 +175,19 @@ public class SocketConnection extends BasicConnection { ...@@ -179,16 +175,19 @@ public class SocketConnection extends BasicConnection {
* *
* @param packet The packet to deliver. * @param packet The packet to deliver.
*/ */
public void deliver(XMPPPacket packet) throws public void deliver(Packet packet) throws UnauthorizedException, PacketException, XmlPullParserException {
UnauthorizedException, PacketException, XMLStreamException {
if (isClosed()) { if (isClosed()) {
deliverer.deliver(packet); deliverer.deliver(packet);
} }
else { else {
packet.setSending(true);
synchronized (writer) { synchronized (writer) {
packet.send(xmlSerializer, 0); // packet.send(xmlSerializer, 0);
xmlSerializer.flush(); try {
xmlSerializer.flush();
}
catch (IOException e) {
Log.error(e);
}
} }
auditor.audit(packet); auditor.audit(packet);
session.incrementServerPacketCount(); session.incrementServerPacketCount();
......
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