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

Jackson2JsonpInterceptor does not render closing bracket

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 3.0.11.Final
    • 3.0.10.Final
    • jaxrs
    • None
      1. Enable Jackson2JsonpInterceptor
      2. Call any GET method which returns some json using ResteasyJackson2Provider
      3. Add ?callback=foo to the request
      4. Response will be incorrect
    • Low

      Jackson2JsonpInterceptor does not render closing bracket

      So

      foo({"foo":"bar"}

      Is rendered instead of

      foo({"foo":"bar"})

      The problem is in this method:

      Jackson2JsonpInterceptor.java
          @Override
          public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
              String function = uri.getQueryParameters().getFirst(callbackQueryParameter);
              if (function != null && !function.trim().isEmpty() && !jsonpCompatibleMediaTypes.getPossible(context.getMediaType()).isEmpty()){
                  OutputStreamWriter writer = new OutputStreamWriter(context.getOutputStream());
                  
                  writer.write(function + "(");
                  writer.flush();
                  context.proceed();
                  writer.write(")");
                  writer.flush();
              } else {
                  context.proceed();
              }
          }

      context.proceed() call can close the underlying OutputStream and the bracket appended on the next line will be ignored

              patriot1burke@gmail.com Bill Burke (Inactive)
              bedrin_jira Dmitry Bedrin (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved:

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 2 hours
                  2h