Details
-
Feature Request
-
Resolution: Obsolete
-
Minor
-
None
-
1.0.2.GA
-
None
-
None
Description
Try to deliver a big chunk of data using JAXB + FastInfoset.
The idea is to efficiently deliver big archives using XML.
Unfortunately, there are two issues:
1. the resulting FastInfoset uses base64 encoding instead of "octet"
2. provider first encode the JAXB object and then sends it to a client
here is my test code:
[code]
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.xml.bind.annotation.XmlMimeType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;
@Path("/test_service")
public class TestService
{
@GET
@Path("/hello")
@Produces("application/fastinfoset")
public Hello helloWorld()
@XmlRootElement(name="hello")
public static class Hello
{
private DataHandler handler;
public Hello()
{
try
catch (Exception ex)
{ ex.printStackTrace(); }}
@XmlValue
@XmlMimeType("application/octet-stream")
public DataHandler getHello()
public void sethello(DataHandler handler)
{ this.handler = handler; }}
private static class StreamDataSource implements DataSource
{
private InputStream stream;
public StreamDataSource(byte[] data)
{ stream = new ByteArrayInputStream(data); }public StreamDataSource(InputStream stream)
{ this.stream = stream; }public InputStream getInputStream() throws IOException
{ return stream; }public OutputStream getOutputStream() throws IOException
{ throw new IOException("operation not supported"); }public String getContentType()
{ return "application/octet-stream"; }public String getName()
{ return "StreamDataSource"; } }
}
[/code]
Cheers,
D.