0

I am writing a REST service using Apache Wink. My service needs some server side configurations like defining some System properties etc. The user of the rest service need not know these and provide any value for these. I would like to understand what is the ideal/best way to initialize this properties in a REST service. Should I do this configuration in the constructor of the Resource class? or some place else?

Thanks.

Niks
  • 41
  • 2
  • 8
  • This configuration is a one time thing, not needed per request basis but only when the server starts the service. – Niks Mar 30 '15 at 10:22
  • An alternate question - Is the constructor of Rest service class the right place to initialize Bussiness class objects? – Niks Mar 31 '15 at 05:50

1 Answers1

0

Usually the right place to make the boots depends.

Usually they use at least 3 layers on a draft REST services.

REST layer (with the REST calls) <---->        Layer of business (with the logic of business) <---->

Layer of data (data rescue)   Must be initialize the variables of the objects that belong to the business layer in the REST layer.

The variables of the objects belonging to the data layer must be initialized in the business layer.

System properties must be initialized in the places where they are first used.

João Marcos
  • 3,872
  • 1
  • 19
  • 14
  • Thanks, but this not what I am exactly looking for. I need to know/understand what is the right way/place to do some initializations required for service, like inialization of some Bussiness classes and setting some system properties. This does not involve any http request, simple java code. – Niks Mar 30 '15 at 14:28
  • I dont understand your question. I change completely my anwser. Please check it! – João Marcos Mar 30 '15 at 17:05
  • Thanks again, you are almost there, I just need little more specific answer, like where in REST layer, like I mentioned - is the constructor of the REST service class where I should initalize the Bussiness classes so that they would be shared accross all my Resource methods (http methods of my resource class) or I need to initialize the bussiness classes per resource method? – Niks Mar 31 '15 at 05:43
  • When you start a server (Tomcat, JBoss, etc...), the root resource class constructor not run. The better way to initialize the bussiness classes is per resource method because this have better performance to. You can have n resources inside a class and your clients can only use one or two for example. – João Marcos Mar 31 '15 at 08:48
  • it helps you? pls approve the answer if yes. – João Marcos Mar 31 '15 at 18:23
  • I am little confused, I have read that the constructor of the Resource class gets called, and every time a request comes a new object of the Resouce class gets created so each instance would have its own bussiness class objects - so where is the performance impacted? – Niks Apr 01 '15 at 10:13
  • if we talk about tomcat server, the root resource is not called. the performance is impacted if you initialize all the variables and you only need half of them for example. – João Marcos Apr 01 '15 at 14:55