Hi Ramesh,

Ok, I see that

          @Path("utf8")
          @Produces("text/plain;charset=utf-8")
          @POST
          public String utf8()
          {
             System.out.println("TestResource.utf8()");
             return "ok";
          }
       ...
       @Test
       public void testAcceptNoUtf8() throws Exception
       {
          ClientRequest request = new
   ClientRequest("http://localhost:8081/utf8/";);
          request.accept("text/plain");
          ClientResponse<?> response = request.post();
          Assert.assertEquals(200, response.getStatus());
          String entity = response.getEntity(String.class);
          System.out.println("result: " + entity);
       }

results in

org.jboss.resteasy.spi.NotAcceptableException: RESTEASY001530: No match for accept header

whereas

          @Path("nocharset")
          @Produces("text/plain")
          @POST
          public String noCharset()
          {
             return "ok";
          }

       ...

       @Test
       public void testAcceptUtf8No() throws Exception
       {
          ClientRequest request = new
   ClientRequest("http://localhost:8081/nocharset/";);
          request.accept("text/plain;charset=utf-8");
          ClientResponse<?> response = request.post();
          Assert.assertEquals(200, response.getStatus());
          String entity = response.getEntity(String.class);
          System.out.println("result: " + entity);
       }

works fine. The relevant code is

   @Override
   public boolean isCompatible(MediaType other)
   {
      boolean result;
      if (other == null)
         result = false;
if (getType().equals(MEDIA_TYPE_WILDCARD) || other.getType().equals(MEDIA_TYPE_WILDCARD))
         result = true;
else if (getType().equalsIgnoreCase(other.getType()) && (getSubtype().equals(MEDIA_TYPE_WILDCARD) || other.getSubtype().equals(MEDIA_TYPE_WILDCARD)))
         result = true;
      else
      {
         if (getType().equalsIgnoreCase(other.getType())
                 && this.getSubtype().equalsIgnoreCase(other.getSubtype()))
         {
            if (getParameters() == null || getParameters().size() == 0)
            {
               result = true;
            }
            else
            {
               result = this.equals(other);
            }
         }
         else
         {
            result = false;
         }
      }
      return result;
   }

in org.jboss.resteasy.util.WeightedMediaType in the resteasy-jaxrs module.

Very interesting. Honestly, I'm not sure how to think about this. The JAX-RS 1.1 spec says "An implementation MUST NOT invoke a method whose effective value of @Produces does not match the request Accept header.", but I don't see where it ever actually defines "match". And Resteasy passes the TCK tests. Really, I'm not even sure what "match" SHOULD mean. We could get crazy and do full blown unification (http://en.wikipedia.org/wiki/Unification_%28computer_science%29). Ugh.

Resource matching is a very fundamental notion in JAX-RS, and I wouldn't want to make any changes without being very careful.

Any thoughts about how to interpret "match"?

-Ron


  public boolean isCompatible(MediaType other)
   {
      boolean result;
      if (other == null)
         result = false;
if (getType().equals(MEDIA_TYPE_WILDCARD) || other.getType().equals(MEDIA_TYPE_WILDCARD))
         result = true;
else if (getType().equalsIgnoreCase(other.getType()) && (getSubtype().equals(MEDIA_TYPE_WILDCARD) || other.getSubtype().equals(MEDIA_TYPE_WILDCARD)))
         result = true;
      else
      {
         if (getType().equalsIgnoreCase(other.getType())
&& this.getSubtype().equalsIgnoreCase(other.getSubtype()))
         {
            if (getParameters() == null || getParameters().size() == 0)
            {
               result = true;
            }
            else
            {
               result = this.equals(other);
            }
         }
         else
         {
            result = false;
         }
      }
      return result;
   }

On 05/12/2015 03:55 PM, Ramesh Reddy wrote:
We are using under EAP 6.3 (2.3.8) and EAP 6.4 (2.3.9 or 2.3.10)

------------------------------------------------------------------------

    Meant to reply to list.

    Anyway, it looks like Resteasy 2.3.10.Final, more or less.

    -Ron


    -------- Forwarded Message --------
    Subject:    Re: [Resteasy-users] Question about Accepts Header
    Date:       Mon, 11 May 2015 21:19:24 -0400
    From:       Ron Sigal <rsi...@redhat.com>
    To:         Ramesh Reddy <rare...@redhat.com>



    Hi Ramesh,

    Which version of Resteasy are you using in Teiid?

    Thanks,
    Ron

    On 05/11/2015 05:05 PM, Ramesh Reddy wrote:
    > Hi,
    >
    > In Teiid we have used RestEasy to implement the OData layer. We are seeing an issue 
with "Accepts" header. It is described 
herehttps://issues.jboss.org/browse/TEIID-3471  see 2nd comment. Any pointers to resolve are 
appreciated.
    >
    > Thanks
    >
    > Ramesh..
    >
    > 
------------------------------------------------------------------------------
    > One dashboard for servers and applications across Physical-Virtual-Cloud
    > Widest out-of-the-box monitoring support with 50+ applications
    > Performance metrics, stats and reports that give you Actionable Insights
    > Deep dive visibility with transaction tracing using APM Insight.
    >http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
    > _______________________________________________
    > Resteasy-users mailing list
    >Resteasy-users@lists.sourceforge.net
    >https://lists.sourceforge.net/lists/listinfo/resteasy-users




    
------------------------------------------------------------------------------
    One dashboard for servers and applications across
    Physical-Virtual-Cloud
    Widest out-of-the-box monitoring support with 50+ applications
    Performance metrics, stats and reports that give you Actionable
    Insights
    Deep dive visibility with transaction tracing using APM Insight.
    http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
    _______________________________________________
    Resteasy-users mailing list
    Resteasy-users@lists.sourceforge.net
    https://lists.sourceforge.net/lists/listinfo/resteasy-users



package org.jboss.resteasy.test.mediatype;

import java.util.Hashtable;

import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

import junit.framework.Assert;

import org.jboss.resteasy.client.ClientRequest;
import org.jboss.resteasy.client.ClientResponse;
import org.jboss.resteasy.core.Dispatcher;
import org.jboss.resteasy.spi.ResteasyDeployment;
import org.jboss.resteasy.test.EmbeddedContainer;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * @author <a href="mailto:ron.si...@jboss.com">Ron Sigal</a>
 * @date May 13, 2015
 */
public class TestAcceptsMediaType
{
   protected static ResteasyDeployment deployment;
   protected static Dispatcher dispatcher;

   @Path("/")
   public static class TestResource
   {
      @Path("nocharset")
      @Produces("text/plain")
      @POST
      public String noCharset()
      {
         System.out.println("TestResource.noCharset()");
         return "ok";
      }

      @Path("utf8")
      @Produces("text/plain;charset=utf-8")
      @POST
      public String utf8()
      {
         System.out.println("TestResource.utf8()");
         return "ok";
      }
      
      @Path("utf16")
      @Produces("text/plain;charset=utf-16")
      @POST
      public String utf16()
      {
         System.out.println("TestResource.utf16()");
         return "ok";
      }
   }

   @Before
   public void before() throws Exception
   {
      Hashtable<String,String> initParams = new Hashtable<String,String>();
      Hashtable<String,String> contextParams = new Hashtable<String,String>();
      deployment = EmbeddedContainer.start(initParams, contextParams);
      dispatcher = deployment.getDispatcher();
      deployment.getRegistry().addPerRequestResource(TestResource.class);
   }

   @After
   public void after() throws Exception
   {
      EmbeddedContainer.stop();
      dispatcher = null;
      deployment = null;
   }

   //@Test
   public void testAcceptNoNo() throws Exception
   {
      ClientRequest request = new ClientRequest("http://localhost:8081/nocharset/";);
      request.accept("text/plain");
      ClientResponse<?> response = request.post();
      Assert.assertEquals(200, response.getStatus());
      String entity = response.getEntity(String.class);
      System.out.println("result: " + entity);
   }

   //@Test
   public void testAcceptUtf8No() throws Exception
   {
      ClientRequest request = new ClientRequest("http://localhost:8081/nocharset/";);
      request.accept("text/plain;charset=utf-8");
      ClientResponse<?> response = request.post();
      Assert.assertEquals(200, response.getStatus());
      String entity = response.getEntity(String.class);
      System.out.println("result: " + entity);
   }
   
   //@Test
   public void testAcceptUtf16No() throws Exception
   {
      ClientRequest request = new ClientRequest("http://localhost:8081/nocharset/";);
      request.accept("text/plain;charset=utf-16");
      ClientResponse<?> response = request.post();
      Assert.assertEquals(200, response.getStatus());
      String entity = response.getEntity(String.class);
      System.out.println("result: " + entity);
   }
   
   @Test
   public void testAcceptNoUtf8() throws Exception
   {
      ClientRequest request = new ClientRequest("http://localhost:8081/utf8/";);
      request.accept("text/plain");
      ClientResponse<?> response = request.post();
      Assert.assertEquals(200, response.getStatus());
      String entity = response.getEntity(String.class);
      System.out.println("result: " + entity);
   }
   
   //@Test
   public void testAcceptNoUtf16() throws Exception
   {
      ClientRequest request = new ClientRequest("http://localhost:8081/utf16/";);
      request.accept("text/plain");
      ClientResponse<?> response = request.post();
      Assert.assertEquals(200, response.getStatus());
      String entity = response.getEntity(String.class);
      System.out.println("result: " + entity);
   }
   
   //@Test
   public void testAcceptUtf16Utf16() throws Exception
   {
      ClientRequest request = new ClientRequest("http://localhost:8081/utf16/";);
      request.accept("text/plain;charset=utf-16");
      ClientResponse<?> response = request.post();
      Assert.assertEquals(200, response.getStatus());
      String entity = response.getEntity(String.class);
      System.out.println("result: " + entity);
   }
}
------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Resteasy-users mailing list
Resteasy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/resteasy-users

Reply via email to