TwilioAdapter { protected String renderClosedQuestion(Question question, ArrayList<String> prompts, String sessionKey) { try { sessionKey = URLEncoder.encode(sessionKey, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } TwiMLResponse twiml = new TwiMLResponse(); Gather gather = new Gather(); gather.setAction(getAnswerUrl()); gather.setMethod("GET"); gather.setNumDigits(1); String noAnswerTimeout = question.getMediaPropertyValue(MediumType.BROADSOFT, MediaPropertyKey.TIMEOUT); boolean useHash = true; if(question.getAnswers().size() > 11) { useHash = false; } else { List<Answer> answers = question.getAnswers(); for (Answer answer : answers) { if (answer != null && answer.getAnswer_text() != null && answer.getAnswer_text().startsWith("dtmfKey: useHash = true; break; } } } noAnswerTimeout = noAnswerTimeout != null ? noAnswerTimeout : "5"; if (noAnswerTimeout.endsWith("s")) { log.warning("No answer timeout must end with 's'. E.g. 10s. Found: " + noAnswerTimeout); noAnswerTimeout = noAnswerTimeout.replace("s", ""); } int timeout = 5; try { timeout = Integer.parseInt(noAnswerTimeout); } catch (NumberFormatException e) { e.printStackTrace(); } gather.setTimeout(timeout); if(useHash) { gather.setFinishOnKey(""); } try { addPrompts(prompts, gather, ServerUtils.getTTSInfoFromSession(question, sessionKey)); twiml.append(gather); Redirect redirect = new Redirect(getTimeoutUrl()); redirect.setMethod("GET"); twiml.append(redirect); } catch (TwiMLException e) { e.printStackTrace(); } return twiml.toXML(); }  static HashMap<String, String> dial(Map<String, String> addressNameMap, String dialogIdOrUrl,
        AdapterConfig config, String accountId, String applicationId, String bearerToken); @Path("new") @GET @Produces("application/xml") Response getNewDialog(@QueryParam("CallSid") String CallSid, @QueryParam("AccountSid") String AccountSid,
        @QueryParam("From") String localID, @QueryParam("To") String remoteID, @QueryParam("Direction") String direction, 
        @QueryParam("ForwardedFrom") String forwardedFrom, @QueryParam("CallStatus") String callStatus, @QueryParam("isTest") Boolean isTest); @Path("new") @POST @Produces("application/xml") Response getNewDialogPost(@FormParam("CallSid") String CallSid, @FormParam("AccountSid") String AccountSid,
        @FormParam("From") String localID, @FormParam("To") String remoteID, @FormParam("Direction") String direction,
        @FormParam("ForwardedFrom") String forwardedFrom, @FormParam("CallStatus") String callStatus, @QueryParam("isTest") Boolean isTest); @Path("answer") @GET @Produces("application/xml") Response answer(@QueryParam("answerId") String answer_id, @QueryParam("Digits") String answer_input,
        @QueryParam("From") String localID, @QueryParam("To") String remoteID,
        @QueryParam("Direction") String direction, @QueryParam("RecordingUrl") String recordingUrl,
        @QueryParam("DialCallStatus") String dialCallStatus, @QueryParam("DialCallSid") String dialCallSid,
        @QueryParam("CallSid") String callSid, @QueryParam("ConferenceSid") String conferenceSid, 
        @QueryParam("CallStatus") String callStatus); @Path("timeout") @GET @Produces("application/xml") Response timeout(@QueryParam("From") String localID, @QueryParam("To") String remoteID,
        @QueryParam("Direction") String direction, @QueryParam("CallSid") String callSid, @QueryParam("CallStatus") String callStatus); @Path("preconnect") @GET @Produces("application/xml") Response preconnect(@QueryParam("From") String localID, @QueryParam("AccountSid") String accountSid,
        @QueryParam("To") String remoteID, @QueryParam("Direction") String direction,
        @QueryParam("CallSid") String callSid, @QueryParam("ParentCallSid") String parentCallSid); @Path("cc") @GET Response receiveCCMessage(@QueryParam("CallSid") String callSid, @QueryParam("From") String localID,
        @QueryParam("To") String remoteID, @QueryParam("Direction") String direction,
        @QueryParam("CallStatus") String status); void answered(String direction, String remoteID, String localID, String sessionKey); Response hangup(Session session); static Session updateSessionWithCallTimes(Session session, Call call); Return formQuestion(Question question, String adapterID, String address, String ddrRecordId,
        Session session, Map<String, String> extraParams); static Account getTwilioAccount(String accountSid, String authToken); Session fetchSessionFromParent(String localID, String remoteID, String accountSid, String callSid,
        String parentCallSid);  }
@Test public void renderClosedQuestionTest() throws Exception { Question question = getClosedQuestion( false ); AdapterConfig adapter = createTwilioAdapter(); Session session = createSession(adapter, remoteAddressVoice); String result = renderQuestion( question, adapter, session); Document doc = getXMLDocumentBuilder( result ); Node response = doc.getFirstChild(); Node gather = response.getFirstChild(); Node play1 = gather.getFirstChild(); Node play2 = play1.getNextSibling(); Node play3 = play2.getNextSibling(); Node redirect = gather.getNextSibling(); assertEquals( "Gather", gather.getNodeName() ); assertEquals( "GET", gather.getAttributes().getNamedItem( "method" ) .getTextContent() ); assertTrue( gather.getAttributes().getNamedItem( "action" ) .getTextContent().endsWith( "/dialoghandler/rest/twilio/answer" ) ); assertEquals( "Play", play1.getNodeName() ); assertEquals( "http: assertEquals( "Play", play2.getNodeName() ); assertEquals( "http: assertEquals( "Play", play3.getNodeName() ); assertEquals( "http: assertEquals( "Redirect", redirect.getNodeName() ); assertTrue( redirect.getTextContent() .endsWith( "/dialoghandler/rest/twilio/timeout" ) ); assertEquals( "GET", redirect.getAttributes().getNamedItem( "method" ) .getTextContent() ); }