PUT method in jersey - jersey

I am new to Restful webservice. When I was going through the tutorials, I saw that PUT method can be used to create the resource. the creation means adding into the database or somewhere by implementing our own effort? or will Jersey take care of creating the resource its own?
Sorry for asking silly questions.. I did not get the way what PUT is doing..
Thanks
Bhanu

Jersey won't do anything except you tell it to. A PUT request semantically should create or update a ressource, so if you plan to create some entity, thats the HTTP method to use. Use #PUT to annotate your method and implement your functionality (as your tutorials tell you).

Related

Injecting custom objects into the Request Bean

In my JAX-RS, Jersey application, I need to include a custom check before any API is invoked before the all the request to be processed. The best approach is to use a JAX-RS filter. To do this custom check, I need to do a database hit, check a few things etc. The results from the database hit, would be useful to code path so I would like to pass them on. Rather than have the rest of code path have to make another B hit. I see I can inject lots of thins using the #Context annotation. Is there anyway I can extend this to get JAX-RS / Jersey to inject some custom objects?
Thanks

Spring Data Rest modify Repository method URI

This may be a bit of a rudimentary question, but I have a repository where I can do a find by username as follows:
....../items/search/byUsername/?username=myusername
However, this is generally inconsistent with how AngularJS Resources treat queries. Is there a way to instead make the request URI for the same thing to be
....../items/?username=myusername
Or does that functionality not exist with spring data rest? custom methods can be made in the angular resource but it is tedious to do that for every possible search category
If Angular (read: a client library) defines what URI's have to look like, then it's fundamentally violating a core REST principle — which is that clients follow links and URI templates.
That said, if you're using Querydsl and let your repository extend QuerydslPredicateExecutor, collection resources can be filtered by using property expressions. See the reference documentation for details.
Another option would be to manually expose resources under the URIs expected and manually forward the calls. But again, I'd argue you're better off teaching Angular to behave like a proper REST client in the first place 🙃.

ehcache restful service methods override/extend

my question may be vague to ask. I am trying to use ehcache restful service methods such as get or put. I am not sure how this works under hood, is there any way I can override these methods? I mean, get always looks up in cache, but I want to look up in database if not found in cache. I can implement this behavior by writing my own rest service methods, but is there anyway to use ehcache built-in rest functionality by overriding their methods or extend their methods to look up in database if not found in cache. Appreciate your help, thanks.

Spring mvc - get data from other server, what object to use and how to reuse it?

I have some url that I need to read data from there and use it in my controller.
Usually in java application I use http client, to get data from some url.
My questions are:
What object to use in spring mvc to get data from some url (like http client) ?
How to reuse this objects, so every time not to create it ?
Thank you!
In agreement with the comment by #Evgeny and #Beau above, you can use any client library you like. HttpClient is VERY bean friendly and, for cases where it might be difficult to construct the configuration, you can always provide a Spring factory bean to construct the object.
If you are looking to abstract away the plumbing of the HttpClient API usage, utilize the RestTemplate suggested by #Evgeny (I believe that it is also his brainchild) It is a VERY rich and simple API to leverage.

Spring MVC Custom Authentication

What I am looking to accomplish is a filter (or similar) that would handle the authentication model for my Spring MVC application. My application is also hosted on Google App Engine.
The authentication on this application can tend to be very dynamic and the permissions are not something that would fit cleanly into a predefined Role structure. These permissions would be tied to the different action methods on my controllers. Ideally I would like to be able to annotate these permissions but I am open for other suggestions.
I am finding that there is not very much information around on how to accomplish this. Ideally I would like to be able to intercept the call to my controller actions and be able to read off the annotations and handle accordingly. What I am hoping is that someone here has a little bit more knowledge on Spring MVC and where I can inject some custom code, and would be able to point me in the right direction.
I would still use Spring Security to do this. It may not have a class that 100% fits your login scheme, but that's what inheritance is for. Write your own. You can easily get rid of the ROLE based DecisionManager and make it fit your paradigm.
Based on your comments have you checked out the MethodInterceptor in Spring? It creates a Proxy that will intercept calls to any method on the proxied class and allow you to run or disallow the method based on any code you want. In Spring Security there is an AbstractSecurityInterceptor, but I find it very hard to use and for most access decisions I think it's overkill.
So I would use Spring Security to authenticate the user (and populate the SecurityContext) and then use interceptors to wall off access to methods in your controllers that you want protected.

Resources