Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-342

Easy way to enable jsonp in resteasy

XMLWordPrintable

    • Icon: Feature Request Feature Request
    • Resolution: Done
    • Icon: Minor Minor
    • 3.0-beta-4
    • None
    • None
    • None

      here are some lines of code which basicly allow to wrap a dto objet in to a javascript method callback.

      @Produces("text/javascript")
      public class JsonpProvider implements MessageBodyWriter<Object> {
      ...
      public void writeTo(final Object object, final Class<?> clazz, final Type type, final Annotation[] annotations,
      final MediaType mediaType, final MultivaluedMap<String, Object> multivaluedMap, final OutputStream out)
      throws IOException, WebApplicationException {

      out.write(methodName);
      if (clazz != null && !clazz.equals(Object.class)) {
      MessageBodyWriter writer = providers.getMessageBodyWriter(clazz, type, annotations,
      MediaType.APPLICATION_JSON_TYPE);
      if (writer != null)

      { writer.writeTo(object, clazz, type, annotations, MediaType.APPLICATION_JSON_TYPE, multivaluedMap, out); }

      else

      { .... }

      } else

      { out.write(emptyJsonObject); }

      out.write(methodEnd);
      }
      }

      This would work with annotating a method with @Produces(text/javascript). The only problem is the injection of the javascript method name. This could be configured in xml or by additional annotation.

              patriot1burke@gmail.com Bill Burke (Inactive)
              alexander.tremel Tremel Alexander (Inactive)
              Votes:
              7 Vote for this issue
              Watchers:
              8 Start watching this issue

                Created:
                Updated:
                Resolved: