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

Lukasz Lenart updated WW-3975:
------------------------------

    Description: 
Setting the HTTP Content-Type request header to either application/json or 
application/json;charset=UTF-8 does not get handled correctly by the 
DefaultContentTypeHandlerManager. At line 91 (v2.3.8) in 
DefaultContentTypeHandlerManager, the content type is stripped of everything 
after and including the semi-colon (i.e., application/json;charset=UTF-8 
becomes application/json).  Line 91-93:

{code:java}
int index = contentType.indexOf(';');
if( index != -1)
    contentType = contentType.substring(0,index).trim();
{code}

Unfortunately, the JsonLibHandler getContentType() method returns 
"application/json;charset=ISO-8859-1" and because the charset was stripped, the 
JsonLibHandler is not correctly chosen. 

This issue is can potentially be mitigated by additionally setting the 
extension to .json but it would be nice to rely solely on the Content-Type 
header.

I see the value of stripping the header down to the basic type so it's likely 
that the handlersByContentType Map will need to be interrogated twice.  
Something like this:

{code:java}
String contentType = req.getContentType();
if (contentType != null) {
    handler = handlersByContentType.get(contentType);
    if ( handler == null ) {
        int index = contentType.indexOf(';');
        if( index != -1)
            contentType = contentType.substring(0,index).trim();
        handler = handlersByContentType.get(contentType);
    }
}
{code}        

  was:
Setting the HTTP Content-Type request header to either application/json or 
application/json;charset=UTF-8 does not get handled correctly by the 
DefaultContentTypeHandlerManager. At line 91 (v2.3.8) in 
DefaultContentTypeHandlerManager, the content type is stripped of everything 
after and including the semi-colon (i.e., application/json;charset=UTF-8 
becomes application/json).  Line 91-93:

                int index = contentType.indexOf(';');
                if( index != -1)
                        contentType = contentType.substring(0,index).trim();

Unfortunately, the JsonLibHandler getContentType() method returns 
"application/json;charset=ISO-8859-1" and because the charset was stripped, the 
JsonLibHandler is not correctly chosen. 

This issue is can potentially be mitigated by additionally setting the 
extension to .json but it would be nice to rely solely on the Content-Type 
header.

I see the value of stripping the header down to the basic type so it's likely 
that the handlersByContentType Map will need to be interrogated twice.  
Something like this:

       String contentType = req.getContentType();
        if (contentType != null) {
            handler = handlersByContentType.get(contentType);
                        if ( handler == null ) {
                                int index = contentType.indexOf(';');
                                if( index != -1)
                                        contentType = 
contentType.substring(0,index).trim();
                                handler = 
handlersByContentType.get(contentType);
                        }
        }
        

    
> DefaultContentTypeHandlerManager does not  handle application/json content 
> type correctly
> -----------------------------------------------------------------------------------------
>
>                 Key: WW-3975
>                 URL: https://issues.apache.org/jira/browse/WW-3975
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Plugin - REST
>    Affects Versions: 2.3.4.1, 2.3.8
>         Environment: windows 7 64-bit 
> java 1.7.0_05
>            Reporter: justin miller
>            Priority: Minor
>             Fix For: 2.3.10
>
>         Attachments: diff
>
>
> Setting the HTTP Content-Type request header to either application/json or 
> application/json;charset=UTF-8 does not get handled correctly by the 
> DefaultContentTypeHandlerManager. At line 91 (v2.3.8) in 
> DefaultContentTypeHandlerManager, the content type is stripped of everything 
> after and including the semi-colon (i.e., application/json;charset=UTF-8 
> becomes application/json).  Line 91-93:
> {code:java}
> int index = contentType.indexOf(';');
> if( index != -1)
>     contentType = contentType.substring(0,index).trim();
> {code}
> Unfortunately, the JsonLibHandler getContentType() method returns 
> "application/json;charset=ISO-8859-1" and because the charset was stripped, 
> the JsonLibHandler is not correctly chosen. 
> This issue is can potentially be mitigated by additionally setting the 
> extension to .json but it would be nice to rely solely on the Content-Type 
> header.
> I see the value of stripping the header down to the basic type so it's likely 
> that the handlersByContentType Map will need to be interrogated twice.  
> Something like this:
> {code:java}
> String contentType = req.getContentType();
> if (contentType != null) {
>     handler = handlersByContentType.get(contentType);
>     if ( handler == null ) {
>         int index = contentType.indexOf(';');
>       if( index != -1)
>           contentType = contentType.substring(0,index).trim();
>       handler = handlersByContentType.get(contentType);
>     }
> }
> {code}        

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to