org.xmpp.component.ComponentException Java Examples

The following examples show how to use org.xmpp.component.ComponentException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JigasiWrapper.java    From openfire-ofmeet-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public void destroy()
{
    if (componentManager != null && component != null)
    {
        try
        {
            componentManager.removeComponent(component.getSubdomain());
        }
        catch (ComponentException ce)
        {
            Log.warn( "An unexpected exception occurred while destroying the wrapper.", ce );
        }
        componentManager = null;
        component = null;
    }
    pluginDirectory = null;
}
 
Example #2
Source File: ComponentFinder.java    From Whack with Apache License 2.0 6 votes vote down vote up
/**
 * Shuts down running components that were found by the service.
 */
public void shutdown() {
    // Stop the component monitoring service.
    if (executor != null) {
        executor.shutdown();
    }
    // Shutdown found components.
    for (String subdomain : componentDomains.values()) {
        try {
            manager.removeComponent(subdomain);
        } catch (ComponentException e) {
            manager.getLog().error("Error shutting down component", e);
        }
    }
    components.clear();
    componentDirs.clear();
    classloaders.clear();
    componentDomains.clear();
}
 
Example #3
Source File: ComponentFinder.java    From Whack with Apache License 2.0 6 votes vote down vote up
/**
 * Unloads a component. The {@link ComponentManager#removeComponent(String)} method will be
 * called and then any resources will be released. The name should be the name of the component
 * directory and not the name as given by the component meta-data. This method only removes
 * the component but does not delete the component JAR file. Therefore, if the component JAR
 * still exists after this method is called, the component will be started again the next
 * time the component monitor process runs. This is useful for "restarting" components.<p>
 *
 * This method is called automatically when a component's JAR file is deleted.
 *
 * @param componentName the name of the component to unload.
 */
public void unloadComponent(String componentName) {
    manager.getLog().debug("Unloading component " + componentName);
    Component component = components.get(componentName);
    if (component == null) {
        return;
    }
    File webXML = new File(componentDirectory + File.separator + componentName +
            File.separator + "web" + File.separator + "web.xml");
    if (webXML.exists()) {
        //AdminConsole.removeModel(componentName);
        ComponentServlet.unregisterServlets(webXML);
    }

    ComponentClassLoader classLoader = classloaders.get(component);
    try {
        manager.removeComponent(componentDomains.get(component));
    } catch (ComponentException e) {
        manager.getLog().error("Error shutting down component", e);
    }
    classLoader.destroy();
    components.remove(componentName);
    componentDirs.remove(component);
    classloaders.remove(component);
    componentDomains.remove(component);
}
 
Example #4
Source File: MultiUserChatManager.java    From Openfire with Apache License 2.0 6 votes vote down vote up
public void unregisterMultiUserChatService(String subdomain, boolean allNodes) {
    Log.debug("MultiUserChatManager: Unregistering MUC service "+subdomain);
    MultiUserChatService service = mucServices.get(subdomain);
    if (service != null) {
        service.shutdown();
        try {
            ComponentManagerFactory.getComponentManager().removeComponent(subdomain);
        }
        catch (ComponentException e) {
            Log.error("MultiUserChatManager: Unable to remove "+subdomain+" from component manager.", e);
        }
        mucServices.remove(subdomain);
    }
    if (allNodes) {
        CacheFactory.doClusterTask(new ServiceRemovedEvent(subdomain));
    }
}
 
Example #5
Source File: ExternalComponentManager.java    From Whack with Apache License 2.0 5 votes vote down vote up
public void addComponent(String subdomain, Component component, Integer port) throws ComponentException {
    if (componentsByDomain.containsKey(subdomain)) {
        if (componentsByDomain.get(subdomain).getComponent() == component) {
            // Do nothing since the component has already been registered
            return;
        }
        else {
            throw new IllegalArgumentException("Subdomain already in use by another component");
        }
    }
    // Create a wrapping ExternalComponent on the component
    ExternalComponent externalComponent = new ExternalComponent(component, this);
    try {
        // Register the new component
        componentsByDomain.put(subdomain, externalComponent);
        components.put(component, externalComponent);
        // Ask the ExternalComponent to connect with the remote server
        externalComponent.connect(host, port, subdomain, startEncrypted);
        // Initialize the component
        JID componentJID = new JID(null, externalComponent.getDomain(), null);
        externalComponent.initialize(componentJID, this);
    }
    catch (ComponentException e) {
        // Unregister the new component
        componentsByDomain.remove(subdomain);
        components.remove(component);
        // Re-throw the exception
        throw e;
    }
    // Ask the external component to start processing incoming packets
    externalComponent.start();
}
 
Example #6
Source File: ExternalComponentManager.java    From Whack with Apache License 2.0 5 votes vote down vote up
public void removeComponent(String subdomain) throws ComponentException {
    ExternalComponent externalComponent = componentsByDomain.remove(subdomain);
    if (externalComponent != null) {
        components.remove(externalComponent.getComponent());
        externalComponent.shutdown();
    }
}
 
Example #7
Source File: MultiUserChatManager.java    From Openfire with Apache License 2.0 5 votes vote down vote up
public void registerMultiUserChatService(MultiUserChatService service, boolean allNodes) {
    Log.debug("MultiUserChatManager: Registering MUC service "+service.getServiceName());
    try {
        ComponentManagerFactory.getComponentManager().addComponent(service.getServiceName(), service);
        mucServices.put(service.getServiceName(), service);
    }
    catch (ComponentException e) {
        Log.error("MultiUserChatManager: Unable to add "+service.getServiceName()+" as component.", e);
    }
    if (allNodes) {
        CacheFactory.doClusterTask(new ServiceAddedEvent(service.getServiceName(), service.getDescription(), service.isHidden()));
    }
}
 
Example #8
Source File: WeatherComponent.java    From Whack with Apache License 2.0 4 votes vote down vote up
/**
 * Handle the receied packet and answer the weather information of the requested station id.
 * The request must be made using Message packets where the body of the message should be the
 * station id.<p>
 *
 * Note: I don't know the list of valid station ids so if you find the list please send it to me
 * so I can add it to this example.
 *
 * @param packet the Message requesting information about a certain station id.
 */
public void processPacket(Packet packet) {
    System.out.println("Received package:"+packet.toXML());
    // Only process Message packets
    if (packet instanceof Message) {
        // Get the requested station to obtain it's weather information
        Message message = (Message) packet;
        String station = message.getBody();
        // Send the request and get the weather information
        Metar metar = Weather.getMetar(station, 5000);

        // Build the answer
        Message reply = new Message();
        reply.setTo(message.getFrom());
        reply.setFrom(message.getTo());
        reply.setType(message.getType());
        reply.setThread(message.getThread());

        // Append the discovered information if something was found
        if (metar != null) {
            StringBuilder sb = new StringBuilder();
            sb.append("station id : " + metar.getStationID());
            sb.append("\rwind dir   : " + metar.getWindDirection() + " degrees");
            sb.append("\rwind speed : " + metar.getWindSpeedInMPH() + " mph, " +
                                                 metar.getWindSpeedInKnots() + " knots");
            if (!metar.getVisibilityLessThan()) {
                sb.append("\rvisibility : " + metar.getVisibility() + " mile(s)");
            } else {
                sb.append("\rvisibility : < " + metar.getVisibility() + " mile(s)");
            }

            sb.append("\rpressure   : " + metar.getPressure() + " in Hg");
            sb.append("\rtemperaturePrecise: " +
                               metar.getTemperaturePreciseInCelsius() + " C, " +
                               metar.getTemperaturePreciseInFahrenheit() + " F");
            sb.append("\rtemperature: " +
                               metar.getTemperatureInCelsius() + " C, " +
                               metar.getTemperatureInFahrenheit() + " F");
            sb.append("\rtemperatureMostPrecise: " +
                               metar.getTemperatureMostPreciseInCelsius() + " C, " +
                               metar.getTemperatureMostPreciseInFahrenheit() + " F");
            reply.setBody(sb.toString());
        }
        else {
            // Answer that the requested station id does not exist
            reply.setBody("Unknown station ID");
        }

        // Send the response to the sender of the request
        try {
            ComponentManagerFactory.getComponentManager().sendPacket(this, reply);
        } catch (ComponentException e) {
            e.printStackTrace();
        }
    }
}
 
Example #9
Source File: ExternalComponentManager.java    From Whack with Apache License 2.0 4 votes vote down vote up
public void addComponent(String subdomain, Component component) throws ComponentException {
    addComponent(subdomain, component, this.port);
}
 
Example #10
Source File: ExternalComponentManager.java    From Whack with Apache License 2.0 4 votes vote down vote up
public void query(Component component, IQ packet, IQResultListener listener) throws ComponentException {
    ExternalComponent externalComponent = components.get(component);
    // Add listenet with a timeout of 5 minutes to prevent memory leaks
    externalComponent.addIQResultListener(packet.getID(), listener, 300000);
    sendPacket(component, packet);
}
 
Example #11
Source File: ExternalComponent.java    From Whack with Apache License 2.0 4 votes vote down vote up
public void initialize(JID jid, ComponentManager componentManager) throws ComponentException {
    component.initialize(jid, componentManager);
}
 
Example #12
Source File: ExternalComponent.java    From Whack with Apache License 2.0 4 votes vote down vote up
/**
 * Notification message that the connection with the server was lost unexpectedly. We will try
 * to reestablish the connection for ever until the connection has been reestablished or this
 * thread has been stopped.
 */
public void connectionLost() {
    // Ensure that only one thread will try to reconnect.
    synchronized(this) {
        if (reconnecting) {
            return;
        }
        reconnecting = true;
    }
    readerThread = null;
    boolean isConnected = false;
    if (!shutdown) {
        // Notify the component that connection was lost so it needs to shutdown. The component is
        // still registered in the local component manager but just not connected to the server
        component.shutdown();
    }
    while (!isConnected && !shutdown) {
        try {
            connect(host, port, subdomain, startEncrypted);
            isConnected = true;
            // It may be possible that while a new connection was being established the
            // component was required to shutdown so in this case we need to close the new
            // connection
            if (shutdown) {
                disconnect();
            }
            else {
                // Component is back again working so start it up again
                start();
            }
        } catch (ComponentException e) {
            manager.getLog().error("Error trying to reconnect with the server", e);
            // Wait for 5 seconds until the next retry
            try {
                Thread.sleep(5000);
            }
            catch (InterruptedException e1) {
                // Do nothing
            }
        }
    }
    reconnecting = false;
}
 
Example #13
Source File: LocalComponentSession.java    From Openfire with Apache License 2.0 4 votes vote down vote up
/**
 * Authenticate the external component using a digest method. The digest includes the
 * stream ID and the secret key of the main domain of the external component. A component
 * needs to authenticate just once but it may bind several domains.
 *
 * @param digest the digest sent in the handshake.
 * @return true if the authentication was successful.
 */
public boolean authenticate(String digest) {
    // Perform authentication. Wait for the handshake (with the secret key)
    String secretKey = ExternalComponentManager.getSecretForComponent(defaultSubdomain);
    String anticipatedDigest = AuthFactory.createDigest(getStreamID().getID(), secretKey);
    // Check that the provided handshake (secret key + sessionID) is correct
    if (!anticipatedDigest.equalsIgnoreCase(digest)) {
        Log.debug("LocalComponentSession: [ExComp] Incorrect handshake for component with domain: " +
                defaultSubdomain);
        //  The credentials supplied by the initiator are not valid (answer an error
        // and close the connection)
        conn.deliverRawText(new StreamError(StreamError.Condition.not_authorized).toXML());
        // Close the underlying connection
        conn.close();
        return false;
    }
    else {
        // Component has authenticated fine
        setStatus(STATUS_AUTHENTICATED);
        // Send empty handshake element to acknowledge success
        conn.deliverRawText("<handshake></handshake>");
        // Bind the domain to this component
        ExternalComponent component = getExternalComponent();
        try {
            InternalComponentManager.getInstance().addComponent(defaultSubdomain, component);
            conn.registerCloseListener( handback -> InternalComponentManager.getInstance().removeComponent( defaultSubdomain, (ExternalComponent) handback ), component );
            Log.debug(
                    "LocalComponentSession: [ExComp] External component was registered SUCCESSFULLY with domain: " +
                            defaultSubdomain);
            return true;
        }
        catch (ComponentException e) {
            Log.debug("LocalComponentSession: [ExComp] Another component is already using domain: " +
                    defaultSubdomain);
            //  The credentials supplied by the initiator are not valid (answer an error
            // and close the connection)
            conn.deliverRawText(new StreamError(StreamError.Condition.conflict).toXML());
            // Close the underlying connection
            conn.close();
            return false;
        }
    }
}
 
Example #14
Source File: ExternalComponent.java    From Whack with Apache License 2.0 2 votes vote down vote up
/**
 * Generates a connection with the server and tries to authenticate. If an error occurs in any
 * of the steps then a ComponentException is thrown.
 *
 * @param host          the host to connect with.
 * @param port          the port to use.
 * @param subdomain     the subdomain that this component will be handling.
 * @throws ComponentException if an error happens during the connection and authentication steps.
 */
@Deprecated
public void connect(String host, int port, String subdomain) throws ComponentException {
    connect(host,port,subdomain,false);
}