Bad Content-Type on SugarCRM REST API Interface

Today I discovered a really tedious bug on SugarCRM, one of those bugs that take away precious time and you do not expect. The object of the bug are the REST services of SugarCRM. The version on which I have found the problem is the 6.1 Community Edition, but I think also the other editions (Professional and Enterprise) are affected. The versions of the REST Service are: 2 and 3, for more information see document at http://www.sugarcrm.com/crm/support/documentation/SugarCommunityEdition/6.1/-docs-Developer_Guides-Sugar_Developer_Guide_6.1.0-Chapter%202%20Application%20Framework.html#9000259.

Calling a REST service, requiring the response in JSON format, the server responds with an incorrect Content-Type: text/html instead of application/json.

The incorrect value of the Content-Type can cause problems with some frameworks used to consume RESTful JSON services, one of many frameworks is Jersey. See the error returned from Jersey to resulting from the wrong Content-Type.

For more information see the following documents available on the network:

Following is an example of calling the login service via Firefox Browser and Firebug as debugger.

Bad Content-Type SugarCRM REST API Interface

Bad Content-Type SugarCRM REST API Interface

View JSON Response

View JSON Response

The solution is simple: add one line of code to the class SugarRestJSON defined in service/core/REST/SugarRestJSON.php. The line of code sets the correct Content-Type takes to respond to the service (see the method body generateResponse ()).

Following the service responses after applying the Fix.

Content-Type after applying the fix.

Content-Type after applying the fix.

View JSON Response after applying the fix (JSON View Firefox Plugin).

View JSON Response after applying the fix (JSON View Firefox Plugin).

See SugarCRM Bug #43368
For any questions please feel free to leave your comments.

Liferay Portal Security AuditCos'è e come funzione il framework di Security Audit

Vi siete mai chiesti cos'è e come funziona il sistema di Security Audit di Liferay? Ho cercato di rispondere alla domanda non soffermandomi solo al "cosè e come funziona", sono andato ben oltre. Non vi resta che leggere questo EBook per scoprire.

Ottieni il tuo EBook

Antonio Musarra

I began my journey into the world of computing from an Olivetti M24 PC (http://it.wikipedia.org/wiki/Olivetti_M24) bought by my father for his work. Day after day, quickly taking control until … Now doing business consulting for projects in the enterprise application development using web-oriented technologies such as J2EE, Web Services, ESB, TIBCO, PHP.

Potrebbero interessarti anche...

Liferay SSL/TLS SecurityCome configurare il bundle Liferay per abilitare il protocollo SSL/TLS

Sei curioso di scoprire come configurare il bundle Liferay per funzionare in modalità sicura tramite protocollo SSL/TLS? In questo eBook ( #LFRDEPGUIDE ) ti spiego come farlo step-by-step; per il bundle Apache Tomcat e WildFly. Ricorda di lasciare un tuo feedback dopo averlo letto.