resteasy

RestEasy - Jax-rs - Sending custom Object in response body

荒凉一梦 提交于 2019-11-29 10:42:41
How do I send my custom object in a response. I just want the values printed from my object. Lets say I have an object of type Person . I am trying to send in REST response body like this. ResponseBuilder response = Response.ok().entity(personObj); return response.build(); But I get 500 error. Tried this one too: ResponseBuilder response = Response.status(Status.OK).entity(personObj); return response.build(); Same error. Tried setting content type as text/xml . No use. What am I missing here? I tried googling. But not many examples out there, especially with the custom objects; It returns fine

ContainerResponseFilter not working

我怕爱的太早我们不能终老 提交于 2019-11-29 10:32:05
In wildfly 8.1 with REST services, I wanted to implement CORS ContainerRequestFilter and ContainerResponseFilter. My request filter is working properly but ContainerResponseFilter never gets loaded nor called package org.test.rest; import java.io.IOException; import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.container.ContainerResponseContext; import javax.ws.rs.container.ContainerResponseFilter; import javax.ws.rs.container.PreMatching; import javax.ws.rs.ext.Provider; @Provider @PreMatching // <-- EDIT : This was my mistake ! DO NOT ADD THIS public class

Serialize Date in a JSON REST web service as ISO-8601 string

天涯浪子 提交于 2019-11-29 09:10:43
I have a JAX-RS application using JBoss AS 7.1, and I POST/GET JSON and XML objects which include Dates (java.util.Date): @XmlRootElement @XmlAccessorType(XmlAccessField.FIELD) public class MyObject implements Serializable { @XmlSchemaType(name = "dateTime") private Date date; ... } When I use @Produce("application/xml") on the get method, the objets are serialized as XML and the dates are converted into ISO-8601 strings (e.g. "2012-12-10T14:50:12.123+02:00"). However, if I use @Produce("application/json") on the get method, the dates in the JSON objects are timestamps (e.g. "1355147452530")

How to catch RESTEasy Bean Validation Errors?

佐手、 提交于 2019-11-29 08:21:06
I am developing a simple RESTFul service using JBoss-7.1 and RESTEasy. I have a REST Service, called CustomerService as follows: @Path(value="/customers") @ValidateRequest class CustomerService { @Path(value="/{id}") @GET @Produces(MediaType.APPLICATION_XML) public Customer getCustomer(@PathParam("id") @Min(value=1) Integer id) { Customer customer = null; try { customer = dao.getCustomer(id); } catch (Exception e) { e.printStackTrace(); } return customer; } } Here when I hit the url http://localhost:8080/SomeApp/customers/-1 then @Min constraint will fail and showing the stacktrace on the

RESTeasy client code for attaching a file

杀马特。学长 韩版系。学妹 提交于 2019-11-29 08:09:38
I need to attach a file to my service end-point . I tested the functionality via POSTMAN ( chrome browser plugin to test rest service ) , it is working fine. But I need to test the same with JUNIT . For that case I am using RESTeasy client . I was trying with this code : StringBuilder sb = new StringBuilder(); BufferedReader br = new BufferedReader(new FileReader("C:/Temp/tempfile.txt")); try { String line = br.readLine(); while (line != null) { sb.append(line); sb.append(System.lineSeparator()); line = br.readLine(); } } finally { br.close(); } byte[] file = sb.toString().getBytes(); Client

Jackson - ignore Map superclass when serializing

痴心易碎 提交于 2019-11-29 07:33:26
I have a few model classes that extend LinkedHashMap<String, Object> : they define getters and setters which wrap the Map's get and put methods. I am trying to serialize instances of these classes using Jackson (with RESTEasy), but Jackson refuses to pay attention to my getters, which are annotated with @JsonProperty . Instead, it is only serializing the key-value pairs of the backing map. I tried using @JsonAutoDetect to disable auto-detection for all methods and fields, but that didn't change anything. Is there a way to prevent Jackson from automatically serializing a Map, or must I create

Capture Response Payload in JAX-RS filter

半世苍凉 提交于 2019-11-29 04:18:30
I want to capture and log the response payload in JAX-RS filter. Here is the code snippet of the filter method that I'm using to intercept the response. (FYI - I'm using RestEasy for implementation) @Override public void filter(final ContainerRequestContext requestContext, final ContainerResponseContext responseContext) throws IOException { ... final OutputStream out = responseContext.getEntityStream(); try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { out.write(baos.toByteArray()); .... } } However, the ByteArrayOutputStream turns out be empty. Looking at the RestEasy code, it

How enable JSONP in RESTEasy?

ぃ、小莉子 提交于 2019-11-29 03:56:25
Title say about my issue. I need wrap DTO in to a javascript method callback. Currently I return on request JSON. But problem with using this in Ajax because I send GET to other domain. and of course security police. I have idea to create addition provide. Have you any example, links or suggestion how can do this. joelittlejohn There's no explicit support for JSONP in RESTEasy, however one easy way to enable JSONP in your application is to write a Servlet Filter. Here's a few links that can help you write a filter: jsonp-java: server side filter wraps any response into a jsonp callback Serving

RESTEasy Client Proxy Overhead?

不羁的心 提交于 2019-11-29 03:52:27
问题 I'm creating a RESTEasy service using Client proxies and it works fine so far. However, I did notice that in a few of my functions I see the same line of code: MyClass client = ProxyFactory.create(MyClass.class, "http://localhost:8080"); Is it better to take that out of the functions and make it a member variable of the class to reduce possible overhead? This service will handle load of 10000 reqs/min. Thanks 回答1: You can specify MyClass client as a spring bean, for instance, and inject it

JAX-RS 2.0 change default implementation

杀马特。学长 韩版系。学妹 提交于 2019-11-29 03:04:40
I'm trying to use RESTEasy as JAX-RS 2.0 client implementation. The problem is that I got runtime exception: 06-28 13:29:06.410: E/AndroidRuntime(5745): Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: org.glassfish.jersey.client.JerseyClientBuilder 06-28 13:29:06.410: E/AndroidRuntime(5745): at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:103) So the newBuilder() method is searching for JerseyClientBuilder if I understand it correct. How can I tell the system to use RESTEasy instead? Well, JAX-RS relies on the Service Provider convention. On the first