PageRenderTime 31ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/servers/jain-slee/resources/sip11/ra/src/main/java/org/mobicents/slee/resource/sip11/SleeSipProviderImpl.java

http://mobicents.googlecode.com/
Java | 732 lines | 436 code | 71 blank | 225 comment | 60 complexity | 3418de185813787436ba9bb763d3164f MD5 | raw file
Possible License(s): LGPL-3.0, GPL-3.0, LGPL-2.1, GPL-2.0, CC-BY-SA-3.0, CC0-1.0, Apache-2.0, BSD-3-Clause
  1. /*
  2. * JBoss, Home of Professional Open Source
  3. * Copyright 2011, Red Hat, Inc. and individual contributors
  4. * by the @authors tag. See the copyright.txt in the distribution for a
  5. * full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.mobicents.slee.resource.sip11;
  23. import gov.nist.javax.sip.DialogExt;
  24. import gov.nist.javax.sip.ListeningPointImpl;
  25. import gov.nist.javax.sip.Utils;
  26. import gov.nist.javax.sip.address.SipUri;
  27. import gov.nist.javax.sip.message.SIPRequest;
  28. import gov.nist.javax.sip.stack.SIPClientTransaction;
  29. import gov.nist.javax.sip.stack.SIPServerTransaction;
  30. import java.net.InetAddress;
  31. import java.net.UnknownHostException;
  32. import java.text.ParseException;
  33. import java.util.HashSet;
  34. import java.util.Set;
  35. import java.util.TooManyListenersException;
  36. import java.util.concurrent.ConcurrentHashMap;
  37. import javax.sip.ClientTransaction;
  38. import javax.sip.Dialog;
  39. import javax.sip.InvalidArgumentException;
  40. import javax.sip.ListeningPoint;
  41. import javax.sip.ObjectInUseException;
  42. import javax.sip.ServerTransaction;
  43. import javax.sip.SipException;
  44. import javax.sip.SipListener;
  45. import javax.sip.SipProvider;
  46. import javax.sip.SipStack;
  47. import javax.sip.Transaction;
  48. import javax.sip.TransactionAlreadyExistsException;
  49. import javax.sip.TransactionUnavailableException;
  50. import javax.sip.TransportAlreadySupportedException;
  51. import javax.sip.address.Address;
  52. import javax.sip.address.AddressFactory;
  53. import javax.sip.address.SipURI;
  54. import javax.sip.header.CallIdHeader;
  55. import javax.sip.header.FromHeader;
  56. import javax.sip.header.HeaderFactory;
  57. import javax.sip.header.ToHeader;
  58. import javax.sip.header.ViaHeader;
  59. import javax.sip.message.MessageFactory;
  60. import javax.sip.message.Request;
  61. import javax.sip.message.Response;
  62. import javax.slee.facilities.Tracer;
  63. import net.java.slee.resource.sip.CancelRequestEvent;
  64. import net.java.slee.resource.sip.DialogActivity;
  65. import net.java.slee.resource.sip.SleeSipProvider;
  66. import org.mobicents.ha.javax.sip.ClusteredSipStack;
  67. import org.mobicents.ha.javax.sip.LoadBalancerElector;
  68. import org.mobicents.slee.resource.sip11.wrappers.ClientTransactionWrapper;
  69. import org.mobicents.slee.resource.sip11.wrappers.DialogWrapper;
  70. import org.mobicents.slee.resource.sip11.wrappers.ClientDialogWrapper;
  71. import org.mobicents.slee.resource.sip11.wrappers.ServerTransactionWrapper;
  72. /**
  73. *
  74. * @author B.Baranowski
  75. * @author martins
  76. *
  77. */
  78. public class SleeSipProviderImpl implements SleeSipProvider {
  79. protected AddressFactory addressFactory = null;
  80. protected HeaderFactory headerFactory = null;
  81. protected MessageFactory messageFactory = null;
  82. protected ClusteredSipStack stack = null;
  83. protected SipResourceAdaptor ra = null;
  84. protected SipProvider provider = null;
  85. protected final Tracer tracer;
  86. private boolean active;
  87. public SleeSipProviderImpl(SipResourceAdaptor ra) {
  88. this.ra = ra;
  89. this.tracer = ra.getTracer(SleeSipProviderImpl.class.getSimpleName());
  90. }
  91. public void raActive(AddressFactory addressFactory,
  92. HeaderFactory headerFactory, MessageFactory messageFactory,
  93. ClusteredSipStack stack,SipProvider provider) {
  94. this.addressFactory = addressFactory;
  95. this.headerFactory = headerFactory;
  96. this.messageFactory = messageFactory;
  97. this.stack = stack;
  98. this.provider = provider;
  99. this.active = true;
  100. }
  101. public void raInactive() {
  102. this.addressFactory = null;
  103. this.headerFactory = null;
  104. this.messageFactory = null;
  105. this.stack = null;
  106. this.provider = null;
  107. this.active = false;
  108. }
  109. private void checkState() throws IllegalStateException {
  110. if (!active) {
  111. throw new IllegalStateException("ra not active");
  112. }
  113. }
  114. /**
  115. *
  116. * @return
  117. */
  118. public SipProvider getRealProvider() {
  119. return provider;
  120. }
  121. /*
  122. * (non-Javadoc)
  123. *
  124. * @see net.java.slee.resource.sip.SleeSipProvider#getAddressFactory()
  125. */
  126. public AddressFactory getAddressFactory() {
  127. checkState();
  128. return this.addressFactory;
  129. }
  130. /*
  131. * (non-Javadoc)
  132. *
  133. * @see net.java.slee.resource.sip.SleeSipProvider#getHeaderFactory()
  134. */
  135. public HeaderFactory getHeaderFactory() {
  136. checkState();
  137. return this.headerFactory;
  138. }
  139. private ConcurrentHashMap<String, SipUri> localSipURIs = new ConcurrentHashMap<String, SipUri>();
  140. /*
  141. * (non-Javadoc)
  142. *
  143. * @see
  144. * net.java.slee.resource.sip.SleeSipProvider#getLocalSipURI(java.lang.String
  145. * )
  146. */
  147. public SipURI getLocalSipURI(String transport) {
  148. checkState();
  149. SipUri sipURI = localSipURIs.get(localSipURIs);
  150. if (sipURI == null) {
  151. ListeningPoint lp = getListeningPoint(transport);
  152. if (lp != null) {
  153. sipURI = new SipUri();
  154. try {
  155. sipURI.setHost(lp.getIPAddress());
  156. sipURI.setTransportParam(transport);
  157. } catch (ParseException e) {
  158. tracer.severe("Failed to create local sip uri for transport "+transport,e);
  159. }
  160. sipURI.setPort(lp.getPort());
  161. localSipURIs.put(transport, sipURI);
  162. }
  163. }
  164. return sipURI;
  165. }
  166. /*
  167. * (non-Javadoc)
  168. *
  169. * @see
  170. * net.java.slee.resource.sip.SleeSipProvider#getLocalVia(java.lang.String,
  171. * java.lang.String)
  172. */
  173. public ViaHeader getLocalVia(String transport, String branch) {
  174. checkState();
  175. final ListeningPoint lp = provider.getListeningPoint(transport);
  176. if (lp != null) {
  177. try {
  178. return headerFactory.createViaHeader(lp.getIPAddress(), lp
  179. .getPort(), lp.getTransport(), branch);
  180. } catch (ParseException e) {
  181. tracer.severe(e.getMessage(), e);
  182. } catch (InvalidArgumentException e) {
  183. tracer.severe(e.getMessage(), e);
  184. }
  185. }
  186. return null;
  187. }
  188. /**
  189. *
  190. * @return
  191. * @throws InvalidArgumentException
  192. * @throws ParseException
  193. */
  194. public ViaHeader getLocalVia() throws ParseException,
  195. InvalidArgumentException {
  196. checkState();
  197. final ListeningPointImpl lp = (ListeningPointImpl) provider.getListeningPoints()[0];
  198. return lp != null ? lp.createViaHeader() : null;
  199. }
  200. /*
  201. * (non-Javadoc)
  202. *
  203. * @see net.java.slee.resource.sip.SleeSipProvider#getMessageFactory()
  204. */
  205. public MessageFactory getMessageFactory() {
  206. checkState();
  207. return this.messageFactory;
  208. }
  209. /*
  210. * (non-Javadoc)
  211. *
  212. * @see
  213. * net.java.slee.resource.sip.SleeSipProvider#isLocalHostname(java.lang.
  214. * String)
  215. */
  216. public boolean isLocalHostname(String host) {
  217. checkState();
  218. try {
  219. InetAddress[] addresses = InetAddress.getAllByName(host);
  220. Set<InetAddress> stackAddresses = new HashSet<InetAddress>();
  221. for (ListeningPoint lp : this.provider.getListeningPoints()) {
  222. InetAddress tmp = InetAddress.getByName(lp.getIPAddress());
  223. if (tmp != null)
  224. stackAddresses.add(tmp);
  225. }
  226. for (InetAddress ia : addresses) {
  227. if (stackAddresses.contains(ia))
  228. return true;
  229. }
  230. } catch (UnknownHostException e) {
  231. if (tracer.isFineEnabled()) {
  232. tracer.fine("Unknown host",e);
  233. }
  234. }
  235. return false;
  236. }
  237. /*
  238. * (non-Javadoc)
  239. *
  240. * @see
  241. * net.java.slee.resource.sip.SleeSipProvider#isLocalSipURI(javax.sip.address
  242. * .SipURI)
  243. */
  244. public boolean isLocalSipURI(SipURI uri) {
  245. checkState();
  246. // XXX: InetAddress api is
  247. // crude.....!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  248. ListeningPoint lp = this.provider.getListeningPoint(uri
  249. .getTransportParam());
  250. if (lp != null && lp.getIPAddress().equals(uri.getHost())
  251. && lp.getPort() == uri.getPort()) {
  252. return true;
  253. } else {
  254. if (tracer.isFineEnabled()) {
  255. tracer.fine("Passed uri not local? Passed URI[" + uri
  256. + "] doesnt match lp[" + lp + "]");
  257. }
  258. return false;
  259. }
  260. }
  261. /*
  262. * (non-Javadoc)
  263. *
  264. * @see javax.sip.SipProvider#addListeningPoint(javax.sip.ListeningPoint)
  265. */
  266. public void addListeningPoint(ListeningPoint arg0)
  267. throws ObjectInUseException, TransportAlreadySupportedException {
  268. throw new UnsupportedOperationException("No dynamic change to LP");
  269. }
  270. public void addSipListener(SipListener arg0)
  271. throws TooManyListenersException {
  272. throw new TooManyListenersException(
  273. "RA can be the only Listener for this stack!!");
  274. }
  275. /*
  276. * (non-Javadoc)
  277. *
  278. * @see javax.sip.SipProvider#getListeningPoint()
  279. */
  280. @SuppressWarnings("deprecation")
  281. public ListeningPoint getListeningPoint() {
  282. checkState();
  283. return this.provider.getListeningPoint();
  284. }
  285. /*
  286. * (non-Javadoc)
  287. *
  288. * @see javax.sip.SipProvider#getListeningPoint(java.lang.String)
  289. */
  290. public ListeningPoint getListeningPoint(String arg0) {
  291. checkState();
  292. return this.provider.getListeningPoint(arg0);
  293. }
  294. /*
  295. * (non-Javadoc)
  296. *
  297. * @see javax.sip.SipProvider#getListeningPoints()
  298. */
  299. public ListeningPoint[] getListeningPoints() {
  300. checkState();
  301. return this.provider.getListeningPoints();
  302. }
  303. /*
  304. * (non-Javadoc)
  305. *
  306. * @see javax.sip.SipProvider#getNewCallId()
  307. */
  308. public CallIdHeader getNewCallId() {
  309. checkState();
  310. return this.provider.getNewCallId();
  311. }
  312. /*
  313. * (non-Javadoc)
  314. *
  315. * @see javax.sip.SipProvider#getSipStack()
  316. */
  317. public SipStack getSipStack() {
  318. throw new UnsupportedOperationException();
  319. }
  320. /*
  321. * (non-Javadoc)
  322. *
  323. * @see javax.sip.SipProvider#removeListeningPoint(javax.sip.ListeningPoint)
  324. */
  325. public void removeListeningPoint(ListeningPoint arg0)
  326. throws ObjectInUseException {
  327. throw new UnsupportedOperationException();
  328. }
  329. /*
  330. * (non-Javadoc)
  331. *
  332. * @see javax.sip.SipProvider#removeSipListener(javax.sip.SipListener)
  333. */
  334. public void removeSipListener(SipListener arg0) {
  335. throw new UnsupportedOperationException();
  336. }
  337. /*
  338. * (non-Javadoc)
  339. *
  340. * @see javax.sip.SipProvider#sendRequest(javax.sip.message.Request)
  341. */
  342. public void sendRequest(Request arg0) throws SipException {
  343. checkState();
  344. this.provider.sendRequest(arg0);
  345. }
  346. /*
  347. * (non-Javadoc)
  348. *
  349. * @see javax.sip.SipProvider#sendResponse(javax.sip.message.Response)
  350. */
  351. public void sendResponse(Response arg0) throws SipException {
  352. checkState();
  353. this.provider.sendResponse(arg0);
  354. }
  355. /*
  356. * (non-Javadoc)
  357. *
  358. * @see javax.sip.SipProvider#setAutomaticDialogSupportEnabled(boolean)
  359. */
  360. public void setAutomaticDialogSupportEnabled(boolean arg0) {
  361. checkState();
  362. this.provider.setAutomaticDialogSupportEnabled(arg0);
  363. }
  364. /*
  365. * (non-Javadoc)
  366. *
  367. * @see javax.sip.SipProvider#setListeningPoint(javax.sip.ListeningPoint)
  368. */
  369. public void setListeningPoint(ListeningPoint arg0)
  370. throws ObjectInUseException {
  371. throw new UnsupportedOperationException();
  372. }
  373. /*
  374. * (non-Javadoc)
  375. *
  376. * @see
  377. * javax.sip.SipProvider#getNewClientTransaction(javax.sip.message.Request)
  378. */
  379. public ClientTransaction getNewClientTransaction(Request request)
  380. throws TransactionUnavailableException {
  381. checkState();
  382. // add load balancer to route if it is configured
  383. try {
  384. addLoadBalancerToRoute(request);
  385. } catch (SipException e) {
  386. throw new TransactionUnavailableException("Failed to add load balancer to route",e);
  387. }
  388. final SIPClientTransaction ct = (SIPClientTransaction) provider.getNewClientTransaction(request);
  389. final ClientTransactionWrapper ctw = new ClientTransactionWrapper(ct,
  390. ra);
  391. ctw.setActivity(true);
  392. final DialogWrapper dw = ctw.getDialogWrapper();
  393. if (dw != null) {
  394. dw.addOngoingTransaction(ctw);
  395. }
  396. if (!ra.addSuspendedActivity(ctw)) {
  397. throw new TransactionUnavailableException(
  398. "Failed to create activity");
  399. }
  400. return ctw;
  401. }
  402. /**
  403. * Creates a new {@link ClientTransactionWrapper} bound to a
  404. * {@link DialogWrapper}, which is not an activity in SLEE.
  405. *
  406. * @param dialogWrapper
  407. * @param request
  408. * @return
  409. * @throws TransactionUnavailableException
  410. */
  411. public ClientTransactionWrapper getNewDialogActivityClientTransaction(
  412. DialogWrapper dialogWrapper, Request request)
  413. throws TransactionUnavailableException {
  414. final SIPClientTransaction ct = (SIPClientTransaction) provider.getNewClientTransaction(request);
  415. final ClientTransactionWrapper ctw = new ClientTransactionWrapper(ct,
  416. ra);
  417. dialogWrapper.addOngoingTransaction(ctw);
  418. return ctw;
  419. }
  420. /*
  421. * (non-Javadoc)
  422. *
  423. * @see
  424. * javax.sip.SipProvider#getNewServerTransaction(javax.sip.message.Request)
  425. */
  426. public ServerTransaction getNewServerTransaction(Request request)
  427. throws TransactionAlreadyExistsException,
  428. TransactionUnavailableException {
  429. checkState();
  430. // TODO: add checks for wrapper
  431. final SIPServerTransaction st = (SIPServerTransaction) provider.getNewServerTransaction(request);
  432. ServerTransactionWrapper stw = new ServerTransactionWrapper(st, ra);
  433. if (stw.getDialogWrapper() == null) {
  434. // SLEE 1.1 specs: D.4
  435. // ServerTransaction Activity objects are created automatically when
  436. // the resource adaptor receives an
  437. // incoming SIP request. The activity ends when a final response is
  438. // sent on the ServerTransaction.
  439. stw.setActivity(true);
  440. if (!ra.addSuspendedActivity(stw)) {
  441. throw new TransactionUnavailableException(
  442. "Failed to create activity.");
  443. }
  444. }
  445. return stw;
  446. }
  447. /*
  448. * (non-Javadoc)
  449. *
  450. * @see javax.sip.SipProvider#getNewDialog(javax.sip.Transaction)
  451. */
  452. public Dialog getNewDialog(Transaction transaction) throws SipException {
  453. checkState();
  454. if (transaction.getClass() == ServerTransactionWrapper.class) {
  455. return getNewDialog((ServerTransactionWrapper) transaction);
  456. } else if (transaction.getClass() == ClientTransactionWrapper.class) {
  457. return getNewDialog((ClientTransactionWrapper) transaction);
  458. } else {
  459. throw new IllegalArgumentException("unknown transaction class");
  460. }
  461. }
  462. private Dialog getNewDialog(ServerTransactionWrapper stw) throws SipException {
  463. final ServerTransaction st = stw.getWrappedServerTransaction();
  464. final Dialog d = provider.getNewDialog(st);
  465. if(ra.disableSequenceNumberValidation())
  466. {
  467. ((DialogExt)d).disableSequenceNumberValidation();
  468. }
  469. String localTag = d.getLocalTag();
  470. String dialogId = d.getDialogId();
  471. if (localTag == null) {
  472. // some hacking in jsip, we need a dialog id now and the real dialog
  473. // does not have a local tag
  474. localTag = Utils.getInstance().generateTag();
  475. dialogId = ((SIPRequest) st.getRequest()).getDialogId(
  476. true, localTag);
  477. }
  478. final DialogWithIdActivityHandle h = new DialogWithIdActivityHandle(dialogId);
  479. final DialogWrapper dw = new DialogWrapper(h,ra);
  480. dw.setLocalTag(localTag);
  481. dw.setWrappedDialog(d);
  482. ra.addSuspendedActivity(dw);
  483. return dw;
  484. }
  485. private Dialog getNewDialog(ClientTransactionWrapper ctw) throws SipException {
  486. final Request r = ctw.getWrappedTransaction().getRequest();
  487. final FromHeader fh = (FromHeader)r.getHeader(FromHeader.NAME);
  488. String localTag = fh.getTag();
  489. if(localTag == null) {
  490. localTag = Utils.getInstance().generateTag();
  491. try {
  492. fh.setTag(localTag);
  493. } catch (ParseException e) {
  494. throw new SipException("Failed to set local tag.", e);
  495. }
  496. }
  497. final Dialog d = provider.getNewDialog(ctw.getWrappedTransaction());
  498. if(ra.disableSequenceNumberValidation())
  499. {
  500. ((DialogExt)d).disableSequenceNumberValidation();
  501. }
  502. final DialogWrapper dw = _getNewDialog(
  503. fh.getAddress(),
  504. localTag,
  505. ((ToHeader) r.getHeader(ToHeader.NAME)).getAddress(), d.getCallId());
  506. dw.setWrappedDialog(d);
  507. dw.addOngoingTransaction(ctw);
  508. return dw;
  509. }
  510. /*
  511. * (non-Javadoc)
  512. *
  513. * @see
  514. * net.java.slee.resource.sip.SleeSipProvider#getNewDialog(javax.sip.address
  515. * .Address, javax.sip.address.Address)
  516. */
  517. public DialogActivity getNewDialog(Address from, Address to)
  518. throws SipException {
  519. checkState();
  520. if (from == null) {
  521. throw new IllegalArgumentException("From address cant be null");
  522. }
  523. if (to == null) {
  524. throw new IllegalArgumentException("To address cant be null");
  525. }
  526. return _getNewDialog(from, gov.nist.javax.sip.Utils.getInstance()
  527. .generateTag(), to, null);
  528. }
  529. /*
  530. * (non-Javadoc)
  531. *
  532. * @see
  533. * net.java.slee.resource.sip.SleeSipProvider#getNewDialog(net.java.slee
  534. * .resource.sip.DialogActivity, boolean)
  535. */
  536. public DialogActivity getNewDialog(DialogActivity incomingDialog,
  537. boolean useSameCallId) throws SipException {
  538. checkState();
  539. if (incomingDialog == null || !incomingDialog.isServer()) {
  540. throw new IllegalArgumentException(
  541. "Incoming dialog is either null or is UAC dialog!!");
  542. }
  543. CallIdHeader callIdHeader = null;
  544. if (useSameCallId) {
  545. callIdHeader = incomingDialog.getCallId();
  546. }
  547. return _getNewDialog(incomingDialog.getRemoteParty(), Utils.getInstance().generateTag(), incomingDialog.getLocalParty(), callIdHeader);
  548. }
  549. /**
  550. *
  551. * @param from
  552. * @param to
  553. * @param callIdHeader
  554. * @return
  555. * @throws SipException
  556. */
  557. private DialogWrapper _getNewDialog(Address from, String localTag,
  558. Address to, CallIdHeader callIdHeader) throws SipException {
  559. if (callIdHeader == null) {
  560. callIdHeader = provider.getNewCallId();
  561. }
  562. final DialogWithoutIdActivityHandle h = new DialogWithoutIdActivityHandle(callIdHeader.getCallId(),
  563. localTag);
  564. final ClientDialogWrapper dw = new ClientDialogWrapper(h,ra);
  565. dw.setLocalTag(localTag);
  566. dw.setFromAddress(from);
  567. dw.setToAddress(to);
  568. dw.setCustomCallId(callIdHeader == null ? provider.getNewCallId()
  569. : callIdHeader);
  570. if (!ra.addSuspendedActivity(dw)) {
  571. throw new SipException("Failed to create activity.");
  572. }
  573. return dw;
  574. }
  575. /*
  576. * (non-Javadoc)
  577. *
  578. * @see
  579. * net.java.slee.resource.sip.SleeSipProvider#acceptCancel(net.java.slee
  580. * .resource.sip.CancelRequestEvent, boolean)
  581. */
  582. public boolean acceptCancel(CancelRequestEvent cancelEvent, boolean isProxy) {
  583. checkState();
  584. if (cancelEvent.getMatchingTransaction() != null) {
  585. try {
  586. Response response = this.getMessageFactory().createResponse(
  587. Response.OK, cancelEvent.getRequest());
  588. cancelEvent.getServerTransaction().sendResponse(response);
  589. } catch (Exception e) {
  590. // specs doesn't provide any throws clause
  591. throw new RuntimeException(e.getMessage(), e);
  592. }
  593. if (!isProxy)
  594. try {
  595. Response response = this.getMessageFactory()
  596. .createResponse(
  597. Response.REQUEST_TERMINATED,
  598. cancelEvent.getMatchingTransaction()
  599. .getRequest());
  600. cancelEvent.getMatchingTransaction().sendResponse(response);
  601. } catch (Exception e) {
  602. // specs doesn't provide any throws clause
  603. throw new RuntimeException(e.getMessage(), e);
  604. }
  605. return true;
  606. } else {
  607. if (!isProxy) {
  608. try {
  609. Response txDoesNotExistsResponse = this
  610. .getMessageFactory()
  611. .createResponse(
  612. Response.CALL_OR_TRANSACTION_DOES_NOT_EXIST,
  613. cancelEvent.getRequest());
  614. cancelEvent.getServerTransaction().sendResponse(
  615. txDoesNotExistsResponse);
  616. } catch (Exception e) {
  617. // specs doesn't provide any throws clause
  618. throw new RuntimeException(e.getMessage(), e);
  619. }
  620. }
  621. return false;
  622. }
  623. }
  624. /*
  625. * (non-Javadoc)
  626. *
  627. * @see
  628. * net.java.slee.resource.sip.SleeSipProvider#forwardForkedResponse(javax
  629. * .sip.ServerTransaction, javax.sip.message.Response)
  630. */
  631. public DialogActivity forwardForkedResponse(
  632. ServerTransaction origServerTransaction, Response response)
  633. throws SipException {
  634. // TODO
  635. throw new UnsupportedOperationException();
  636. }
  637. /**
  638. * @return the stack
  639. */
  640. public ClusteredSipStack getClusteredSipStack() {
  641. return stack;
  642. }
  643. /**
  644. *
  645. * @param r
  646. * @throws SipException
  647. */
  648. @SuppressWarnings("deprecation")
  649. public void addLoadBalancerToRoute(Request r) throws SipException {
  650. LoadBalancerElector loadBalancerElector = stack.getLoadBalancerElector();
  651. if (loadBalancerElector != null) {
  652. Address lbAddress = loadBalancerElector.getLoadBalancer();
  653. if (lbAddress == null) {
  654. return;
  655. }
  656. lbAddress = (Address) loadBalancerElector.getLoadBalancer().clone();
  657. ((SipURI)lbAddress.getURI()).setLrParam();
  658. r.addFirst(headerFactory.createRouteHeader(lbAddress));
  659. }
  660. }
  661. }