每次运行我的服务时都会出现500错误,因为谷歌消息告诉我几乎没有什么我开始上传服务和评论部分。使用JDO持久性管理器对象似乎工作正常。如果有人可以快速查看我的代码并告诉我是否使用JDO Persistence Manager错误,那将会很棒。这对我很有帮助。
@Path("/surveymakerpro/")
public class SurveyResource {
// JDO Persistence object
private PersistenceManager surveyDataStore = SurveyPersistenceManagerFactory
.get().getPersistenceManager();
@GET
@Produces({ "application/xml", "application/json" })
@Path("/survey/{surveyName}/")
public Survey getSurvey(@PathParam("surveyName") String surveyName) {
Survey e = surveyDataStore.getObjectById(Survey.class, surveyName);
return e;
}
@GET
@Produces({ "application/xml", "application/json" })
@Path("/allsurveys")
public SurveyNames getListOfSurveys() {
//test code
SurveyQuestion one = new SurveyQuestion();
one.setAnswer("Yes");
one.setId(3);
one.setQuestion("Do you like cake?");
SurveyQuestion two = new SurveyQuestion();
two.setAnswer("Yes");
two.setId(3);
two.setQuestion("Do you like cake?");
List<SurveyConverter> sur = new ArrayList<SurveyConverter>();
sur.add(new SurveyConverter(one));
sur.add(new SurveyConverter(two));
Survey surv = new Survey(sur);
surv.setSurveyName("Test Survey");
Survey survv = new Survey(sur);
survv.setSurveyName("sdd");
surveyDataStore.makePersistent(surv);
surveyDataStore.makePersistent(survv);
//test code
List<String> surveyNames = new ArrayList<String>();
Extent<Survey> extent = surveyDataStore.getExtent(Survey.class, false);
for (Survey survey : extent) {
surveyNames.add(survey.getSurveyName());
}
extent.closeAll();
SurveyNames surveyName = new SurveyNames(surveyNames);
surveyDataStore.close();
return surveyName;
}
@POST
@Consumes({ MediaType.APPLICATION_XML })
@Path("/addSurvey")
public void addSurvey(Survey survey) {
surveyDataStore.makePersistent(survey);
}
// This method gets a survey object stores its data into a TakenSurvey
// object and stores it
// in the Google data store.
@POST
@Consumes({ MediaType.APPLICATION_XML })
@Path("/addTakenSurvey")
public void addTakenSurvey(Survey survey) {
List<SurveyConverter> surveyConverter = survey.getSurvey();
TakenSurvey takenSurvey = new TakenSurvey();
for (SurveyConverter s : surveyConverter) {
TakenSurveyQuestion tsq = new TakenSurveyQuestion(s.getId(),
s.getQuestion(), s.getAnswer());
takenSurvey.getSurvey().add(tsq);
}
surveyDataStore.makePersistent(takenSurvey);
}
@GET
@Produces({ "application/xml", "application/json" })
@Path("/analysis/{surveyName}/{question}/")
public SurveyDataConverter analyzeSurveys(
@PathParam("surveyName") String surveyName,
@PathParam("question") String questionNum) {
Extent<TakenSurvey> extent = surveyDataStore.getExtent(
TakenSurvey.class, false);
List<TakenSurvey> takenSurveys = new ArrayList<TakenSurvey>();
for (TakenSurvey ts : extent) {
if (ts.getSurveyName().equals(surveyName)) {
takenSurveys.add(ts);
}
}
extent.closeAll();
SurveyAnalyzer analyze = new SurveyAnalyzer(takenSurveys);
analyze.getData();
SurveyData data = analyze.getSurveyData(Integer.parseInt(questionNum));
return new SurveyDataConverter(data);
}
// remove survey
// remove taken survey
}
答案 0 :(得分:2)
不要指望错误页面会给你一个堆栈跟踪 - 出于安全性和可用性的原因,这将是非常糟糕的做法。相反,在“日志记录”下的App Engine管理控制台中记录了异常。那里的堆栈跟踪会告诉你什么是错的;如果您仍然无法弄明白,请更新您的问题以便将其包含在内,以便我们进一步提供帮助。