java - Dynamically extend Spring MVC powered REST api with access to application jar only -


i in situation have nascent rest api architecture each method has tons of ceremony (validation, db connection acquisition/release, authentication), raw request/response objects parameters, , hard-coded json strings output. want use spring mvc @ least of these issues (auth & db stuff i'll need hold off on). render lot of current architecture unnecessary. pretty easy except 1 feature of current architecture: dynamically adding api calls.

the entry point (servlet) architecture reads xml file contains path request , corresponding class load. class must implement interface contains 'execute' method has logic request. servlet calls execute method after loading class. allows dynamic extension of api follows. app packaged jar associated config (xml) files , given client. client includes jar in project, creates class implements aforementioned interface, , adds mapping request url class in included xml file. runs app , gets access both original api , custom api.

example:

client given app.war, interface.jar , custom-mappings.xml. app.war contains implementation of core api (rest webservice), , interface.jar exposes interface basecontroller has method 'execute' (app.jar uses interface in controller). client defines own class follows.

package custapi.controllers;  public class extendedcontroller implements basecontroller { public void execute(httpservletrequest request, httpservletresponse response) { // logic } } 

he compiles class , adds app.war. next, updates custom-mappings.xml following entry.

/custcall/mycall custapi.controllers.extendedcontroller

he deploys app. controller provided core api receives request /custcall/mycall, looks in custom-mappings.xml, finds class custapi.controllers.extendedcontroller, loads class, , runs 'execute' method. allows logic defined client run.

ideal:

current architecture replaced spring-mvc. is, there no more 'super' controller parses requests , delegates appropriate class and, finally, method. spring handles this. app uses new architecture, client receive app.war , spring mvc deps expose controller annotations. client create new spring mvc controller (taking advantage of validation, parameter -> pojo mapping, object -> json conversion), compile it, , add resulting class file app.war. controller become extension core api exposed app. when app deployed, able make request /custcall/mycall before , have execute logic defined. ideal scenario allows clean code core api (which , others programmed) , extended api. (a downside approach client tied spring. in more ideal scenario, client use framework-agnostic annotations mapped spring annotations app. i'm not sure how easy be.)

i'm not sure how above realized spring-aware controller without sacrificing benefits of spring. don't believe client define spring-aware controller (correct me if i'm wrong on this). solution can think of have spring-aware controller has wildcard path (e.g., /cust_rest/*) acts same current controller. client not advantages spring has offer, core api lot cleaner. hoping there better solution, however. ideally client benefits of spring without having access core api source code. ideas on this, or solution best can hoped for?

thanks.

(note: both scenarios, guessing how client gains access dependencies/interfaces , deploys. have had access core api project 1 day, , understanding of not complete.)

related: runtime loading of controllers spring mvc , dynamically mapping requests/urls

the above question looks pretty similar mine. replies sparse (second 1 off topic, believe).

provided setup classpath scanning there's no need interface. clients can annotate classes @controller @requestmapping("/foo/bar"). if class located in own jar still scanned. if rest service consider using @restcontroller instead avoid having place @responsebody on each handler method.

use spring security declarative authentication & authorization (what you're doing programmatic security)


Comments

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

The canvas has been tainted by cross-origin data in chrome only -