Skip to content
This repository was archived by the owner on Jan 18, 2025. It is now read-only.

Commit a09d99f

Browse files
committed
fixed bug of initinite retry. #16
#16
1 parent 5a962f9 commit a09d99f

File tree

1 file changed

+135
-108
lines changed

1 file changed

+135
-108
lines changed

Charlotte - Java dialog tooling/src/com/almende/dialog/adapter/VoiceXMLRESTProxy.java

+135-108
Original file line numberDiff line numberDiff line change
@@ -225,95 +225,105 @@ public Response getDTMF2Hash() {
225225
return Response.ok(result).build();
226226
}
227227

228-
@Path("new")
229-
@GET
230-
@Produces("application/voicexml")
231-
public Response getNewDialog(@QueryParam("direction") String direction,@QueryParam("remoteID") String remoteID,@QueryParam("localID") String localID, @Context UriInfo ui){
232-
log.info("call started:"+direction+":"+remoteID+":"+localID);
233-
this.host=ui.getBaseUri().toString().replace(":80", "");
234-
235-
String adapterType="broadsoft";
236-
AdapterConfig config = AdapterConfig.findAdapterConfig(adapterType, localID);
237-
String sessionKey = adapterType+"|"+localID+"|"+remoteID+(direction.equals("outbound")?"@outbound":"");
238-
Session session = Session.getSession(sessionKey);
239-
240-
// Remove retry counter because call is succesfull
241-
if(direction.equalsIgnoreCase("outbound")) {
242-
StringStore.dropString(sessionKey+"_retry");
243-
log.info("Removed retry!");
244-
}
245-
246-
String url="";
247-
if (direction.equals("inbound")){
248-
url = config.getInitialAgentURL();
249-
session.setStartUrl(url);
250-
session.setDirection("inbound");
251-
session.setRemoteAddress(remoteID);
252-
session.setType(adapterType);
253-
session.setPubKey(config.getPublicKey());
254-
session.setTrackingToken(UUID.randomUUID().toString());
255-
session.setAdapterID(config.getConfigId());
256-
257-
Broadsoft bs = new Broadsoft( config );
258-
bs.startSubscription();
259-
}
260-
else
261-
{
228+
@Path("new")
229+
@GET
230+
@Produces("application/voicexml")
231+
public Response getNewDialog(@QueryParam("direction") String direction,@QueryParam("remoteID") String remoteID,@QueryParam("localID") String localID, @Context UriInfo ui){
232+
log.info("call started:"+direction+":"+remoteID+":"+localID);
233+
this.host=ui.getBaseUri().toString().replace(":80", "");
234+
235+
String adapterType="broadsoft";
236+
AdapterConfig config = AdapterConfig.findAdapterConfig(adapterType, localID);
237+
String sessionKey = adapterType+"|"+localID+"|"+remoteID+(direction.equals("outbound")?"@outbound":"");
238+
Session session = Session.getSession(sessionKey);
239+
240+
// Remove retry counter because call is succesfull
241+
if(direction.equalsIgnoreCase("outbound")) {
242+
StringStore.dropString(sessionKey+"_retry");
243+
log.info("Removed retry!");
244+
}
245+
246+
String url="";
247+
if (direction.equals("inbound")){
248+
url = config.getInitialAgentURL();
249+
session.setStartUrl(url);
250+
session.setDirection("inbound");
251+
session.setRemoteAddress(remoteID);
252+
session.setType(adapterType);
253+
session.setPubKey(config.getPublicKey());
254+
session.setTrackingToken(UUID.randomUUID().toString());
255+
session.setAdapterID(config.getConfigId());
256+
257+
Broadsoft bs = new Broadsoft( config );
258+
bs.startSubscription();
259+
}
260+
else
261+
{
262262
if (session != null) {
263263
url = session.getStartUrl();
264264
} else {
265265
log.severe(String.format("Session %s not found", sessionKey));
266266
return null;
267267
}
268-
}
269-
270-
String json = StringStore.getString("InitialQuestion_"+sessionKey);
271-
Question question = null;
272-
if(json!=null) {
273-
log.info("Getting question from cache");
274-
question = Question.fromJSON(json, session.getAdapterConfig().getConfigId());
275-
StringStore.dropString("InitialQuestion_"+sessionKey);
276-
} else {
277-
question = Question.fromURL(url,session.getAdapterConfig().getConfigId(),remoteID,localID);
278-
}
279-
DDRWrapper.log(question,session,"Start",config);
280-
session.storeSession();
281-
282-
return handleQuestion(question,session.getAdapterConfig().getConfigId(),remoteID,sessionKey);
283-
}
284-
285-
@Path("answer")
286-
@GET
287-
@Produces("application/voicexml+xml")
288-
public Response answer(@QueryParam("question_id") String question_id, @QueryParam("answer_id") String answer_id, @QueryParam("answer_input") String answer_input, @QueryParam("sessionKey") String sessionKey, @Context UriInfo ui){
289-
this.host=ui.getBaseUri().toString().replace(":80", "");
290-
String reply="<vxml><exit/></vxml>";
291-
Session session = Session.getSession(sessionKey);
292-
if (session!=null) {
293-
String json = StringStore.getString("question_"+session.getRemoteAddress()+"_"+session.getLocalAddress());
294-
if (json != null){
295-
Question question = Question.fromJSON(json, session.getAdapterConfig().getConfigId());
296-
//String responder = StringStore.getString(question_id+"-remoteID");
297-
String responder = session.getRemoteAddress();
298-
if (session.killed){
299-
log.warning("session is killed");
300-
return Response.status(Response.Status.BAD_REQUEST).build();
301-
}
302-
DDRWrapper.log(question,session,"Answer");
303-
304-
StringStore.dropString(question_id);
305-
StringStore.dropString(question_id+"-remoteID");
306-
StringStore.dropString("question_"+session.getRemoteAddress()+"_"+session.getLocalAddress());
268+
}
269+
270+
String json = StringStore.getString("InitialQuestion_"+sessionKey);
271+
Question question = null;
272+
if(json!=null) {
273+
log.info("Getting question from cache");
274+
question = Question.fromJSON(json, session.getAdapterConfig().getConfigId());
275+
StringStore.dropString("InitialQuestion_"+sessionKey);
276+
} else {
277+
question = Question.fromURL(url,session.getAdapterConfig().getConfigId(),remoteID,localID);
278+
}
279+
DDRWrapper.log(question,session,"Start",config);
280+
session.storeSession();
281+
282+
return handleQuestion(question,session.getAdapterConfig().getConfigId(),remoteID,sessionKey);
283+
}
307284

308-
question = question.answer(responder,session.getAdapterConfig().getConfigId(),answer_id,answer_input);
309-
310-
return handleQuestion(question, session.getAdapterConfig().getConfigId(),responder,sessionKey);
311-
}
312-
} else {
313-
log.warning("No session found for: "+sessionKey);
314-
}
315-
return Response.ok(reply).build();
316-
}
285+
@Path( "answer" )
286+
@GET
287+
@Produces( "application/voicexml+xml" )
288+
public Response answer( @QueryParam( "question_id" ) String question_id,
289+
@QueryParam( "answer_id" ) String answer_id, @QueryParam( "answer_input" ) String answer_input,
290+
@QueryParam( "sessionKey" ) String sessionKey, @Context UriInfo ui )
291+
{
292+
this.host = ui.getBaseUri().toString().replace( ":80", "" );
293+
String reply = "<vxml><exit/></vxml>";
294+
Session session = Session.getSession( sessionKey );
295+
if ( session != null )
296+
{
297+
String json = StringStore.getString( "question_" + session.getRemoteAddress() + "_"
298+
+ session.getLocalAddress() );
299+
if ( json != null )
300+
{
301+
Question question = Question.fromJSON( json, session.getAdapterConfig().getConfigId() );
302+
//String responder = StringStore.getString(question_id+"-remoteID");
303+
String responder = session.getRemoteAddress();
304+
if ( session.killed )
305+
{
306+
log.warning( "session is killed" );
307+
return Response.status( Response.Status.BAD_REQUEST ).build();
308+
}
309+
DDRWrapper.log( question, session, "Answer" );
310+
311+
StringStore.dropString( question_id );
312+
StringStore.dropString( question_id + "-remoteID" );
313+
StringStore.dropString( "question_" + session.getRemoteAddress() + "_" + session.getLocalAddress() );
314+
question = question.answer( responder, session.getAdapterConfig().getConfigId(), answer_id,
315+
answer_input, Question.getRetryCount( sessionKey ) );
316+
return handleQuestion( question, session.getAdapterConfig().getConfigId(), responder, sessionKey );
317+
} else {
318+
log.warning( "No question found in session!" );
319+
}
320+
}
321+
else
322+
{
323+
log.warning( "No session found for: " + sessionKey );
324+
}
325+
return Response.ok( reply ).build();
326+
}
317327

318328
@Path( "timeout" )
319329
@GET
@@ -374,7 +384,7 @@ public Response exception(@QueryParam("question_id") String question_id, @QueryP
374384
}
375385
return Response.ok(reply).build();
376386
}
377-
387+
378388
@Path("hangup")
379389
@GET
380390
@Produces("application/voicexml+xml")
@@ -402,7 +412,7 @@ public Response hangup( @QueryParam( "direction" ) String direction,
402412
question = ServerUtils.deserialize( questionNode.get( "question" ).toString(), Question.class );
403413
remoteID = questionNode.get( "remoteCallerId" ).asText();
404414
//not deleting the remoteCallerIdQuestionMap as hangup (personality: Originator callState: Released)
405-
//is received via the ccxml file
415+
//is received via the ccxml file
406416
// StringStore.dropString( direction + "_" + session.getRemoteAddress() + "_" + session.getLocalAddress() );
407417
}
408418
else
@@ -422,16 +432,22 @@ public Response hangup( @QueryParam( "direction" ) String direction,
422432
question = Question.fromURL(session.getStartUrl(), session.getAdapterConfig().getConfigId(),remoteID,localID);
423433
}
424434

425-
HashMap<String, Object> timeMap = getTimeMap( startTime, answerTime, releaseTime );
426-
if ( notPickedUp != null )
435+
if ( question != null )
427436
{
428-
timeMap.put( "notPickedUp", notPickedUp );
437+
HashMap<String, Object> timeMap = getTimeMap( startTime, answerTime, releaseTime );
438+
if ( notPickedUp != null )
439+
{
440+
timeMap.put( "notPickedUp", notPickedUp );
441+
}
442+
question.event( "hangup", "Hangup", timeMap, remoteID );
443+
DDRWrapper.log( question, session, "Hangup" );
444+
445+
handleQuestion( null, session.getAdapterConfig().getConfigId(), remoteID, sessionKey );
446+
}
447+
else
448+
{
449+
log.info( "no question received" );
429450
}
430-
question.event("hangup", "Hangup", timeMap, remoteID);
431-
DDRWrapper.log(question,session,"Hangup");
432-
433-
handleQuestion(null, session.getAdapterConfig().getConfigId(),remoteID,sessionKey);
434-
435451
return Response.ok("").build();
436452
}
437453

@@ -447,21 +463,25 @@ public Response answered( String direction, String remoteID, String localID, Str
447463
String adapterType = "broadsoft";
448464
String sessionKey = adapterType+"|"+localID+"|"+remoteID;
449465
Session session = Session.getSession(sessionKey);
450-
466+
log.info( "question from session got: "+ session.getSession_id() );
451467
Question question = null;
452468
String json = StringStore.getString( direction + "_" + remoteID + "_" + localID );
453-
ObjectNode questionNode = ServerUtils.deserialize( json, false, ObjectNode.class);
454-
log.info( "questionNode at answered: "+ questionNode.toString() );
455-
if ( questionNode != null && questionNode.get( "question" ) != null)
469+
log.info( "question from session: "+ json );
470+
471+
if ( json != null )
456472
{
457-
question = ServerUtils.deserialize( questionNode.get( "question" ).toString(),
458-
Question.class );
459-
}
473+
ObjectNode questionNode = ServerUtils.deserialize( json, false, ObjectNode.class );
474+
log.info( "questionNode at answered: " + questionNode.toString() );
475+
if ( questionNode != null && questionNode.get( "question" ) != null )
476+
{
477+
question = ServerUtils.deserialize( questionNode.get( "question" ).toString(), Question.class );
478+
}
460479

461-
HashMap<String, Object> timeMap = getTimeMap( startTime, answerTime, releaseTime );
462-
question.event( "answered", "Answered", timeMap, questionNode.get( "remoteCallerId" ).asText() );
463-
DDRWrapper.log( question, session, "Answered" );
464-
handleQuestion( null, session.getAdapterConfig().getConfigId(), remoteID, sessionKey );
480+
HashMap<String, Object> timeMap = getTimeMap( startTime, answerTime, releaseTime );
481+
question.event( "answered", "Answered", timeMap, questionNode.get( "remoteCallerId" ).asText() );
482+
DDRWrapper.log( question, session, "Answered" );
483+
handleQuestion( null, session.getAdapterConfig().getConfigId(), remoteID, sessionKey );
484+
}
465485
return Response.ok( "" ).build();
466486
}
467487

@@ -582,11 +602,12 @@ else if ( node.getNodeName().equals( "releaseTime" ) )
582602
//when the receiver hangs up, an active callstate is also triggered.
583603
// but the releaseCause is also set to Temporarily Unavailable
584604
if ( callState.getTextContent().equals( "Active" )
585-
&& ( releaseCause == null || !releaseCause.getTextContent()
586-
.equalsIgnoreCase( "Temporarily Unavailable" ) ) )
605+
&& ( releaseCause != null && !releaseCause.getTextContent().equalsIgnoreCase(
606+
"Temporarily Unavailable" ) && !releaseCause.getTextContent().equalsIgnoreCase(
607+
"User Not Found" )))
587608
{
588-
answered( direction, address, config.getMyAddress(),
589-
startTimeString, answerTimeString, releaseTimeString );
609+
answered( direction, address, config.getMyAddress(), startTimeString,
610+
answerTimeString, releaseTimeString );
590611
}
591612
}
592613
else if ( personality.getTextContent().equals( "Originator" ) )
@@ -844,6 +865,12 @@ private String renderClosedQuestion(Question question,ArrayList<String> prompts,
844865
outputter.endTag();
845866
outputter.endTag();
846867
}
868+
if(answers.size()>11) {
869+
outputter.startTag("property");
870+
outputter.attribute("name", "termchar");
871+
outputter.attribute("value", "");
872+
outputter.endTag();
873+
}
847874
for(int cnt=0; cnt<answers.size(); cnt++){
848875
Integer dtmf = cnt+1;
849876
String dtmfValue = dtmf.toString();
@@ -1107,7 +1134,7 @@ else if ( res.prompts.size() > 0 )
11071134
log.info("Sending xml: "+result);
11081135
return Response.ok(result).build();
11091136
}
1110-
1137+
11111138
protected String getAnswerUrl() {
11121139
return "/vxml/answer";
11131140
}

0 commit comments

Comments
 (0)