Uploaded image for project: 'Wink'
  1. Wink
  2. WINK-286

GET methods fail to serve requests without Content-Type if the class/interface has @Consumes

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.1
    • 1.1.2
    • Server
    • None

    Description

      When the JAX-RS resource (the method with @GET) is accessed from a web browser, the Content-Type is not set and it's default to application/octet-stream. Wink fails to match to the method as it inherits @Consumes (say, application/json) from the class/interface and it is not compatible with application/octet-stream. For example:

      @Produces(MediaType.APPLICATION_JSON)
      @Consumes(MediaType.APPLICATION_JSON)
      public interface Catalog {
      @GET
      List<Item> get();

      @GET
      @Path("

      {id}

      ")
      Item get(@PathParam("id") String id);
      }

      The GET method doesn't have the request entity. Why do we need to compare the media type for the request? I assume we should only check the methods that take the HTTP body.

      I had to work around this issue for Tuscany to add / or application/octet-stream to the GET method's consumes set. It's ugly .

      private synchronized void fixMediaTypes(DeploymentConfiguration config) {
      if (fixed)

      { return; }

      // FIXME: A hacky workaround for https://issues.apache.org/jira/browse/TUSCANY-3572
      ResourceRecord record = config.getResourceRegistry().getRecord(resourceClass);

      for (MethodMetadata methodMetadata : record.getMetadata().getResourceMethods()) {
      String method = methodMetadata.getHttpMethod();
      if (HttpMethod.GET.equals(method) || HttpMethod.HEAD.equals(method) || HttpMethod.DELETE.equals(method))

      { methodMetadata.addConsumes(MediaType.APPLICATION_OCTET_STREAM_TYPE); methodMetadata.addConsumes(MediaType.WILDCARD_TYPE); }
      if (HttpMethod.HEAD.equals(method) || HttpMethod.DELETE.equals(method)) { methodMetadata.addProduces(MediaType.APPLICATION_OCTET_STREAM_TYPE); methodMetadata.addConsumes(MediaType.WILDCARD_TYPE); }
      }
      for (MethodMetadata methodMetadata : record.getMetadata().getSubResourceMethods()) {
      String method = methodMetadata.getHttpMethod();
      if (HttpMethod.GET.equals(method) || HttpMethod.HEAD.equals(method) || HttpMethod.DELETE.equals(method)) { methodMetadata.addConsumes(MediaType.APPLICATION_OCTET_STREAM_TYPE); methodMetadata.addConsumes(MediaType.WILDCARD_TYPE); }

      if (HttpMethod.HEAD.equals(method) || HttpMethod.DELETE.equals(method))

      { methodMetadata.addProduces(MediaType.APPLICATION_OCTET_STREAM_TYPE); methodMetadata.addConsumes(MediaType.WILDCARD_TYPE); }

      }
      fixed = true;
      }

      Attachments

        Issue Links

          Activity

            People

              bluk Bryant Luk
              rfeng Zhaohui Feng
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: