cancel
Showing results for 
Search instead for 
Did you mean: 

Batch Request error in Update for multiple row giving 500 error response

Former Member
0 Kudos



Dear Experts /Claudia Pacheco /Jitendra Kansal/ Midhun VP - SCN Member of the Month May 2014Jitendra Kansal,

     I am facing a problem when I am trying to push multiple rows for Update operation into a single request. I am using Batch request, for multiple data its not working for me, below are the code I am using for Update Operation . Please suggest for the same.

NOTE : When I update single row same code is working for me but for multiple files same code not woking giving error with ERROR Code 500.

   public static String updateReassignLeadBatch(ArrayList<ReassignBean> leadData, String userCode) throws OfflineODataStoreException {

  String code = "";

   if (createOfflineStore == null)

   return "";

   try {

   //Creates the entity payload


     // //Note: headers may not be required... test with and without it in case of issues
   Map<String, String> createHeaders = new HashMap<String, String>();

  createHeaders.put("accept", "application/atom+xml");

  createHeaders.put("content-type", "application/atom+xml");


   ODataRequestParamBatch RequestParamBatch = new ODataRequestParamBatchDefaultImpl();

  ODataRequestChangeSet updateLead = new ODataRequestChangeSetDefaultImpl();

  ODataEntity newEntity = new ODataEntityDefaultImpl("AppModel.user_RetailData");

  newEntity.getProperties().put("USER_Code", new ODataPropertyDefaultImpl("\"USER_Code\"", userCode));

  ODataRequestParamSingle batchItem = null;


   for (int i = 0; i < leadData.size(); i++) {

   //Creating Batch Item
   batchItem = new ODataRequestParamSingleDefaultImpl();

 
   batchItem.setResourcePath("user_RetailData(" + leadData.get(i).regCode + "L)");


  batchItem.setMode(ODataRequestParamSingle.Mode.Update);

  batchItem.setCustomTag("Batch Request to Update");

  batchItem.setPayload(newEntity);

  batchItem.setOptions(createHeaders);

   //Creting Batch Set


   updateLead.add(batchItem);

  RequestParamBatch.add(updateLead);

  }

  ODataResponse dataResponse = createOfflineStore.executeRequest(RequestParamBatch);

  Map<ODataResponse.Headers, String> headerMap = dataResponse.getHeaders();

   if (headerMap != null) {

  code = headerMap.get(ODataResponse.Headers.Code);

  }

  } catch (Exception e) {

// System.out.println("Record create func in exception");

   throw new OfflineODataStoreException(e);

  }

   return code;

  }

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Dear , , Former Member Experts,

Can you please suggest me how can we differentiate the normal URL and Batch Request URL,

because in my case i am able to update single record as i described above , but when i try to update more than one record its give me error code 500.


URL-- http://xxx.yyy.com:8080/user_RetailData



i tried also --

a) http://xxx.yyy.com:8080/user_RetailData/$batch

b) http://xxx.yyy.com:8080/user_RetailData$batch


all gives error in my case.




Jitendra_Kansal
Product and Topic Expert
Product and Topic Expert
0 Kudos

Did you test it via REST client? Can you share your findings?

Regards,

JK

Former Member
0 Kudos

Hi ,

We test it via REST Client but its giving 403 Forbidden exception in Rest Client attached are the Screen shot of Rest client details we are using .

We try it using PUT or POST both but did't get any success.

Please suggest us if we are doing anything wrong.

Thanks

Jitendra_Kansal
Product and Topic Expert
Product and Topic Expert
0 Kudos

URI for batch operation (via SMP) should be: http(s)://smpserver:port/appid/$batch

Have you already tried it?

Can you share the complete payload again?

Regards,

JK

Former Member
0 Kudos

Hi Jitendra Kansal,

     Yes , We tried this with https(s):

Please find the below payload :

----------------------------------------------

--batch

Content-Type: multipart/mixed; boundary=changeset

--changeset

Content-Type: application/http

Content-Transfer-Encoding: binary

PUT cmsRetailOutletData('12') HTTP/1.1

Content-Type: application/atom+xml

Content-Length: 975

<atom:entry xmlns:atom="http://www.w3.org/2005/Atom">

  <atom:content type="application/xml">

  <m:properties

  xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"

  xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">

  <d:Registration_no>12</d:Registration_no>

  <d:RegCode>MH180914100011</d:RegCode>

  <d:Full_Name>Test Batch</d:Full_Name>

  </m:properties>

  </atom:content>

</atom:entry>

--changeset

--batch