---
title: "jsr289 学习手记（一）"
author: "terrycong"
date: "2009-09-08T13:36:25Z"
tags: []
slug: "jsr289"
draft: false
lastmod: "2009-09-08T13:39:05Z"
id: 464697
url: "https://terrycong.iteye.com/blog/464697"
---

jsr289 学习手记
jsr289是jcp在2008年推出的sip servlet 1.1标准。代替之前比较旧的jsr116 sip servlet1.0
近段时间在看这个。
没有很多有条理的归纳，只是以提纲提要的形式归纳一下就好。

1 如果应用设置了load on startup的时候报错，容器应该调用SipApplicationRouter.applicationUndeployed().方法

2 sip servlet 与Http servlet生命周期类似，一次初始化，多次反复调用

3 Servlet接口内If the message is a request the response argument MUST be null, and if the message is a response, the request argument MUST be null.

4 SipServlet内有一大堆do***方法，其中很多方法默认的response是501/nothing
but The doAck and doCancel do nothing

5 如果接收到unknown的request，按么可以override doRequest()方法

6 在所有情况下都会被容器调用service()而调用，并且带有一个request的  object和null的response

7 调用过程中出错的话必须返回500，最好在sip Header给出出错信息
8不要手动修改from 和to的头的tag，交由容器管理
9为提高性能，尽快创建ApplicationSession和sipSession对象
10 Session
From the SDP specification: “A multimedia session is a set of multimedia senders and receivers and the data streams flowing from senders to receivers. A multimedia conference is an example of a multimedia session.”  (A session as defined for SDP can comprise one or more RTP sessions.) As defined, a callee can be invited several times, by different calls, to the same session. If SDP is used, a session is defined by the concatenation of the user name, session id, network type, address type and address elements in the origin field.

11 SIP transaction
A SIP transaction occurs between a client and a server and comprises all messages from the first request sent from the client to the server up to a final (non-1xx) response sent from the server to the client.
核心API：

12 并行搜索：同时向多个地址发送请求，寻找其中的有效的案例。

SipFactory sipfactory = (SipFactory) getServletContext().getAttribute(
				SIP_FACTORY);

相比上一版本的改进
不再将from和to header定义为System header以便提供更加灵活的身份识别。RFC 4916