Skip to content

Commit

Permalink
Merge pull request #29618 from TiborBeres/28193-allowReProxyOnCancell…
Browse files Browse the repository at this point in the history
…edBranch

allow reproxy of request on cancelled branch
  • Loading branch information
TiborBeres authored Nov 22, 2024
2 parents 06d4e61 + 28e25da commit 80a99c0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -2015,3 +2030,4 @@ public OutboundInterface getOutboundInterface(InetSocketAddress address) {
}

}

Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -794,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);
Expand Down

0 comments on commit 80a99c0

Please sign in to comment.