1

I have implemented a REST service using the Restlet Framework (2.3.1). The service accepts (username, password) and returns an MD5 authentication string. A jQuery Ajax-call is executed as follows:

$.ajax({ 
    url: host + '/authentication',   
    data: { username:'aaa', password:'bbb' },
    dataType: 'json' })
.done( function( data, textStatus, xhr ) 
{
    // The server returns a JSON data object. Display it as a string
    //
    console.log( JSON.stringify( data ) );   

    // Display the authString corresponding to username and password
    //                    
    console.log( data.authString );         
})
.fail( function( xhr, textStatus, errorThrown ) 
{   
    // Display error info
    //   
    console.log( xhr.status, xhr.statusText, xhr.responseText );       
});

The server has the following Java code:

try
{
    String md5 = MD5Converter.encryptUsernamePassword( username, password );

    result = new JSONObject();
    result.put( "authString", md5 );
}
catch ( AuthenticationException e )
{
    setStatus( Status.CLIENT_ERROR_BAD_REQUEST);  
    result = new JSONObject();
    result.put( "error", "Invalid username and password" );
    return new JsonRepresentation( result );             
}            

return new JsonRepresentation( result ); 

If username and password are accepted, everything works fine. However, when the status code CLIENT_ERROR_BAD_REQUEST is returned, the test server (Windows 7, Tomcat) gives the following correct result:

xhr.status = 400 
xhr.statusText = Bad Request 
xhr.responseText = {"error":"Invalid username and password"}

However, when the same code is executed in the production server (Windows Server 2008, Tomcat), the result is

xhr.status = 400 
xhr.statusText = Bad Request 
xhr.responseText = Bad Request

The production server is not returning {"error":"Invalid username and password"}. This means that in the Ajax .fail() part all informative error messages are lost, being replaced by 'Bad Request'.

Any idea what could be the reason for this different behaviour between the test and production servers?

matt
  • 41
  • 1
  • 6

0 Answers0