Hi,
we have a client/server Application with restlet 1.1,
Encode/DecodeRepresentation (for GZIP compression) and JaxbRepresention.
Now ne need a new client and we tried restlet 2.0 on the client side.
With restlet 2.0 we run into some trouble using JaxB and GZIP. After
some debuging i found a problem. The DecodeRepresentation decodes only
on getStream. The getText method uses getStream, so it works. The
JaxbRepresentaion.getObject uses getReader instead of getStream (this
changed since version 1.1.8 we use until now). getReader from the
superclass WrappedRepresentation uses the getStream on the wrapped
entity, so DecodeRepresentation.getStream is never called and Jaxb
cannot read the GZIP Stream.
I've some test classes attached. At the ClientTest i override getReader
with the code from StreamRepresentation.getReader to fix that problem.
So, is it a bug or just the wrong way to use jaxb and gzip? What ist the
best practise for this usecase?
Thanks,
Felix
public class ClientTest {
public static void main(final String[] args) throws
ResourceException, IOException {
ClientResource resource = new
ClientResource("http://localhost:8182");
Representation r = new DecodeRepresentation(resource.get()) {
@Override
public Reader getReader() throws IOException {
return BioUtils.getReader(getStream(), getCharacterSet());
}
};
JaxbRepresentation<TestDTO> jaxb = new
JaxbRepresentation<TestDTO>(r, TestDTO.class);
TestDTO object = jaxb.getObject();
System.out.println("Output : " + object.getString());
}
}
public class ServerTest extends ServerResource {
public static void main(final String[] args) throws Exception {
new Server(Protocol.HTTP, 8182, ServerTest.class).start();
}
@Get("xml")
public Representation getRepresentation() {
TestDTO test = new TestDTO();
test.setString("test");
JaxbRepresentation<TestDTO> rep = new
JaxbRepresentation<TestDTO>(test);
return new EncodeRepresentation(Encoding.GZIP, rep);
}
}
@XmlRootElement
public class TestDTO {
private String string;
public String getString() {
return string;
}
public void setString(final String string) {
this.string = string;
}
}
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2925839