当前位置: 首页>>代码示例>>Java>>正文


Java Connection.setXMPPVersion方法代码示例

本文整理汇总了Java中org.androidpn.server.xmpp.net.Connection.setXMPPVersion方法的典型用法代码示例。如果您正苦于以下问题:Java Connection.setXMPPVersion方法的具体用法?Java Connection.setXMPPVersion怎么用?Java Connection.setXMPPVersion使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.androidpn.server.xmpp.net.Connection的用法示例。


在下文中一共展示了Connection.setXMPPVersion方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createSession

import org.androidpn.server.xmpp.net.Connection; //导入方法依赖的package包/类
/**
 * 在服务器和客户端之间创建一个新的会话,并返回它。
 * 
 * @param serverName
 *            服务名
 * @param connection
 *            连接
 * @param xpp
 *            XML解析器来处理传入的数据
 * @return 一个新创建的会话
 * @throws XmlPullParserException
 *             如果解析传入的数据时发生错误
 */
public static ClientSession createSession(String serverName,
		Connection connection, XmlPullParser xpp)
		throws XmlPullParserException {
	log.debug("createSession()...");

	if (!xpp.getName().equals("stream")) {
		throw new XmlPullParserException("坏的开始标签 (not stream)");
	}

	if (!xpp.getNamespace(xpp.getPrefix()).equals(ETHERX_NAMESPACE)) {
		throw new XmlPullParserException("不正确的名称空间的流");
	}

	String language = "en";
	for (int i = 0; i < xpp.getAttributeCount(); i++) {
		if ("lang".equals(xpp.getAttributeName(i))) {
			language = xpp.getAttributeValue(i);
		}
	}

	// 存储语言和版本信息
	connection.setLanaguage(language);
	connection.setXMPPVersion(MAJOR_VERSION, MINOR_VERSION);

	// 创建一个ClientSession
	ClientSession session = SessionManager.getInstance()
			.createClientSession(connection);

	// 建立开始数据包响应
	StringBuilder sb = new StringBuilder(200);
	sb.append("<?xml version='1.0' encoding='UTF-8'?>");
	sb.append("<stream:stream ");
	sb.append("xmlns:stream=\"http://etherx.jabber.org/streams\" xmlns=\"jabber:client\" from=\"");
	sb.append(serverName);
	sb.append("\" id=\"");
	sb.append(session.getStreamID().toString());
	sb.append("\" xml:lang=\"");
	sb.append(language);
	sb.append("\" version=\"");
	sb.append(MAJOR_VERSION).append(".").append(MINOR_VERSION);
	sb.append("\">");
	connection.deliverRawText(sb.toString());

	// XMPP 1.0 需要 stream features
	sb = new StringBuilder();
	sb.append("<stream:features>");
	if (connection.getTlsPolicy() != Connection.TLSPolicy.disabled) {
		sb.append("<starttls xmlns=\"urn:ietf:params:xml:ns:xmpp-tls\">");
		if (connection.getTlsPolicy() == Connection.TLSPolicy.required) {
			sb.append("<required/>");
		}
		sb.append("</starttls>");
	}

	// 具体功能
	String specificFeatures = session.getAvailableStreamFeatures();
	if (specificFeatures != null) {
		sb.append(specificFeatures);
	}
	sb.append("</stream:features>");

	connection.deliverRawText(sb.toString());
	return session;
}
 
开发者ID:lijian17,项目名称:androidpn-server,代码行数:78,代码来源:ClientSession.java

示例2: createSession

import org.androidpn.server.xmpp.net.Connection; //导入方法依赖的package包/类
/**
 * Creates a new session between the server and a client, and returns it.
 * 
 * @param serverName the server name
 * @param connection the connection
 * @param xpp the XML parser to handle incoming data 
 * @return a newly created session
 * @throws XmlPullParserException if an error occurs while parsing incoming data
 */
public static ClientSession createSession(String serverName,
        Connection connection, XmlPullParser xpp)
        throws XmlPullParserException {
    log.debug("createSession()...");

    if (!xpp.getName().equals("stream")) {
        throw new XmlPullParserException("Bad opening tag (not stream)");
    }

    if (!xpp.getNamespace(xpp.getPrefix()).equals(ETHERX_NAMESPACE)) {
        throw new XmlPullParserException("Stream not in correct namespace");
    }

    String language = "en";
    for (int i = 0; i < xpp.getAttributeCount(); i++) {
        if ("lang".equals(xpp.getAttributeName(i))) {
            language = xpp.getAttributeValue(i);
        }
    }

    // Store language and version information
    connection.setLanaguage(language);
    connection.setXMPPVersion(MAJOR_VERSION, MINOR_VERSION);

    // Create a ClientSession
    ClientSession session = SessionManager.getInstance()
            .createClientSession(connection);

    // Build the start packet response
    StringBuilder sb = new StringBuilder(200);
    sb.append("<?xml version='1.0' encoding='UTF-8'?>");
    sb.append("<stream:stream ");
    sb
            .append("xmlns:stream=\"http://etherx.jabber.org/streams\" xmlns=\"jabber:client\" from=\"");
    sb.append(serverName);
    sb.append("\" id=\"");
    sb.append(session.getStreamID().toString());
    sb.append("\" xml:lang=\"");
    sb.append(language);
    sb.append("\" version=\"");
    sb.append(MAJOR_VERSION).append(".").append(MINOR_VERSION);
    sb.append("\">");
    connection.deliverRawText(sb.toString());

    // XMPP 1.0 needs stream features
    sb = new StringBuilder();
    sb.append("<stream:features>");
    if (connection.getTlsPolicy() != Connection.TLSPolicy.disabled) {
        sb.append("<starttls xmlns=\"urn:ietf:params:xml:ns:xmpp-tls\">");
        if (connection.getTlsPolicy() == Connection.TLSPolicy.required) {
            sb.append("<required/>");
        }
        sb.append("</starttls>");
    }

    String specificFeatures = session.getAvailableStreamFeatures();
    if (specificFeatures != null) {
        sb.append(specificFeatures);
    }
    sb.append("</stream:features>");

    connection.deliverRawText(sb.toString());
    return session;
}
 
开发者ID:elphinkuo,项目名称:Androidpn,代码行数:74,代码来源:ClientSession.java

示例3: createSession

import org.androidpn.server.xmpp.net.Connection; //导入方法依赖的package包/类
/**
 * Creates a new session between the server and a client, and returns it.
 * 
 * @param serverName the server name
 * @param connection the connection
 * @param xpp the XML parser to handle incoming data 
 * @return a newly created session
 * @throws XmlPullParserException if an error occurs while parsing incoming data
 */
public static ClientSession createSession(String serverName,
        Connection connection, XmlPullParser xpp)
        throws XmlPullParserException {
    log.debug("createSession()...");

    if (!xpp.getName().equals("stream")) {
        throw new XmlPullParserException("Bad opening tag (not stream)");
    }

    if (!xpp.getNamespace(xpp.getPrefix()).equals(ETHERX_NAMESPACE)) {
        throw new XmlPullParserException("Stream not in correct namespace");
    }

    String language = "en";
    for (int i = 0; i < xpp.getAttributeCount(); i++) {
        if ("lang".equals(xpp.getAttributeName(i))) {
            language = xpp.getAttributeValue(i);
        }
    }

    // Store language and version information
    connection.setLanaguage(language);
    connection.setXMPPVersion(MAJOR_VERSION, MINOR_VERSION);

    // Create a ClientSession
    ClientSession session = SessionManager.getInstance()
            .createClientSession(connection);

    // Build the start packet response
    StringBuilder sb = new StringBuilder(200);
    sb.append("<?xml version='1.0' encoding='UTF-8'?>");
    sb.append("<stream:stream ");
    sb
            .append("xmlns:stream=\"http://etherx.jabber.org/streams\" xmlns=\"jabber:client\" from=\"");
    sb.append(serverName);
    sb.append("\" id=\"");
    sb.append(session.getStreamID().toString());
    sb.append("\" xml:lang=\"");
    sb.append(language);
    sb.append("\" version=\"");
    sb.append(MAJOR_VERSION).append(".").append(MINOR_VERSION);
    sb.append("\">");
    connection.deliverRawText(sb.toString());

    // XMPP 1.0 needs stream features
    sb = new StringBuilder();
    sb.append("<stream:features>");
    String specificFeatures = session.getAvailableStreamFeatures();
    if (specificFeatures != null) {
        sb.append(specificFeatures);
    }
    sb.append("</stream:features>");

    connection.deliverRawText(sb.toString());
    return session;
}
 
开发者ID:elphinkuo,项目名称:Androidpn,代码行数:66,代码来源:ClientSession.java

示例4: createSession

import org.androidpn.server.xmpp.net.Connection; //导入方法依赖的package包/类
public static ClientSession createSession(String serverName,
        XmlPullParser xpp, Connection connection)
        throws XmlPullParserException {
    if (!xpp.getName().equals("stream")) {
        throw new XmlPullParserException("Bad opening tag (not stream)");
    }

    if (!xpp.getNamespace(xpp.getPrefix()).equals(ETHERX_NAMESPACE)) {
        throw new XmlPullParserException("Stream not in correct namespace");
    }

    String language = "en";
    for (int i = 0; i < xpp.getAttributeCount(); i++) {
        if ("lang".equals(xpp.getAttributeName(i))) {
            language = xpp.getAttributeValue(i);
        }
    }

    // Store language and version information in the connection.
    connection.setLanaguage(language);
    connection.setXMPPVersion(MAJOR_VERSION, MINOR_VERSION);

    // Create a ClientSession for this user.
    ClientSession session = SessionManager.getInstance()
            .createClientSession(connection);

    // Build the start packet response
    StringBuilder sb = new StringBuilder(200);
    sb.append("<?xml version='1.0' encoding='");
    sb.append(CHARSET);
    sb.append("'?>");
    sb.append("<stream:stream ");
    sb
            .append("xmlns:stream=\"http://etherx.jabber.org/streams\" xmlns=\"jabber:client\" from=\"");
    sb.append(serverName);
    sb.append("\" id=\"");
    sb.append(session.getStreamID().toString());
    sb.append("\" xml:lang=\"");
    sb.append(language);
    sb.append("\" version=\"");
    sb.append(MAJOR_VERSION).append(".").append(MINOR_VERSION);
    sb.append("\">");
    connection.deliverRawText(sb.toString());

    // XMPP 1.0 so we need to announce stream features.
    sb = new StringBuilder(490);
    sb.append("<stream:features>");
    // Include Stream features
    String specificFeatures = session.getAvailableStreamFeatures();
    if (specificFeatures != null) {
        sb.append(specificFeatures);
    }
    sb.append("</stream:features>");

    connection.deliverRawText(sb.toString());
    return session;
}
 
开发者ID:elphinkuo,项目名称:Androidpn,代码行数:58,代码来源:ClientSession.java

示例5: createSession

import org.androidpn.server.xmpp.net.Connection; //导入方法依赖的package包/类
public static ClientSession createSession(String serverName,
        XmlPullParser xpp, Connection connection)
        throws XmlPullParserException {
    if (!xpp.getName().equals("stream")) {
        throw new XmlPullParserException("Bad opening tag (not stream)");
    }

    if (!xpp.getNamespace(xpp.getPrefix()).equals(ETHERX_NAMESPACE)) {
        throw new XmlPullParserException("Stream not in correct namespace");
    }

    String language = "en";
    for (int i = 0; i < xpp.getAttributeCount(); i++) {
        if ("lang".equals(xpp.getAttributeName(i))) {
            language = xpp.getAttributeValue(i);
        }
    }

    // Store language and version information
    connection.setLanaguage(language);
    connection.setXMPPVersion(MAJOR_VERSION, MINOR_VERSION);

    // Create a ClientSession
    ClientSession session = SessionManager.getInstance()
            .createClientSession(connection);

    // Build the start packet response
    StringBuilder sb = new StringBuilder(200);
    sb.append("<?xml version='1.0' encoding='");
    sb.append(CHARSET);
    sb.append("'?>");
    sb.append("<stream:stream ");
    sb
            .append("xmlns:stream=\"http://etherx.jabber.org/streams\" xmlns=\"jabber:client\" from=\"");
    sb.append(serverName);
    sb.append("\" id=\"");
    sb.append(session.getStreamID().toString());
    sb.append("\" xml:lang=\"");
    sb.append(language);
    sb.append("\" version=\"");
    sb.append(MAJOR_VERSION).append(".").append(MINOR_VERSION);
    sb.append("\">");
    connection.deliverRawText(sb.toString());

    // XMPP 1.0 needs stream features
    sb = new StringBuilder();
    sb.append("<stream:features>");
    String specificFeatures = session.getAvailableStreamFeatures();
    if (specificFeatures != null) {
        sb.append(specificFeatures);
    }
    sb.append("</stream:features>");

    connection.deliverRawText(sb.toString());
    return session;
}
 
开发者ID:elphinkuo,项目名称:Androidpn,代码行数:57,代码来源:ClientSession.java

示例6: createSession

import org.androidpn.server.xmpp.net.Connection; //导入方法依赖的package包/类
public static ClientSession createSession(String serverName,
        XmlPullParser xpp, Connection connection)
        throws XmlPullParserException {
    if (!xpp.getName().equals("stream")) {
        throw new XmlPullParserException("Bad opening tag (not stream)");
    }

    if (!xpp.getNamespace(xpp.getPrefix()).equals(ETHERX_NAMESPACE)) {
        throw new XmlPullParserException("Stream not in correct namespace");
    }

    String language = "en";
    for (int i = 0; i < xpp.getAttributeCount(); i++) {
        if ("lang".equals(xpp.getAttributeName(i))) {
            language = xpp.getAttributeValue(i);
        }
    }

    // Store language and version information in the connection.
    connection.setLanaguage(language);
    connection.setXMPPVersion(MAJOR_VERSION, MINOR_VERSION);

    // Create a ClientSession for this user.
    ClientSession session = SessionManager.getInstance()
            .createClientSession(connection);

    // Build the start packet response
    StringBuilder sb = new StringBuilder(200);
    sb.append("<?xml version='1.0' encoding='");
    sb.append(CHARSET);
    sb.append("'?>");
    sb.append("<stream:stream ");
    sb
            .append("xmlns:stream=\"http://etherx.jabber.org/streams\" xmlns=\"jabber:client\" from=\"");
    sb.append(serverName);
    sb.append("\" id=\"");
    sb.append(session.getStreamID().toString());
    sb.append("\" xml:lang=\"");
    sb.append(language);
    sb.append("\" version=\"");
    sb.append(MAJOR_VERSION).append(".").append(MINOR_VERSION);
    sb.append("\">");
    connection.deliverRawText(sb.toString());

    // XMPP 1.0 so we need to announce stream features.
    sb = new StringBuilder(490);
    sb.append("<stream:features>");
    //        // Include available SASL Mechanisms
    //        sb.append(SASLAuthentication.getSASLMechanisms(session));
    // Include Stream features
    String specificFeatures = session.getAvailableStreamFeatures();
    if (specificFeatures != null) {
        sb.append(specificFeatures);
    }
    sb.append("</stream:features>");

    connection.deliverRawText(sb.toString());
    return session;
}
 
开发者ID:elphinkuo,项目名称:Androidpn,代码行数:60,代码来源:ClientSession.java


注:本文中的org.androidpn.server.xmpp.net.Connection.setXMPPVersion方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。