Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    http 204 response and restful interface on multiple platforms.

    Our SmartClient version is 7.0rc2.

    Our issue is that we use a Restful interface. With that in mind any request we make that returns a 204 response is an issue. HTTP PUT and DELETE requests are an issue for us. It is an issue because on these requests it returns a 204 response(No Body Found) and then does not call the transformResponse method.

    In our implementation, after a PUT, or DELETE has succeeded we want to perform further functionality. The transformResponse not being called on a 204 response has become a problem for us. Is there anything we can do to resolve this? Is there a fix in the works?

    This seems like an issue with Smartclient and an application that uses a Restful interface, because of that I have not provided a server log, or a Developer Console log. There is not a JavaScript error that I see. If you need any of these things just reply with what you need and I will provide.

    In the Documentation it seems that PUT and DELETE methods seem to be valid:
    http://www.smartclient.com/docs/7.0r...est.httpMethod

    I have also seen other posts:
    http://forums.smartclient.com/showth...ht=http+DELETE

    NOTE: To get around this issue we were putting a response body in all responses. Now we are supporting WebLogic, as well as other platforms, and it follows the HTTP spec more closely and is not allowing us to inject a body on the response on a DELETE request. In order to support a single code base for multiple platforms we really need the transformResponse to be called even if there is no body in the response.
    Last edited by dt29735; 7 Dec 2010, 07:55.

    #2
    Sorry to reactivate this old thread, but no answer was ever provided and I have the same problem.

    I use a REST Java backend that returns an HTTP 204 status when a successful DELETE operation
    gets carried out. The REST Java backend doesn't return any data as per the HTTP 204 header.

    I have a Smartclient ListGrid bound to a DataSource for which I've implemented the following configuration:

    Code:
    BaseDataSource.addProperties
    ({
    	ID : 'dsTest',
    	dataURL : '.../myResourceBaseUrl',
    	fields :
    	[
    		{ name : 'code', type : 'text', length : 80, primaryKey : true },
    		{ name : 'firstName', type : 'text', length : 80 },
    		{ name : 'lastName', type : 'text', length : 80 }
    	]
    	requestProperties :
    	{
    		httpHeaders : { 'Accept' : 'application/json' }
    	},
    	operationBindings :
    	[
    		{ operationType : 'fetch', dataProtocol : 'getParams',
                    dataFormat : 'json', requestProperties : { httpMethod : 'GET' } },
    
    		{ operationType : 'remove', dataProtocol : 'getParams',
                    dataFormat : 'custom', requestProperties : { httpMethod : 'DELETE' } }
    	],
    	//--------------------------------------------------------------------------------------------------------------------------------
    	transformRequest : function(dsRequest)
    	{
    		if (dsRequest.operationType == 'remove')
    		{
    			var keyFld = this.getPrimaryKeyField();
    			if (keyFld)
    				dsRequest.dataURL = this.dataURL + '/' + dsRequest.data[keyFld.name];
    
    			dsRequest.data = null;
    		}
    
        	return dsRequest.data;
    	}
    });
    My 2 questions:

    1) When I call the removeData() on my listGrid which is bound to the above DataSource, the
    server call gets issued but the row doesn't get removed from the listGrid. I think that the SmartClient
    framework is expecting a valid JSON payload even though an HTTP 204 was issued. I tried
    both 'custom' and 'json' for the dataFormat property but it doesn't work. What would be the
    approach to work around this ?

    2) Is there a more optimal approach to building the REST URL to include the key portion of the
    record such as being currently implemented in the transformRequest() method above?

    Thanking you in advance for your answers. Kind regards,

    Comment


      #3
      You can implement transformResponse and put together the expected response data, which is a Record containing the primary key of the record that was deleted - this is an acknowledgement that the request succeeded as opposed to, for example affecting no records.

      Comment


        #4
        I will try that, but are you sure that the transformReponse() method will get called, as dt29735
        seemed to be saying it wouldn't ...

        Comment


          #5
          Thank you for information sharing, it useful to me.



          ___________
          Oakland Raiders Jerseys
          Darren McFadden jersey
          Marcus Allen jersey

          Comment


            #6
            Hi,

            I added the following method to my data source definition and it indeed did the trick ...

            Code:
            	//--------------------------------------------------------------------------------------------------------------------------------
            	transformResponse : function(dsResponse, dsRequest, data)
            	{
            		if (dsRequest.operationType == 'remove' && dsResponse.httpResponseCode == 204)
            		{
            			var keyFld = this.getPrimaryKeyField();
            			dsResponse.data = {};
            			dsResponse.data[keyFld.name] = dsRequest.originalData[keyFld.name];
            		}
            
                	return dsResponse;
            	}
            Not sure if using dsRequest.originalData is the right place to grab my record key, but it does work ... ?

            Thanks!

            Comment


              #7
              What we did to fix this was add a default body to all responses by returning an object that contained only the id. In testing the latest version of SmartClient this seems to be resolved.

              Comment


                #8
                I confirm it was resolved. I implemented the transformResponse() from the previous post and everything works A1.

                Thanks!

                Comment

                Working...
                X