0

I have create a RestFUL service using Spring MVC, but this server was not built like others RESTFull servers.

The server has just 1 controller(It a kind of Faced) with 3 mapping, see bellow

Mapping 1

   @RequestMapping(value = "domain/{entity}/{action}", method = {
        RequestMethod.POST }, consumes = "application/json", produces="application/json")

As you can see, this mapping process ALL request about DOMAIN and receive as Request body an object called Request ex: /domain/customer/save

/domain/customer/delete

/domain/customer/find

/domain/customer/anyotherserviceaboutcustomer

/domain/employer/save

/domain/employer/employerEspecificService etc.

Mapping 2

    @RequestMapping(value = "service/{service}/{action}", method = {
        RequestMethod.POST }, consumes = "application/json", produces="application/json")

This mapping process ALL service class, like

/service/email/send

/service/report/getreport

/service/schema/getschema

Mapping 3

This maping is about login, after login client receive an token to send future request to consume other resources


Everything is working fine, the controller process de request using Reflection and Spring manage the objects requested (Beans).

Advantages ?

Using Conversion over Configuration is possible to have a standard behavior about process request from only one controller.

The business logic keep in only Service layer, never in Controller or domain class

I just need to process the request in only one place.

...

Question 1

So, even it works, I'd like to know the opinion about you guys, what's the problem about this "design"?

Question 2

Independent of this approach, the Client receive an Response, in this case in JSON Format, so, I wouldn't like the Client knows about any class of the server, how can I process the server objects with no knows them?

For example, if I receive the JSON about CUSTOMER

 {
  "id" : "1",
  "name" : "RODRIGO" 
 }

I can convert it to Object in the client, but after that?

I'm thinking to create a kind of "Container Object" that will convert received JSOn to Container object, this Container it seen like a database table, it will be a Class to manipulate the data from client side

Thanks

Sunil Singh Bora
  • 771
  • 9
  • 24
Rodrigo Rodrigues
  • 649
  • 2
  • 12
  • 25
  • Q1 I do not thik that is good design, for instance you can not use simple validation like if you use separated controlers for entities. I do not understend motivation for Q2 sorry – JosefN Jan 28 '14 at 14:21
  • Q1 After receive the data from controller, the services about the entity perform the validation and return to controller that return to client, so the validation ocurrs in the service layer. Q2 is about how can I process the response data from server. – Rodrigo Rodrigues Jan 28 '14 at 14:29
  • may you show any validation example? for example, duplicate field value, range field value, maxlengh, minlength, wrong email address? using url /service/schema/getschema i can provider shchema to client for validation, but these validations will perform in server side too – Rodrigo Rodrigues Jan 28 '14 at 14:33

0 Answers0