Revision: ede0c118c203
Author: [email protected] <[email protected]>
Date: Wed Aug 22 14:09:24 2012
Log: Issue 14: Support for configuring timeout if application doesn't
revert
back in pre configured time
http://code.google.com/p/ussdgateway/source/detail?r=ede0c118c203
Modified:
/core/domain/src/main/java/org/mobicents/ussdgateway/UssdPropertiesManagement.java
/core/domain/src/main/java/org/mobicents/ussdgateway/UssdPropertiesManagementMBean.java
/core/domain/src/main/java/org/mobicents/ussdgateway/UssdShellExecutor.java
/core/slee/sbbs/src/main/java/org/mobicents/ussdgateway/slee/ChildSbb.java
/core/slee/sbbs/src/main/java/org/mobicents/ussdgateway/slee/http/HttpClientSbb.java
/core/slee/sbbs/src/main/resources/META-INF/sbb-jar.xml
=======================================
---
/core/domain/src/main/java/org/mobicents/ussdgateway/UssdPropertiesManagement.java
Sun Aug 19 10:20:29 2012
+++
/core/domain/src/main/java/org/mobicents/ussdgateway/UssdPropertiesManagement.java
Wed Aug 22 14:09:24 2012
@@ -48,6 +48,8 @@
protected static final String DIALOG_TIMEOUT_ERROR_MESSAGE
= "dialogtimeouterrmssg";
+ protected static final String DIALOG_TIMEOUT = "dialogtimeout";
+
private static final String TAB_INDENT = "\t";
private static final String CLASS_ATTRIBUTE = "type";
private static final XMLBinding binding = new XMLBinding();
@@ -65,6 +67,12 @@
private String serverErrorMessage;
private String dialogTimeoutErrorMessage;
+ /**
+ * Dialog time out in milliseconds. Once HTTP request is sent, it
expects
+ * back response in dialogTimeout milli seconds.
+ */
+ private long dialogTimeout = 25000;
+
private UssdPropertiesManagement(String name) {
this.name = name;
binding.setClassAttribute(CLASS_ATTRIBUTE);
@@ -125,6 +133,17 @@
this.dialogTimeoutErrorMessage = dialogTimeoutErrorMessage;
this.store();
}
+
+ @Override
+ public long getDialogTimeout() {
+ return dialogTimeout;
+ }
+
+ @Override
+ public void setDialogTimeout(long dialogTimeout) {
+ this.dialogTimeout = dialogTimeout;
+ this.store();
+ }
public void start() throws Exception {
@@ -171,6 +190,7 @@
writer.write(this.noRoutingRuleConfiguredMessage,
NO_ROUTING_RULE_CONFIGURED_ERROR_MESSAGE, String.class);
writer.write(this.serverErrorMessage, SERVER_ERROR_MESSAGE,
String.class);
writer.write(this.dialogTimeoutErrorMessage,
DIALOG_TIMEOUT_ERROR_MESSAGE, String.class);
+ writer.write(this.dialogTimeout, DIALOG_TIMEOUT,
Long.class);
writer.close();
} catch (Exception e) {
@@ -193,6 +213,7 @@
this.noRoutingRuleConfiguredMessage =
reader.read(NO_ROUTING_RULE_CONFIGURED_ERROR_MESSAGE, String.class);
this.serverErrorMessage = reader.read(SERVER_ERROR_MESSAGE,
String.class);
this.dialogTimeoutErrorMessage =
reader.read(DIALOG_TIMEOUT_ERROR_MESSAGE, String.class);
+ this.dialogTimeout = reader.read(DIALOG_TIMEOUT,
Long.class);
reader.close();
} catch (XMLStreamException ex) {
=======================================
---
/core/domain/src/main/java/org/mobicents/ussdgateway/UssdPropertiesManagementMBean.java
Sun Aug 19 10:20:29 2012
+++
/core/domain/src/main/java/org/mobicents/ussdgateway/UssdPropertiesManagementMBean.java
Wed Aug 22 14:09:24 2012
@@ -39,4 +39,8 @@
public void setDialogTimeoutErrorMessage(String
dialogTimeoutErrorMessage);
+ public long getDialogTimeout();
+
+ public void setDialogTimeout(long dialogTimeout);
+
}
=======================================
---
/core/domain/src/main/java/org/mobicents/ussdgateway/UssdShellExecutor.java
Sun Aug 19 10:20:29 2012
+++
/core/domain/src/main/java/org/mobicents/ussdgateway/UssdShellExecutor.java
Wed Aug 22 14:09:24 2012
@@ -179,6 +179,10 @@
ussdPropertiesManagement.setDialogTimeoutErrorMessage(this.formFullMessage(options,
3));
} else if
(parName.equals(UssdPropertiesManagement.SERVER_ERROR_MESSAGE)) {
ussdPropertiesManagement.setServerErrorMessage(this.formFullMessage(options,
3));
+ } else if
(parName.equals(UssdPropertiesManagement.DIALOG_TIMEOUT)) {
+
ussdPropertiesManagement.setDialogTimeout(Long.parseLong(options[3]));
+ } else {
+ return UssdOAMMessages.INVALID_COMMAND;
}
return UssdOAMMessages.PARAMETER_SUCCESSFULLY_SET;
@@ -208,6 +212,8 @@
sb.append(ussdPropertiesManagement.getDialogTimeoutErrorMessage());
} else if
(parName.equals(UssdPropertiesManagement.SERVER_ERROR_MESSAGE)) {
sb.append(ussdPropertiesManagement.getServerErrorMessage());
+ } else if
(parName.equals(UssdPropertiesManagement.DIALOG_TIMEOUT)) {
+
sb.append(ussdPropertiesManagement.getDialogTimeout());
} else {
return UssdOAMMessages.INVALID_COMMAND;
}
@@ -222,6 +228,10 @@
sb.append(UssdPropertiesManagement.DIALOG_TIMEOUT_ERROR_MESSAGE + "
= ");
sb.append(ussdPropertiesManagement.getDialogTimeoutErrorMessage());
sb.append("\n");
+
+ sb.append(UssdPropertiesManagement.DIALOG_TIMEOUT + " =
");
+ sb.append(ussdPropertiesManagement.getDialogTimeout());
+ sb.append("\n");
sb.append(UssdPropertiesManagement.SERVER_ERROR_MESSAGE + "
= ");
sb.append(ussdPropertiesManagement.getServerErrorMessage());
=======================================
---
/core/slee/sbbs/src/main/java/org/mobicents/ussdgateway/slee/ChildSbb.java
Sun Aug 19 10:20:29 2012
+++
/core/slee/sbbs/src/main/java/org/mobicents/ussdgateway/slee/ChildSbb.java
Wed Aug 22 14:09:24 2012
@@ -29,6 +29,10 @@
import javax.slee.SbbContext;
import javax.slee.SbbLocalObject;
import javax.slee.TransactionRequiredLocalException;
+import javax.slee.facilities.TimerEvent;
+import javax.slee.facilities.TimerFacility;
+import javax.slee.facilities.TimerID;
+import javax.slee.facilities.TimerOptions;
import javax.slee.facilities.Tracer;
import javax.slee.resource.ResourceAdaptorTypeID;
@@ -39,6 +43,7 @@
import org.mobicents.protocols.ss7.map.api.MAPParameterFactory;
import org.mobicents.protocols.ss7.map.api.MAPProvider;
import org.mobicents.protocols.ss7.map.api.dialog.MAPUserAbortChoice;
+import org.mobicents.protocols.ss7.map.api.primitives.USSDString;
import
org.mobicents.protocols.ss7.map.api.service.supplementary.MAPDialogSupplementary;
import
org.mobicents.protocols.ss7.map.api.service.supplementary.ProcessUnstructuredSSRequest;
import
org.mobicents.protocols.ss7.map.api.service.supplementary.ProcessUnstructuredSSResponse;
@@ -63,6 +68,7 @@
import org.mobicents.ussdgateway.Dialog;
import org.mobicents.ussdgateway.DialogType;
import org.mobicents.ussdgateway.EventsSerializeFactory;
+import org.mobicents.ussdgateway.UssdPropertiesManagement;
import org.mobicents.ussdgateway.rules.ScRoutingRule;
import org.mobicents.ussdgateway.slee.cdr.AbortType;
import org.mobicents.ussdgateway.slee.cdr.ChargeInterface;
@@ -94,6 +100,35 @@
protected Tracer logger;
private EventsSerializeFactory eventsSerializeFactory = null;
+
+ private TimerFacility timerFacility = null;
+
+ private static final UssdPropertiesManagement ussdPropertiesManagement =
UssdPropertiesManagement.getInstance();
+
+ /**
+ * Timer event
+ */
+ public void onTimerEvent(TimerEvent event, ActivityContextInterface
aci) {
+
+ if (this.logger.isWarningEnabled()) {
+ this.logger.warning(String.format(
+ "Application didn't revert in %d milliseconds. Sending back
dialogtimeouterrmssg",
+
ussdPropertiesManagement.getDialogTimeout()));
+ }
+
+ try {
+ MAPDialogSupplementary mapDialogSupplementary =
(MAPDialogSupplementary) aci.getActivity();
+ String errorMssg =
ussdPropertiesManagement.getDialogTimeoutErrorMessage();
+ this.sendErrorMessage(mapDialogSupplementary,
errorMssg);
+ } catch (Exception e) {
+ logger.severe("Error while trying to send Dialog timeout error message
to user", e);
+ } finally {
+ // this.getCDRChargeInterface().createTerminateRecord();
+ // TODO CDR?
+ }
+
+ this.terminateProtocolConnection();
+ }
// //////////////////////
// MAP Stuff handlers //
@@ -105,45 +140,36 @@
public void onProcessUnstructuredSSRequest(ProcessUnstructuredSSRequest
evt, ActivityContextInterface aci) {
try {
- if (this.checkProtocolConnection()) {
- if (this.logger.isFineEnabled()) {
- this.logger.fine("Received PROCESS_UNSTRUCTURED_SS_REQUEST_INDICATION
for MAP Dialog Id "
- + evt.getMAPDialog().getDialogId() + ", with active session,
terminating both.");
- }
- try {
- this.abort(evt.getMAPDialog());
- } catch (MAPException e) {
- this.logger.severe("Error while aborting
MAPDialog ", e);
- }
- terminateProtocolConnection();
- } else {
- if (this.logger.isFineEnabled()) {
- this.logger.fine("Received PROCESS_UNSTRUCTURED_SS_REQUEST_INDICATION
for MAP Dialog Id "
- +
evt.getMAPDialog().getDialogId());
- }
- Dialog dialog = this.getDialog();
- dialog.setMAPMessage(((MAPEvent)
evt).getWrappedEvent());
- ChargeInterface cdrInterface =
this.getCDRChargeInterface();
- USSDCDRState state = cdrInterface.getState();
- if (!state.isInitialized()) {
- String serviceCode =
evt.getUSSDString().getString();
- serviceCode = serviceCode.substring(serviceCode.indexOf("*") + 1,
serviceCode.indexOf("#"));
- state.init(dialog.getId(), serviceCode, dialog.getDestReference(),
dialog.getOrigReference(), evt
- .getMSISDNAddressString(), evt.getMAPDialog().getLocalAddress(),
evt.getMAPDialog()
- .getRemoteAddress());
- cdrInterface.setState(state);
- cdrInterface.createInitRecord();
- // attach, in case impl wants to use
more of dialog.
- SbbLocalObject sbbLO = (SbbLocalObject)
cdrInterface;
- aci.attach(sbbLO);
- } else {
- // use this, since getDialog.type is
not changed now
- cdrInterface.createContinueRecord();
- }
- byte[] data =
this.getEventsSerializeFactory().serialize(dialog);
- this.sendUssdData(data);
+ if (this.logger.isFineEnabled()) {
+ this.logger.fine("Received PROCESS_UNSTRUCTURED_SS_REQUEST_INDICATION
for MAP Dialog Id "
+ +
evt.getMAPDialog().getDialogId());
}
+
+
this.setProcessUnstructuredSSRequestInvokeId(evt.getInvokeId());
+ this.setTimer(aci);
+
+ Dialog dialog = this.getDialog();
+ dialog.setMAPMessage(((MAPEvent)
evt).getWrappedEvent());
+ ChargeInterface cdrInterface =
this.getCDRChargeInterface();
+ USSDCDRState state = cdrInterface.getState();
+ if (!state.isInitialized()) {
+ String serviceCode =
evt.getUSSDString().getString();
+ serviceCode = serviceCode.substring(serviceCode.indexOf("*") + 1,
serviceCode.indexOf("#"));
+ state.init(dialog.getId(), serviceCode, dialog.getDestReference(),
dialog.getOrigReference(), evt
+ .getMSISDNAddressString(), evt.getMAPDialog().getLocalAddress(),
evt.getMAPDialog()
+ .getRemoteAddress());
+ cdrInterface.setState(state);
+ cdrInterface.createInitRecord();
+ // attach, in case impl wants to use more of
dialog.
+ SbbLocalObject sbbLO = (SbbLocalObject)
cdrInterface;
+ aci.attach(sbbLO);
+ } else {
+ // use this, since getDialog.type is not
changed now
+ cdrInterface.createContinueRecord();
+ }
+ byte[] data =
this.getEventsSerializeFactory().serialize(dialog);
+ this.sendUssdData(data);
} catch (Exception e) {
logger.severe(
String.format("Exception while processing
PROCESS_UNSTRUCTURED_SS_REQUEST_INDICATION = %s", evt), e);
@@ -153,31 +179,21 @@
public void onUnstructuredSSResponse(UnstructuredSSResponse evt,
ActivityContextInterface aci) {
try {
- if (!this.checkProtocolConnection()) {
- if (this.logger.isFineEnabled()) {
- this.logger.fine("Received UNSTRUCTURED_SS_RESPONSE_INDICATION for
MAP Dialog Id "
- + evt.getMAPDialog().getDialogId() + ", without active session,
terminating both.");
- }
- try {
- this.abort(evt.getMAPDialog());
- } catch (MAPException e) {
- this.logger.severe("Error while aborting
MAPDialog ", e);
- }
- terminateProtocolConnection();
- } else {
- if (this.logger.isFineEnabled()) {
- this.logger.fine("Received UNSTRUCTURED_SS_RESPONSE_INDICATION for
MAP Dialog Id "
- +
evt.getMAPDialog().getDialogId());
- }
- Dialog dialog = new Dialog(DialogType.CONTINUE,
evt.getMAPDialog().getDialogId(), null, null);
- dialog.setMAPMessage(((MAPEvent)
evt).getWrappedEvent());
-
this.getCDRChargeInterface().createContinueRecord();
- EventsSerializeFactory factory =
this.getEventsSerializeFactory();
- byte[] data = factory.serialize(dialog);
-
- this.sendUssdData(data);
+ if (this.logger.isFineEnabled()) {
+ this.logger.fine("Received UNSTRUCTURED_SS_RESPONSE_INDICATION for MAP
Dialog Id "
+ +
evt.getMAPDialog().getDialogId());
}
+
+ this.setTimer(aci);
+
+ Dialog dialog = new Dialog(DialogType.CONTINUE,
evt.getMAPDialog().getDialogId(), null, null);
+ dialog.setMAPMessage(((MAPEvent)
evt).getWrappedEvent());
+ this.getCDRChargeInterface().createContinueRecord();
+ EventsSerializeFactory factory =
this.getEventsSerializeFactory();
+ byte[] data = factory.serialize(dialog);
+
+ this.sendUssdData(data);
} catch (Exception e) {
logger.severe(String.format("Exception while processing
UNSTRUCTURED_SS_RESPONSE_INDICATION = %s", evt), e);
// TODO Abort DIalog?
@@ -190,13 +206,13 @@
public void onDialogDelimiter(DialogDelimiter evt,
ActivityContextInterface aci) {
if (logger.isFineEnabled()) {
- this.logger.fine("Rx : onDialogDelimiter" + evt);
+ this.logger.fine("Rx : onDialogDelimiter " + evt);
}
}
public void onDialogAccept(DialogAccept evt, ActivityContextInterface
aci) {
if (logger.isFineEnabled()) {
- this.logger.fine("Rx : onDialogAccept" + evt);
+ this.logger.fine("Rx : onDialogAccept " + evt);
}
}
@@ -213,6 +229,7 @@
if (logger.isWarningEnabled()) {
this.logger.warning("Rx : DialogUserAbort " + evt);
}
+
// TODO: CDR, how this should be covered?
// TODO : Should we add any xml content?
this.terminateProtocolConnection();
@@ -308,6 +325,15 @@
* @return
*/
protected abstract boolean checkProtocolConnection();
+
+ protected void sendErrorMessage(MAPDialogSupplementary
mapDialogSupplementary, String errorMssg)
+ throws MAPException {
+ USSDString ussdString =
mapParameterFactory.createUSSDString(errorMssg);
+
mapDialogSupplementary.addProcessUnstructuredSSResponse(this.getProcessUnstructuredSSRequestInvokeId(),
+ (byte) 0x00, ussdString);
+ mapDialogSupplementary.close(false);
+
+ }
// ///////////////////
// Charge interface //
@@ -357,6 +383,8 @@
this.mapProvider = (MAPProvider)
this.sbbContext.getResourceAdaptorInterface(mapRATypeID, mapRaLink);
this.mapParameterFactory =
this.mapProvider.getMAPParameterFactory();
+ this.timerFacility = this.sbbContext.getTimerFacility();
+
} catch (Exception ne) {
logger.severe("Could not set SBB context:", ne);
}
@@ -410,6 +438,17 @@
public abstract USSDCDRState getCDRState();
+ // 'timerID' CMP field setter
+ public abstract void setTimerID(TimerID value);
+
+ // 'timerID' CMP field getter
+ public abstract TimerID getTimerID();
+
+ public abstract void setProcessUnstructuredSSRequestInvokeId(long
processUnstructuredSSRequestInvokeId);
+
+ // 'timerID' CMP field getter
+ public abstract long getProcessUnstructuredSSRequestInvokeId();
+
// //////////////////
// SBB LO methods //
// //////////////////
@@ -559,4 +598,23 @@
}
// TODO : Check if the Dialog Type is CONTINUE or END?
}
+
+ protected void cancelTimer() {
+ try {
+ TimerID timerID = this.getTimerID();
+ if (timerID != null) {
+ this.timerFacility.cancelTimer(timerID);
+ }
+ } catch (Exception e) {
+ logger.severe("Could not cancel Timer", e);
+ }
+ }
+
+ private void setTimer(ActivityContextInterface ac) {
+ TimerOptions options = new TimerOptions();
+ long waitingTime = ussdPropertiesManagement.getDialogTimeout();
+ // Set the timer on ACI
+ TimerID timerID = this.timerFacility.setTimer(ac, null,
System.currentTimeMillis() + waitingTime, options);
+ this.setTimerID(timerID);
+ }
}
=======================================
---
/core/slee/sbbs/src/main/java/org/mobicents/ussdgateway/slee/http/HttpClientSbb.java
Sun Aug 19 10:20:29 2012
+++
/core/slee/sbbs/src/main/java/org/mobicents/ussdgateway/slee/http/HttpClientSbb.java
Wed Aug 22 14:09:24 2012
@@ -86,6 +86,8 @@
public void onResponseEvent(ResponseEvent event, ActivityContextInterface
aci) {
+ this.cancelTimer();
+
HttpResponse response = event.getHttpResponse();
HttpClientActivity httpClientActivity = ((HttpClientActivity)
aci.getActivity());
=======================================
--- /core/slee/sbbs/src/main/resources/META-INF/sbb-jar.xml Tue May 22
00:37:35 2012
+++ /core/slee/sbbs/src/main/resources/META-INF/sbb-jar.xml Wed Aug 22
14:09:24 2012
@@ -105,12 +105,10 @@
<sbb-abstract-class>
<sbb-abstract-class-name>org.mobicents.ussdgateway.slee.http.HttpClientSbb</sbb-abstract-class-name>
- <cmp-field>
- <cmp-field-name>call</cmp-field-name>
- </cmp-field>
- <cmp-field>
- <cmp-field-name>dialog</cmp-field-name>
- </cmp-field>
+
<cmp-field><cmp-field-name>call</cmp-field-name></cmp-field>
+
<cmp-field><cmp-field-name>dialog</cmp-field-name></cmp-field>
+
<cmp-field><cmp-field-name>processUnstructuredSSRequestInvokeId</cmp-field-name></cmp-field>
+
<cmp-field><cmp-field-name>timerID</cmp-field-name></cmp-field>
<get-child-relation-method>
<sbb-alias-ref>CDRSbb</sbb-alias-ref>
<get-child-relation-method-name>getCDRInterfaceChildRelation</get-child-relation-method-name>
@@ -122,6 +120,15 @@
</sbb-local-interface>
</sbb-classes>
+ <event event-direction="Receive" initial-event="False">
+ <event-name>TimerEvent</event-name>
+ <event-type-ref>
+
<event-type-name>javax.slee.facilities.TimerEvent</event-type-name>
+
<event-type-vendor>javax.slee</event-type-vendor>
+ <event-type-version>1.0</event-type-version>
+ </event-type-ref>
+ </event>
+
<!-- USSD Events -->
<event event-direction="Receive" initial-event="False">
<event-name>ProcessUnstructuredSSRequest</event-name>