Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8797385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:50:43+00:00 2026-06-13T23:50:43+00:00

I have a servelet which can take a request from either a rest service

  • 0

I have a servelet which can take a request from either a rest service or from a jsp form post that will both call a internal method (internalAddPodcast()) to add an entity to the datastore.

When I hit the internalAddPodcast() from the jsp page, it works fine, I can see the that the entity has been added successfully by querying for it right after adding. BUT when I do it from the rest method addPodcast() the datastore.put() doesn’t seem to be actually adding to the datastore, because I try and retreive it right after put() and nothing is coming back. Look down near the bottom of this class where I put the comment “//THIS QUERY IS EMPTY WHEN ADDED FROM THE REST SERVICE :(” That is where I expect to have some results come back, especially the entity that I just put in the data store.

    package com.aol.sharepodder;

import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.logging.Logger;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Consumes;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.FetchOptions;
import com.google.appengine.api.datastore.KeyFactory;
import com.google.appengine.api.datastore.PreparedQuery;
import com.google.appengine.api.datastore.Query;
import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

@Path("/add/podcast/")
public class AddPodcastServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    private static final Logger log = Logger.getLogger(AddPodcastServlet.class
            .getName());

    public void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws IOException {

        String email = req.getParameter("email");
        String collectionName = req.getParameter("collectionName");
        String podcast_url = req.getParameter("podcast_url");
        String podcast_description = req.getParameter("podcast_description");
        String podcast_title = req.getParameter("podcast_title");

        log.info("--post adding " + collectionName);

        internalAddPodcast(email, collectionName, podcast_url,
                podcast_description, podcast_title);

        resp.sendRedirect("/collection_details.jsp?collectionName="
                + collectionName + "&email=" + email);
    }

    @POST
    @Produces("text/plain")
    @Consumes("application/x-www-form-urlencoded")
    public String addPodcast(
            @DefaultValue("barrand@gmail.com") @FormParam("email") String email,
            @DefaultValue("default") @FormParam("collectionName") String collectionName,
            @DefaultValue("") @FormParam("podcast_url") String podcast_url,
            @DefaultValue("") @FormParam("podcast_description") String podcast_description,
            @DefaultValue("") @FormParam("podcast_title") String podcast_title) {
        try {
            internalAddPodcast(email, collectionName, podcast_url,
                    podcast_description, podcast_title);
            if (podcast_url == "") {
                return "No url supplied";
            }
            return "true";
        } catch (Exception e) {
            return e.getMessage();
        }
    }

    private void internalAddPodcast(String email, String collectionName,
            String podcast_url, String podcast_description, String podcast_title) {
        log.info("--INTERNAL ADD ");
        log.info("--email " + email);
        log.info("--collectionName " + collectionName);
        log.info("--podcast_url " + podcast_url);
        log.info("--podcast_description " + podcast_description);
        log.info("--podcast_title " + podcast_title);

        UserService userService = UserServiceFactory.getUserService();
        User user = userService.getCurrentUser();

        Entity podcast = new Entity("Podcast");
        podcast.setProperty("collectionName", collectionName);
        podcast.setProperty("user", user);
        podcast.setProperty("email", email);
        Date date = new Date();
        podcast.setProperty("date", date);
        podcast.setProperty("podcast_title", podcast_title);
        podcast.setProperty("podcast_description", podcast_description);
        podcast.setProperty("podcast_url", podcast_url);

        DatastoreService datastore = DatastoreServiceFactory
                .getDatastoreService();
        datastore.put(podcast);

        //try to log the podcast that I just got done adding to the datastore
        Query query = new Query("Podcast");
        PreparedQuery pq = datastore.prepare(query);

            //THIS QUERY IS EMPTY WHEN ADDED FROM THE REST SERVICE :(
        for (Entity p : pq.asIterable()) {
            log.info("_loop " + " - " + KeyFactory.keyToString(p.getKey())
                    + " -- " + p.getProperty("podcast_title") + " - "
                    + p.getProperty("podcast_url"));
        }
    }
}

Any ideas what I’m doing wrong, and why the entity I’m trying to add from the rest method isn’t getting added to the data store.

I know that in both cases, (either from the jsp post, or the rest service) when I get to the internalAddPodcast() all the method params are coming in correctly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:50:45+00:00Added an answer on June 13, 2026 at 11:50 pm

    Ah HA! I found it. I wasn’t logging the exception that was being thrown. Basically I was trying to store a string property that was more than 500 characters and it was throwing an exception that I needed to pay attention to 🙂 So it was never getting to the datastore.put()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an attribute which I have forwarded from a servelet to a jsp
I have a Java Servlet, which is handling a REST request. However, this is
I have a java servelet segment, which can generate a XML file and print
I have a servlet which handles a multipart form post. The post is actually
I have code called from a servlet that calls out to an external service.
I have a servlet which takes us to an existing jsp, say home.jsp. This
I have a Java servlet from which I need to send few notifications to
I have a web servlet that returns a json which is stored in my
I'm currently working on a Java web application which will take data submitted by
I ve created a sample REST web service which writes some data in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.