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

Easy way to enable jsonp in resteasy

    XMLWordPrintable

    Details

    • Type: Feature Request
    • Status: Closed (View Workflow)
    • Priority: Minor
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: 3.0-beta-4
    • Component/s: None
    • Labels:
      None

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              bill.burke Bill Burke (Inactive)
              Reporter:
              alexander.tremel Tremel Alexander (Inactive)
              Votes:
              7 Vote for this issue
              Watchers:
              8 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: