Search in sources :

Example 1 with ApiImplementor

use of org.zaproxy.zap.extension.api.ApiImplementor in project zaproxy by zaproxy.

the class ExtensionLoader method removeExtension.

/**
     * Removes an extension from internal list. As a result listeners added via
     * the {@link ExtensionHook} object are unregistered.
     *
     * @param extension
     * @param hook
     */
public void removeExtension(Extension extension, ExtensionHook hook) {
    extensionList.remove(extension);
    extensionsMap.remove(extension.getClass());
    if (hook == null) {
        logger.info("ExtensionHook is null for \"" + extension.getClass().getCanonicalName() + "\" the hooked objects will not be automatically removed.");
        return;
    }
    // by removing the ExtensionHook object,
    // the following listeners are no longer informed:
    // 		* SessionListeners
    // 		* OptionsChangedListeners
    extensionHooks.values().remove(hook);
    unloadOptions(hook);
    removePersistentConnectionListener(hook);
    removeProxyListener(hook);
    removeOverrideMessageProxyListener(hook);
    removeConnectRequestProxyListener(hook);
    removeSiteMapListener(hook);
    for (ContextDataFactory contextDataFactory : hook.getContextDataFactories()) {
        try {
            model.removeContextDataFactory(contextDataFactory);
        } catch (Exception e) {
            logger.error("Error while removing a ContextDataFactory from " + extension.getClass().getCanonicalName(), e);
        }
    }
    for (ApiImplementor apiImplementor : hook.getApiImplementors()) {
        try {
            API.getInstance().removeApiImplementor(apiImplementor);
        } catch (Exception e) {
            logger.error("Error while removing an ApiImplementor from " + extension.getClass().getCanonicalName(), e);
        }
    }
    removeViewInEDT(extension, hook);
}
Also used : ContextDataFactory(org.zaproxy.zap.model.ContextDataFactory) ApiImplementor(org.zaproxy.zap.extension.api.ApiImplementor) DatabaseException(org.parosproxy.paros.db.DatabaseException) DatabaseUnsupportedException(org.parosproxy.paros.db.DatabaseUnsupportedException)

Example 2 with ApiImplementor

use of org.zaproxy.zap.extension.api.ApiImplementor in project zaproxy by zaproxy.

the class ExtensionLoader method unhook.

private void unhook(Extension extension) {
    ExtensionHook hook = extensionHooks.remove(extension);
    if (hook == null) {
        logger.error("ExtensionHook not found for: " + extension.getClass().getCanonicalName());
        return;
    }
    unloadOptions(hook);
    unhookProxies(hook);
    removeSiteMapListener(hook);
    for (ContextDataFactory contextDataFactory : hook.getContextDataFactories()) {
        try {
            model.removeContextDataFactory(contextDataFactory);
        } catch (Exception e) {
            logger.error("Error while removing a ContextDataFactory from " + extension.getClass().getCanonicalName(), e);
        }
    }
    for (ApiImplementor apiImplementor : hook.getApiImplementors()) {
        try {
            API.getInstance().removeApiImplementor(apiImplementor);
        } catch (Exception e) {
            logger.error("Error while removing an ApiImplementor from " + extension.getClass().getCanonicalName(), e);
        }
    }
    for (HttpSenderListener httpSenderListener : hook.getHttpSenderListeners()) {
        try {
            HttpSender.removeListener(httpSenderListener);
        } catch (Exception e) {
            logger.error("Error while removing an HttpSenderListener from " + extension.getClass().getCanonicalName(), e);
        }
    }
    for (Class<? extends Variant> variant : hook.getVariants()) {
        try {
            model.getVariantFactory().removeVariant(variant);
        } catch (Exception e) {
            logger.error("Error while removing a Variant from " + extension.getClass().getCanonicalName(), e);
        }
    }
    removeViewInEDT(extension, hook);
}
Also used : ContextDataFactory(org.zaproxy.zap.model.ContextDataFactory) HttpSenderListener(org.zaproxy.zap.network.HttpSenderListener) ApiImplementor(org.zaproxy.zap.extension.api.ApiImplementor) InvocationTargetException(java.lang.reflect.InvocationTargetException) DatabaseException(org.parosproxy.paros.db.DatabaseException) DatabaseUnsupportedException(org.parosproxy.paros.db.DatabaseUnsupportedException)

Aggregations

DatabaseException (org.parosproxy.paros.db.DatabaseException)2 DatabaseUnsupportedException (org.parosproxy.paros.db.DatabaseUnsupportedException)2 ApiImplementor (org.zaproxy.zap.extension.api.ApiImplementor)2 ContextDataFactory (org.zaproxy.zap.model.ContextDataFactory)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HttpSenderListener (org.zaproxy.zap.network.HttpSenderListener)1