Skip to Content
0
Former Member
Sep 24, 2012 at 07:44 AM

Put operation not working through code

16 Views

Hi All,

I am new to this Odata development.I am getting an error whenever i am trying to do PUT operation in Odata link.

This is the Scenario

1) I am Using the GET method to get the detail of ttatthe particular entity which needs to be updated.While geting i am also geting the csrf token

customHeaderMap = new HashMap<String, String>();

searchReqeust = new SDMBaseRequest();

customHeaderMap.put("x-csrf-token", "fetch");

searchReqeust.setRequestUrl(searchURL);

searchReqeust.setHeaders(customHeaderMap);

searchReqeust.setRequestMethod(ISDMRequest.REQUEST_METHOD_GET);

searchReqeust.setPriority(ISDMRequest.PRIORITY_NORMAL);

searchReqeust.setListener(this);

bundleReqeust.addRequest(searchReqeust);

2) From the above step i can able to retreive the Csrf token and store it in a variable from response given by the above request

Header header=response.getFirstHeader("x-csrf-token");

csrfTokenValue=header.getValue();

mLogger.i(LOGGER_TAG, "Name ="+ header.getName()+"Value="+csrfTokenValue);

This is also working fine as i can able to see the csrf token values in the logger

3)From the response received from the above request

String responseString = EntityUtils.toString(response.getEntity());

i am updating the data while sending the request again using put method

customHeaderMaprequest = new HashMap<String, String>();

/*Updating the response string here*/

responseString=reponseStringUpdated

/*Converting the responseString to byte Array to set it as content*/

byte[] stringlength= responseString.getBytes();;

byte[] requestData = new byte[stringlength.length];

for(int i=0; i<stringlength.length; i++){

requestData[i] = stringlength[i];

}

searchReqeust = new SDMBaseRequest();

customHeaderMaprequest.put("x-csrf-token", csrfTokenValue);

//customHeaderMap.put("set-cookie", cookieString);

customHeaderMaprequest.put("Content-Type", "application/atom+xml;");

//searchReqeust.setRequestUrl(searchURL +"'"+ userName+"'"+ " and PassWord eq '"+ Password+"'");

searchReqeust.setRequestUrl(searchURL);

//searchReqeust.setRequestUrl(searchURLpara);

searchReqeust.setHeaders(customHeaderMaprequest);

searchReqeust.setData(requestData);

searchReqeust.setRequestMethod(ISDMRequest.REQUEST_METHOD_PUT);

Map<String, String> header= searchReqeust.getHeaders();

mLogger.i(LOGGER_TAG, "HeaderEmpty : " +header.isEmpty()+"Contains csrf token"+header.containsKey("x-csrf-token"));

this logger displays the values as true for header.containsKey("x-csrf-token") and false for header.isEmpty()

searchReqeust.setPriority(ISDMRequest.PRIORITY_NORMAL);

searchReqeust.setListener(this);

bundleReqeust.addRequest(searchReqeust);

4) But i get the error code as 403 means forbidden here is the log of headers what i get in response

I/SUPGateway(275): Header Name : content-type

I/SUPGateway(275): Header Valur : text/plain; charset=utf-8

I/SUPGateway(275): Header Name : x-csrf-token

I/SUPGateway(275): Header Valur : Required

I/SUPGateway(275): Header Name : Date

I/SUPGateway(275): Header Valur : Sat, 22 Sep 2012 05:45:53 GMT

I/SUPGateway(275): Header Name : set-cookie

As from the log we can see that it is not taking the csrf-token parsed this is is returned from SUPGateway

5) But when i tried to update using FirefoxRestClient in which i am hitting directly the Netwaver machine it is getting updated fine

Kindly suggest is there any setting needs to be done on netweaver or gateway or SCC for PUT operation to do with CSRF token

Thanks & Regards

Deepak