@Override
	@SuppressWarnings("unchecked")
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		// Retrieves GET parameters.
		String validationToken = FbBotMillContext.getInstance()
				.getValidationToken();
		Map<String, String[]> parameters = req.getParameterMap();
		String hubMode = safeUnwrapGetParameters(parameters
				.get(FbBotMillNetworkConstants.HUB_MODE_PARAMETER));
		String hubToken = safeUnwrapGetParameters(parameters
				.get(FbBotMillNetworkConstants.HUB_VERIFY_TOKEN_PARAMETER));
		String hubChallenge = safeUnwrapGetParameters(parameters
				.get(FbBotMillNetworkConstants.HUB_CHALLENGE_PARAMETER));

		// Checks parameters and responds according to that.
		if (hubMode.equals(FbBotMillNetworkConstants.HUB_MODE_SUBSCRIBE)
				&& hubToken.equals(validationToken)) {
			logger.info("Subscription OK.");
			resp.setStatus(200);
			resp.setContentType("text/plain");
			resp.getWriter().write(hubChallenge);
		} else {
			logger.warn("GET received is not a subscription or wrong validation token. Ensure you have set the correct validation token using FbBotMillContext.getInstance().setup(String, String).");
			resp.sendError(403);
		}
	}
@ Override @ SuppressWarnings ( "unchecked" ) protected void doGet ( HttpServletRequest req , HttpServletResponse resp ) throws ServletException , IOException { String validationToken = FbBotMillContext . getInstance ( ) . getValidationToken ( ) ; Map < String , String [ ] > parameters = req . getParameterMap ( ) ; String hubMode = safeUnwrapGetParameters ( parameters . get ( FbBotMillNetworkConstants . HUB_MODE_PARAMETER ) ) ; String hubToken = safeUnwrapGetParameters ( parameters . get ( FbBotMillNetworkConstants . HUB_VERIFY_TOKEN_PARAMETER ) ) ; String hubChallenge = safeUnwrapGetParameters ( parameters . get ( FbBotMillNetworkConstants . HUB_CHALLENGE_PARAMETER ) ) ; if ( hubMode . equals ( FbBotMillNetworkConstants . HUB_MODE_SUBSCRIBE ) && hubToken . equals ( validationToken ) ) { logger . info ( "Subscription OK." ) ; resp . setStatus ( 200 ) ; resp . setContentType ( "text/plain" ) ; resp . getWriter ( ) . write ( hubChallenge ) ; } else { logger . warn ( "GET received is not a subscription or wrong validation token. Ensure you have set the correct validation token using FbBotMillContext.getInstance().setup(String, String)." ) ; resp . sendError ( 403 ) ; } }
Specifies how to handle a GET request. GET requests are used by Facebook
only during the WebHook registration. During this phase, the
FbBotMillServlet checks that the
{@link FbBotMillNetworkConstants#HUB_MODE_PARAMETER} value received
equals to {@link FbBotMillNetworkConstants#HUB_MODE_SUBSCRIBE} and that
the {@link FbBotMillNetworkConstants#HUB_VERIFY_TOKEN_PARAMETER} value
received equals to the {@link FbBotMillContext#getValidationToken()}. If
that's true, then the FbBotMillServlet will reply sending back the value
of the {@link FbBotMillNetworkConstants#HUB_CHALLENGE_PARAMETER}
received, in order to confirm the registration, otherwise it will return
an error 403.

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