Search in sources :

Example 1 with Entity

use of io.milton.http.Response.Entity in project lobcder by skoulouzis.

the class ResponseAdapter method setTargetEntity.

// Grab the Milton entity, wrap it in a Restlet entity, set it on target
public void setTargetEntity() {
    final Entity entity;
    if ((entity = getEntity()) != null) {
        MediaType contentType = MediaType.valueOf(getContentTypeHeader());
        getTarget().setEntity(new OutputRepresentation(contentType) {

            @Override
            public void write(OutputStream outputStream) throws IOException {
                try {
                    entity.write(ResponseAdapter.this, outputStream);
                } catch (IOException ex) {
                    throw ex;
                } catch (Exception ex) {
                    throw new RuntimeException(ex);
                }
            }
        });
    }
}
Also used : Entity(io.milton.http.Response.Entity) OutputRepresentation(org.restlet.representation.OutputRepresentation) OutputStream(java.io.OutputStream) MediaType(org.restlet.data.MediaType) IOException(java.io.IOException) IOException(java.io.IOException)

Aggregations

Entity (io.milton.http.Response.Entity)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 MediaType (org.restlet.data.MediaType)1 OutputRepresentation (org.restlet.representation.OutputRepresentation)1