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

Jackson2JsonpInterceptor does not render closing bracket

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: 3.0.10.Final
    • Fix Version/s: 3.0.11.Final
    • Component/s: jaxrs
    • Labels:
      None
    • Steps to Reproduce:
      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
    • Estimated Difficulty:
      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

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                bill.burke Bill Burke
                Reporter:
                bedrin Dmitry Bedrin
              • 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