Hi all, I have read the email the from Francesco Izzi (21.04.2009). He was searching for a possibility to reload the Geoserver configuration via Rest. -> http://www.mail-archive.com/[email protected]/msg04914.html I had the same problem, so I tried to find a solution. I'm not sure if the way I have implemented the function is really correct, but it seems to work. Hoping somebody can take a look at the code to upgrade and correct it.
Justin Deoliveira provides an indication to take a look at the restconfig extension and specially at the CatalogResource Base.java. Greetings, Lars Schrader 1. The solution should accept the following url to reload the catalog curl -u username:password -v -XPOST http://localhost:8080/geoserver/rest/catalogreload 2.1 adding the following code into the applicationContext.xml of the restconfig extension <entry> <key><value>/catalogreload</value></key> <value>catalogReloader</value> </entry> ............. <bean id="catalogReloader" class="org.geoserver.catalog.rest.CatalogReloader" parent="abstractCatalogFinder"/> 2.2 create a new class org.geoserver.catalog.rest.CatalogReloader package org.geoserver.catalog.rest; import java.util.logging.Logger; public class CatalogReloader extends AbstractCatalogFinder { static Logger LOGGER = Logging.getLogger( "org.geoserver.catalog.rest"); public CatalogReloader(Catalog catalog) { super(catalog); } @Override public Resource findTarget(Request request, Response response){ try{ CatalogResourceBase.reloadCatalog(); }catch(Exception e){ LOGGER.warning(CatalogReloader.class.getName()+" : catalog couldn't be reloaded."); } response.setStatus(Status.SUCCESS_ACCEPTED); return null; } } 2.3 adding the following code into the org.geoserver.catalog.rest.CatalogResourceBase of the restconfig extension /** * Static method to reload the catalog */ protected static void reloadCatalog() throws Exception { GeoServerLoader loader = GeoServerExtensions.bean( GeoServerLoader.class ); try { synchronized (org.geoserver.config.GeoServer.CONFIGURATION_LOCK) { loader.reload(); LOGGER.info(CatalogResourceBase.class.getName()+" : catalog could be reloaded."); } } catch (Exception e) { throw new RuntimeException( e ); } } 3. After that I have created a new restconfig-1.7.x.jar with the complete restconfig extension. The answer of the curl statement is: < HTTP/1.1 202 Accepted < Server: Apache-Coyote/1.1 < Date: Fri, 24 Jul 2009 08:05:01 GMT < Server: Noelios-Restlet-Engine/1.0..8 < Transfer-Encoding: chunked < * Connection #0 to host localhost left intact * Closing connection #0 4. You can also access the rest patch via java. The solution based on the email from Santiago Montico (21.07.2009). -> http://www.mail-archive.com/[email protected]/msg06425.html import java.io.IOException; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.ProtocolException; import java.net.URL; import org.apache.log4j.Logger; import sun.misc.BASE64Encoder; public class GeoServerCatalogReloadRest { private static Logger geoServerCatalogReloadLogger = Logger .getLogger(GeoServerCatalogReloadRest.class.getName()); public GeoServerCatalogReloadRest () { } public static Boolean doReload (String urlGeoserver, String usernameGeoserver, String passwordGeoserver) { String result = null; try { // example: // username:admin // password:geoserver // url:http://localhost:8080/geoserver/rest/catalogreload URL url = new URL(urlGeoserver + "rest/catalogreload"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); // write auth header BASE64Encoder encoder = new BASE64Encoder(); String encodedCredential = encoder.encode((usernameGeoserver + ":" + passwordGeoserver) .getBytes()); connection.setRequestProperty("Authorization", "Basic " + encodedCredential); connection.setRequestProperty("Content-Type", "text/xml"); connection.connect(); result = connection.getResponseMessage(); } catch (MalformedURLException mue) { geoServerCatalogReloadLogger.warn(GeoServerCatalogReloadRest.class.getName() + ": url not correct -> " + result + " : " + mue.getMessage()); return new Boolean(false); } catch (ProtocolException pe) { geoServerCatalogReloadLogger.warn(GeoServerCatalogReloadRest.class.getName() + ": protocol not correct -> " + result + " : " + pe.getMessage()); return new Boolean(false); } catch (IOException ioe) { geoServerCatalogReloadLogger.warn(GeoServerCatalogReloadRest.class.getName() + ": connection failed -> " + result + " : " + ioe.getMessage()); return new Boolean(false); } return new Boolean(true); } } ------------------------------------------------------------------------------ _______________________________________________ Geoserver-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/geoserver-devel
