/*
 *    Copyright 2015 Benjamin Schmid, @bentolor
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package bentolor.grocerylist;

import jodd.madvoc.ScopeType;
import jodd.madvoc.meta.*;

import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;

@MadvocAction
public class ListAction {

    @In @Scope(ScopeType.SERVLET)
    HttpServletRequest request;

    public ListAction() {
    }

    @Action("/list") @GET
    public JsonResult listAllLists() {
        return GroceryService.get().getAllGroceryLists();
    }

    @Action("/list/{id}") @GET
    public JsonResult getList(@In("id") String id) {
        return GroceryService.get().getGroceryList(id);
    }

    @Action("/list/{id}") @DELETE
    public JsonResult deleteList(@In("id") String id) {
        return GroceryService.get().deleteGroceryList(id);
    }

    @Action("/list/{id}") @PUT
    public JsonResult updateList(@In("id") String id) throws IOException {
        return GroceryService.get().updateGroceryList(id, request.getReader());
    }

    @Action("/list") @POST
    public JsonResult createList() throws IOException {
        BufferedReader reader = request.getReader();
        return GroceryService.get().createGroceryList(reader);
    }

}

@@ -787,24 +787,50 @@
 .io.
-Buffered
+IOException;%0Aimport java.io.String
 Reader;%0A
 impo
@@ -829,34 +829,52 @@
 er;%0A
+%0A
 import 
-java.io.IOException
+static jodd.madvoc.ScopeType.SERVLET
 ;%0A%0A@
@@ -1529,36 +1529,57 @@
 tring id
-) throws IOException
+, @In @Scope(SERVLET) String requestBody)
  %7B%0A     
@@ -1631,34 +1631,44 @@
 ist(id, 
-request.getReader(
+new StringReader(requestBody
 ));%0A    
@@ -1734,83 +1734,68 @@
 ist(
-) throws IOException %7B%0A        BufferedReader reader = request.getReader();
+@In @Scope(SERVLET) String requestBody) throws IOException %7B
 %0A   
@@ -1849,14 +1849,37 @@
 ist(
-reader
+new StringReader(requestBody)
 );%0A 

fix NPEs on PUT and POST due to semantic change