That’s exactly what I was looking for Justin. Thanks very much.
···
On Thu, Apr 10, 2014 at 12:12 PM, Justin Deoliveira <jdeolive@anonymised.com…> wrote:
Hey Blake,
As Ian notes the restconfig api might be a better fit, and simpler.
But to answer the question, normally in spring you would just declare a dependency on the catalog in the application context, through regular spring injection.
Would correspond to a constructor in your bean class that takes the Catalog as an argument. However, dependencies on the catalog during startup are kind of tricky because a lot of another initialization is based on the catalog, so introducing a new dependency can change the order of operations on startup, and i have seen that break some things.
So safer would to be to use the event that i pointed you at earlier and do a “manual lookup” of the catalog. That can be done with the GeoServerExtensions class. It will look something like this:
Catalog catalog = (Catalog) GeoServerExtensions.bean(“catalog”);
On Thu, Apr 10, 2014 at 10:16 AM, Ian Schneider <ischneider@anonymised.com> wrote:
Hi Blake,
While it might be possible to achieve your goal of configuring geoserver with an extension, that functionality already exists via the REST config API. I can’t say if this approach would meet your specific requirements but it might save you a bunch of time. The advantage of the REST config API is you can configure during runtime. The disadvantage of this approach is that without additional orchestration (waiting until geoserver is running, for example), you’d need to execute the script manually.
http://docs.geoserver.org/stable/en/user/rest/index.html
–
Justin Deoliveira
Vice President, Engineering | Boundless
jdeolive@anonymised.com
@j_deolive
On Thu, Apr 10, 2014 at 9:56 AM, Blake Peno <blakepeno1991@anonymised.com> wrote:
That helps a lot, Justin, thanks. I’m not nearly as familiar with spring as I would like.
In regards to question 2, I have a bean that runs on startup fine, but the “stuff” (adding data stores, mostly) that I want to do on startup requires access to GeoServer’s Catalog. How can I go about getting access to that from one of my extensions?
Thanks
Put Bad Developers to Shame
Dominate Development with Jenkins Continuous Integration
Continuously Automate Build, Test & Deployment
Start a new project now. Try Jenkins in the cloud.
http://p.sf.net/sfu/13600_Cloudbees
Geoserver-devel mailing list
Geoserver-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-devel
–
Ian Schneider
Software Engineer | Boundless
ischneider@anonymised.com
On Thu, Apr 10, 2014 at 9:44 AM, Justin Deoliveira <jdeolive@anonymised.com> wrote:
Hey Blake,
Unfortunately developing GeoServer plugins is very poorly documented
So if I understand it you have two requirements.
- Need access to the servlet context
- Need to do “stuff” on startup
For (1) the easiest way would be to implement the spring ApplicationContextAware interface in one of your beans that is registered in the spring context. In GeoServer, as with any webapp that uses spring, the ApplicationContext interface will be a an instance of WebApplicationContext which exposes the servlet context. Here is an example in code that does this.
https://github.com/geoserver/geoserver/blob/master/src/platform/src/main/java/org/geoserver/platform/GeoServerExtensions.java#L48
https://github.com/geoserver/geoserver/blob/master/src/platform/src/main/java/org/geoserver/platform/GeoServerExtensions.java#L353
for (2) you have a few options. If what you need to do on startup doesn’t depend on anything else in GeoServer startup then you can just do whatever you need in the constructor of a bean registered in the spring context and it will run whenver spring decides to instantiate it. This of course assumes the bean is a singleton. However if you want to initialize after everything else has started you can implement the spring ApplicationListener interface in one of your beans. Once Geoserver has completely fired up it will fire a ContextLoadedEvent. Here is an example of using that.
https://github.com/geoserver/geoserver/blob/master/src/main/src/main/java/org/geoserver/security/GeoServerSecurityManager.java#L311
Hope that helps!
-Justin
On Wed, Apr 9, 2014 at 2:04 PM, Blake Peno <blakepeno1991@anonymised.com> wrote:
Hey guys,
I’ve been looking around and can’t seem to find much information on the geoserver extension points. The documentation page seems to be blank, and information seems pretty sparse everywhere else.
I’ve managed to get extensions up and running for new data store types, and a new wicket page linked on the geoserver tool bar without too much hassle, but I’m stuck on what I’m trying to do next. For easier deployment, I’m trying to write an extension that loads when geoserver starts and creates/updates some data stores based on some config files, but I can’t seem to figure out how to get access to the servlet context/ geoserver catalog from my extension. I can get access to the catalog by extending GeoServerBasePage, but as far as I know that code requires a user to actually go through the web interface for any of that code to actually run, which isn’t what I’m looking for.
Can anyone give me any insight on how to go about this?
I figured I would ask you guys before I spent another week perusing the source code. Thanks in advance.
Put Bad Developers to Shame
Dominate Development with Jenkins Continuous Integration
Continuously Automate Build, Test & Deployment
Start a new project now. Try Jenkins in the cloud.
http://p.sf.net/sfu/13600_Cloudbees
Geoserver-devel mailing list
Geoserver-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-devel
–
Justin Deoliveira
Vice President, Engineering | Boundless
jdeolive@anonymised.com
@j_deolive