Revision: 15595
Author: [email protected]
Date: Wed Dec 1 08:25:59 2010
Log: Update Issue 1875
test for stateful proxy use case working
http://code.google.com/p/mobicents/source/detail?r=15595
Modified:
/trunk/servers/jain-sip-ha/core/src/main/java/gov/nist/javax/sip/stack/MobicentsHASIPserverTransaction.java
/trunk/servers/jain-sip-ha/core/src/main/java/org/mobicents/ha/javax/sip/ClusteredSipStackImpl.java
/trunk/servers/jain-sip-ha/jboss-5/src/test/java/org/mobicents/ha/javax/sip/ProxyEarlyDialogRecoveryOn1xxTest.java
/trunk/servers/jain-sip-ha/jboss-5/src/test/java/org/mobicents/ha/javax/sip/SimpleStatefulProxy.java
=======================================
---
/trunk/servers/jain-sip-ha/core/src/main/java/gov/nist/javax/sip/stack/MobicentsHASIPserverTransaction.java
Tue Nov 30 11:48:22 2010
+++
/trunk/servers/jain-sip-ha/core/src/main/java/gov/nist/javax/sip/stack/MobicentsHASIPserverTransaction.java
Wed Dec 1 08:25:59 2010
@@ -145,7 +145,9 @@
String dialogId = (String) transactionMetaData.get(DIALOG_ID);
if(dialogId != null) {
SIPDialog sipDialog = sipStack.getDialog(dialogId);
- setDialog(sipDialog, dialogId);
+ if(sipDialog != null) {
+ setDialog(sipDialog, dialogId);
+ }
if
(sipStack.getStackLogger().isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
sipStack.getStackLogger().logDebug(transactionId + " : dialog Id " +
dialogId + " dialog " + sipDialog);
}
=======================================
---
/trunk/servers/jain-sip-ha/core/src/main/java/org/mobicents/ha/javax/sip/ClusteredSipStackImpl.java
Mon Nov 29 12:25:49 2010
+++
/trunk/servers/jain-sip-ha/core/src/main/java/org/mobicents/ha/javax/sip/ClusteredSipStackImpl.java
Wed Dec 1 08:25:59 2010
@@ -442,7 +442,16 @@
// fetch the corresponding server transaction
from the cache instance
try {
sipTransaction =
sipCache.getServerTransaction(transactionId);
- serverTransactionTable.put(transactionId, (SIPServerTransaction)
sipTransaction);
+ if(sipTransaction != null) {
+
if(getStackLogger().isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
+ getStackLogger().logDebug("sipStack " + this + " transaction " +
transactionId + " server = " + isServer + " is present in the distributed
cache");
+ }
+ serverTransactionTable.put(transactionId, (SIPServerTransaction)
sipTransaction);
+ } else {
+
if(getStackLogger().isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
+ getStackLogger().logDebug("sipStack " + this + " transaction " +
transactionId + " server = " + isServer + " is not present in the
distributed cache");
+ }
+ }
} catch (SipCacheException e) {
getStackLogger().logError("sipStack " + this + " problem getting
transaction " + transactionId + " server = " + isServer + " from the
distributed cache", e);
}
=======================================
---
/trunk/servers/jain-sip-ha/jboss-5/src/test/java/org/mobicents/ha/javax/sip/ProxyEarlyDialogRecoveryOn1xxTest.java
Wed Dec 1 07:18:45 2010
+++
/trunk/servers/jain-sip-ha/jboss-5/src/test/java/org/mobicents/ha/javax/sip/ProxyEarlyDialogRecoveryOn1xxTest.java
Wed Dec 1 08:25:59 2010
@@ -762,7 +762,7 @@
throw new IllegalStateException("The From and To Headers are
reversed !!!!");
}
try {
- if(failoverOn2xx || failoverOn1xx) {
+ if(failoverOn1xx && stopNodeOnReinvite) {
//restart the sip stack
try {
proxyNode1.initStack(IP_ADDRESS, ListeningPoint.UDP);
@@ -1262,14 +1262,14 @@
shootist = new Shootist("shootist_reinvite", true);
shootme = new Shootme("shootme_reinvite", 5070, true);
- proxyNode1 = new SimpleStatefulProxy("proxyNode1_reinvite",
IP_ADDRESS, 5080, ListeningPoint.UDP,
ReplicationStrategy.ConfirmedDialogNoApplicationData);
+ proxyNode1 = new SimpleStatefulProxy("proxyNode1_reinvite",
IP_ADDRESS, 5080, ListeningPoint.UDP, ReplicationStrategy.EarlyDialog);
Thread.sleep(5000);
- proxyNode2 = new SimpleStatefulProxy("proxyNode2_reinvite",
IP_ADDRESS, 5081, ListeningPoint.UDP,
ReplicationStrategy.ConfirmedDialogNoApplicationData);
+ proxyNode2 = new SimpleStatefulProxy("proxyNode2_reinvite",
IP_ADDRESS, 5081, ListeningPoint.UDP, ReplicationStrategy.EarlyDialog);
proxyNode1.pingBalancer();
Thread.sleep(1000);
proxyNode2.pingBalancer();
Thread.sleep(1000);
-// shootist.setFailoverOn2xx(true);
+ shootist.setFailoverOn2xx(true);
shootme.init();
shootist.init("ReInvite");
@@ -1336,9 +1336,9 @@
shootist = new Shootist("shootist_reinvite", true);
shootme = new Shootme("shootme_reinvite", 5070, true);
- proxyNode1 = new SimpleStatefulProxy("proxyNode1_reinvite",
IP_ADDRESS, 5080, ListeningPoint.UDP,
ReplicationStrategy.ConfirmedDialogNoApplicationData);
+ proxyNode1 = new SimpleStatefulProxy("proxyNode1_reinvite",
IP_ADDRESS, 5080, ListeningPoint.UDP, ReplicationStrategy.EarlyDialog);
Thread.sleep(5000);
- proxyNode2 = new SimpleStatefulProxy("proxyNode2_reinvite",
IP_ADDRESS, 5081, ListeningPoint.UDP,
ReplicationStrategy.ConfirmedDialogNoApplicationData);
+ proxyNode2 = new SimpleStatefulProxy("proxyNode2_reinvite",
IP_ADDRESS, 5081, ListeningPoint.UDP, ReplicationStrategy.EarlyDialog);
Thread.sleep(5000);
proxyNode1.pingBalancer();
Thread.sleep(1000);
@@ -1411,9 +1411,9 @@
shootist = new Shootist("shootist_reinvite", true);
shootme = new Shootme("shootme_reinvite", 5070, true);
- proxyNode1 = new SimpleStatefulProxy("proxyNode1_reinvite",
IP_ADDRESS, 5080, ListeningPoint.UDP,
ReplicationStrategy.ConfirmedDialogNoApplicationData);
+ proxyNode1 = new SimpleStatefulProxy("proxyNode1_reinvite",
IP_ADDRESS, 5080, ListeningPoint.UDP, ReplicationStrategy.EarlyDialog);
Thread.sleep(5000);
- proxyNode2 = new SimpleStatefulProxy("proxyNode2_reinvite",
IP_ADDRESS, 5081, ListeningPoint.UDP,
ReplicationStrategy.ConfirmedDialogNoApplicationData);
+ proxyNode2 = new SimpleStatefulProxy("proxyNode2_reinvite",
IP_ADDRESS, 5081, ListeningPoint.UDP, ReplicationStrategy.EarlyDialog);
Thread.sleep(5000);
proxyNode1.pingBalancer();
Thread.sleep(1000);
=======================================
---
/trunk/servers/jain-sip-ha/jboss-5/src/test/java/org/mobicents/ha/javax/sip/SimpleStatefulProxy.java
Wed Dec 1 07:18:45 2010
+++
/trunk/servers/jain-sip-ha/jboss-5/src/test/java/org/mobicents/ha/javax/sip/SimpleStatefulProxy.java
Wed Dec 1 08:25:59 2010
@@ -70,7 +70,9 @@
private HeaderFactory headerFactory;
private AddressFactory addressFactory;
private ServerTransaction serverTransaction;
- private ClientTransaction clientTransaction;
+ private ClientTransaction clientTransaction;
+ private String currentCtxBranchId;
+ private Integer currentCtxRemotePort;
int myPort;
String transport;
String ipAddress;
@@ -135,6 +137,19 @@
((SipStackImpl)sipStack).getStackLogger().logError("unexpected
exception", e);
}
}
+
+ private void storeClientTransactionId(String branchId, int port) {
+
((ClusteredSipStack)sipProvider.getSipStack()).getStackLogger().logDebug("Storing
client Id " + branchId + " and remote port" + port);
+ currentCtxBranchId = branchId;
+ currentCtxRemotePort = Integer.valueOf(port);
+ try {
+
((MobicentsSipCache)((ClusteredSipStack)sipProvider.getSipStack()).getSipCache()).getMobicentsCache().getJBossCache().put(Fqn.fromString("CTX_IDS"), "clientTransactionId",
branchId);
+
((MobicentsSipCache)((ClusteredSipStack)sipProvider.getSipStack()).getSipCache()).getMobicentsCache().getJBossCache().put(Fqn.fromString("CTX_PORT"), "clientTransactionRemotePort",
currentCtxRemotePort);
+ } catch (CacheException e) {
+ // TODO Auto-generated catch block
+ ((SipStackImpl)sipStack).getStackLogger().logError("unexpected
exception", e);
+ }
+ }
/**
* @return the outgoingDialog
@@ -153,7 +168,8 @@
if(serverTransactionId == null) {
return null;
}
- return (ServerTransaction)
((ClusteredSipStack)sipProvider.getSipStack()).findTransaction(serverTransactionId,
true);
+ serverTransaction = (ServerTransaction)
((ClusteredSipStack)sipProvider.getSipStack()).findTransaction(serverTransactionId,
true);
+ return serverTransaction;
}
/**
@@ -175,6 +191,36 @@
}
return (ClientTransaction)
((ClusteredSipStack)sipProvider.getSipStack()).findTransaction(clientTransactionId,
false);
}
+
+ /**
+ * @return the outgoingDialog
+ */
+ public String getClientTransactionId() {
+ String clientTransactionId = currentCtxBranchId;
+ if(clientTransactionId == null) {
+ try {
+ clientTransactionId = (String)
((MobicentsSipCache)((ClusteredSipStack)sipProvider.getSipStack()).getSipCache()).getMobicentsCache().getJBossCache().get(Fqn.fromString("CTX_IDS"), "clientTransactionId");
+ } catch (CacheException e) {
+ ((SipStackImpl)sipStack).getStackLogger().logError("unexpected
exception", e);
+ }
+ }
+ return clientTransactionId;
+ }
+
+ /**
+ * @return the outgoingDialog
+ */
+ public int getClientTransactionPort() {
+ Integer clientTransactionRemotePort = currentCtxRemotePort;
+ if(clientTransactionRemotePort == null) {
+ try {
+ clientTransactionRemotePort = (Integer)
((MobicentsSipCache)((ClusteredSipStack)sipProvider.getSipStack()).getSipCache()).getMobicentsCache().getJBossCache().get(Fqn.fromString("CTX_PORT"), "clientTransactionRemotePort");
+ } catch (CacheException e) {
+ ((SipStackImpl)sipStack).getStackLogger().logError("unexpected
exception", e);
+ }
+ }
+ return clientTransactionRemotePort.intValue();
+ }
public void processInvite(RequestEvent requestEvent) {
//System.out.println("Got invite: "+requestEvent.getRequest());
@@ -220,10 +266,15 @@
}
RecordRouteHeader recordRouteHeader =
headerFactory.createRecordRouteHeader(address);
request.addFirst(recordRouteHeader);
+ RouteHeader routeHeader = (RouteHeader)
request.getHeader(RouteHeader.NAME);
+ if(routeHeader != null &&
(((SipURI)routeHeader.getAddress().getURI()).getPort() == 5080 ||
((SipURI)routeHeader.getAddress().getURI()).getPort() == 5081)) {
+ request.removeFirst(RouteHeader.NAME);
+ }
request.addHeader(headerFactory.createViaHeader(ipAddress, myPort,
transport, null));
- ClientTransaction ct =
sipProvider.getNewClientTransaction(request);
+ ClientTransaction ct =
sipProvider.getNewClientTransaction(request);
clientTransaction = ct;
clientTransaction.sendRequest();
+ storeClientTransactionId(clientTransaction.getBranchId(),
peerPort);
}
@SuppressWarnings("unchecked")
@@ -243,10 +294,14 @@
((ClusteredSipStack)sipStack).getStackLogger().logDebug("remotePort = "
+ remotePort);
try {
final Request ack = (Request)
requestEvent.getRequest().clone();
- String branchId = getClientTransaction().getBranchId();
+ String branchId = getClientTransactionId();
ack.addHeader(headerFactory.createViaHeader(ipAddress, myPort,
transport, branchId));
-
((SipURI)ack.getRequestURI()).setPort(((SipURI)getClientTransaction().getRequest().getRequestURI()).getPort());
+
((SipURI)ack.getRequestURI()).setPort(getClientTransactionPort());
ack.removeLast(RouteHeader.NAME);
+ RouteHeader routeHeader = (RouteHeader)
ack.getHeader(RouteHeader.NAME);
+ if(routeHeader != null &&
(((SipURI)routeHeader.getAddress().getURI()).getPort() == 5080 ||
((SipURI)routeHeader.getAddress().getURI()).getPort() == 5081)) {
+ ack.removeFirst(RouteHeader.NAME);
+ }
sipProvider.sendRequest(ack);
} catch (Exception e) {
((SipStackImpl)sipStack).getStackLogger().logError("unexpected
exception", e);
@@ -273,6 +328,10 @@
final Request request = (Request)
requestEvent.getRequest().clone();
((SipURI)request.getRequestURI()).setPort(5070);
request.removeLast(RouteHeader.NAME);
+ RouteHeader routeHeader = (RouteHeader)
request.getHeader(RouteHeader.NAME);
+ if(routeHeader != null &&
(((SipURI)routeHeader.getAddress().getURI()).getPort() == 5080 ||
((SipURI)routeHeader.getAddress().getURI()).getPort() == 5081)) {
+ request.removeFirst(RouteHeader.NAME);
+ }
request.addHeader(headerFactory.createViaHeader(ipAddress, myPort,
transport, null));
final ClientTransaction ct =
sipProvider.getNewClientTransaction(request);
ct.sendRequest();
@@ -499,7 +558,10 @@
listeningPoint = null;
sipProvider = null;
sipFactory.resetFactory();
-
+ serverTransaction = null;
+ clientTransaction = null;
+ currentCtxBranchId = null;
+ currentCtxRemotePort = null;
if(stopSipStack){
sipStack.stop();
sipStack = null;