resteasy

Missing grammar in JBoss Resteasy generated WADL

北城余情 提交于 2019-12-01 12:07:00
I managed to get a WADL by using the org.jboss.resteasy.wadl.ResteasyWadlServlet ( https://stackoverflow.com/a/41471710/2528609 ), but the WADL does not contain the Grammar. The representation nodes also do not contain an element attribute defining the response type. Given the following rest endpoint class import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @Path("user") public class UserEndpoint { @GET @Path("") @Produces(MediaType.APPLICATION_JSON) public UserResponse getUser() { UserResponse

Passing indefinite Query Parameters with RESTful URL and reading them in RESTEasy

[亡魂溺海] 提交于 2019-12-01 08:59:24
I have a requirement to design a RESTful Service using RESTEasy. Clients can call this common service with any number of Query Parameters they would want to. My REST code should be able to read these Query Params in some way. For example if I have a book search service, clients can make the following calls. http://domain.com/context/rest/books/searchBook?bookName=someBookName http://domain.com/context/rest/books/searchBook?authorName=someAuthor& pubName=somePublisher http://domain.com/context/rest/books/searchBook?isbn=213243 http://domain.com/context/rest/books/searchBook?authorName

Customizing JAX-RS response when a ConstraintViolationException is thrown by Bean Validation

和自甴很熟 提交于 2019-12-01 06:19:06
Bean Validation is a good option to validate objects, but how to customize the response of a REST API (using RESTeasy) when a ConstraintViolationException is thrown? For example: @POST @Path("company") @Consumes("application/json") public void saveCompany(@Valid Company company) { ... } A request with invalid data will return a HTTP 400 status code with the following body: [PARAMETER] [saveCompany.arg0.name] [{company.name.size}] [a] It's nice but not enough, I would like to normalize these kind of errors in a JSON document. How can I customize this behavior? With JAX-RS can define an

How to Pass Object from ContainerRequestFilter to Resource

对着背影说爱祢 提交于 2019-12-01 05:52:14
问题 How can/should I pass an object from a ContainerRequestFilter to a (post-matching) resource in (JAX-RS) Resteasy version 3.0.11 that has undertow embedded and uses Guice? 回答1: The method ContainerRequestContext#setProperty stores values which are synced with the HttpServletRequest . So with plain JAX-RS you can store an attribute like this: @Provider public class SomeFilter implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext requestContext) throws

How to filter a request that has an invalid parameter in JAX-RS?

偶尔善良 提交于 2019-12-01 05:36:01
问题 By "invalid" I mean a parameter that is not expected. For example: @Path("/") public interface ExampleInterface { @GET @Path("/example") public Response test( @QueryParam("param1") String param1, @QueryParam("param2") String param2 ); } And then I call ".../example?param3=foo" 回答1: You can check use a ContainerRequestFilter and compare the passed parameters with the defined parameters: @Provider public class RequestParamFilter implements ContainerRequestFilter { @Context private ResourceInfo

RestEasy - Unable to find MessageBodyReader?

百般思念 提交于 2019-12-01 05:18:29
I've written a simple RestEasy client proxy to perform an iTunes search. It looks like this: @Path("/") public interface AppleAppStoreLookupClient { /** * Attempts to lookup an apple app store item by its ID * * @param id * The item ID * @return The app details */ @GET @Path("/lookup") @Produces(value = { "text/javascript" }) public AppleAppDetailsResponse lookupByID(@QueryParam("id") String id); } My JSON model class is simple, as well. In fact, for the first call all I want is the "resultCount" value, just to make sure connectivity works. @XmlRootElement @XmlAccessorType(XmlAccessType.NONE)

Customizing JAX-RS response when a ConstraintViolationException is thrown by Bean Validation

隐身守侯 提交于 2019-12-01 02:52:41
问题 Bean Validation is a good option to validate objects, but how to customize the response of a REST API (using RESTeasy) when a ConstraintViolationException is thrown? For example: @POST @Path("company") @Consumes("application/json") public void saveCompany(@Valid Company company) { ... } A request with invalid data will return a HTTP 400 status code with the following body: [PARAMETER] [saveCompany.arg0.name] [{company.name.size}] [a] It's nice but not enough, I would like to normalize these

Bean Validation with JAX-RS (rest-easy): parameter name not recognized

Deadly 提交于 2019-12-01 02:41:12
问题 I'm using JAX-RS resources with Bean Validation and integration between these two works as expected. However, the default error messages generated in case of a validation error report parameter names as arg0, like so [PARAMETER] [login.arg0.password] [password is required] [] Corresponding method definition: @POST //and other JAX-RS annotations public Response login( @NotNull @Valid LoginBody loginBody) { [...] protected static class LoginBody { @NotNull(message = EMAIL_REQUIRED) public

Root element name in collections returned by RESTEasy

隐身守侯 提交于 2019-12-01 02:38:48
I'm using JAX-RS via RestEasy in JBoss AS 6. When my JAX-RS resource returns a collection of items (e.g. via a List), RESTEasy always uses the name collection as the root element. E.g. <collection> <item> <description>computer</description> <price>2500</price> </item> <item> <description>tv</description> <price>1500</price> </item> </collection> This XML is generated by e.g.: @Produces("application/xml") @Path("xml") @RequestScoped public class MyResource { @GET @Path("myitems") public List<Item> getMyItems() { return ... } } As can be seen the root tag that has been created by RESTEasy is

Is RestEasy the right choice? [closed]

百般思念 提交于 2019-11-30 23:59:45
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . Of the JAX-RS implementations it seems RestEasy is the most difficult to get help for. If you look at the mailing list archive for the