• Post Reply Bookmark Topic Watch Topic
  • New Topic

Generating RESTful web services dynamically

 
Flo Gutierrez
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi !

First, I have to apologize if this post is not in the right forum, but as the final goal is about Web Services, and as someone can give me another way to generate web services dynamically I think that my post should be here.

So, as I said, I want to be able to create a web service on certain call from a method.
Right now, I am trying to use a proxy design pattern (or something near) to instanciate my generic RESTful web service class.
Using JAX-RS, I use the @Path annotation. That's where the problem comes from.
In fact, I want to be able to use this annotation in a way like which is not allowed as the attribute must be a constant.

Therefore, I was thinking of declaring my own @Path annotation in which I would call the JAX-RS @Path implementation with the correct id.
Problem is, I don't know if I can do that, nor how to.

I hope someone will be able to give me some clues…

Thank you in advance.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not quite clear on what you want to do.

Are you trying to write new Java code to implement a requested service, compile it and add the new class to the server?

-or-

Are you trying to stitch together existing code methods to implement a requested service, without writing new Java code?

Bill
 
Flo Gutierrez
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although I know this is awful to read, it is more explicit. I want to make an annotation like that :


where java.ws.rs.Path is
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That would be contrary to the design of annotations - you appear to want a single instance of a class to behave in a variety of different ways by changing an annotation dynamically. How would that cope with multiple requests?

Carefully read this annotation tutorial

Back off a bit and choose a different architecture. Do you really want to compile a new class for every request? Why not use normal Java to control behavior of a single service class instance.

Bill


 
Flo Gutierrez
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, thank you for the reply.
After reading the link you gave me, I do have a better understanding of annotations. But the fact is I wanted to change the value of the annotation for each instance of the class so I don't have to create a new class each time.

Thinking again about the goal I want to reach, I ask myself again "why do I want to instantiate a new web service each time ?" I realized that it was to be sure my web service is available all time. But the web services container threads automatically the WS… So in fact all I wanted to do is useless…

Anyway, I am sorry to have you lose time, but I do know a lot more about annotations right now thanks to you and google.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't HAVE to use annotations at all, dynamically configurable RESTful services can be accomplished other ways.

Look at the various methods in javax.servlet.http.HttpServletRequest which you can use to take apart the request to locate the desired service and parameters.

Bill

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!