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


Java Packet类代码示例

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


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

示例1: deliver

import org.xmpp.packet.Packet; //导入依赖的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

示例2: ComponentPacketTransport

import org.xmpp.packet.Packet; //导入依赖的package包/类
@Inject
public ComponentPacketTransport(IncomingPacketHandler handler,
    @Named(FederationSettings.XMPP_COMPONENT_NAME) String componentName,
    @Named(FederationSettings.XMPP_SERVER_HOSTNAME) String serverDomain,
    @Named(FederationSettings.XMPP_SERVER_SECRET) String serverSecret,
    @Named(FederationSettings.XMPP_SERVER_IP) String serverAddress,
    @Named(FederationSettings.XMPP_SERVER_PORT) int serverPort) {
  this.handler = handler;
  this.componentName = componentName;
  this.serverDomain = serverDomain;
  this.serverSecret = serverSecret;
  this.serverAddress = serverAddress;
  this.serverPort = serverPort;

  queuedPackets = new LinkedList<Packet>();
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:17,代码来源:ComponentPacketTransport.java

示例3: sendErrorResponse

import org.xmpp.packet.Packet; //导入依赖的package包/类
/**
 * Send an error response to the passed incoming request. Throws
 * IllegalArgumentException if the original packet is also an error, or is of
 * the IQ result type.
 *
 * According to RFC 3920 (9.3.1), the error packet may contain the original
 * packet. However, this implementation does not include it.
 *
 * @param request packet request, to/from is inverted for response
 * @param error packet error describing error condition
 */
void sendErrorResponse(Packet request, PacketError error) {
  if (request instanceof IQ) {
    IQ.Type type = ((IQ) request).getType();
    if (!(type.equals(IQ.Type.get) ||  type.equals(IQ.Type.set))) {
      throw new IllegalArgumentException("May only return an error to IQ get/set, not: " + type);
    }
  } else if (request instanceof Message) {
    Message message = (Message) request;
    if (message.getType().equals(Message.Type.error)) {
      throw new IllegalArgumentException("Can't return an error to another message error");
    }
  } else {
    throw new IllegalArgumentException("Unexpected Packet subclass, expected Message/IQ: "
        + request.getClass());
  }

  LOG.fine("Sending error condition in response to " + request.getID() + ": "
      + error.getCondition().name());

  // Note that this does not include the original packet; just the ID.
  final Packet response = XmppUtil.createResponsePacket(request);
  response.setError(error);

  transport.sendPacket(response);
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:37,代码来源:XmppManager.java

示例4: processGetSignerResponse

import org.xmpp.packet.Packet; //导入依赖的package包/类
/**
 * Parses a GetSigner response, passes result to the waveserver.
 *
 * @param packet   the response packet
 * @param listener the interface to the wave server
 */
private void processGetSignerResponse(Packet packet, DeltaSignerInfoResponseListener listener) {
  IQ response = (IQ) packet;
  Element items = response.getChildElement().element("items");
  Element signature = items.element("signature");
  if (signature == null) {
    LOG.severe("Empty getDeltaSignerRequest response: " + response);
    listener.onFailure(FederationErrors.badRequest("Bad getDeltaSignatureRequest response"));
    return;
  }
  String domain = signature.attributeValue("domain");
  String hashName = signature.attributeValue("algorithm");
  if (domain == null || hashName == null || signature.element("certificate") == null) {
    LOG.severe("Bad getDeltaSignerRequest response: " + response);
    listener.onFailure(FederationErrors.badRequest("Bad getDeltaSignatureRequest response"));
    return;
  }
  ProtocolSignerInfo signer;
  try {
    signer = XmppUtil.xmlToProtocolSignerInfo(signature);
  } catch (UnknownSignerType e) {
    listener.onFailure(FederationErrors.badRequest(e.toString()));
    return;
  }
  listener.onSuccess(signer);
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:32,代码来源:XmppFederationRemote.java

示例5: testDiscoNoRetransmitsAfterReply

import org.xmpp.packet.Packet; //导入依赖的package包/类
/**
 * Tests that starting disco sends a disco#items to the remote server, and no
 * subsequent disco requests start after we get a successful reply.
 */
public void testDiscoNoRetransmitsAfterReply() throws ExecutionException {
  XmppUtil.fakeUniqueId = DISCO_ITEMS_ID;
  disco.discoverRemoteJid(REMOTE_DOMAIN, discoCallback);
  checkAndResetStats(1, 0, 0);  // started
  assertEquals("Expected disco packet to be sent", 1, transport.packetsSent);
  Packet packet = transport.lastPacketSent;
  assertEquals(EXPECTED_DISCO_ITEMS_GET, packet.toString());
  assertTrue(disco.isDiscoRequestPending(REMOTE_DOMAIN));

  IQ discoItemsResult = createDiscoItems(true /* wave */, false /* not pubsub */);
  discoItemsResult.setID(packet.getID());
  XmppUtil.fakeUniqueId = DISCO_INFO_ID;
  manager.receivePacket(discoItemsResult);
  assertEquals("Expected disco info get to be sent", 2, transport.packetsSent);
  assertEquals(EXPECTED_DISCO_INFO_GET, transport.lastPacketSent.toString());

  // Check that we haven't yet finished - we should only get up to sending the items request.
  verifyZeroInteractions(discoCallback);
  assertTrue(disco.isDiscoRequestPending(REMOTE_DOMAIN));
  checkAndResetStats(0, 0, 0);  // no additional varz
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:26,代码来源:XmppDiscoTest.java

示例6: testDiscoItemsResult

import org.xmpp.packet.Packet; //导入依赖的package包/类
/**
 * Tests stage 2 of disco. Inject a disco#items into the disco code, check it
 * calls disco#info on the JID.
 */
public void testDiscoItemsResult() {
  initiateDiscoRequest();  // sends one packet.
  checkAndResetStats(1, 0, 0);  // started
  // create with wave, no pubsub
  IQ discoItemsResult = createDiscoItems(true /* wave */, false /* not pubsub */);

  XmppUtil.fakeUniqueId = DISCO_INFO_ID;
  manager.receivePacket(discoItemsResult);
  assertEquals(2, transport.packetsSent);
  Packet packet = transport.lastPacketSent;
  assertEquals(REMOTE_JID, packet.getTo().toString());
  assertEquals(LOCAL_JID, packet.getFrom().toString());
  assertEquals(EXPECTED_DISCO_INFO_GET, packet.toString());
  checkAndResetStats(0, 0, 0);  // no additional varz
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:20,代码来源:XmppDiscoTest.java

示例7: testDiscoInfoResultWave

import org.xmpp.packet.Packet; //导入依赖的package包/类
/**
 * Tests stage 3 of disco. Inject a disco#info into the disco code (one that
 * matches wave) and check the callback gets run.
 */
public void testDiscoInfoResultWave() {
  initiateDiscoRequest();  // sends one packet.
  checkAndResetStats(1, 0, 0);  // started
  // create with wave, no pubsub
  IQ discoItemsResult = createDiscoItems(true /* wave */, false /* not pubsub */);
  // Start the process.
  XmppUtil.fakeUniqueId = DISCO_INFO_ID;
  manager.receivePacket(discoItemsResult);
  assertEquals(2, transport.packetsSent);
  Packet packet = transport.lastPacketSent;
  assertEquals(EXPECTED_DISCO_INFO_GET, packet.toString());
  // create a wave disco result, inject into disco.
  manager.receivePacket(createDiscoInfo(true /* wave */));
  assertEquals(2, transport.packetsSent);
  verify(discoCallback).onSuccess(eq(REMOTE_JID));
  checkAndResetStats(0, 1, 0);  // success
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:22,代码来源:XmppDiscoTest.java

示例8: testDiscoItemsFallback

import org.xmpp.packet.Packet; //导入依赖的package包/类
/**
 * Tests that if a disco items requests fails due to some error, that we still
 * perform a disco info request on fallback JIDs.
 */
public void testDiscoItemsFallback() {
  XmppUtil.fakeUniqueId = DISCO_INFO_ID;
  disco.discoverRemoteJid(REMOTE_DOMAIN, discoCallback);
  assertEquals("Should have sent disco packet", 1, transport.packetsSent);
  checkAndResetStats(1, 0, 0);  // started

  // Generate an error response.
  IQ errorResponse = IQ.createResultIQ((IQ) transport.packets.poll());
  errorResponse.setError(PacketError.Condition.conflict);
  manager.receivePacket(errorResponse);

  // Confirm that two outgoing packets are sent.
  assertEquals(3, transport.packetsSent);

  // Expect a wave request
  Packet wavePacket = transport.packets.poll();
  assertEquals(EXPECTED_DISCO_INFO_GET, wavePacket.toString());

  // Expect packet targeted at TLD
  Packet pubsubPacket = transport.packets.poll();
  assertEquals(REMOTE_DOMAIN, pubsubPacket.getTo().toBareJID());
  checkAndResetStats(0, 0, 0);  // not finished yet
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:28,代码来源:XmppDiscoTest.java

示例9: setUp

import org.xmpp.packet.Packet; //导入依赖的package包/类
@Override
public void setUp() throws Exception {
  super.setUp();

  server1 = new ServerInstances(SERVER1_DOMAIN, new Router() {
    @Override
    public void route(Packet packet) {
      server2.manager.receivePacket(packet);
    }
  });
  server2 = new ServerInstances(SERVER2_DOMAIN, new Router() {
    @Override
    public void route(Packet packet) {
      server1.manager.receivePacket(packet);
    }
  });
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:18,代码来源:RoundTripTest.java

示例10: testUnhandledErrorResponse

import org.xmpp.packet.Packet; //导入依赖的package包/类
/**
 * Test that an unhandled error (e.g. <forbidden>) is translated to
 * UNDEFINED_CONDITION before being returned to the mocked callback.
 */
public void testUnhandledErrorResponse() {
  IQ packet = new IQ();
  packet.setFrom(server1.jid);
  packet.setID("foo");
  packet.setTo(server2.jid);

  // Disable routing so we can intercept the packet.
  server1.transport.router = null;
  PacketCallback callback = mock(PacketCallback.class);
  server1.manager.send(packet, callback, PACKET_TIMEOUT);

  // Generate an explicit error <forbidden>.
  IQ errorPacket = IQ.createResultIQ(packet);
  errorPacket.setError(PacketError.Condition.forbidden);
  server1.manager.receivePacket(errorPacket);

  // Confirm that <forbidden> is transformed to UNDEFINED_CONDITION.
  ArgumentCaptor<FederationError> returnedError = ArgumentCaptor.forClass(FederationError.class);
  verify(callback).error(returnedError.capture());
  verify(callback, never()).run(any(Packet.class));
  assertEquals(FederationError.Code.UNDEFINED_CONDITION, returnedError.getValue().getErrorCode());
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:27,代码来源:RoundTripTest.java

示例11: isValidGeoIQ

import org.xmpp.packet.Packet; //导入依赖的package包/类
public static IQ isValidGeoIQ(Packet packet) {
  if (packet instanceof IQ) {
    IQ iqPacket = (IQ)packet;
    if (IQ.Type.set == iqPacket.getType()) {
      JID to = iqPacket.getTo();
      if (to != null && to.toString().startsWith("pubsub")) {
        // find 'geoloc'
        Element element = iqPacket.getChildElement();
        Element action = element.element("publish");
        if (action != null) {
          String nodeID = action.attributeValue("node");
          if (nodeID != null && nodeID.endsWith(TopicHelper.TOPIC_GEOLOC)) {
            return iqPacket;
          }
        }
      }
    }
  }
  return null;
}
 
开发者ID:magnetsystems,项目名称:message-server,代码行数:21,代码来源:IQUtils.java

示例12: audit

import org.xmpp.packet.Packet; //导入依赖的package包/类
public void audit(Packet packet, Session session) {
    if (auditManager.isEnabled()) {
        if (packet instanceof Message) {
            if (auditManager.isAuditMessage()) {
                writePacket(packet, session);
            }
        }
        else if (packet instanceof Presence) {
            if (auditManager.isAuditPresence()) {
                writePacket(packet, session);
            }
        }
        else if (packet instanceof IQ) {
            if (auditManager.isAuditIQ()) {
                writePacket(packet, session);
            }
        }
    }
}
 
开发者ID:coodeer,项目名称:g3server,代码行数:20,代码来源:AuditorImpl.java

示例13: process

import org.xmpp.packet.Packet; //导入依赖的package包/类
@Override
public void process(Packet packet, String subdomain, String to, String from) throws PacketRejectedException {
	Log.debug("Processing packet in ClientToComponentUpdateProcessor: " + packet.toString());

	Element query = ((IQ) packet).getChildElement();
	List<Node> nodes = findNodesInDocument(query.getDocument(), "//roster:item");
	if (nodes.size() > 0) {
		// We now know we have to check the JID of the to be added User
		// against our valid subdomains.
		for (Node n : nodes) {
			String jid = n.valueOf("@jid");
			// TODO: We ignore remove iq packets for now. There might be
			// conflicts
			// when we remove our legacy network registration.
			String found_subdomain = searchJIDforSubdomain(jid);
			if (found_subdomain.length() > 0 && !n.valueOf("@subscription").equals("remove")) {

				Log.debug("Mirroring packet from local network to legacy component " + found_subdomain);
				IQ forward = (IQ) packet.createCopy();
				forward.setTo(found_subdomain);
				dispatchPacket(forward);
			}
		}
	}
}
 
开发者ID:idwanglu2010,项目名称:openfire,代码行数:26,代码来源:ClientToComponentUpdateProcessor.java

示例14: processPacket

import org.xmpp.packet.Packet; //导入依赖的package包/类
public void processPacket(Packet p) {
    if (!(p instanceof IQ)) {
        return;
    }
    final IQ packet = (IQ) p;

    if (packet.getType().equals(IQ.Type.error) || packet.getType().equals(IQ.Type.result)) {
        return;
    }

    // Packet p is an IQ stanza of type GET or SET. Therefor, it _must_ be
    // replied to.
    final IQ replyPacket = handleIQRequest(packet);

    try {
        componentManager.sendPacket(this, replyPacket);
    } catch (ComponentException e) {
        Log.error(e.getMessage(), e);
    }

}
 
开发者ID:igniterealtime,项目名称:Openfire,代码行数:22,代码来源:SearchPlugin.java

示例15: process

import org.xmpp.packet.Packet; //导入依赖的package包/类
/**
 * Handle presence updates that affect roster subscriptions.
 *
 * @param presence The presence presence to handle
 * @throws PacketException if the packet is null or the packet could not be routed.
 */
public void process(Presence presence) throws PacketException {
    try {
        process((Packet)presence);
    }
    catch (UnauthorizedException e) {
        try {
            LocalSession session = (LocalSession) sessionManager.getSession(presence.getFrom());
            presence = presence.createCopy();
            if (session != null) {
                presence.setFrom(new JID(null, session.getServerName(), null, true));
                presence.setTo(session.getAddress());
            }
            else {
                JID sender = presence.getFrom();
                presence.setFrom(presence.getTo());
                presence.setTo(sender);
            }
            presence.setError(PacketError.Condition.not_authorized);
            deliverer.deliver(presence);
        }
        catch (Exception err) {
            Log.error(LocaleUtils.getLocalizedString("admin.error"), err);
        }
    }
}
 
开发者ID:idwanglu2010,项目名称:openfire,代码行数:32,代码来源:PresenceUpdateHandler.java


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