You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cxf.apache.org by "Neal Hu (JIRA)" <ji...@apache.org> on 2015/04/02 08:51:54 UTC

[jira] [Updated] (CXF-6307) Wrong select the message body reader

     [ https://issues.apache.org/jira/browse/CXF-6307?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Neal Hu updated CXF-6307:
-------------------------
    Description: 
This is a CTS testcase, the resource class is like this:   
   @POST
    @Path("boolean")
    public Boolean postBoolean(Boolean bool) {
    	if(bool){    		 
    		throw new WebApplicationException(Status.NOT_ACCEPTABLE);
    	}
        return false;
    }

The application provided provider is like this:

public class MyReader implements MessageBodyReader<Boolean> {

    @Override
    public boolean isReadable(Class<?> type, Type type1, Annotation[] antns, MediaType mt) {
    	return type== Boolean.class;
    }

    @Override
    public Object readFrom(Class<Object > type,
                             Type type1,
                             Annotation[] antns,
                             MediaType mt, MultivaluedMap<String, String> mm,
                             InputStream in) throws IOException, WebApplicationException {
		return Boolean.valueOf("true");        
    }
}

The request
Content-Type:text/plain
Accept:text/plain 
Method:POST
Body:false

According to jsr339 section 4.2.4 Standard Entity Providers java.lang.Boolean, java.lang.Character, java.lang.Number Only for text/plain. Corresponding primitive types supported via boxing/unboxing conversion.

An implementation MUST support application-provided entity providers and MUST use those in preference to its own pre-packaged providers when either could handle the same request. More precisely, step 4 in Section 4.2.1 and step 5 in Section 4.2.2 MUST prefer application-provided over pre-packaged entity providers.

4.2.1 Message Body Reader
3. Select the set of MessageBodyReader classes that support the media type of the request, see Section
4.2.3.
4. Iterate through the selected MessageBodyReader classes and, utilizing the isReadable method of
each, choose a MessageBodyReader provider that supports the desired Java type.

It says the entity providers should be sorted by media type firstly then(the media type is the same) on Section 4.2.1 and step 5 in Section 4.2.2 MUST prefer application-provided over pre-packaged entity providers. So org.apache.cxf.jaxrs.provider.PrimitiveTextProvider should be selected as its media type MUST be text/plain and the application provider's media type is */*.(x/y>x/*>*/*)

So at this point the CTS expected response code is 200 instead of 406, the application provided provider should not be chosen.

  was:
This is a CTS testcase, the resource class is like this:   
   @POST
    @Path("boolean")
    public Boolean postBoolean(Boolean bool) {
    	if(bool){    		 
    		throw new WebApplicationException(Status.NOT_ACCEPTABLE);
    	}
        return false;
    }

The application provided provider is like this:

public class MyReader implements MessageBodyReader<Boolean> {

    @Override
    public boolean isReadable(Class<?> type, Type type1, Annotation[] antns, MediaType mt) {
    	return type== Boolean.class;
    }

    @Override
    public Boolean readFrom(Class<Boolean> type,
                             Type type1,
                             Annotation[] antns,
                             MediaType mt, MultivaluedMap<String, String> mm,
                             InputStream in) throws IOException, WebApplicationException {
		return Boolean.valueOf("true");        
    }
}

The request
Content-Type:text/plain
Accept:text/plain 
Method:POST
Body:false

According to jsr339 section 4.2.4 Standard Entity Providers java.lang.Boolean, java.lang.Character, java.lang.Number Only for text/plain. Corresponding primitive types supported via boxing/unboxing conversion.

An implementation MUST support application-provided entity providers and MUST use those in preference to its own pre-packaged providers when either could handle the same request. More precisely, step 4 in Section 4.2.1 and step 5 in Section 4.2.2 MUST prefer application-provided over pre-packaged entity providers.

4.2.1 Message Body Reader
3. Select the set of MessageBodyReader classes that support the media type of the request, see Section
4.2.3.
4. Iterate through the selected MessageBodyReader classes and, utilizing the isReadable method of
each, choose a MessageBodyReader provider that supports the desired Java type.

It says the entity providers should be sorted by media type firstly then(the media type is the same) on Section 4.2.1 and step 5 in Section 4.2.2 MUST prefer application-provided over pre-packaged entity providers. So org.apache.cxf.jaxrs.provider.PrimitiveTextProvider should be selected as its media type MUST be text/plain and the application provider's media type is */*.(x/y>x/*>*/*)

So at this point the CTS expected response code is 200 instead of 406, the application provided provider should not be chosen.


> Wrong select the message body reader
> ------------------------------------
>
>                 Key: CXF-6307
>                 URL: https://issues.apache.org/jira/browse/CXF-6307
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 3.0.3
>         Environment: Windows
>            Reporter: Neal Hu
>             Fix For: 3.0.5
>
>
> This is a CTS testcase, the resource class is like this:   
>    @POST
>     @Path("boolean")
>     public Boolean postBoolean(Boolean bool) {
>     	if(bool){    		 
>     		throw new WebApplicationException(Status.NOT_ACCEPTABLE);
>     	}
>         return false;
>     }
> The application provided provider is like this:
> public class MyReader implements MessageBodyReader<Boolean> {
>     @Override
>     public boolean isReadable(Class<?> type, Type type1, Annotation[] antns, MediaType mt) {
>     	return type== Boolean.class;
>     }
>     @Override
>     public Object readFrom(Class<Object > type,
>                              Type type1,
>                              Annotation[] antns,
>                              MediaType mt, MultivaluedMap<String, String> mm,
>                              InputStream in) throws IOException, WebApplicationException {
> 		return Boolean.valueOf("true");        
>     }
> }
> The request
> Content-Type:text/plain
> Accept:text/plain 
> Method:POST
> Body:false
> According to jsr339 section 4.2.4 Standard Entity Providers java.lang.Boolean, java.lang.Character, java.lang.Number Only for text/plain. Corresponding primitive types supported via boxing/unboxing conversion.
> An implementation MUST support application-provided entity providers and MUST use those in preference to its own pre-packaged providers when either could handle the same request. More precisely, step 4 in Section 4.2.1 and step 5 in Section 4.2.2 MUST prefer application-provided over pre-packaged entity providers.
> 4.2.1 Message Body Reader
> 3. Select the set of MessageBodyReader classes that support the media type of the request, see Section
> 4.2.3.
> 4. Iterate through the selected MessageBodyReader classes and, utilizing the isReadable method of
> each, choose a MessageBodyReader provider that supports the desired Java type.
> It says the entity providers should be sorted by media type firstly then(the media type is the same) on Section 4.2.1 and step 5 in Section 4.2.2 MUST prefer application-provided over pre-packaged entity providers. So org.apache.cxf.jaxrs.provider.PrimitiveTextProvider should be selected as its media type MUST be text/plain and the application provider's media type is */*.(x/y>x/*>*/*)
> So at this point the CTS expected response code is 200 instead of 406, the application provided provider should not be chosen.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)