Commit 35b7e0ff authored by Fernando Mino's avatar Fernando Mino Committed by Andrea Aime

Fix for Solr circular Spring Bean reference exception

parent cbec755a
......@@ -8,8 +8,11 @@ This code is licensed under the GPL 2.0 license, available at the root applicati
<bean id="solrXStreamInitializer" class="org.geoserver.solr.SolrXStreamInitializer" />
<bean id="solrFeatureTypeCallback" class="org.geoserver.solr.SolrFeatureTypeCallback" >
<bean id="solrFeatureTypeCallback" class="org.geoserver.solr.SolrFeatureTypeCallback" />
<bean id="solrCatalogInitializer" class="org.geoserver.solr.SolrFeatureTypeCallback.CatalogInitializer"
init-method="initBean" >
<constructor-arg index="0" ref="catalog" />
<constructor-arg index="1" ref="solrFeatureTypeCallback" />
</bean>
<bean id="solrConfigPanel" class="org.geoserver.solr.SolrConfigurationPanelInfo">
......
......@@ -6,6 +6,7 @@ package org.geoserver.solr;
import java.io.IOException;
import java.io.Serializable;
import java.util.logging.Logger;
import org.geoserver.catalog.Catalog;
import org.geoserver.catalog.CatalogException;
import org.geoserver.catalog.FeatureTypeCallback;
......@@ -15,26 +16,23 @@ import org.geoserver.catalog.event.CatalogListener;
import org.geoserver.catalog.event.CatalogModifyEvent;
import org.geoserver.catalog.event.CatalogPostModifyEvent;
import org.geoserver.catalog.event.CatalogRemoveEvent;
import org.geoserver.platform.GeoServerExtensions;
import org.geotools.data.DataAccess;
import org.geotools.data.solr.SolrDataStore;
import org.geotools.data.solr.SolrLayerConfiguration;
import org.geotools.util.logging.Logging;
import org.opengis.feature.Feature;
import org.opengis.feature.type.FeatureType;
import org.opengis.feature.type.Name;
/**
* Implementation of FeatureTypeInitializer extension point to initialize SOLR datastore
* Implementation of FeatureTypeInitializer extension point to initialize SOLR datastore.
*
* @see {@link FeatureTypeCallback}
*/
public class SolrFeatureTypeCallback implements FeatureTypeCallback, CatalogListener {
Catalog catalog;
public SolrFeatureTypeCallback(Catalog catalog) {
this.catalog = catalog;
catalog.addListener(this);
}
public SolrFeatureTypeCallback() {}
@Override
public boolean canHandle(
......@@ -103,7 +101,7 @@ public class SolrFeatureTypeCallback implements FeatureTypeCallback, CatalogList
// go directly to the resource pool to avoid security wrappers
try {
DataAccess<? extends FeatureType, ? extends Feature> dataStore =
catalog.getResourcePool().getDataStore(ft.getStore());
getCatalog().getResourcePool().getDataStore(ft.getStore());
if (dataStore instanceof SolrDataStore) {
SolrDataStore solr = (SolrDataStore) dataStore;
solr.getSolrConfigurations().remove(slc.getLayerName());
......@@ -141,7 +139,7 @@ public class SolrFeatureTypeCallback implements FeatureTypeCallback, CatalogList
// go directly to the resource pool to avoid security wrappers
try {
DataAccess<? extends FeatureType, ? extends Feature> dataStore =
catalog.getResourcePool().getDataStore(ft.getStore());
getCatalog().getResourcePool().getDataStore(ft.getStore());
if (dataStore instanceof SolrDataStore) {
SolrDataStore solr = (SolrDataStore) dataStore;
solr.getSolrConfigurations().remove(slc.getLayerName());
......@@ -151,14 +149,44 @@ public class SolrFeatureTypeCallback implements FeatureTypeCallback, CatalogList
} catch (IOException e) {
throw new CatalogException("Failed to remove layer configuration from data store", e);
}
FeatureTypeInfo proxy = catalog.getFeatureType(ft.getId());
FeatureTypeInfo proxy = getCatalog().getFeatureType(ft.getId());
proxy.setNativeName(ft.getName());
proxy.getMetadata().put(SolrLayerConfiguration.KEY, slc);
catalog.save(proxy);
getCatalog().save(proxy);
}
Catalog getCatalog() {
return (Catalog) GeoServerExtensions.bean("catalog");
}
@Override
public void reloaded() {
// nothing to do
}
/**
* Spring bean used for doing initializing logic with beans Catalog and SolrFeatureTypeCallback
* available and loaded.
*
* @author Fernando Mino - Geosolutions
*/
public static class CatalogInitializer {
private static final Logger LOGGER = Logging.getLogger(CatalogInitializer.class);
private Catalog catalog;
private SolrFeatureTypeCallback solrFeatureTypeCallback;
public CatalogInitializer(
Catalog catalog, SolrFeatureTypeCallback solrFeatureTypeCallback) {
super();
this.catalog = catalog;
this.solrFeatureTypeCallback = solrFeatureTypeCallback;
}
public void initBean() {
LOGGER.info("Registering solrFeatureTypeCallback on catalog.");
catalog.addListener(solrFeatureTypeCallback);
}
}
}
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