Я получаю следующее исключение, когда пытаюсь смоделировать почтовый запрос для загрузки в онлайн-магазин приложений, используя Java:
WARNING: /_ah/login
java.lang.NullPointerException
at com.google.appengine.api.users.dev.LoginCookieUtils.encodeEmailAsUserId(LoginCookieUtils.java:89)
at com.google.appengine.api.users.dev.LoginCookieUtils.createCookie(LoginCookieUtils.java:41)
at com.google.appengine.api.users.dev.LocalLoginServlet.doPost(LocalLoginServlet.java:90)
Вот код, выполняющий запрос POST:
byte[] htmlData = // ...I already have the byte array I want to store/update)
BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
String uploadURL = blobstoreService.createUploadUrl("/upload");
//add host if in dev mode
if(uploadURL.indexOf("http") == -1)
{
uploadURL = "http://localhost:8888" + uploadURL;
}
URL url = new URL(uploadURL);
// create a boundary string
String boundary = MultiPartFormOutputStream.createBoundary();
URLConnection urlConn = MultiPartFormOutputStream.createConnection(url);
urlConn.setReadTimeout(15000);
urlConn.setRequestProperty("Accept", "*/*");
urlConn.setRequestProperty("Content-Type", MultiPartFormOutputStream.getContentType(boundary));
// set some other request headers...
urlConn.setRequestProperty("Connection", "Keep-Alive");
urlConn.setRequestProperty("Cache-Control", "no-cache");
// no need to connect because getOutputStream() does it
MultiPartFormOutputStream out = new MultiPartFormOutputStream(urlConn.getOutputStream(), boundary);
out.writeField("param", "value")
out.writeFile("myFile", "multipart/form-data", "content.html", htmlData);
out.close();
Тогда в upload.java
public class Upload extends HttpServlet
{
private BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
Map<String, BlobKey> blobs = blobstoreService.getUploadedBlobs(req);
BlobKey blobKey = blobs.get("myFile");
String value = req.getParameter("param");
Topic t = pm.getObjectById(Topic.class, key);
t.setParam("value");
try
{
pm.makePersistent(t);
}
....
Почему я получаю исключение для encodeEmailAsUserId?
P.S. Поля writeFields сохраняются и прекрасно обновляются в хранилище данных, но я все еще получаю это исключение.