java - Integrating ExtJS with JAX-RS -


i'm trying integrate extjs jax-rs. setup jersey pojomappingfeature , works fine. want rid of glue code. every class looks this:

@path("/helloworld") public class {      @post     @produces(mediatype.application_json)     public final extjsrestoutput createaction(extjsrestinput<b> tocreate) {         try {             final b created = tocreate.getdata();             // logic             return new extjsrestdataoutput<b>(created);         } catch (exception e) {             return new extjsrestfailure();         }     }      @get     @produces(mediatype.application_json)     public final extjsrestoutput readcollectionaction() {         try {             final list<b> readcollection;             //logic             return new extjsrestdataoutput<list<b>>(readcollection);         } catch (exception e) {             return new extjsrestfailure();         }     }      @put     @path("{id}")     @produces(mediatype.application_json)     public final extjsrestoutput updateaction(extjsrestinput<b> toupdate) {         try {             final b udpated = toupdate.getdata();             // logic             return new extjsrestdataoutput<b>(udpated);         } catch (exception e) {             return new extjsrestfailure();         }     }      @get     @path("{id}")     @produces(mediatype.application_json)     public final extjsrestoutput readaction(@pathparam("id") integer id) {         try {             final t read;             // logic             return new extjsrestdataoutput<b>(read);         } catch (exception e) {             return new extjsrestfailure();         }     }      @delete     @path("{id}")     @produces(mediatype.application_json)     public final extjsrestoutput deleteaction(@pathparam("id") integer id) {         try {             // logic             return new extjsrestsuccess();         } catch (exception e) {             return new extjsrestfailure();         }     } } 

i tried resolve inheritance, , turned that:

public abstract class extjsrestaction<t> {      @get     @path("{id}")     @produces(mediatype.application_json)     public final extjsrestoutput readaction(@pathparam("id") integer id) {         try {             final t read = read(id);             return new extjsrestdataoutput<t>(read);         } catch (exception e) {             log.error("blad wywolania read", e);             return new extjsrestfailure("fail");         }     }      abstract public t read(integer id) throws exception;      // ... similar other methods } 

this makes extending classess clean , extjs agnostic:

@path("/helloworld") public class baction extends extjsrestaction<b> {     b create(b tocreate){         // logic     }      b read(integer id){         // logic     }      // , on...     } 

this quite good, there problems when path looks this:

@path("/helloworld/{anotherid}") 

there no (simple) way access anotherid.

i don't know should solution. there way write interceptor class instead of base class pack/unpack objects extjs? or maybe recommend better solution integrate extjs java. using struts 2 , worked quite json when added custom interceptor, hoping able use jax-rs api better.

if understand question, need path param.

you can using class level path param variable in sub-class like:

@path("/helloworld/{anotherid}") public class subclass {      @pathparam("anotherid")     private string anotherid;      @get     public string hello() {         return anotherid;     } } 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -