@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		logger.trace("POST received!");
		MessengerCallback callback = new MessengerCallback();

		// Extrapolates and logs the JSON for debugging.
		String json = readerToString(req.getReader());
		logger.debug("JSON input: " + json);

		// Parses the request as a MessengerCallback.
		try {
			callback = FbBotMillJsonUtils.fromJson(json, MessengerCallback.class);
		} catch (Exception e) {
			logger.error("Error during MessengerCallback parsing: ", e);
			return;
		}

		// If the received POST is a MessengerCallback, it forwards the last
		// envelope of all the callbacks received to the registered bots.
		if (callback != null) {
			List<MessengerCallbackEntry> callbackEntries = callback.getEntry();
			if (callbackEntries != null) {
				for (MessengerCallbackEntry entry : callbackEntries) {
					List<MessageEnvelope> envelopes = entry.getMessaging();
					if (envelopes != null) {
						MessageEnvelope lastEnvelope = envelopes.get(envelopes.size() - 1);
						IncomingToOutgoingMessageHandler.getInstance().process(lastEnvelope);
					}
				}
			}
		}
		// Always set to ok.
		resp.setStatus(HttpServletResponse.SC_OK);
	}
@ Override protected void doPost ( HttpServletRequest req , HttpServletResponse resp ) throws ServletException , IOException { logger . trace ( "POST received!" ) ; MessengerCallback callback = new MessengerCallback ( ) ; String json = readerToString ( req . getReader ( ) ) ; logger . debug ( "JSON input: " + json ) ; try { callback = FbBotMillJsonUtils . fromJson ( json , MessengerCallback . class ) ; } catch ( Exception e ) { logger . error ( "Error during MessengerCallback parsing: " , e ) ; return ; } if ( callback != null ) { List < MessengerCallbackEntry > callbackEntries = callback . getEntry ( ) ; if ( callbackEntries != null ) { for ( MessengerCallbackEntry entry : callbackEntries ) { List < MessageEnvelope > envelopes = entry . getMessaging ( ) ; if ( envelopes != null ) { MessageEnvelope lastEnvelope = envelopes . get ( envelopes . size ( ) - 1 ) ; IncomingToOutgoingMessageHandler . getInstance ( ) . process ( lastEnvelope ) ; } } } } resp . setStatus ( HttpServletResponse . SC_OK ) ; }
Specifies how to handle a POST request. It parses the request as a
{@link MessengerCallback} object. If the request is not a
MessengerCallback, then the FbBotMillServlet logs an error and does
nothing, otherwise it will forward the request to all registered bots in
order to let them process the callbacks.

@param req
the req
@param resp
the resp
@throws ServletException
the servlet exception
@throws IOException
Signals that an I/O exception has occurred.