Skip to content

Commit

Permalink
Fix for Solr circular Spring Bean reference exception
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandor777 committed Apr 25, 2019
1 parent e8d65a3 commit acfa826
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 12 deletions.
5 changes: 4 additions & 1 deletion src/community/solr/src/main/java/applicationContext.xml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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="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="0" ref="catalog" />
<constructor-arg index="1" ref="solrFeatureTypeCallback" />
</bean> </bean>


<bean id="solrConfigPanel" class="org.geoserver.solr.SolrConfigurationPanelInfo"> <bean id="solrConfigPanel" class="org.geoserver.solr.SolrConfigurationPanelInfo">
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


import java.io.IOException; import java.io.IOException;
import java.io.Serializable; import java.io.Serializable;
import java.util.logging.Logger;
import org.geoserver.catalog.Catalog; import org.geoserver.catalog.Catalog;
import org.geoserver.catalog.CatalogException; import org.geoserver.catalog.CatalogException;
import org.geoserver.catalog.FeatureTypeCallback; import org.geoserver.catalog.FeatureTypeCallback;
Expand All @@ -15,26 +16,23 @@
import org.geoserver.catalog.event.CatalogModifyEvent; import org.geoserver.catalog.event.CatalogModifyEvent;
import org.geoserver.catalog.event.CatalogPostModifyEvent; import org.geoserver.catalog.event.CatalogPostModifyEvent;
import org.geoserver.catalog.event.CatalogRemoveEvent; import org.geoserver.catalog.event.CatalogRemoveEvent;
import org.geoserver.platform.GeoServerExtensions;
import org.geotools.data.DataAccess; import org.geotools.data.DataAccess;
import org.geotools.data.solr.SolrDataStore; import org.geotools.data.solr.SolrDataStore;
import org.geotools.data.solr.SolrLayerConfiguration; import org.geotools.data.solr.SolrLayerConfiguration;
import org.geotools.util.logging.Logging;
import org.opengis.feature.Feature; import org.opengis.feature.Feature;
import org.opengis.feature.type.FeatureType; import org.opengis.feature.type.FeatureType;
import org.opengis.feature.type.Name; 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} * @see {@link FeatureTypeCallback}
*/ */
public class SolrFeatureTypeCallback implements FeatureTypeCallback, CatalogListener { public class SolrFeatureTypeCallback implements FeatureTypeCallback, CatalogListener {


Catalog catalog; public SolrFeatureTypeCallback() {}

public SolrFeatureTypeCallback(Catalog catalog) {
this.catalog = catalog;
catalog.addListener(this);
}


@Override @Override
public boolean canHandle( public boolean canHandle(
Expand Down Expand Up @@ -103,7 +101,7 @@ public void handleRemoveEvent(CatalogRemoveEvent event) throws CatalogException
// go directly to the resource pool to avoid security wrappers // go directly to the resource pool to avoid security wrappers
try { try {
DataAccess<? extends FeatureType, ? extends Feature> dataStore = DataAccess<? extends FeatureType, ? extends Feature> dataStore =
catalog.getResourcePool().getDataStore(ft.getStore()); getCatalog().getResourcePool().getDataStore(ft.getStore());
if (dataStore instanceof SolrDataStore) { if (dataStore instanceof SolrDataStore) {
SolrDataStore solr = (SolrDataStore) dataStore; SolrDataStore solr = (SolrDataStore) dataStore;
solr.getSolrConfigurations().remove(slc.getLayerName()); solr.getSolrConfigurations().remove(slc.getLayerName());
Expand Down Expand Up @@ -141,7 +139,7 @@ private void updateSolrConfiguration(FeatureTypeInfo ft, SolrLayerConfiguration
// go directly to the resource pool to avoid security wrappers // go directly to the resource pool to avoid security wrappers
try { try {
DataAccess<? extends FeatureType, ? extends Feature> dataStore = DataAccess<? extends FeatureType, ? extends Feature> dataStore =
catalog.getResourcePool().getDataStore(ft.getStore()); getCatalog().getResourcePool().getDataStore(ft.getStore());
if (dataStore instanceof SolrDataStore) { if (dataStore instanceof SolrDataStore) {
SolrDataStore solr = (SolrDataStore) dataStore; SolrDataStore solr = (SolrDataStore) dataStore;
solr.getSolrConfigurations().remove(slc.getLayerName()); solr.getSolrConfigurations().remove(slc.getLayerName());
Expand All @@ -151,14 +149,44 @@ private void updateSolrConfiguration(FeatureTypeInfo ft, SolrLayerConfiguration
} catch (IOException e) { } catch (IOException e) {
throw new CatalogException("Failed to remove layer configuration from data store", 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.setNativeName(ft.getName());
proxy.getMetadata().put(SolrLayerConfiguration.KEY, slc); proxy.getMetadata().put(SolrLayerConfiguration.KEY, slc);
catalog.save(proxy); getCatalog().save(proxy);
}

Catalog getCatalog() {
return (Catalog) GeoServerExtensions.bean("catalog");
} }


@Override @Override
public void reloaded() { public void reloaded() {
// nothing to do // 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);
}
}
} }

0 comments on commit acfa826

Please sign in to comment.