Do you have a stack trace or an error? What are the visible symptoms of your
problems running in production?

On Thu, Dec 24, 2009 at 7:50 AM, Bert Peters <[email protected]>wrote:

> Some code, that i created and tested using Eclipse and the google
> plugin, seems not to run while installed on the App Engine, no matter
> what.
> I have really no idea what it couldd be, Anyone else an idea?
>
> By the way, the code for all files is listed below.
>
> Main file:
>
> package poaphost;
>
> import javax.servlet.http.*;
> import javax.jdo.Query;
> import javax.jdo.PersistenceManager;
> import java.io.IOException;
> import poaphost.PMF;
> import poaphost.Address;
> import poaphost.Iphandler;
>
> import java.util.Locale;
> import java.util.Random;
> import java.util.List;
> import java.util.Date;
> import java.util.Formatter;
>
> public class LOGONServlet extends HttpServlet {
>
>        /**
>         *
>         */
>        private static final long serialVersionUID = 1373256072813419920L;
>
>        public void doGet(HttpServletRequest req, HttpServletResponse resp)
>                        throws IOException {
>                String uid = "";
>                Cookie[] cookies = req.getCookies();
>                for (Integer i = 0; i < cookies.length; i++) {
>                        if (cookies[i].getName().equals("poap_uid")
>                                        && cookies[i].getValue().length() ==
> 8) {
>                                uid = cookies[i].getValue();
>                        }
>                }
>                if (uid == "") {
>                        String base =
> "abcdefghijklmnopqrstuvwxyz1234567890";
>                        Random generator = new Random();
>                        for (Integer i = 0; i < 8; i++) {
>                                uid += base.charAt(generator.nextInt(35));
>                        }
>                }
>
>                String ip = req.getRemoteAddr();
>
>                Long ipNo = Iphandler.ip2long(ip);
>
>                PersistenceManager pm = PMF.get().getPersistenceManager();
>
>                Query q = pm.newQuery(Address.class, "ip == ipParam && code
> ==
> uidParam");
>                q.declareParameters("Long ipParam, String uidParam");
>
>                List<Address> result = (List<Address>) q.execute(ipNo, uid);
>
>                if (result.isEmpty()) {
>                        Address a = new Address(ipNo, uid);
>                        pm.makePersistent(a);
>                }
>                Cookie c = new Cookie("poap_uid",uid);
>                c.setPath("/");
>                c.setDomain("http://poaphost.appspot.com";);
>                c.setMaxAge(60*60*24*365);
>
>                resp.setContentType("text/xml");
>                resp.setCharacterEncoding("ISO-8859-1");
>                resp.addCookie(c);
>
>                Date d = new Date();
>
>                Long i = d.getTime();
>
>                Double f = i.doubleValue() / 1000;
>
>                StringBuilder sb = new StringBuilder();
>
>                Formatter formatter = new Formatter(sb, Locale.US);
>                formatter.format("%11.4f", f);
>
>                resp.getWriter().println(
>                                "<?xml version=\"1.0\"
> encoding=\"ISO-8859-1\"?>");
>                resp.getWriter().println("<response>");
>                resp.getWriter().println("<action>logon</action>");
>                resp.getWriter().println("<result>1</result>");
>                resp.getWriter().println("<error>0</error>");
>                resp.getWriter().println("<time>" + sb.toString() +
> "</time>");
>                resp.getWriter().println("<timeOffset>0</timeOffset>");
>                resp.getWriter().println("<uid>" + uid + "</uid>");
>                resp.getWriter().println("</response>");
>        }
>
> }
>
> poaphost.PMF file
>
> package guestbook;
>
> import javax.jdo.JDOHelper;
> import javax.jdo.PersistenceManagerFactory;
>
> public final class PMF {
>    private static final PersistenceManagerFactory pmfInstance =
>        JDOHelper.getPersistenceManagerFactory("transactions-
> optional");
>
>    private PMF() {}
>
>    public static PersistenceManagerFactory get() {
>        return pmfInstance;
>    }
> }
>  file poaphost.iphandler
>
> package poaphost;
>
> public class Iphandler {
>    public static long ip2long( String aIpAddress )
>    {
>        long ip = 0;
>        String[] t = aIpAddress.split("\\.");
>        ip = Long.parseLong(t[0]) * 256 * 256 * 256;
>        ip += Long.parseLong(t[1]) * 256 * 256;
>        ip += Long.parseLong(t[2]) * 256;
>        ip += Long.parseLong(t[3]);
>        return ip;
>    }
>    public static String long2ip( long aIpAddress )
>    {
>        return (aIpAddress >> 24 & 255) + "." + (aIpAddress >> 16 &
> 255) + "." + (aIpAddress >> 8 & 255) + "." + (aIpAddress & 255);
>    }
> }
>
> file poaphost.Address
>
> package poaphost;
>
> import com.google.appengine.api.datastore.Key;
>
> import java.lang.Long;
> import java.lang.String;
>
> import javax.jdo.annotations.IdGeneratorStrategy;
> import javax.jdo.annotations.IdentityType;
> import javax.jdo.annotations.PersistenceCapable;
> import javax.jdo.annotations.Persistent;
> import javax.jdo.annotations.PrimaryKey;
>
> @PersistenceCapable(identityType = IdentityType.APPLICATION)
> public class Address {
>    @PrimaryKey
>    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
>    private Key key;
>
>    @Persistent
>    private Long ip;
>
>    @Persistent
>    private String code;
>
>    public Address(Long ip, String code) {
>        this.setIp(ip);
>        this.setCode(code);
>    }
>
>        public void setKey(Key key) {
>                this.key = key;
>        }
>
>        public Key getKey() {
>                return key;
>        }
>
>        public void setIp(Long ip) {
>                this.ip = ip;
>        }
>
>        public Long getIp() {
>                return ip;
>        }
>
>        public void setCode(String code) {
>                this.code = code;
>        }
>
>        public String getCode() {
>                return code;
>        }
>
> }
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "Google App Engine for Java" group.
> To post to this group, send email to
> [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-appengine-java%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-appengine-java?hl=en.
>
>
>


-- 
Ikai Lan
Developer Programs Engineer, Google App Engine

--

You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.


Reply via email to