How great is the sum of them. If I should count them, they are more in number than the sand.

Serializable 使用心得

Aug 1, 2006
writeObject 和 readObject 必须是 private 的, 否则不会被调用. Object 的 field 的读写顺序, 遵循先进先出的原则. 从 ObjectInputStream 中读 Object 的原理是: 先从流中读出每个元素的类型, 例如是数组, String 还是Object 等, 如果是 Object, 就继续从流中读取这个类的描述信息, load 这个类, 然后取这个类的第一个非 Serializable 的父类的 public 无参数构造函数, 通过构造函数创建实例, 最后调用 readObject 或 defaultReadObject 为这个实例赋值. 从 3 可以看出, 在从 ObjectInputStream 中读出的 Object 时, 和写进去的不是同一个 Object. 不用怀疑, JVM 有办法调用你的类的 private 方法… [More]

SIP Servlet 示例之 Call Forward

Jul 23, 2006
Servlet 将收到的请求转发到指定的 URI. import java.io.IOException; import javax.servlet.sip.*; import javax.servlet.*; public class CallForward extends SipServlet { SipURI m_target = null; SipFactory m_sipFactory; public void init() throws ServletException { m_sipFactory = (SipFactory) getServletContext().getAttribute("javax.servlet.sip.SipFactory"); String forwardURI = (String) getInitParameter("target-uri"); m_target = (SipURI) m_sipFactory.createURI(forwardURI); } public void doRequest(SipServletRequest req) throws TooManyHopsException { log(req.toString()); // ... req.getProxy().proxyTo(m_target); } public void doResponse(SipServletResponse resp) throws IOException { log(resp.toString()); // ... } }

SIP Servlet 示例之 Call Screen

Jul 23, 2006
Screening list: alice@server.test 呼叫流程: sequenceDiagram Alice-Server: INVITE Server--Alice: 603 DECLINE Bob-Server: INVITE Server-Foo: INVITE Servlet 在 doRequest 方法中检查UA的URI是否在 Screening 列表中, 如果在, 返回 603 DECLINE 响应. import java.io.IOException; import java.util.*; import javax.servlet.sip.*; import javax.servlet.*; public class CallScreen extends SipServlet { Collection m_screenings; SipFactory m_sipFactory; public void init() throws ServletException { m_screenings = new Vector(); m_sipFactory = (SipFactory) getServletContext().getAttribute("javax.servlet.sip.SipFactory"); Enumeration names = getInitParameterNames(); if (names == null) { return; } while (names.hasMoreElements()) { String name = (String) names.nextElement(); if (name.startsWith("screening-uri")) { String screeningURI = (String) getInitParameter(name); try { SipURI uri = (SipURI) m_sipFactory.createURI(screeningURI); m_screenings.add(uri); } catch (ServletException e) { } } } } public void doRequest(SipServletRequest req) throws IOException { SipURI from = (SipURI) req.getFrom().getURI(); Iterator uris = m_screenings.iterator(); while (uris.hasNext()) { SipURI uri = (SipURI) uris.next(); if (uri.getHost().equals(from.getHost())) { SipServletResponse resp = req.createResponse(SipServletResponse.SC_DECLINE); try { resp.send(); } catch (java.io.IOException e) { } return; } } log(req.toString()); // ... } public void doResponse(SipServletResponse resp) throws IOException { log(resp.toString()); // ... } }

SSL/TLS 服务器配置

Jun 26, 2006
Secure Sockets Layer (SSL) 和 Transport Layer Security (TLS) 用于在客户端和服务器之间建立加密通信通道. Java 通过 JSSE(javax.net.ssl) , 提供了对 SSL 和 TLS 的支持. 通过其所提供的一系列 API, 开发者可以像使用普通 Socket 一样使用基于 SSL 或 TLS 的安全套接字, 而不用关心 SSL 和 TLS 协议的细节, 例如握手的流程等等. 这使利用 Java 开发安全的 SSL/TLS 服务器或客户端非常容易. 如何使用 javax.net.ssl, 在网上有很多相关的资料, 这里就不多说了. 下面主要说一说如何配置 SSL/TLS 服务器. Sun 在 JDK 中提供了一个安全钥匙与证书的管理工具 Keytool. Keytool 把钥匙, 证… [More]

Developing SIP Applications with SIP Servlet

Jun 24, 2006
原文来自 ATAC, 无网页连接. SIP, the Session Initiation Protocol, is a signaling protocol developed by the Internet Engineering Task Force (IETF) to allow interactive user sessions involving multimedia elements (such as voice, video, and instant messaging). SIP is currently the basic signaling and call setup protocol for IP telephony, and SIP applications are the basic way to provide voice and other multimedia services over IP. SIP, 会话初始协议(Session Initiation Protocol), 是由 IETF 制定的一种信令协议, 用于多方的多媒体通讯, 例如语音, 视频, 和即时通讯等. SIP 是当前 IP 电话的会话建立和信令控制的基础协议, SIP 应用也是实现基于 IP 网络的语音等多种多媒体应用的基本途径. SIP Servlet (JSR-116), developed through the Java Community Process (see www.jcp.org),… [More]