001/* 002 * (C) Copyright 2014 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl-2.1.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * <a href="mailto:grenard@nuxeo.com">Guillaume Renard</a> 016 * 017 */ 018 019package org.nuxeo.ecm.restapi.server.jaxrs.routing.io; 020 021import java.io.IOException; 022import java.io.OutputStream; 023import java.lang.annotation.Annotation; 024import java.lang.reflect.Type; 025 026import javax.ws.rs.WebApplicationException; 027import javax.ws.rs.core.MediaType; 028import javax.ws.rs.core.MultivaluedMap; 029import javax.ws.rs.ext.MessageBodyWriter; 030import javax.ws.rs.ext.Provider; 031 032import org.nuxeo.ecm.automation.io.services.codec.ObjectCodecService; 033import org.nuxeo.ecm.platform.routing.api.DocumentRoute; 034import org.nuxeo.runtime.api.Framework; 035 036/** 037 * @since 7.2 038 */ 039@Provider 040public class WorkflowRequestWriter implements MessageBodyWriter<DocumentRoute> { 041 042 @Override 043 public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { 044 return DocumentRoute.class.isAssignableFrom(type); 045 } 046 047 @Override 048 public long getSize(DocumentRoute t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { 049 return -1; 050 } 051 052 @Override 053 public void writeTo(DocumentRoute t, Class<?> type, Type genericType, Annotation[] annotations, 054 MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) 055 throws IOException, WebApplicationException { 056 Framework.getService(ObjectCodecService.class).write(entityStream, t); 057 } 058 059}