From d65cd7a7ae8af20358b496d10aa32c376f851ffd Mon Sep 17 00:00:00 2001 From: Tibor Beres Date: Wed, 11 Sep 2024 08:48:21 -0700 Subject: [PATCH 1/2] allow reproxy of request on cancelled branch --- .../ws/sip/container/proxy/BranchManager.java | 52 ++++++++++++------- .../ibm/ws/sip/properties/CoreProperties.java | 9 +++- 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/dev/com.ibm.ws.sipcontainer/src/com/ibm/ws/sip/container/proxy/BranchManager.java b/dev/com.ibm.ws.sipcontainer/src/com/ibm/ws/sip/container/proxy/BranchManager.java index 496698780bd7..fd59ad1d99a2 100644 --- a/dev/com.ibm.ws.sipcontainer/src/com/ibm/ws/sip/container/proxy/BranchManager.java +++ b/dev/com.ibm.ws.sipcontainer/src/com/ibm/ws/sip/container/proxy/BranchManager.java @@ -1195,28 +1195,43 @@ private ProxyBranchImpl createBranch(javax.servlet.sip.URI nextHop, if(!("sip".equals(nextHop.getScheme()) || "sips".equals(nextHop.getScheme()))){ throw new IllegalArgumentException ("Unsupported Scheme"); } - } - ProxyBranchImpl curBranch = ThreadLocalStorage.getCurrentBranch(); - if((curBranch != null) && curBranch.isCancelled()){ - throw new IllegalStateException("Cannot create Branches on a canceled proxy branch during doBranchResponse"); - } - - - //if this is a virtual branch we need special treatment - if (isVirtual) { - - if (proxy.isVirtualBranchExists()) { - //if the virtual branch exists already, we should throw IllegalStateException - throw new IllegalStateException("Virtual Branch Already exists"); - } - }else { - //check that no branch was created for this destination - //this check is relevant only for regular branches + + //check that no branch was created for this destination + //this check is relevant only for regular branches if (proxyBranchExists(nextHop)) { throw new IllegalStateException("Duplicate Branch - Attempt to proxy message to the same URI again: " + nextHop); } - } + } + if (PropertiesStore.getInstance().getProperties().getBoolean(CoreProperties.CHECK_STATE_WHEN_CREATING_PROXY_BRANCH)){ + + ProxyBranchImpl curBranch = ThreadLocalStorage.getCurrentBranch(); + + if((curBranch != null) && curBranch.isCancelled()){ + throw new IllegalStateException("Cannot create Branches on a canceled proxy branch during doBranchResponse"); + } + + //if this is a virtual branch we need special treatment + if (isVirtual) { + + if (proxy.isVirtualBranchExists()) { + //if the virtual branch exists already, we should throw IllegalStateException + throw new IllegalStateException("Virtual Branch Already exists"); + + } + } + } + + if(!PropertiesStore.getInstance().getProperties().getBoolean(CoreProperties.CHECK_STATE_WHEN_CREATING_PROXY_BRANCH)){ + if (isVirtual) { + //if the virtual branch exists already, return it + if (proxy.isVirtualBranchExists()) { + + return proxy.getVirtualBranch(); + + } + } + } // Create a new branch and send the request ProxyBranchImpl branch = new ProxyBranchImpl(nextHop, this, proxy, createdViaProxyTo,isVirtual); @@ -2015,3 +2030,4 @@ public OutboundInterface getOutboundInterface(InetSocketAddress address) { } } + diff --git a/dev/com.ibm.ws.sipcontainer/src/com/ibm/ws/sip/properties/CoreProperties.java b/dev/com.ibm.ws.sipcontainer/src/com/ibm/ws/sip/properties/CoreProperties.java index 23774ee681ff..9013756988b8 100644 --- a/dev/com.ibm.ws.sipcontainer/src/com/ibm/ws/sip/properties/CoreProperties.java +++ b/dev/com.ibm.ws.sipcontainer/src/com/ibm/ws/sip/properties/CoreProperties.java @@ -29,7 +29,14 @@ public class CoreProperties */ private static final transient LogMgr c_logger = Log .get(CoreProperties.class); - /** + + /** + * Check branch state before creating new branch + */ + public static final String CHECK_STATE_WHEN_CREATING_PROXY_BRANCH = "checkStateWhenCreatingProxyBranch"; + public static final boolean CHECK_STATE_WHEN_CREATING_PROXY_BRANCH_DEFAULT = true; + + /** * Maximum sipAppSessions allowed. */ public static final String MAX_APP_SESSIONS = "maxAppSessions"; From 28e25da6adfd99254e0d09a52e81bcb167e4936a Mon Sep 17 00:00:00 2001 From: Tibor Beres Date: Wed, 11 Sep 2024 09:13:57 -0700 Subject: [PATCH 2/2] updated copyright date --- .../src/com/ibm/ws/sip/container/proxy/BranchManager.java | 2 +- .../src/com/ibm/ws/sip/properties/CoreProperties.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/dev/com.ibm.ws.sipcontainer/src/com/ibm/ws/sip/container/proxy/BranchManager.java b/dev/com.ibm.ws.sipcontainer/src/com/ibm/ws/sip/container/proxy/BranchManager.java index fd59ad1d99a2..0e92e81367fe 100644 --- a/dev/com.ibm.ws.sipcontainer/src/com/ibm/ws/sip/container/proxy/BranchManager.java +++ b/dev/com.ibm.ws.sipcontainer/src/com/ibm/ws/sip/container/proxy/BranchManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2021 IBM Corporation and others. + * Copyright (c) 2003, 2021, 2024 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at diff --git a/dev/com.ibm.ws.sipcontainer/src/com/ibm/ws/sip/properties/CoreProperties.java b/dev/com.ibm.ws.sipcontainer/src/com/ibm/ws/sip/properties/CoreProperties.java index 9013756988b8..a8e6d9d7c787 100644 --- a/dev/com.ibm.ws.sipcontainer/src/com/ibm/ws/sip/properties/CoreProperties.java +++ b/dev/com.ibm.ws.sipcontainer/src/com/ibm/ws/sip/properties/CoreProperties.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2021 IBM Corporation and others. + * Copyright (c) 2003, 2021, 2024 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -801,6 +801,7 @@ static public void loadDefaultProperties(SipPropertiesMap properties) properties.setInt(MAX_APP_SESSIONS, MAX_APP_SESSIONS_DEFAULT,CustPropSource.DEFAULT); properties.setInt(MAX_MESSAGE_RATE, MAX_MESSAGE_RATE_DEFAULT,CustPropSource.DEFAULT); properties.setInt(MAX_RESPONSE_TIME, MAX_RESPONSE_TIME_DEFAULT,CustPropSource.DEFAULT); + properties.setBoolean(CHECK_STATE_WHEN_CREATING_PROXY_BRANCH, CHECK_STATE_WHEN_CREATING_PROXY_BRANCH_DEFAULT, CustPropSource.DEFAULT); properties.setInt(STAT_UPDATE_RANGE, STAT_UPDATE_RANGE_DEFAULT,CustPropSource.DEFAULT); properties.setInt(STAT_AVERAGE_PERIOD, STAT_AVERAGE_PERIOD_DEFAULT,CustPropSource.DEFAULT); properties.setInt(LOAD_UPDATE_PERIOD, LOAD_UPDATE_PERIOD_DEFAULT,CustPropSource.DEFAULT);