SilverHoodCorp / gdata-java-client

Automatically exported from code.google.com/p/gdata-java-client
Apache License 2.0
0 stars 0 forks source link

Batch Update in Spreadsheets API returns "If-Match or If-None-Match header or entry etag attribute required" #336

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Adding rows into an existing spreadsheet(5 cols, 30 rows, header values in 
first row set, rest of spreadshhet empty) via java API

example:

private void addRows(WorksheetEntry worksheet, String[][] values, int firstRow) 
{
    int row;

    try {
        // request feed of empty cells
        CellQuery query = new CellQuery(worksheet.getCellFeedUrl());
        query.setMinimumRow(firstRow);
        query.setMaximumRow(firstRow + values.length);
        query.setMinimumCol(1);
        query.setMaximumCol(values[0].length);
        query.setReturnEmpty(true);
        CellFeed cellFeed = service.query(query, CellFeed.class);

        CellFeed batchRequestFeed = new CellFeed();

        // set values for each cell
        int currentCellEntry=0;
        for (int i=0; i < values.length; i++) {
            for (int j=0; j < values[i].length; j++) {
                CellEntry entry = new CellEntry(cellFeed.getEntries().get(currentCellEntry));
                entry.changeInputValueLocal(values[i][j]);
                BatchUtils.setBatchId(entry, (new Integer(currentCellEntry)).toString());
                BatchUtils.setBatchOperationType(entry, BatchOperationType.UPDATE);
                batchRequestFeed.getEntries().add(entry);
                currentCellEntry++;
            }
        }

        // upload cells
        Link batchLink = cellFeed.getLink(Link.Rel.FEED_BATCH, Link.Type.ATOM);
        CellFeed batchResponse = service.batch(new URL(batchLink.getHref()), batchRequestFeed);

        for (CellEntry entry : batchResponse.getEntries()) {
            if (!BatchUtils.isSuccess(entry)) {
                System.out.println("Error uploading entry");
                BatchStatus status = BatchUtils.getBatchStatus(entry);
                System.out.printf("%s failed (%s) %s\n", BatchUtils.getBatchId(entry), status.getReason(), status.getContent());
            }
        }
    } catch (IOException e) {
        System.err.println("IOError: " +e);
    } catch (ServiceException e) {
        System.err.println("Google Service Error: " +e);
    }
}

calling:
String[][] values = {   {"1", "2", "3", "4", "5"},
            {"a", "b", "c", "d", "e"},
            {"dummy", "foo", "bar", "x", "y"}};
addRows(worksheet, values, 2);
with service being an authenticated SpreadsheetService and worksheet being an 
existing worksheet (with properties as described above) gives me following 
output (I) on command line:

Error uploading entry
0 failed (If-Match or If-None-Match header or entry etag attribute required) 
null
Error uploading entry
1 failed (Internal Error) null
Error uploading entry
2 failed (Internal Error) null
Error uploading entry
3 failed (Internal Error) null
Error uploading entry
4 failed (Internal Error) null
Error uploading entry
5 failed (Internal Error) null
Error uploading entry
6 failed (Internal Error) null
Error uploading entry
7 failed (Internal Error) null
Error uploading entry
8 failed (Internal Error) null
Error uploading entry
9 failed (Internal Error) null
Error uploading entry
10 failed (Internal Error) null
Error uploading entry
11 failed (Internal Error) null
Error uploading entry
12 failed (Internal Error) null
Error uploading entry
13 failed (Internal Error) null
Error uploading entry
14 failed (Internal Error) null

What is the expected output? What do you see instead?
Expected behavior: Cells should be added to worksheet
Instead I get the output as described in (I).

What version of the product are you using? On what operating system?
Current version(1.4.50) of gdata-java-client on Windows XP, Java SE 6u25

Please provide any additional information below.

Original issue reported on code.google.com by dev...@googlemail.com on 23 Apr 2011 at 6:50

GoogleCodeExporter commented 9 years ago
Actually this seems to be related with issue 103

http://code.google.com/p/gdata-java-client/issues/detail?id=103

Setting
service.setProtocolVersion(SpreadsheetService.Versions.V1);

solves this issue and uploading works fine. Please fix it for the current 
version (V3) of the protocol!

Original comment by dev...@googlemail.com on 24 Apr 2011 at 8:01