Ejemplo n.º 1
0
 public void writeTo(
     T obj,
     Class<?> cls,
     Type genericType,
     Annotation[] anns,
     MediaType m,
     MultivaluedMap<String, Object> headers,
     OutputStream os)
     throws IOException {
   try {
     String encoding = HttpUtils.getSetEncoding(m, headers, null);
     if (InjectionUtils.isSupportedCollectionOrArray(cls)) {
       marshalCollection(cls, obj, genericType, encoding, os, m, anns);
     } else {
       Object actualObject = checkAdapter(obj, cls, anns, true);
       Class<?> actualClass =
           obj != actualObject || cls.isInterface() ? actualObject.getClass() : cls;
       marshal(actualObject, actualClass, genericType, encoding, os, m, anns);
     }
   } catch (JAXBException e) {
     handleJAXBException(e, false);
   } catch (WebApplicationException e) {
     throw e;
   } catch (Exception e) {
     LOG.warning(ExceptionUtils.getStackTrace(e));
     throw ExceptionUtils.toInternalServerErrorException(e, null);
   }
 }
Ejemplo n.º 2
0
 @Override
 public void writeTo(
     T t,
     Class<?> cls,
     Type genericType,
     Annotation[] anns,
     MediaType m,
     MultivaluedMap<String, Object> headers,
     OutputStream os)
     throws IOException {
   String prefix = getContext().getHttpServletRequest().getParameter("_jsonp");
   boolean hasPrefix = !(null == prefix || prefix.isEmpty()); // !isEmpty(prefix);
   if (hasPrefix) {
     os.write(prefix.getBytes(HttpUtils.getSetEncoding(m, headers, "UTF-8")));
     os.write('(');
   }
   super.writeTo(t, cls, genericType, anns, m, headers, os);
   if (hasPrefix) {
     os.write(')');
   }
 }