View Javadoc

1   package com.mycompany;
2   
3   import java.io.IOException;
4   import java.util.Properties;
5   
6   import javax.servlet.ServletException;
7   import javax.servlet.ServletInputStream;
8   
9   import atg.nucleus.naming.ParameterName;
10  import atg.servlet.DynamoHttpServletRequest;
11  import atg.servlet.DynamoHttpServletResponse;
12  import atg.servlet.DynamoServlet;
13  
14  public class SimpleDroplet extends DynamoServlet {
15    /***
16     * 
17     */
18    public static final String USERNAME = "username";
19    String mUsername = null;
20    String mUsernameFromInputStream = null;
21  
22    /***
23     * Called to execute this droplet
24     */
25    @Override
26    public void service(final DynamoHttpServletRequest request,
27        final DynamoHttpServletResponse response) throws ServletException,
28        IOException {
29      logInfo("Starting: " + this.getClass().getName());
30      request.serviceLocalParameter(ParameterName.getParameterName("output"), request, response);
31      request.setParameter("entry", "The Value");
32      response.getOutputStream().write("Some content from the simple droplet".getBytes());
33      mUsername = request.getParameter(USERNAME);
34      // try to read data from the client if it is available
35      if ("POST".equals(request.getMethod())) {
36        ServletInputStream s = request.getInputStream();
37        Properties p = new Properties();
38        p.load(s);
39        mUsernameFromInputStream = p.getProperty(USERNAME);
40      }
41    }
42  
43    /***
44     * Returns the value of the username parameter
45     * 
46     * @return
47     */
48    public String getUsername() {
49      return mUsername;
50    }
51  
52    /***
53     * Returns the value of the username as written to the request input stream
54     * 
55     * @return
56     */
57    public String getUsernameFromInputStream() {
58      return mUsernameFromInputStream;
59    }
60  }