Skip to content

Form and Post data support along with DefaultValue support - #28

Open
arranubels wants to merge 12 commits into
cagataygurturk:masterfrom
arranubels:pr2
Open

Form and Post data support along with DefaultValue support#28
arranubels wants to merge 12 commits into
cagataygurturk:masterfrom
arranubels:pr2

Conversation

@arranubels

@arranubels arranubels commented Jul 7, 2016

Copy link
Copy Markdown

Hi,

I have made a couple improvements to the form data and post data changes, taking into consideration recent updates to master.

With this change the following methods work:

Objects

    public static class Input {
        public String value;

        public Input(String value) {
            this.value = value;
        }

        public Input() {
        }
    }

    @POST
    @Path("test/test1")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public Response test1(Input value) {

        logger.debug("Request got");
        return Response.status(201)
                .entity(value)
                .build();
    }

Request text

{ "value": "asdfasdf" }

Query:

++ curl -X POST -d @testfiles/object.txt https://xxxx.execute-api.eu-west-1.amazonaws.com/production/test/test1 --header 'Content-Type: APPLICATION/JSON'
+ echo '{"value":"asdfasdf"}'

Json text

    @POST
    @Path("test/test2")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public Response test2(String value) {

        logger.debug("Request got");
        return Response.status(201)
                .entity(value)
                .build();
    }

Request text:

"asdfasdf"

Query:

++ curl -X POST -d @testfiles/jsonstring.txt https://xxx.execute-api.eu-west-1.amazonaws.com/production/test/test2 --header 'Content-Type: APPLICATION/JSON'
+ echo '"asdfasdf"'
"asdfasdf"

Form param

    @POST
    @Path("test/test3")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public Response test3(@FormParam("value") String value) {

        logger.debug("Request got");
        return Response.status(201)
                .entity(value)
                .build();
    }

This can be used multiple ways:

Way 1

"value=asdfasdf"

Query

++ curl -X POST -d @testfiles/jsonformenc.txt https://xxxx.execute-api.eu-west-1.amazonaws.com/production/test/test3 --header 'Content-Type: APPLICATION/JSON'
+ echo '"asdfasdf"'
"asdfasdf"

Way 2

value=asdfasdf

Query

++ curl -X POST -d @testfiles/formenc.txt https://xxx.execute-api.eu-west-1.amazonaws.com/production/test/test3 --header 'Content-Type: APPLICATION/JSON'
+ echo '"asdfasdf"'
"asdfasdf"

Multiple values

    @POST
    @Path("test/test4")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public Response test4(@FormParam("value") List<String> value) {

        logger.debug("Request got");
        return Response.status(201)
                .entity(value)
                .build();
    }

Request text:

value=asdfasdf&value=12312312

Query

++ curl -X POST -d @testfiles/arrayformenc.txt https://xxxx.execute-api.eu-west-1.amazonaws.com/production/test/test4 --header 'Content-Type: APPLICATION/JSON'
+ echo '["asdfasdf","12312312"]'
["asdfasdf","12312312"]

Note

Please note: I don't do anything with @produces, other @consumes could be supported easily with some Api Gateway changes.

Please let me know if you need me to change anything.

arran ubels added 3 commits June 29, 2016 11:24
# Conflicts:
#	runtime/src/main/java/org/lambadaframework/runtime/ResourceMethodInvoker.java
@cagataygurturk

Copy link
Copy Markdown
Owner

I'll be looking into it as soon as possible, thanks

@arran4

arran4 commented Jul 13, 2016

Copy link
Copy Markdown

Thanks

arran ubels added 4 commits July 14, 2016 14:59
# Conflicts:
#	runtime/pom.xml
#	runtime/src/main/java/org/lambadaframework/runtime/ResourceMethodInvoker.java
@arranubels

Copy link
Copy Markdown
Author

Updated code in PR with latest from master. (And tested.)

@cagataygurturk

Copy link
Copy Markdown
Owner
  • TravisCI is no longer depending on AWS credentials. So for pull requests tests should pass also. Can you check? There is one failing tests now.
  • Why jackson-databind is not provided dependency? That package is already included in Lambda runtime, there is no need to add it again to our JAR. (Lambda functions has a maximum size of 50 MB and every byte saved in dependencies is more space for user code.)

@arranubels

Copy link
Copy Markdown
Author

Tests now working, it was a type cast issue. I also included a log4j file which will be included only for test and modified the test class path to the default maven one so it didn't have to be explicitly mentioned. Happy to revert if there was a reason for it. (I couldn't see.)

I reverted it back to being a provided dependency, sorry I didn't know why it was provided.

@arran4

arran4 commented Sep 29, 2016

Copy link
Copy Markdown

Ping.

@arran4

arran4 commented Jun 19, 2026

Copy link
Copy Markdown

@cagataygurturk We should probably archive this repo?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants