-4

I am developing an application which needs to accept Java Source code from the client via the Google Cloud Endpoints, and then the Google App Engine would work on it. The simplest solution was to send the Java Source Code as a String from the JavaScript client and make an endpoint which accepts the String. However a GET request more than 2kB is giving errors and Source Codes can be (and are generally often) far larger than 2kB.

It will be important to note here that minification of the code is not allowed.

Then what should be the best way to achieve so?

An advanced thanks for trying to solve my issue.

  • "However GET/POST request can handle not more than 2kB of data" where did you read that? (GET requests are indeed limited since you can only put data into the url and urls have a limit - http://stackoverflow.com/questions/2659952/maximum-length-of-http-get-request). – zapl May 31 '16 at 19:20
  • @zapl edited my mistake out, but the problem remains a Get request larger than 2kB is not working – Swagato Chatterjee May 31 '16 at 19:33
  • Ok, then why not use post? – zapl May 31 '16 at 19:36
  • POST request is causing 413 error on large source size. – Swagato Chatterjee May 31 '16 at 19:40
  • You're probably using it wrong then: http://stackoverflow.com/a/32187807/995891 – zapl May 31 '16 at 19:43
  • Please try it out at [link](https://apis-explorer.appspot.com/apis-explorer/?base=https://pseudogen-2016.appspot.com/_ah/api#p/pseudoGen/v1/pseudoGen.pseudo) and enter a Java Source Code at source tab – Swagato Chatterjee May 31 '16 at 20:31
  • This is the code I used:`@ApiMethod(name = "pseudo", path = "pseudo", httpMethod = HttpMethod.POST) public PseudoCon getPseudoCode(@Named("source")String source){` what's wrong in it? It accepts the source code and not some URL – Swagato Chatterjee May 31 '16 at 20:32

1 Answers1

2

You're using it wrong. @Named parameters become part of the url (like http://server.com/api?source=Java+source+here.), and that has the same limitations as a GET request.

You can encapsulate your data in a pojo and add it as method parameter. For example

@Api(name = "myApi", version = "v1")
public class MyApi {

    public static class PseudoCon {
        public String foo;
    }

    public static class SourceContainer {
        public String source;
    }

    @ApiMethod(name = "pseudo", path = "pseudo", httpMethod = HttpMethod.POST)
    public PseudoCon getPseudoCode(SourceContainer sourceContainer){
        String source = sourceContainer.source;
        PseudoCon result = new PseudoCon();
        result.foo = source.substring(0, 1);
        return result;
    }
}

That allows for a proper POST with a request body:

POST http://localhost:8888/_ah/api/myApi/v1/pseudo

{
 "source": "Java source here."
}

(source becomes encapsulated in a json object)

With reply

200 OK
{
 "foo": "J"
}
zapl
  • 63,179
  • 10
  • 123
  • 154