diff --git a/Charlotte - Java dialog tooling/src/com/almende/dialog/adapter/DialogAgent.java b/Charlotte - Java dialog tooling/src/com/almende/dialog/adapter/DialogAgent.java index 4201ed4a..5e42bc98 100644 --- a/Charlotte - Java dialog tooling/src/com/almende/dialog/adapter/DialogAgent.java +++ b/Charlotte - Java dialog tooling/src/com/almende/dialog/adapter/DialogAgent.java @@ -141,7 +141,7 @@ public HashMap outboundCallWithMap( @Name( "addressMap" ) Map> questionRetryCounter = new ThreadLocal>(); + QuestionIntf question; private String preferred_language = "nl"; @@ -55,48 +58,65 @@ public static Question fromURL(String url,String adapterID) { public static Question fromURL(String url,String adapterID,String remoteID) { return fromURL(url, adapterID, remoteID, ""); } - @JSON(include = false) - public static Question fromURL(String url,String adapterID,String remoteID,String fromID) { - - log.info( String.format( "Trying to parse Question from URL: %s with remoteId: %s and fromId: %s", url, remoteID, fromID )); - if(remoteID==null) - remoteID=""; - String json = ""; - if( !ServerUtils.isInUnitTestingEnvironment() ) - { - Client client = ParallelInit.getClient(); - WebResource webResource = client.resource(url); - try { - webResource = webResource.queryParam("responder", URLEncoder.encode(remoteID, "UTF-8")).queryParam("requester", URLEncoder.encode(fromID, "UTF-8")); - dialogLog.info(adapterID,"Loading new question from: "+webResource.toString()); - json = webResource.type("text/plain").get(String.class); - dialogLog.info(adapterID,"Received new question: "+json); - } catch (ClientHandlerException e) { - log.severe(e.toString()); - dialogLog.severe(adapterID,"ERROR loading question: "+e.toString()); - } catch (UniformInterfaceException e) { - log.severe(e.toString()); - dialogLog.severe(adapterID,"ERROR loading question: "+e.toString()); - } catch (UnsupportedEncodingException e) { - log.severe(e.toString()); - dialogLog.severe(adapterID,"ERROR loading question: "+e.toString()); - } - } - else + + @JSON( include = false ) + public static Question fromURL( String url, String adapterID, String remoteID, String fromID ) + { + log.info( String.format( "Trying to parse Question from URL: %s with remoteId: %s and fromId: %s", url, + remoteID, fromID ) ); + if ( remoteID == null ) + remoteID = ""; + String json = ""; + if ( url != null && !url.trim().isEmpty() ) { - try + if ( !ServerUtils.isInUnitTestingEnvironment() ) { - url = ServerUtils.getURLWithQueryParams( url, "responder", URLEncoder.encode(remoteID, "UTF-8") ); - url = ServerUtils.getURLWithQueryParams( url, "requester", URLEncoder.encode(fromID, "UTF-8") ); - json = TestFramework.fetchResponse( HTTPMethod.GET, url, null ); + Client client = ParallelInit.getClient(); + WebResource webResource = client.resource( url ); + try + { + webResource = webResource.queryParam( "responder", URLEncoder.encode( remoteID, "UTF-8" ) ) + .queryParam( "requester", URLEncoder.encode( fromID, "UTF-8" ) ); + dialogLog.info( adapterID, "Loading new question from: " + webResource.toString() ); + json = webResource.type( "text/plain" ).get( String.class ); + dialogLog.info( adapterID, "Received new question: " + json ); + } + catch ( ClientHandlerException e ) + { + log.severe( e.toString() ); + dialogLog.severe( adapterID, "ERROR loading question: " + e.toString() ); + } + catch ( UniformInterfaceException e ) + { + log.severe( e.toString() ); + dialogLog.severe( adapterID, "ERROR loading question: " + e.toString() ); + } + catch ( UnsupportedEncodingException e ) + { + log.severe( e.toString() ); + dialogLog.severe( adapterID, "ERROR loading question: " + e.toString() ); + } } - catch ( UnsupportedEncodingException e ) + else { - log.severe(e.toString()); + try + { + url = ServerUtils.getURLWithQueryParams( url, "responder", URLEncoder.encode( remoteID, "UTF-8" ) ); + url = ServerUtils.getURLWithQueryParams( url, "requester", URLEncoder.encode( fromID, "UTF-8" ) ); + json = TestFramework.fetchResponse( HTTPMethod.GET, url, null ); + } + catch ( UnsupportedEncodingException e ) + { + log.severe( e.toString() ); + } } + return fromJSON( json, adapterID ); } - return fromJSON(json, adapterID); - } + else + { + return null; + } + } @JSON(include = false) public static Question fromJSON(String json, String adapterID) { @@ -142,116 +162,177 @@ public void generateIds() { } } - @JsonIgnore - @JSON(include = false) - public Question answer(String responder, String adapterID, String answer_id, String answer_input) { - Client client = ParallelInit.getClient(); - boolean answered=false; - Answer answer = null; - if (this.getType().equals("open")) { - answer = this.getAnswers().get(0); // TODO: error handling, what if - // answer doesn't exist, or - // multiple answers - // (=out-of-spec) - } else if(this.getType().equals("openaudio")) { - answer = this.getAnswers().get(0); - try { - answer_input = URLDecoder.decode(answer_input, "UTF-8"); - log.info("Received answer: "+answer_input); - } catch (Exception e) { - } - } else if (this.getType().equals("comment") || this.getType().equals("referral")) { - if(this.getAnswers() == null || this.getAnswers().size()==0) - return null; - answer = this.getAnswers().get(0); - - } else if (answer_id != null) { - answered=true; - Collection answers = question.getAnswers(); - for (Answer ans : answers) { - if (ans.getAnswer_id().equals(answer_id)) { - answer = ans; - break; - } - } - } else if (answer_input != null) { - answered=true; - // check all answers of question to see if they match, possibly - // retrieving the answer_text for each - answer_input = answer_input.trim(); - ArrayList answers = question.getAnswers(); - for (Answer ans : answers) { - if (ans.getAnswer_text()!=null && ans.getAnswer_text().equals(answer_input)) { - answer = ans; - break; - } - } - if (answer == null) { - for (Answer ans : answers) { - if (ans.getAnswer_expandedtext(this.preferred_language).equalsIgnoreCase( - answer_input)) { - answer = ans; - break; - } - } - } - if (answer == null) { - try { - int answer_nr = Integer.parseInt(answer_input); - if(answer_nr <= answers.size()) - answer = answers.get(answer_nr-1); - } catch(NumberFormatException ex) { - - } - } - } - Question newQ = null; - if (!this.getType().equals("comment") && answer == null) { - // Oeps, couldn't find/handle answer, just repeat last question: - // TODO: somewhat smarter behavior? Should dialog standard provide - // error handling? - if(answered) - newQ = this.event("exception","Wrong answer received", null, responder); - if(newQ!=null) - return newQ; - - return this; - } - // Send answer to answer.callback. - WebResource webResource = client.resource(answer.getCallback()); - AnswerPost ans = new AnswerPost(this.getQuestion_id(), - answer.getAnswer_id(), answer_input, responder); - // Check if answer.callback gives new question for this dialog - try { - String post = om.writeValueAsString(ans); - log.info("Going to send: "+post); - String newQuestionJSON = null; - if( !ServerUtils.isInUnitTestingEnvironment() ) - { - newQuestionJSON = webResource.type("application/json").post(String.class, post); - } - else - { - newQuestionJSON = TestFramework.fetchResponse( HTTPMethod.POST, answer.getCallback(), post ); - } - - log.info("Received new question (answer): "+ newQuestionJSON); - dialogLog.info(adapterID, "Received new question (answer): "+newQuestionJSON); - - newQ = om.readValue(newQuestionJSON, Question.class); - newQ.setPreferred_language(preferred_language); - } catch (ClientHandlerException ioe) { - dialogLog.severe(adapterID, "Unable to load question: "+ioe.getMessage()); - log.severe(ioe.toString()); - ioe.printStackTrace(); - newQ = this.event("exception", "Unable to load question", null, responder); - } catch (Exception e) { - dialogLog.severe(adapterID, "Unable to parse question json: "+e.getMessage()); - log.severe(e.toString()); - newQ = this.event("exception", "Unable to parse question json", null, responder); - } - return newQ; - } + /** + * used to fetch an answer for a question. + * @param responder the responder address from the incoming request + * @param adapterID the adapterId used for the communication + * @param answer_id the answerId that must be picked if any. If empty, the {@link answer_input} is matched + * @param answer_input input given by the user + * @param retryCount valid only for VoiceServlet. + * @return + */ + @JsonIgnore + @JSON( include = false ) + public Question answer( String responder, String adapterID, String answer_id, String answer_input, + Integer retryCount ) + { + Client client = ParallelInit.getClient(); + boolean answered = false; + Answer answer = null; + if ( this.getType().equals( "open" ) ) + { + //updated as part of bug#16 at https://github.com/almende/dialog/issues/16 + ArrayList answers = getAnswers(); + answer = answers != null ? answers.get( 0 ) : null; + } + else if ( this.getType().equals( "openaudio" ) ) + { + answer = this.getAnswers().get( 0 ); + try + { + answer_input = URLDecoder.decode( answer_input, "UTF-8" ); + log.info( "Received answer: " + answer_input ); + } + catch ( Exception e ) + { + } + } + else if ( this.getType().equals( "comment" ) || this.getType().equals( "referral" ) ) + { + if ( this.getAnswers() == null || this.getAnswers().size() == 0 ) + return null; + answer = this.getAnswers().get( 0 ); + + } + else if ( answer_id != null ) + { + answered = true; + Collection answers = question.getAnswers(); + for ( Answer ans : answers ) + { + if ( ans.getAnswer_id().equals( answer_id ) ) + { + answer = ans; + break; + } + } + } + else if ( answer_input != null ) + { + answered = true; + // check all answers of question to see if they match, possibly + // retrieving the answer_text for each + answer_input = answer_input.trim(); + ArrayList answers = question.getAnswers(); + for ( Answer ans : answers ) + { + if ( ans.getAnswer_text() != null && ans.getAnswer_text().equals( answer_input ) ) + { + answer = ans; + break; + } + } + if ( answer == null ) + { + for ( Answer ans : answers ) + { + if ( ans.getAnswer_expandedtext( this.preferred_language ).equalsIgnoreCase( answer_input ) ) + { + answer = ans; + break; + } + } + } + if ( answer == null ) + { + try + { + int answer_nr = Integer.parseInt( answer_input ); + if ( answer_nr <= answers.size() ) + answer = answers.get( answer_nr - 1 ); + } + catch ( NumberFormatException ex ) + { + + } + } + } + Question newQ = null; + if ( !this.getType().equals( "comment" ) && answer == null ) + { + // Oeps, couldn't find/handle answer, just repeat last question: + // TODO: somewhat smarter behavior? Should dialog standard provide + // error handling? + if ( answered ) + newQ = this.event( "exception", "Wrong answer received", null, responder ); + if ( newQ != null ) + return newQ; + + String retryLoadLimit = getMediaPropertyValue( MediumType.BROADSOFT, MediaPropertyKey.LENGTH ); + if(retryCount == null) + { + retryCount = getRetryCount( null ); + } + + if ( retryLoadLimit != null && retryCount != null && retryCount < Integer.parseInt( retryLoadLimit ) ) + { + log.warning( String.format( "returning the same question as RetryCount: %s < RetryLoadLimit: %s", + retryCount, retryLoadLimit ) ); + updateRetryCount( null ); + return this; + } + else if ( retryCount != null && retryCount < DEFAULT_MAX_QUESTION_LOAD ) + { + log.warning( String.format( "returning the same question as RetryCount: %s < DEFAULT_MAX: %s", + retryCount, DEFAULT_MAX_QUESTION_LOAD ) ); + updateRetryCount( null ); + return this; + } + else + { + //only TextServlets must get into this + return this; + } + } + // Send answer to answer.callback. + WebResource webResource = client.resource( answer.getCallback() ); + AnswerPost ans = new AnswerPost( this.getQuestion_id(), answer.getAnswer_id(), answer_input, responder ); + // Check if answer.callback gives new question for this dialog + try + { + String post = om.writeValueAsString( ans ); + log.info( "Going to send: " + post ); + String newQuestionJSON = null; + if ( !ServerUtils.isInUnitTestingEnvironment() ) + { + newQuestionJSON = webResource.type( "application/json" ).post( String.class, post ); + } + else + { + newQuestionJSON = TestFramework.fetchResponse( HTTPMethod.POST, answer.getCallback(), post ); + } + + log.info( "Received new question (answer): " + newQuestionJSON ); + dialogLog.info( adapterID, "Received new question (answer): " + newQuestionJSON ); + + newQ = om.readValue( newQuestionJSON, Question.class ); + newQ.setPreferred_language( preferred_language ); + } + catch ( ClientHandlerException ioe ) + { + dialogLog.severe( adapterID, "Unable to load question: " + ioe.getMessage() ); + log.severe( ioe.toString() ); + ioe.printStackTrace(); + newQ = this.event( "exception", "Unable to load question", null, responder ); + } + catch ( Exception e ) + { + dialogLog.severe( adapterID, "Unable to parse question json: " + e.getMessage() ); + log.severe( e.toString() ); + newQ = this.event( "exception", "Unable to parse question json", null, responder ); + } + return newQ; + } public Question event(String eventType, String message, Object extras, String responder) { @@ -470,4 +551,48 @@ public void addMedia_Properties( MediaProperty mediaProperty ) media_properties = media_properties == null ? new ArrayList() : media_properties; media_properties.add( mediaProperty ); } + + public static Integer getRetryCount( String sessionKey ) + { + if(sessionKey == null && questionRetryCounter.get() != null && questionRetryCounter.get().size() == 1) + { + sessionKey = questionRetryCounter.get().keySet().iterator().next(); + } + else if ( questionRetryCounter.get() != null ) + { + if ( questionRetryCounter.get().get( sessionKey ) == null ) + { + HashMap retryHashMap = questionRetryCounter.get(); + retryHashMap.put( sessionKey, 0 ); + questionRetryCounter.set( retryHashMap ); + } + } + else if(sessionKey != null) + { + HashMap retryHashMap = new HashMap(); + retryHashMap.put( sessionKey, 0 ); + questionRetryCounter.set( retryHashMap ); + } + return sessionKey != null ? questionRetryCounter.get().get( sessionKey ) : null; + } + + /** + * updates The retryCount based on the sessionKey. + * If sessionKey is null and questionRetryCounter has only one element, then increments it + * @param sessionKey + * @return + */ + public static Integer updateRetryCount( String sessionKey ) + { + Integer retryCount = getRetryCount( sessionKey ); + if(sessionKey == null && questionRetryCounter.get() != null && questionRetryCounter.get().size() == 1) + { + sessionKey = questionRetryCounter.get().keySet().iterator().next(); + } + if ( retryCount != null && questionRetryCounter.get() != null ) + { + questionRetryCounter.get().put( sessionKey, ++retryCount ); + } + return retryCount; + } } \ No newline at end of file diff --git a/Charlotte - Java dialog tooling/test/com/almende/dialog/adapter/CMServletTest.java b/Charlotte - Java dialog tooling/test/com/almende/dialog/adapter/CMServletTest.java index e28deff6..dc43a389 100644 --- a/Charlotte - Java dialog tooling/test/com/almende/dialog/adapter/CMServletTest.java +++ b/Charlotte - Java dialog tooling/test/com/almende/dialog/adapter/CMServletTest.java @@ -9,7 +9,6 @@ import java.util.HashMap; import java.util.Map; -import org.junit.Ignore; import org.junit.Test; import org.w3c.dom.Document; import org.w3c.dom.Node; @@ -63,34 +62,6 @@ public void outBoundSMSCallSenderNameNotNullTest() throws Exception "outBoundSMSCallSenderNameNotNullTest" ); } - /** - * this test is to check the bug which rethrows the same question when an open question doesnt - * have an answer nor a timeout eventtype - * @throws Exception - */ - @Test - @Ignore - //TODO: fix this unit test - public void inbountSMSCall_WithOpenQuestion_MissingAnswerTest() throws Exception - { - String senderName = "TestUser"; - String url = ServerUtils.getURLWithQueryParams( TestServlet.TEST_SERVLET_PATH, "questionType", - QuestionInRequest.OPEN_QUESTION.name() ); - url = ServerUtils.getURLWithQueryParams( url, "question", simpleQuestion ); - //create SMS adapter - AdapterConfig adapterConfig = createAdapterConfig( "CM", TEST_PUBLIC_KEY, localAddressBroadsoft, url ); - - //create session - getOrCreateSession( adapterConfig, remoteAddressVoice ); - TextMessage textMessage = smsAppointmentInteraction( "hi" ); - HashMap addressNameMap = new HashMap(); - addressNameMap.put( textMessage.getAddress(), textMessage.getRecipientName() ); - String expectedQuestion = TestServlet.getResponseQuestionWithOptionsInString( TestServlet - .getJsonAppointmentQuestion() ); - assertXMLGeneratedFromOutBoundCall( addressNameMap, adapterConfig, expectedQuestion, - textMessage.getLocalAddress(), null ); - } - /** * tests if an outbound call works when the sender name is null. In this * case it should pick up the adapter.Myaddress as the senderName.
diff --git a/Charlotte - Java dialog tooling/test/com/almende/dialog/adapter/MailServletTest.java b/Charlotte - Java dialog tooling/test/com/almende/dialog/adapter/MailServletTest.java index 101959f8..b82a5b8c 100644 --- a/Charlotte - Java dialog tooling/test/com/almende/dialog/adapter/MailServletTest.java +++ b/Charlotte - Java dialog tooling/test/com/almende/dialog/adapter/MailServletTest.java @@ -42,7 +42,9 @@ public void sendDummyMessageTest() throws Exception //fetch and invoke the receieveMessage method HashMap addressNameMap = new HashMap(); addressNameMap.put( remoteAddressEmail, "Test" ); - String url = "http://askfastmarket1.appspot.com/resource/question/"+ testMessage; + String url = ServerUtils.getURLWithQueryParams( TestServlet.TEST_SERVLET_PATH, "questionType", QuestionInRequest.SIMPLE_COMMENT.name() ); + url = ServerUtils.getURLWithQueryParams( url, "question", testMessage ); + MailServlet mailServlet = new MailServlet(); mailServlet.startDialog( addressNameMap, url, "test", "sendDummyMessageTest", adapterConfig ); diff --git a/Charlotte - Java dialog tooling/test/com/almende/dialog/adapter/VoiceXMLServletTest.java b/Charlotte - Java dialog tooling/test/com/almende/dialog/adapter/VoiceXMLServletTest.java index 83488d17..f00beef6 100644 --- a/Charlotte - Java dialog tooling/test/com/almende/dialog/adapter/VoiceXMLServletTest.java +++ b/Charlotte - Java dialog tooling/test/com/almende/dialog/adapter/VoiceXMLServletTest.java @@ -3,11 +3,18 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import java.net.URI; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; + +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; import org.junit.Test; +import org.mockito.Mockito; import org.w3c.dom.Document; import org.w3c.dom.Node; @@ -17,14 +24,70 @@ import com.almende.dialog.model.Answer; import com.almende.dialog.model.MediaProperty; import com.almende.dialog.model.MediaProperty.MediaPropertyKey; -import com.almende.dialog.model.Question; import com.almende.dialog.model.MediaProperty.MediumType; +import com.almende.dialog.model.Question; +import com.almende.dialog.test.TestServlet; +import com.almende.dialog.test.TestServlet.QuestionInRequest; +import com.almende.dialog.util.ServerUtils; +import com.thetransactioncompany.cors.HTTPMethod; public class VoiceXMLServletTest extends TestFramework { protected static final String COMMENT_QUESTION_ID = "1"; protected static final String COMMENT_QUESTION_AUDIO = "http://audio.wav"; + /** + * this test is to check the bug which rethrows the same question when an open question doesnt + * have an answer nor a timeout eventtype + * @throws Exception + */ + @Test + public void inbountPhoneCall_WithOpenQuestion_MissingAnswerTest() throws Exception + { + String senderName = "TestUser"; + String url = ServerUtils.getURLWithQueryParams( TestServlet.TEST_SERVLET_PATH, "questionType", + QuestionInRequest.OPEN_QUESTION.name() ); + url = ServerUtils.getURLWithQueryParams( url, "question", COMMENT_QUESTION_AUDIO ); + //create SMS adapter + AdapterConfig adapterConfig = createAdapterConfig( "broadsoft", TEST_PUBLIC_KEY, localAddressBroadsoft, url ); + + //create session + getOrCreateSession( adapterConfig, remoteAddressVoice ); + + //mock the Context + UriInfo uriInfo = Mockito.mock( UriInfo.class ); + Mockito.when( uriInfo.getBaseUri() ).thenReturn( new URI( TestServlet.TEST_SERVLET_PATH ) ); + VoiceXMLRESTProxy voiceXMLRESTProxy = new VoiceXMLRESTProxy(); + Response newDialog = voiceXMLRESTProxy.getNewDialog( "inbound", remoteAddressVoice, localAddressBroadsoft, + uriInfo ); + HashMap answerVariables = assertOpenQuestionWithDTMFType( newDialog.getEntity().toString() ); + + //answer the dialog + Question retrivedQuestion = ServerUtils.deserialize( TestFramework.fetchResponse( HTTPMethod.GET, url, null ), + Question.class ); + String mediaPropertyValue = retrivedQuestion.getMediaPropertyValue( MediumType.BROADSOFT, MediaPropertyKey.LENGTH ); + + Integer retryCount = Question.getRetryCount( answerVariables.get( "sessionKey" ) ); + int i = 0; + while ( i++ < 10 ) + { + voiceXMLRESTProxy.answer( answerVariables.get( "question_id" ), null, + answerVariables.get( "answer_input" ), answerVariables.get( "sessionKey" ), uriInfo ); + } + retryCount = Question.getRetryCount( answerVariables.get( "sessionKey" ) ); + assertTrue( retryCount != null ); + if(mediaPropertyValue != null) + { + assertTrue( retryCount < i ); + assertTrue( retryCount == Integer.parseInt( mediaPropertyValue ) ); + } + else + { + assertTrue( retryCount < i ); + assertTrue( retryCount == Question.DEFAULT_MAX_QUESTION_LOAD ); + } + } + private Question getCommentQuestion() { Question question = new Question(); @@ -145,19 +208,7 @@ public void renderOpenQuestionWithTypeDTMFTest() throws Exception { String result = renderQuestion(question, adapter, sessionKey); - Document doc = getXMLDocumentBuilder(result); - Node vxml = doc.getFirstChild(); - Node form = vxml.getChildNodes().item(3); - - Node field = form.getFirstChild(); - - assertNotNull(doc); - assertEquals(doc.getChildNodes().getLength(), 1); - assertEquals(vxml.getNodeName(), "vxml"); - assertEquals(form.getNodeName(), "form"); - assertEquals(field.getNodeName(), "field"); - - assertEquals(field.getChildNodes().getLength(), 4); + assertOpenQuestionWithDTMFType( result ); } @Test @@ -186,4 +237,49 @@ public void renderOpenQuestionWithTypeAudioTest() throws Exception { assertEquals(record.getNodeName(), "record"); assertEquals(subdialog.getNodeName(), "subdialog"); } + + /** + * @param result + * @throws Exception + */ + protected HashMap assertOpenQuestionWithDTMFType( String result ) throws Exception + { + HashMap variablesForAnswer = new HashMap(); + + Document doc = getXMLDocumentBuilder( result ); + Node vxml = doc.getFirstChild(); + Node answerInputNode = vxml.getChildNodes().item( 0 ); + Node questionIdNode = vxml.getChildNodes().item( 1 ); + Node sessionKeyNode = vxml.getChildNodes().item( 2 ); + Node form = vxml.getChildNodes().item( 3 ); + + Node field = form.getFirstChild(); + + assertNotNull( doc ); + assertEquals( doc.getChildNodes().getLength(), 1 ); + assertEquals( vxml.getNodeName(), "vxml" ); + assertEquals( form.getNodeName(), "form" ); + assertEquals( "answer_input", answerInputNode.getAttributes().getNamedItem( "name" ).getNodeValue() ); + assertEquals( "question_id", questionIdNode.getAttributes().getNamedItem( "name" ).getNodeValue() ); + assertEquals( "sessionKey", sessionKeyNode.getAttributes().getNamedItem( "name" ).getNodeValue() ); + assertEquals( field.getNodeName(), "field" ); + assertEquals( field.getChildNodes().getLength(), 4 ); + + if(answerInputNode.getAttributes().getNamedItem( "expr" ) != null) + { + variablesForAnswer.put( "answer_input", answerInputNode.getAttributes().getNamedItem( "expr" ).getNodeValue() + .replace( "'", "" ) ); + } + if(questionIdNode.getAttributes().getNamedItem( "expr" ) != null) + { + variablesForAnswer.put( "question_id", questionIdNode.getAttributes().getNamedItem( "expr" ).getNodeValue() + .replace( "'", "" ) ); + } + if(sessionKeyNode.getAttributes().getNamedItem( "expr" ) != null) + { + variablesForAnswer.put( "sessionKey", sessionKeyNode.getAttributes().getNamedItem( "expr" ).getNodeValue() + .replace( "'", "" ) ); + } + return variablesForAnswer; + } } diff --git a/Charlotte - Java dialog tooling/test/com/almende/dialog/test/TestServlet.java b/Charlotte - Java dialog tooling/test/com/almende/dialog/test/TestServlet.java index 0ea8a701..390b55b7 100644 --- a/Charlotte - Java dialog tooling/test/com/almende/dialog/test/TestServlet.java +++ b/Charlotte - Java dialog tooling/test/com/almende/dialog/test/TestServlet.java @@ -94,7 +94,14 @@ private String getJsonSimpleOpenQuestion( String questionText ) Question question = new Question(); question.setQuestion_id( "1" ); question.setType( "open" ); - question.setQuestion_text( "text://" + questionText ); + if(questionText.startsWith( "http://" )) + { + question.setQuestion_text( questionText ); + } + else + { + question.setQuestion_text( "text://" + questionText ); + } return question.toJSON(); }