001    package com.khubla.pragmatach.plugin.json;
002    
003    import java.io.ByteArrayInputStream;
004    
005    import com.khubla.pragmatach.framework.api.PragmatachException;
006    import com.khubla.pragmatach.framework.api.Response;
007    import com.khubla.pragmatach.framework.controller.BeanBoundController;
008    import com.khubla.pragmatach.framework.controller.impl.AbstractController;
009    
010    /**
011     * @author tome
012     */
013    public class JSONController extends AbstractController implements BeanBoundController {
014       /**
015        * ctor
016        */
017       public JSONController() {
018       }
019    
020       @Override
021       public void populateController() throws PragmatachException {
022          PragmaticControllerSerializer.deserialize(this, new ByteArrayInputStream(getRequest().getPostBody().getBytes()));
023       }
024    
025       /**
026        * for testing purposes
027        */
028       public void populateController(String JSON) throws PragmatachException {
029          PragmaticControllerSerializer.deserialize(this, new ByteArrayInputStream(JSON.getBytes()));
030       }
031    
032       /**
033        * render
034        */
035       public Response render() throws PragmatachException {
036          try {
037             return new JSONResponse(getCacheHeaders(), this);
038          } catch (final Exception e) {
039             throw new PragmatachException("Exception in render", e);
040          }
041       }
042    }