on 01-20-2016 7:36 AM
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;
}
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
User | Count |
---|---|
87 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.