jax-rs

Is there a way to get a variable in to a custom ConstraintValidator when using JAX-RS?

天涯浪子 提交于 2020-01-06 05:36:10
问题 When de-serializing a JSON payload i want to validate a phone number using a custom validator. This validator needs to know what country the customer is in to correctly parse the phone number. The country i can find in the http header Accept-Language. The problem is how can i provide the custom validator with this extra meta data? I was sure that @Context would inject the HttpHeaders into the PhoneNumberValidator but this does not work: @Context private HttpHeaders mHttpHeaders; The field is

RESTEasy support for JAX-RS @RolesAllowed

时光总嘲笑我的痴心妄想 提交于 2020-01-06 04:24:46
问题 I've spend hours installing a custom login service in embedded Jetty 9.1.0.v20131115 and RESTEasy 3.0.5.Final. My login service will look users up in a database and assign them roles. It looks something like this: final Constraint restConstraint = new Constraint(); restConstraint.setName(Constraint.__BASIC_AUTH); restConstraint.setRoles(new String[]{"user", "admin"); restConstraint.setAuthenticate(true); final ConstraintMapping restConstraintMapping = new ConstraintMapping();

Jersey 2 - ContainerRequestFilter get method annotation

☆樱花仙子☆ 提交于 2020-01-06 02:46:08
问题 Im trying to get the Method annotation in ContainerRequestFilter object. Controler: @GET @RolesAllowed("ADMIN") public String message() { return "Hello, rest12!"; } ContainerRequestFilter : @Provider public class SecurityInterceptor implements javax.ws.rs.container.ContainerRequestFilter { @Override public void filter(ContainerRequestContext requestContext) { //Here I need To get the @RolesAllowed("ADMIN") annotation value } Application : @ApplicationPath("/rest") public class ExpertApp

Rest Api Post request

佐手、 提交于 2020-01-06 02:44:02
问题 I cannot seem to get this to work for me ,I have seen this in other posts and was hoping someone may be able to spot what im doing wrong.I am trying to get the body of a request to this rest api but cannot seem to pull back what i need and just get null in the string below. @POST @Path("/SetFeeds") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public String setFeed(@PathParam("name")String name2, @QueryParam("name") String name,@Context UriInfo uriInfo){

Rest Api Post request

六月ゝ 毕业季﹏ 提交于 2020-01-06 02:43:12
问题 I cannot seem to get this to work for me ,I have seen this in other posts and was hoping someone may be able to spot what im doing wrong.I am trying to get the body of a request to this rest api but cannot seem to pull back what i need and just get null in the string below. @POST @Path("/SetFeeds") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public String setFeed(@PathParam("name")String name2, @QueryParam("name") String name,@Context UriInfo uriInfo){

Jersey - validate REST service parameters

一个人想着一个人 提交于 2020-01-05 14:04:56
问题 is there any tool to simply validate query params using Jersey (and Maven)? I'm trying to do something like this using @NotNull annotation (jersey-bean-validation): @GET @Path("/count") @Produces(MediaType.APPLICATION_XML) public Response count(@NotNull @QueryParam("my_param") String my_param) { //TODO automatically return 400 Bad Request if my_param is null return Response.ok("This is a response", MediaType.APPLICATION_XML).build(); } I'd like the method to automatically validate query

Jersey - validate REST service parameters

扶醉桌前 提交于 2020-01-05 14:04:39
问题 is there any tool to simply validate query params using Jersey (and Maven)? I'm trying to do something like this using @NotNull annotation (jersey-bean-validation): @GET @Path("/count") @Produces(MediaType.APPLICATION_XML) public Response count(@NotNull @QueryParam("my_param") String my_param) { //TODO automatically return 400 Bad Request if my_param is null return Response.ok("This is a response", MediaType.APPLICATION_XML).build(); } I'd like the method to automatically validate query

Jersey Client Xml Collection Unmarshalling

一个人想着一个人 提交于 2020-01-05 09:34:22
问题 I'm writing a rest client using jersey-client v2.3.1 and need to unmarshal an xml response with a root node containing a collection of widget nodes. Like something resembling the following ... <widgets> <widget /> ... <widget /> </widgets> Currently I have a Widget model ... public class Widget { ... } However I do not have a wrapper for this model (at least not yet), but I presume I could create one that would allow the response to be unmarshalled. It'd probably look something like this ...

Jersey Client Xml Collection Unmarshalling

大憨熊 提交于 2020-01-05 09:34:14
问题 I'm writing a rest client using jersey-client v2.3.1 and need to unmarshal an xml response with a root node containing a collection of widget nodes. Like something resembling the following ... <widgets> <widget /> ... <widget /> </widgets> Currently I have a Widget model ... public class Widget { ... } However I do not have a wrapper for this model (at least not yet), but I presume I could create one that would allow the response to be unmarshalled. It'd probably look something like this ...

how to bind HTTP POST data to python object in Django Rest Framework?

拈花ヽ惹草 提交于 2020-01-05 08:24:28
问题 I will give an example to better explain my question my request: POST http://localhost:8080/users/ request body: (This gets posted) {"name":"Matt", "salary":10000, "blog_url":"www.myblog.com", "dept_name":"ENG" } class CustomRequest(object): def __init__(self,name,salary,blog_url,dept_name): self.name=name self.salary=10000 self.blog_url=blog_url self.dept_name=dept_name models.py class myUser(models.Model): //fields -- username, salary class myUserProfile(models.Model): User=models