Что я хочу сделать:
Я использую tomcat v8.5.3 и Firebase Admin SDK v6.8.1 для java.
выше изображение - это то, что я хочу сделать.
Но у меня проблема с переадресацией запроса из сервлета на jsp
это код doPost сервлета A.
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if(FirebaseApp.getApps().isEmpty()) {
FirebaseOptions options = (FirebaseOptions)getServletContext().getAttribute("options");
FirebaseApp.initializeApp(options);
}
dispatcher = request.getRequestDispatcher("/b.jsp");
try {
process(request, response);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Ref.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
for(DataSnapshot item: snapshot.getChildren()) {
couponList.add(item.getValue(CouponItem.class));
}
request.setAttribute("bodyObject", requestBody);
try {
dispatcher.forward(request, response);
} catch (ServletException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void onCancelled(DatabaseError error) {
// TODO Auto-generated method stub
}});
}
protected void process(HttpServletRequest request, HttpServletResponse response)
throws IOException, ParseException{
initMember();
//requestBodyString = getBody(request);
requestBodyString = (String) request.getParameter("body");
JSONParser parser = new JSONParser();
JSONObject jobj = (JSONObject) parser.parse(requestBodyString);
convert(jobj, requestBody);
Ref = FirebaseDatabase.getInstance().getReference("Coupon").child(requestBody.getRequestId());
}
В onDataChange ValueEventListener пересылка диспетчера не работает.
Я обнаружил, что поток демона изменяется, когда код Ref.addListenerForSingleValueEvent изменяется с
Daemon Thread [http-nio-8080-exec-5] (Suspended (breakpoint at line 67 in ServletA))
owns: NioEndpoint$NioSocketWrapper (id=426)
ServletA.doPost(HttpServletRequest, HttpServletResponse) line: 67
ServletA(HttpServlet).service(HttpServletRequest, HttpServletResponse) line: 660
ServletA(HttpServlet).service(ServletRequest, ServletResponse) line: 741
ApplicationFilterChain.internalDoFilter(ServletRequest, ServletResponse) line: 231
ApplicationFilterChain.doFilter(ServletRequest, ServletResponse) line: 166
WsFilter.doFilter(ServletRequest, ServletResponse, FilterChain) line: 52
ApplicationFilterChain.internalDoFilter(ServletRequest, ServletResponse) line: 193
ApplicationFilterChain.doFilter(ServletRequest, ServletResponse) line: 166
StandardWrapperValve.invoke(Request, Response) line: 199
StandardContextValve.invoke(Request, Response) line: 96
NonLoginAuthenticator(AuthenticatorBase).invoke(Request, Response) line: 493
StandardHostValve.invoke(Request, Response) line: 137
ErrorReportValve.invoke(Request, Response) line: 81
AccessLogValve(AbstractAccessLogValve).invoke(Request, Response) line: 660
StandardEngineValve.invoke(Request, Response) line: 87
CoyoteAdapter.service(Request, Response) line: 343
Http11Processor.service(SocketWrapperBase<?>) line: 798
Http11Processor(AbstractProcessorLight).process(SocketWrapperBase<?>, SocketEvent) line: 66
AbstractProtocol$ConnectionHandler<S>.process(SocketWrapperBase<S>, SocketEvent) line: 808
NioEndpoint$SocketProcessor.doRun() line: 1498
NioEndpoint$SocketProcessor(SocketProcessorBase<S>).run() line: 49
ThreadPoolExecutor(ThreadPoolExecutor).runWorker(ThreadPoolExecutor$Worker) line: 1149
ThreadPoolExecutor$Worker.run() line: 624
TaskThread$WrappingRunnable.run() line: 61
TaskThread(Thread).run() line: 748
на
Daemon Thread [firebase-database-event-target] (Suspended (breakpoint at line 87 in ServletA$1))
ServletA$1.onDataChange(DataSnapshot) line: 87
Query$1.onDataChange(DataSnapshot) line: 182
ValueEventRegistration.fireEvent(DataEvent) line: 77
DataEvent.fire() line: 65
EventRaiser$1.run() line: 55
Executors$RunnableAdapter<T>.call() line: 511
ScheduledThreadPoolExecutor$ScheduledFutureTask<V>(FutureTask<V>).run() line: 266
ScheduledThreadPoolExecutor$ScheduledFutureTask<V>.access$201(ScheduledThreadPoolExecutor$ScheduledFutureTask) line: 180
ScheduledThreadPoolExecutor$ScheduledFutureTask<V>.run() line: 293
FirebaseScheduledExecutor(ThreadPoolExecutor).runWorker(ThreadPoolExecutor$Worker) line: 1149
ThreadPoolExecutor$Worker.run() line: 624
Thread.run() line: 748
Мне кажется, у меня недостаточно опыта работы с Tomcat и Java для решения этой проблемы.