Commit 1e8072fd authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Improved registration of components.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@8720 b35dd754-fafc-0310-a699-88a17e54d16e
parent f04e87b4
...@@ -43,7 +43,7 @@ import java.util.List; ...@@ -43,7 +43,7 @@ import java.util.List;
*/ */
public class LocalComponentSession extends LocalSession implements ComponentSession { public class LocalComponentSession extends LocalSession implements ComponentSession {
private ExternalComponent component; private LocalExternalComponent component;
/** /**
* Returns a newly created session between the server and a component. The session will be * Returns a newly created session between the server and a component. The session will be
...@@ -97,6 +97,8 @@ public class LocalComponentSession extends LocalSession implements ComponentSess ...@@ -97,6 +97,8 @@ public class LocalComponentSession extends LocalSession implements ComponentSess
if (index > -1) { if (index > -1) {
subdomain = domain.substring(0, index -1); subdomain = domain.substring(0, index -1);
} }
domain = subdomain + "." + serverName;
JID componentJID = new JID(domain);
// Check that an external component for the specified subdomain may connect to this server // Check that an external component for the specified subdomain may connect to this server
if (!ExternalComponentManager.canAccess(subdomain)) { if (!ExternalComponentManager.canAccess(subdomain)) {
Log.debug("[ExComp] Component is not allowed to connect with subdomain: " + subdomain); Log.debug("[ExComp] Component is not allowed to connect with subdomain: " + subdomain);
...@@ -122,7 +124,7 @@ public class LocalComponentSession extends LocalSession implements ComponentSess ...@@ -122,7 +124,7 @@ public class LocalComponentSession extends LocalSession implements ComponentSess
return null; return null;
} }
// Check that the requested subdomain is not already in use // Check that the requested subdomain is not already in use
if (InternalComponentManager.getInstance().hasComponent(new JID(subdomain + "." + serverName))) { if (InternalComponentManager.getInstance().hasComponent(componentJID)) {
Log.debug("[ExComp] Another component is already using domain: " + domain); Log.debug("[ExComp] Another component is already using domain: " + domain);
// Domain already occupied so return a conflict error and close the connection // Domain already occupied so return a conflict error and close the connection
// Include the conflict error in the response // Include the conflict error in the response
...@@ -136,9 +138,8 @@ public class LocalComponentSession extends LocalSession implements ComponentSess ...@@ -136,9 +138,8 @@ public class LocalComponentSession extends LocalSession implements ComponentSess
} }
// Create a ComponentSession for the external component // Create a ComponentSession for the external component
LocalComponentSession session = LocalComponentSession session = SessionManager.getInstance().createComponentSession(componentJID, connection);
SessionManager.getInstance().createComponentSession(new JID(null, domain, null), connection); session.component = new LocalExternalComponent(session, connection);
session.component = new LocalExternalComponent(connection);
try { try {
Log.debug("[ExComp] Send stream header with ID: " + session.getStreamID() + Log.debug("[ExComp] Send stream header with ID: " + session.getStreamID() +
...@@ -209,9 +210,7 @@ public class LocalComponentSession extends LocalSession implements ComponentSess ...@@ -209,9 +210,7 @@ public class LocalComponentSession extends LocalSession implements ComponentSess
} }
void deliver(Packet packet) throws PacketException { void deliver(Packet packet) throws PacketException {
// Since ComponentSessions are not being stored in the RoutingTable this messages is very component.deliver(packet);
// unlikely to be sent
component.processPacket(packet);
} }
public ExternalComponent getExternalComponent() { public ExternalComponent getExternalComponent() {
...@@ -231,7 +230,7 @@ public class LocalComponentSession extends LocalSession implements ComponentSess ...@@ -231,7 +230,7 @@ public class LocalComponentSession extends LocalSession implements ComponentSess
* @author Gaston Dombiak * @author Gaston Dombiak
*/ */
public static class LocalExternalComponent implements ComponentSession.ExternalComponent { public static class LocalExternalComponent implements ComponentSession.ExternalComponent {
private LocalComponentSession session;
private Connection connection; private Connection connection;
private String name = ""; private String name = "";
private String type = ""; private String type = "";
...@@ -243,11 +242,23 @@ public class LocalComponentSession extends LocalSession implements ComponentSess ...@@ -243,11 +242,23 @@ public class LocalComponentSession extends LocalSession implements ComponentSess
private List<String> subdomains = new ArrayList<String>(); private List<String> subdomains = new ArrayList<String>();
public LocalExternalComponent(Connection connection) { public LocalExternalComponent(LocalComponentSession session, Connection connection) {
this.session = session;
this.connection = connection; this.connection = connection;
} }
public void processPacket(Packet packet) { public void processPacket(Packet packet) {
// Ask the session to process the outgoing packet. This will
// give us the chance to apply PacketInterceptors
session.process(packet);
}
/**
* Delivers the packet to the external component.
*
* @param packet the packet to deliver.
*/
void deliver(Packet packet) {
if (connection != null && !connection.isClosed()) { if (connection != null && !connection.isClosed()) {
try { try {
connection.deliver(packet); connection.deliver(packet);
......
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