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

Jackson2JsonpInterceptor does not render closing bracket

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • 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

    Description

      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

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

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