Search code examples
google-app-enginejsfprimefacesgoogle-cloud-sql

The request to API call datastore_v3.Put() was too large without using datastore


com.google.apphosting.api.ApiProxy$RequestTooLargeException: The request to API call datastore_v3.Put() was too large.

public static List<Area> readAreas(URL url) {
    List<Area> areas = new ArrayList<Area>();
    try {
        BufferedReader br = new BufferedReader(new FileReader(new File(url.toURI())));
        String row;
        while ((row = br.readLine()) != null) {
            if (row.contains(SEARCHED_ROW)) {
                //get the part after "c"
                String coord[] = (row.split("c"));
                String startCoordM = ((coord[0].trim()).split(" "))[1];
                String curvesCoord= coord[1];

                Area area = new Area();
                area.mPoint= Point.toStartPoint(Point.readPoints(startCoordM));
                area.curves = Curve.readCurves (curvesCoord);
                areas.add(area);
            }
        }
        br.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return areas;
} 

This method runs without any errors but when I log out and log in to the same page of my web application this method runs again and again without problem but then this exception is thrown. I'm using google app engine 1.8.1 with jsf2 and primefaces 3.5. This method is invoked from managed bean :

public MapMB () {
    eps = EPDAO.getEPList();
    populateAdvancedModel(eps);
    drawPolilines();
}

void drawPolilines() {
    List<Area> areas = Area.readAreas(getFacesContext().getClass().getResource("/map-inksc.svg") );

    for (Area area : areas) {

        List<Curve> curves = area.getCurves();
        Point endPoint = area.getmPoint();

        Polyline polyline = new Polyline();
        polyline.setStrokeWeight(1);  
        polyline.setStrokeColor("#FF0000");  
        polyline.setStrokeOpacity(1);

        for (Curve curve : curves) {
            polyline.getPaths().add( new LatLng(endPoint.getY(),endPoint.getX()) );
            // curve start point is the end point of previous curve (endPoint.getX(),endPoint.getY() )
            double step = 0.01;
            for (double t=0;t<= 1;t=t+step) {
                double x = getCoordFromCurve(endPoint.getX(), endPoint.getX() + curve.getP1().getX(),endPoint.getX() + curve.getP2().getX(),endPoint.getX() + curve.getP3().getX(), t);
                double y = getCoordFromCurve(endPoint.getY(), endPoint.getY() + curve.getP1().getY(),endPoint.getY() + curve.getP2().getY(),endPoint.getY() + curve.getP3().getY(), t);
                polyline.getPaths().add(  new LatLng(y, x) );
            }
            endPoint = new Point (endPoint.getX() + curve.getP3().getX(), endPoint.getY() + curve.getP3().getY());
        }
        advancedModel.addOverlay(polyline);
        polyline = new Polyline();
    }
}

When I don't read any data (don't use readAreas() above) then everything works fine. So how reading from file is connected to this error? I don't understand.

If there is some information that I didn't put here please just say. All these methods run without errors and then this exception is thrown


Solution

  • See the edit

    Ok. So ... somehow the problem is solved. How? I'm not sure. So I had:

    a.xhtml  < include b.xhtml 
    c.xhtml  < include b.xhtml
    a.xhtml and c.xhtml had the same method bFilterMethod()
    

    JSF beans: a, b, c all ViewScoped b had a and c as Managed Properties a.xhtml and c.xhtml have bFilterMethod() that getsSome() data from the database and sets aProperty and cProperty(which are the same). I saw in google app engine logs that the method getsSome() runs about 20 times like infinite loop after that the exception was thrown.

    Now all beans are request scoped

    a.xhtml has aFilterMethod that getsSome() data
    b.xhtml has bFilterMethod that getsSome() data
    and a and b has c as Managed Property 
    

    Hope this helps someone but as I sad I'm not sure what is the exact error but obviously is caused by too big request from the database no matter this request contains only 3 rows (this request is invoked too many times)

    EDIT After so many years I came back to my topic accidentally. The real reason for all this is that GAE saves the session in the datastore and jsf ViewScoped beans are not removed from the session as in normal java application server. So the solution is just don't use ViewScoped beans