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


Java JID类代码示例

本文整理汇总了Java中org.xmpp.packet.JID的典型用法代码示例。如果您正苦于以下问题:Java JID类的具体用法?Java JID怎么用?Java JID使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: getSession

import org.xmpp.packet.JID; //导入依赖的package包/类
/**
 * 根据JID返回与之关联的会话
 * 
 * @param from
 * @return
 */
public ClientSession getSession(JID from) {
	if (from == null || serverName == null
			|| !serverName.equals(from.getDomain())) {
		return null;
	}
	// 检查预认证会话
	if (from.getResource() != null) {
		ClientSession session = preAuthSessions.get(from.getResource());
		if (session != null) {
			return session;
		}
	}
	if (from.getResource() == null || from.getNode() == null) {
		return null;
	}
	return clientSessions.get(from.toString());
}
 
开发者ID:lijian17,项目名称:androidpn-server,代码行数:24,代码来源:SessionManager.java

示例2: removeSession

import org.xmpp.packet.JID; //导入依赖的package包/类
/**
 * 移除一个客户端会话
 * 
 * @param session
 * @return true:会话成功删除;false:删除失败
 */
public boolean removeSession(ClientSession session) {
	if (session == null || serverName == null) {
		return false;
	}
	JID fullJID = session.getAddress();

	// 从列表中删除会话
	boolean clientRemoved = clientSessions.remove(fullJID.toString()) != null;
	boolean preAuthRemoved = (preAuthSessions.remove(fullJID.getResource()) != null);

	// 用户会话的计数器执行自减
	if (clientRemoved || preAuthRemoved) {
		connectionsCounter.decrementAndGet();
		return true;
	}
	return false;
}
 
开发者ID:lijian17,项目名称:androidpn-server,代码行数:24,代码来源:SessionManager.java

示例3: route

import org.xmpp.packet.JID; //导入依赖的package包/类
/**
 * 路由这个Presence包
 * 
 * @param packet
 */
public void route(Presence packet) {
	if (packet == null) {
		throw new NullPointerException();
	}
	ClientSession session = sessionManager.getSession(packet.getFrom());

	if (session == null || session.getStatus() != Session.STATUS_CONNECTED) {
		handle(packet);
	} else {
		packet.setTo(session.getAddress());
		packet.setFrom((JID) null);
		packet.setError(PacketError.Condition.not_authorized);
		session.process(packet);
	}
}
 
开发者ID:lijian17,项目名称:androidpn-server,代码行数:21,代码来源:PresenceRouter.java

示例4: route

import org.xmpp.packet.JID; //导入依赖的package包/类
/**
 * 路由基于命名空间的IQ数据包。
 * 
 * @param packet
 */
public void route(IQ packet) {
	if (packet == null) {
		throw new NullPointerException();
	}
	JID sender = packet.getFrom();
	ClientSession session = sessionManager.getSession(sender);

	if (session == null
			|| session.getStatus() == Session.STATUS_AUTHENTICATED
			|| ("jabber:iq:auth".equals(packet.getChildElement()
					.getNamespaceURI())
					|| "jabber:iq:register".equals(packet.getChildElement()
							.getNamespaceURI()) || "urn:ietf:params:xml:ns:xmpp-bind"
						.equals(packet.getChildElement().getNamespaceURI()))) {
		handle(packet);
	} else {
		IQ reply = IQ.createResultIQ(packet);
		reply.setChildElement(packet.getChildElement().createCopy());
		reply.setError(PacketError.Condition.not_authorized);
		session.process(reply);
	}
}
 
开发者ID:lijian17,项目名称:androidpn-server,代码行数:28,代码来源:IQRouter.java

示例5: deliver

import org.xmpp.packet.JID; //导入依赖的package包/类
/**
 * 将数据包传递给数据包收件人
 * 
 * @param packet
 *            要被投递的数据包
 * @throws PacketException
 *             如果数据包为空,或收件人未找到
 */
public static void deliver(Packet packet) throws PacketException {
	if (packet == null) {
		throw new PacketException("数据包为null");
	}

	try {
		JID recipient = packet.getTo();
		if (recipient != null) {
			ClientSession clientSession = SessionManager.getInstance()
					.getSession(recipient);
			if (clientSession != null) {
				clientSession.deliver(packet);
			}
		}
	} catch (Exception e) {
		log.error("不能提供数据包: " + packet.toString(), e);
	}
}
 
开发者ID:lijian17,项目名称:androidpn-server,代码行数:27,代码来源:PacketDeliverer.java

示例6: buildToJID

import org.xmpp.packet.JID; //导入依赖的package包/类
private JID buildToJID() {
  MMXid[] tos = (MMXid[]) mmxMeta.getHeader(MmxHeaders.TO, null);
  if (tos == null || tos.length == 0) {
    return null;
  }
  String userId, devId;
  if (tos.length > 1) {
    userId = Constants.MMX_MULTICAST;
    devId = null;
  } else {
    userId = tos[0].getUserId();
    devId = tos[0].getDeviceId();
    if (userId.indexOf('@') >= 0) {
      userId = JID.escapeNode(userId);
    }
  }
  return new JID(JIDUtil.makeNode(userId, appId), domain, devId);
}
 
开发者ID:magnetsystems,项目名称:message-server,代码行数:19,代码来源:MessageBuilder.java

示例7: build

import org.xmpp.packet.JID; //导入依赖的package包/类
/**
 * Build a DeliveryConfirmationMessage using the source Message
 * @param source
 * @return DeliveryConfirmationMessage if the source message represents a DeliveryConfirmation
 * null other wise.
 */
public static DeliveryConfirmationMessage build (Message source) {
  DeliveryConfirmationMessage dc = null;
  if (source != null) {
    PacketExtension confirmation = source.getExtension(Constants.XMPP_RECEIVED, Constants.XMPP_NS_RECEIPTS);
    if (confirmation != null) {
      //make sure we have the id attribute which identifies the id of the message
      //for which this message represents a delivery confirmation
      Element extensionElement = confirmation.getElement();
      String idVal = extensionElement.attributeValue(Constants.XMPP_ATTR_ID);
      if (idVal != null || !idVal.isEmpty()) {
        dc = new DeliveryConfirmationMessage();
        dc.messageId = idVal;
        dc.wrapped = source;

        JID from = source.getFrom();
        if (from != null && from.getResource() != null) {
          dc.confirmingDeviceId = from.getResource();
        }
      }
    }
  }
  return dc;
}
 
开发者ID:magnetsystems,项目名称:message-server,代码行数:30,代码来源:DeliveryConfirmationMessage.java

示例8: isOnline

import org.xmpp.packet.JID; //导入依赖的package包/类
@Override
public boolean isOnline(JID user) {
  long start = System.nanoTime();
  SessionManager sessionManager = getSessionManager();
  Collection<ClientSession> sessions = sessionManager.getSessions(user.getNode());
  boolean activeSession = false;
  for (ClientSession clientSession : sessions) {
    JID clientSessionAddress = clientSession.getAddress();
    //compare the node and the resource
    if (clientSessionAddress.getNode().equals(user.getNode()) && clientSessionAddress.getResource().equals(user.getResource())) {
      //if (clientSession.getAddress().equals(user)) {
      if (clientSession.isInitialized()) {
        activeSession = true;
        break;
      }
    }
  }
  long end = System.nanoTime();
  if (LOGGER.isDebugEnabled()) {
    LOGGER.debug(String.format ("For user:%s presence value:%s", user, activeSession));
    long delta = end - start;
    LOGGER.debug("Presence was checked in:" + (delta/1000) + " ms");
  }
  return activeSession;
}
 
开发者ID:magnetsystems,项目名称:message-server,代码行数:26,代码来源:MMXPresenceFinderImpl.java

示例9: handleIQ

import org.xmpp.packet.JID; //导入依赖的package包/类
@Override
public IQ handleIQ(IQ iq) throws UnauthorizedException {
  LOGGER.trace("handleIQ : {}", iq);
  JID fromJID = iq.getFrom();
  String appId = JIDUtil.getAppId(fromJID);
  Element element = iq.getChildElement();
  String customType = element.attributeValue(Constants.MMX_ATTR_COMMAND);
  String dst = element.attributeValue(Constants.MMX_ATTR_DST);
  LOGGER.trace("handleIQ : dst={}, type={}", dst, customType);
  
  MMXPushManager pushMsgMgr = MMXPushManager.getInstance();
  MMXid to = new MMXid(JIDUtil.getUserId(dst), JIDUtil.getResource(dst), null);
  PushResult result = pushMsgMgr.send(fromJID, appId, to,
      Action.PUSH, customType, element.getText());
  return IQUtils.createResultIQ(iq, GsonData.getGson().toJson(result));
}
 
开发者ID:magnetsystems,项目名称:message-server,代码行数:17,代码来源:MMXPushNSHandler.java

示例10: handleIQ

import org.xmpp.packet.JID; //导入依赖的package包/类
@Override
public IQ handleIQ(IQ iq) throws UnauthorizedException {
  LOGGER.trace("handleIQ : {}", iq);
  JID fromJID = iq.getFrom();
  String appId = JIDUtil.getAppId(fromJID);
  Element element = iq.getChildElement();
  String customType = element.attributeValue(Constants.MMX_ATTR_COMMAND);
  String dst = element.attributeValue(Constants.MMX_ATTR_DST);
  LOGGER.trace("handleIQ : dst={}, type={}", dst, customType);
  
  MMXPushManager pushMsgMgr = MMXPushManager.getInstance();
  MMXid to = new MMXid(JIDUtil.getUserId(dst), JIDUtil.getResource(dst), null);
  PushResult result = pushMsgMgr.send(fromJID, appId, to,
      Action.WAKEUP, customType, element.getText());
  return IQUtils.createResultIQ(iq, GsonData.getGson().toJson(result));
}
 
开发者ID:magnetsystems,项目名称:message-server,代码行数:17,代码来源:MMXWakeupNSHandler.java

示例11: deleteChannel

import org.xmpp.packet.JID; //导入依赖的package包/类
public MMXStatus deleteChannel(JID from, String appId,
                        ChannelAction.DeleteRequest rqt) throws MMXException {
  String channel = ChannelHelper.normalizePath(rqt.getChannel());
  String userId = JIDUtil.getUserId(from);
  JID owner = from.asBareJID();
  String realChannel = ChannelHelper.makeChannel(appId, rqt.isPersonal() ?
          userId : null, channel);
  Node node = mPubSubModule.getNode(realChannel);
  if (node == null) {
    throw new MMXException(StatusCode.CHANNEL_NOT_FOUND.getMessage(channel),
        StatusCode.CHANNEL_NOT_FOUND.getCode());
  }
  int count = deleteNode(node, owner);
  MMXStatus status = (new MMXStatus())
      .setCode(StatusCode.SUCCESS.getCode())
      .setMessage(count+" channel"+((count==1)?" is":"s are")+" deleted");
  return status;
}
 
开发者ID:magnetsystems,项目名称:message-server,代码行数:19,代码来源:MMXChannelManager.java

示例12: getChannel

import org.xmpp.packet.JID; //导入依赖的package包/类
public ChannelInfo getChannel(JID from, String appId, MMXChannelId channel)
                          throws MMXException {
    String realChannel = ChannelHelper.makeChannel(appId, channel.getEscUserId(),
            ChannelHelper.normalizePath(channel.getName()));
    Node node = mPubSubModule.getNode(realChannel);
    if (node == null) {
      throw new MMXException(StatusCode.CHANNEL_NOT_FOUND.getMessage(channel.getName()),
          StatusCode.CHANNEL_NOT_FOUND.getCode());
    }
//    // A user can get the channel info if the channel is a global channel, or the owner
//    // of a user channel, or a subscriber to a user channel.
//    if (channel.isUserChannel() && !node.getOwners().contains(from.asBareJID()) &&
//        node.getSubscriptions(from.asBareJID()).size() > 0) {
//      throw new MMXException(StatusCode.FORBIDDEN.getMessage(channel.getName()),
//          StatusCode.FORBIDDEN.getCode());
//    }
    return nodeToInfo(channel.getUserId(), channel.getName(), node);
  }
 
开发者ID:magnetsystems,项目名称:message-server,代码行数:19,代码来源:MMXChannelManager.java

示例13: unsubscribeForDev

import org.xmpp.packet.JID; //导入依赖的package包/类
public MMXStatus unsubscribeForDev(JID from, String appId,
                ChannelAction.UnsubscribeForDevRequest rqt) throws MMXException {
  String prefix = ChannelHelper.CHANNEL_DELIM + appId + ChannelHelper.CHANNEL_DELIM;
  int count = 0;
  JID owner = from.asBareJID();
  String devId = rqt.getDevId();
  for (Node node : mPubSubModule.getNodes()) {
    if (!node.getNodeID().startsWith(prefix)) {
      continue;
    }
    for (NodeSubscription subscription : node.getSubscriptions(owner)) {
      if (devId.equals(subscription.getJID().getResource())) {
        ++count;
        node.cancelSubscription(subscription);
      }
    }
  }
  MMXStatus status = (new MMXStatus())
      .setCode(StatusCode.SUCCESS.getCode())
      .setMessage(count+" subscription"+((count==1)?" is":"s are")+" cancelled");
  return status;
}
 
开发者ID:magnetsystems,项目名称:message-server,代码行数:23,代码来源:MMXChannelManager.java

示例14: isAdmin

import org.xmpp.packet.JID; //导入依赖的package包/类
/**
   * Check if the <code>from</code> has admin capability.  Only the escaped
   * node part (userID) is validate.  TODO: it is not clear how the Openfire
   * stores the node as escaped or unescaped JID.
   *
   * @param from A full JID or bare JID.
   * @return
   */
  public static boolean isAdmin(JID from) {
    XMPPServer server = XMPPServer.getInstance();
    if (server.isLocal(from)) {
      String userId = from.getNode();
      for (JID admin : server.getAdmins()) {
//        if (JID.equals(admin.getNode(), userId)) {
//          return true;
//        }
        String adminNode = admin.getNode();
        if (adminNode.equals(userId)) {
          return true;
        }
      }
    }
    return false;
  }
 
开发者ID:magnetsystems,项目名称:message-server,代码行数:25,代码来源:Helper.java

示例15: handleDeleteUser

import org.xmpp.packet.JID; //导入依赖的package包/类
/**
 * Handle delete user.  The initiator (e.g. app-server user) must be from 
 * the same app.
 * @param packet
 * @return
 * @throws UnauthorizedException
 */
IQ handleDeleteUser(IQ packet, JID from, String appId, String payload) 
                        throws UnauthorizedException {
  UserCreate userRqt = UserCreate.fromJson(payload);
  AppDAO appDAO = new AppDAOImpl(getConnectionProvider());

  IQ validationError = validateUserDeleteRequest(packet, userRqt, appDAO);
  if (validationError != null) {
    return validationError;
  }
  String userId = userRqt.getUserId();
  String constructedUserId = JIDUtil.makeNode(userId, appId);
  MMXUserManager userManager = getUserManager();
  userManager.deleteUser(constructedUserId);
  LOGGER.info("Deleted a user with userId:" + constructedUserId);
  MMXStatus userResp = new MMXStatus();
  userResp.setCode(UserOperationStatusCode.USER_DELETED.getCode());
  userResp.setMessage(UserOperationStatusCode.USER_DELETED.getMessage());
  IQ response = IQUtils.createResultIQ(packet, userResp.toJson());
  return response;
}
 
开发者ID:magnetsystems,项目名称:message-server,代码行数:28,代码来源:MMXUserHandler.java


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