Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-6149

ContainerRequestContextImpl hasEntity() always returns true for non-GET requests. Similar for ClientResponseContextImpl

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.0.3
    • 3.0.4, 3.1
    • JAX-RS
    • Moderate

    Description

      According to JAX-RS API 2.0 documentation the ContainerRequestContext.hasEntity() should return true only, when there is non-empty entity input stream available.

      But ContainerRequestContextImpl always returns true for any non-GET request even if there is no entity passed with request - check ContainerRequestContextImpl.java:70:

          @Override
          public boolean hasEntity() {
              InputStream is = getEntityStream();
              return is != null && !HttpMethod.GET.equals(getMethod());
          }
      

      This happens due to the fact that getEntityStream() is never null. It always returns a DelegatingInputStream wrapper around javax.servlet.ServletInputStream put in message in AbstractHTTPDestination - check AbstractHTTPDestination.java:298:

              DelegatingInputStream in = new DelegatingInputStream(req.getInputStream()) {
      
                           ... // skipped
      
              };
              
              inMessage.setContent(DelegatingInputStream.class, in);
              inMessage.setContent(InputStream.class, in);
      

      Thus method contract is not satisfied. Presence of input stream doesn't mean that this stream has content. Implementation should check that there is indeed non-empty entity stream, e.g. via checking EOF using read() (obviously caching results for actual consumer).

      N.B.: I believe the same issue affects ClientResponseContextImpl - check ClientResponseContextImpl.java:62:

          @Override
          public boolean hasEntity() { 
              return getEntityStream() != null;
          }
      

      Attachments

        Activity

          People

            sergey_beryozkin Sergey Beryozkin
            kozlovda Dmitry Kozlov
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: