@@ -225,95 +225,105 @@ public Response getDTMF2Hash() {
225
225
return Response .ok (result ).build ();
226
226
}
227
227
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
+ {
262
262
if (session != null ) {
263
263
url = session .getStartUrl ();
264
264
} else {
265
265
log .severe (String .format ("Session %s not found" , sessionKey ));
266
266
return null ;
267
267
}
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
+ }
307
284
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
+ }
317
327
318
328
@ Path ( "timeout" )
319
329
@ GET
@@ -374,7 +384,7 @@ public Response exception(@QueryParam("question_id") String question_id, @QueryP
374
384
}
375
385
return Response .ok (reply ).build ();
376
386
}
377
-
387
+
378
388
@ Path ("hangup" )
379
389
@ GET
380
390
@ Produces ("application/voicexml+xml" )
@@ -402,7 +412,7 @@ public Response hangup( @QueryParam( "direction" ) String direction,
402
412
question = ServerUtils .deserialize ( questionNode .get ( "question" ).toString (), Question .class );
403
413
remoteID = questionNode .get ( "remoteCallerId" ).asText ();
404
414
//not deleting the remoteCallerIdQuestionMap as hangup (personality: Originator callState: Released)
405
- //is received via the ccxml file
415
+ //is received via the ccxml file
406
416
// StringStore.dropString( direction + "_" + session.getRemoteAddress() + "_" + session.getLocalAddress() );
407
417
}
408
418
else
@@ -422,16 +432,22 @@ public Response hangup( @QueryParam( "direction" ) String direction,
422
432
question = Question .fromURL (session .getStartUrl (), session .getAdapterConfig ().getConfigId (),remoteID ,localID );
423
433
}
424
434
425
- HashMap <String , Object > timeMap = getTimeMap ( startTime , answerTime , releaseTime );
426
- if ( notPickedUp != null )
435
+ if ( question != null )
427
436
{
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" );
429
450
}
430
- question .event ("hangup" , "Hangup" , timeMap , remoteID );
431
- DDRWrapper .log (question ,session ,"Hangup" );
432
-
433
- handleQuestion (null , session .getAdapterConfig ().getConfigId (),remoteID ,sessionKey );
434
-
435
451
return Response .ok ("" ).build ();
436
452
}
437
453
@@ -447,21 +463,25 @@ public Response answered( String direction, String remoteID, String localID, Str
447
463
String adapterType = "broadsoft" ;
448
464
String sessionKey = adapterType +"|" +localID +"|" +remoteID ;
449
465
Session session = Session .getSession (sessionKey );
450
-
466
+ log . info ( "question from session got: " + session . getSession_id () );
451
467
Question question = null ;
452
468
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 )
456
472
{
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
+ }
460
479
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
+ }
465
485
return Response .ok ( "" ).build ();
466
486
}
467
487
@@ -582,11 +602,12 @@ else if ( node.getNodeName().equals( "releaseTime" ) )
582
602
//when the receiver hangs up, an active callstate is also triggered.
583
603
// but the releaseCause is also set to Temporarily Unavailable
584
604
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" )))
587
608
{
588
- answered ( direction , address , config .getMyAddress (),
589
- startTimeString , answerTimeString , releaseTimeString );
609
+ answered ( direction , address , config .getMyAddress (), startTimeString ,
610
+ answerTimeString , releaseTimeString );
590
611
}
591
612
}
592
613
else if ( personality .getTextContent ().equals ( "Originator" ) )
@@ -844,6 +865,12 @@ private String renderClosedQuestion(Question question,ArrayList<String> prompts,
844
865
outputter .endTag ();
845
866
outputter .endTag ();
846
867
}
868
+ if (answers .size ()>11 ) {
869
+ outputter .startTag ("property" );
870
+ outputter .attribute ("name" , "termchar" );
871
+ outputter .attribute ("value" , "" );
872
+ outputter .endTag ();
873
+ }
847
874
for (int cnt =0 ; cnt <answers .size (); cnt ++){
848
875
Integer dtmf = cnt +1 ;
849
876
String dtmfValue = dtmf .toString ();
@@ -1107,7 +1134,7 @@ else if ( res.prompts.size() > 0 )
1107
1134
log .info ("Sending xml: " +result );
1108
1135
return Response .ok (result ).build ();
1109
1136
}
1110
-
1137
+
1111
1138
protected String getAnswerUrl () {
1112
1139
return "/vxml/answer" ;
1113
1140
}
0 commit comments