I am using GWT and Google Apps to host my app. As I am new to both GWT and Web Programming (Spent most of my life doing drivers), hopefully I am simply missing something. I found some sample code online which works perfectly well in development mode. When I deploy, it does not work. I have put code in the Upload classes to write data to the DB when called, but it looks like the call to my service is never made as the DB never changes. Included is the code I am using. It would be great if I could get rid of the JSP code, but I can't instantiate the Blobstore stuff. It would be great to move this into Java, but first things first.
FileUpload.jsp:
<%@ page import="com.google.appengine.api.blobstore.BlobstoreServiceFactory" %>
<%@ page import="com.google.appengine.api.blobstore.BlobstoreService" %>
<%
BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
%>
<html>
<head>
<title>Upload Test</title>
</head>
<body>
<form action="<%= blobstoreService.createUploadUrl("/upload") %>" method="post" enctype="multipart/form-data">
<input type="text" name="foo">
<input type="file" name="myFile" size="50">
<input type="submit" value="Submit">
</form>
</body>
</html>
Ugly dialog that needs replacing, but essentially this works. The user enters a file name and hits submit. Now, on the server side I have the following code:
// Upload.java
public class Upload extends HttpServlet {
private static final long serialVersionUID = 1L;
private BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
DebugViaDb.writeDebugData("AA"); // I know my DB write code works as other parts of the code work with the DB
HttpSession session = req.getSession(true);
System.out.println("Session is " + session);
Map<String, BlobKey> blobs = blobstoreService.getUploadedBlobs(req);
BlobKey blobKey = blobs.get("myFile");
if(blobKey == null) {
res.sendRedirect("/");
}
else {
res.sendRedirect("/uploadServlet?blob-key=" + blobKey.getKeyString());
}
}
}
This is called by the JSP, which in turn calls my upload servlet:
// UploadServlet.java
public class UploadServlet extends HttpServlet {
<edited>
public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException {
DebugViaDb.writeDebugData("BB");
BlobKey blobKey = new BlobKey(req.getParameter("blob-key"));
...
}
}
My web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee">
<!-- Servlets -->
<servlet>
<servlet-name>myDataServiceImpl</servlet-name>
<servlet-class>com.blah.server.MyDataServiceImpl</servlet-class>
</servlet>
<servlet>
<servlet-name>Upload</servlet-name>
<servlet-class>com.blah.server.Upload</servlet-class>
</servlet>
<servlet>
<servlet-name>UploadServlet</servlet-name>
<servlet-class>com.blah.server.UploadServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>myDataServiceImpl</servlet-name>
<url-pattern>/my/myData</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Upload</servlet-name>
<url-pattern>/upload</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>UploadServlet</servlet-name>
<url-pattern>/uploadServlet</url-pattern>
</servlet-mapping>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>my.html</welcome-file>
</welcome-file-list>
</web-app>
So, the issue is, everything works perfectly when I run this in development mode. When I deploy, it does not appear as though the "upload" is ever called. I am stuck as far as debugging this on the server, so I am not sure what is going on. No luck getting logfiles.