ObjectMessageBodyReader.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */

  20. package org.openspcoop2.utils.jaxrs;

  21. import java.io.IOException;
  22. import java.io.InputStream;
  23. import java.lang.annotation.Annotation;
  24. import java.lang.reflect.Type;

  25. import javax.ws.rs.WebApplicationException;
  26. import javax.ws.rs.core.MediaType;
  27. import javax.ws.rs.core.MultivaluedMap;
  28. import javax.ws.rs.ext.Provider;

  29. /**
  30.  * ObjectMessageBodyReader
  31.  *
  32.  * @author Poli Andrea (apoli@link.it)
  33.  * @author $Author$
  34.  * @version $Rev$, $Date$
  35.  */
  36. @Provider
  37. //@javax.ws.rs.Consumes({"application/zip","application/xml"})
  38. public class ObjectMessageBodyReader implements javax.ws.rs.ext.MessageBodyReader<Object>
  39.     //, javax.ws.rs.ext.MessageBodyWriter<Object>
  40. {

  41.     @Override
  42.     public boolean isReadable(Class<?> paramClass, Type paramType,
  43.             Annotation[] paramArrayOfAnnotation, MediaType paramMediaType) {
  44.         // paramMediaType is application/zip, application/xml ...
  45.         // realizzare un if se si desidera gestire solo un tipo in particolare
  46.         String compare = "java.lang.Object";
  47.         String parametro = paramClass.getName();
  48.         parametro = parametro + "";
  49.         if(parametro.equals(compare)) {
  50.             return true;
  51.         }
  52.         else {
  53.             return false; // il tipo viene gestito correttamente
  54.         }
  55.     }

  56.     @Override
  57.     public Object readFrom(Class<Object> paramClass, Type paramType,
  58.             Annotation[] paramArrayOfAnnotation, MediaType paramMediaType,
  59.             MultivaluedMap<String, String> paramMultivaluedMap,
  60.             InputStream paramInputStream) throws IOException, WebApplicationException {
  61.         return paramInputStream;
  62.     }

  63. }