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


Java Packet类代码示例

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


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

示例1: waitResponse

import org.jivesoftware.smack.packet.Packet; //导入依赖的package包/类
private SampleResult waitResponse(SampleResult res, String recipient) throws InterruptedException, SmackException {
    long time = 0;
    do {
        Iterator<Message> packets = responseMessages.iterator();
        Thread.sleep(conn.getPacketReplyTimeout() / 100); // optimistic
        while (packets.hasNext()) {
            Packet packet = packets.next();
            Message response = (Message) packet;
            if (XmppStringUtils.parseBareAddress(response.getFrom()).equals(recipient)) {
                packets.remove();
                res.setResponseData(response.toXML().toString().getBytes());
                if (response.getError() != null) {
                    res.setSuccessful(false);
                    res.setResponseCode("500");
                    res.setResponseMessage(response.getError().toString());
                }
                return res;
            }
        }
        time += conn.getPacketReplyTimeout() / 10;
        Thread.sleep(conn.getPacketReplyTimeout() / 10);
    } while (time < conn.getPacketReplyTimeout());
    throw new SmackException.NoResponseException();
}
 
开发者ID:Blazemeter,项目名称:jmeter-bzm-plugins,代码行数:25,代码来源:SendMessage.java

示例2: processPacket

import org.jivesoftware.smack.packet.Packet; //导入依赖的package包/类
@Override
public void processPacket(Packet packet) throws SmackException.NotConnectedException {
    if (packet instanceof Message) {
        Message inMsg = (Message) packet;
        if (inMsg.getBody() != null) {
            if (inMsg.getBody().endsWith(NEED_RESPONSE_MARKER)) {
                if (inMsg.getExtension(NS_DELAYED) == null) {
                    log.debug("Will respond to message: " + inMsg.toXML());
                    sendResponseMessage(inMsg);
                } else {
                    log.debug("Will not consider history message: " + inMsg.toXML());
                }
            } else if (inMsg.getBody().endsWith(RESPONSE_MARKER)) {
                responseMessages.add(inMsg);
            }
        }
    }
}
 
开发者ID:Blazemeter,项目名称:jmeter-bzm-plugins,代码行数:19,代码来源:SendMessage.java

示例3: process

import org.jivesoftware.smack.packet.Packet; //导入依赖的package包/类
public void process(Packet packet) {
  if (roomResponseFilter.accept(packet)) {
    final DiscoverItems result = (DiscoverItems) packet;
    final JabberPlayer player = playerMgr.getPlayer(packet.getFrom());
    // Collect the entityID for each returned item
    for (Iterator<DiscoverItems.Item> items = result.getItems(); items.hasNext();) {
      final String roomJID = items.next().getEntityID();
      final JabberRoom room = roomMgr.getRoomByJID(JabberClient.this, roomJID);
      try {
       room.setInfo(MultiUserChat.getRoomInfo(JabberClient.this
            .getConnection(), roomJID));
      }
      catch (XMPPException e) {
        // Ignore Error
      }
      if (!roomJID.equals(monitorRoom.getRoom())) {
        player.join(roomMgr.getRoomByJID(JabberClient.this, roomJID));
      }
    }
    fireRoomsUpdated();
  }
  else if (newPlayerFilter.accept(packet)) {
    sendRoomQuery(getAbsolutePlayerJID(packet.getFrom()));
  }
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:26,代码来源:JabberClient.java

示例4: processPacket

import org.jivesoftware.smack.packet.Packet; //导入依赖的package包/类
/**
 * This method handles incoming packets.
 *
 * @param packet
 *            The incoming packet.
 * @throws NotConnectedException
 */
@Override
public void processPacket(Packet packet) throws NotConnectedException {
    if (!(packet instanceof Message)) {
        return;
    }
    Message message = (Message) packet;
    if (message.getBody() == null) {
        return;
    }
    PacketExtension extension = packet.getExtension(AliasPacketExtension.ALIAS_ELEMENT_NAME,
            AliasPacketExtension.ALIAS_NAMESPACE);
    if (extension == null) {
        sendMessage(
                packet.getFrom(),
                packet.getTo(),
                ResourceBundleManager.instance().getText(
                        "xmpp.message.error.bot",
                        XMPPPatternUtils.extractKenmeiUser(packet.getFrom())
                        .getLanguageLocale(),
                        XMPPPatternUtils.extractClientIdFromUser(packet.getFrom()),
                        XMPPPatternUtils.getBlogSuffix()));
    } else {
        sendMessageToCommunote(message, (AliasPacketExtension) extension);
    }
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:33,代码来源:XMPPMessagePacketListener.java

示例5: processPacket

import org.jivesoftware.smack.packet.Packet; //导入依赖的package包/类
@Override
public void processPacket(Packet packet) {
	if(packet.getFrom().equals(packet.getTo())){
		return;
	}
	 if (packet instanceof Presence) {  
            Presence presence = (Presence) packet;  
            String from = presence.getFrom();//发送方  
            String to = presence.getTo();//接收方  
            if (presence.getType().equals(Presence.Type.subscribe)) {//好友申请  
                  Log.e("jj", "好友申请");
            } else if (presence.getType().equals(Presence.Type.subscribed)) {//同意添加好友  
           	 Log.e("jj", "同意添加好友");
            } else if (presence.getType().equals(Presence.Type.unsubscribe)) {//拒绝添加好友  和  删除好友  
           	 Log.e("jj", "拒绝添加好友");
            } else if (presence.getType().equals(Presence.Type.unsubscribed)){
           	 
            } else if (presence.getType().equals(Presence.Type.unavailable)) {//好友下线   要更新好友列表,可以在这收到包后,发广播到指定页面   更新列表  
           	 Log.e("jj", "好友下线");
            } else if(presence.getType().equals(Presence.Type.available)){//好友上线  
           	 Log.e("jj", "好友上线");
            }  else{
           	 Log.e("jj", "error");
            }
        }  
      }
 
开发者ID:cowthan,项目名称:AyoSunny,代码行数:27,代码来源:FriendsPacketListener.java

示例6: testRespondWithErrorOnInBandBytestreamRequest

import org.jivesoftware.smack.packet.Packet; //导入依赖的package包/类
/**
 * Target should respond with not-acceptable error if no listeners for incoming In-Band
 * Bytestream requests are registered.
 * 
 * @throws XMPPException should not happen
 */
public void testRespondWithErrorOnInBandBytestreamRequest() throws XMPPException {
    XMPPConnection targetConnection = getConnection(0);

    XMPPConnection initiatorConnection = getConnection(1);

    Open open = new Open("sessionID", 1024);
    open.setFrom(initiatorConnection.getUser());
    open.setTo(targetConnection.getUser());

    PacketCollector collector = initiatorConnection.createPacketCollector(new PacketIDFilter(
                    open.getStanzaId()));
    initiatorConnection.sendStanza(open);
    Packet result = collector.nextResult();

    assertNotNull(result.getError());
    assertEquals(XMPPError.Condition.no_acceptable.toString(), result.getError().getCondition());

}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:25,代码来源:InBandBytestreamTest.java

示例7: testRespondWithErrorOnSocks5BytestreamRequest

import org.jivesoftware.smack.packet.Packet; //导入依赖的package包/类
/**
 * Target should respond with not-acceptable error if no listeners for incoming Socks5
 * bytestream requests are registered.
 * 
 * @throws XMPPException should not happen
 */
public void testRespondWithErrorOnSocks5BytestreamRequest() throws XMPPException {
    XMPPConnection targetConnection = getConnection(0);

    XMPPConnection initiatorConnection = getConnection(1);

    Bytestream bytestreamInitiation = Socks5PacketUtils.createBytestreamInitiation(
                    initiatorConnection.getUser(), targetConnection.getUser(), "session_id");
    bytestreamInitiation.addStreamHost("proxy.localhost", "127.0.0.1", 7777);

    PacketCollector collector = initiatorConnection.createPacketCollector(new PacketIDFilter(
                    bytestreamInitiation.getStanzaId()));
    initiatorConnection.sendStanza(bytestreamInitiation);
    Packet result = collector.nextResult();

    assertNotNull(result.getError());
    assertEquals(XMPPError.Condition.no_acceptable.toString(), result.getError().getCondition());

}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:25,代码来源:Socks5ByteStreamTest.java

示例8: populateXmppPacket

import org.jivesoftware.smack.packet.Packet; //导入依赖的package包/类
/**
 * Populates the given XMPP packet from the inbound exchange
 */
public void populateXmppPacket(Packet packet, Exchange exchange) {
    Set<Map.Entry<String, Object>> entries = exchange.getIn().getHeaders().entrySet();
    for (Map.Entry<String, Object> entry : entries) {
        String name = entry.getKey();
        Object value = entry.getValue();
        if (!headerFilterStrategy.applyFilterToCamelHeaders(name, value, exchange)) {
            try {
                JivePropertiesManager.addProperty(packet, name, value);
                LOG.debug("Added property name: " + name + " value: " + value.toString());
            } catch (IllegalArgumentException iae) {
                LOG.debug("Not adding property " + name + " to XMPP message due to " + iae);
            }
        }
    }
    String id = exchange.getExchangeId();
    if (id != null) {
        JivePropertiesManager.addProperty(packet, "exchangeId", id);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:XmppBinding.java

示例9: extractHeadersFromXmpp

import org.jivesoftware.smack.packet.Packet; //导入依赖的package包/类
public Map<String, Object> extractHeadersFromXmpp(Packet xmppPacket, Exchange exchange) {
    Map<String, Object> answer = new HashMap<String, Object>();

    PacketExtension jpe = xmppPacket.getExtension(JivePropertiesExtension.NAMESPACE);
    if (jpe != null && jpe instanceof JivePropertiesExtension) {
        extractHeadersFrom((JivePropertiesExtension)jpe, exchange, answer);
    }
    if (jpe != null && jpe instanceof DefaultPacketExtension) {
        extractHeadersFrom((DefaultPacketExtension)jpe, exchange, answer);
    }

    if (xmppPacket instanceof Message) {
        Message xmppMessage = (Message) xmppPacket;
        answer.put(XmppConstants.MESSAGE_TYPE, xmppMessage.getType());
        answer.put(XmppConstants.SUBJECT, xmppMessage.getSubject());
        answer.put(XmppConstants.THREAD_ID, xmppMessage.getThread());
    } else if (xmppPacket instanceof PubSub) {
        PubSub pubsubPacket = (PubSub) xmppPacket;
        answer.put(XmppConstants.MESSAGE_TYPE, pubsubPacket.getType());
    }
    answer.put(XmppConstants.FROM, xmppPacket.getFrom());
    answer.put(XmppConstants.PACKET_ID, xmppPacket.getPacketID());
    answer.put(XmppConstants.TO, xmppPacket.getTo());

    return answer;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:27,代码来源:XmppBinding.java

示例10: processPacket

import org.jivesoftware.smack.packet.Packet; //导入依赖的package包/类
public void processPacket(Packet packet) {
    if (packet instanceof IQ) {
        IQ result = (IQ) packet;
        if (result.getType().equals(IQ.Type.RESULT) && result.getExtensions().isEmpty()) {
            Collection<String> addedEntries = new ArrayList<String>();
            Collection<String> updatedEntries = new ArrayList<String>();
            Collection<String> deletedEntries = new ArrayList<String>();
            if (persistentStorage != null) {
                for (RosterPacket.Item item : persistentStorage.getEntries()) {
                    insertRosterItem(item, addedEntries, updatedEntries, deletedEntries);
                }
            }
            fireRosterChangedEvent(addedEntries, updatedEntries, deletedEntries);
        }
    }
    connection.removePacketListener(this);
}
 
开发者ID:CJC-ivotten,项目名称:androidPN-client.,代码行数:18,代码来源:Roster.java

示例11: setFilterOnReceiver

import org.jivesoftware.smack.packet.Packet; //导入依赖的package包/类
/**
 * Sets a filter for all the incoming XMPP-Messages on the Receiver's JID (XMPP-Account ID).
 * Also creates a listener for the incoming messages and connects the listener to the
 * XMPPConnection alongside the set filter.
 *
 * @param receiverJID the JID (XMPP-Account ID of the receiver) to which the filter is to be
 *                    set.
 */
protected void setFilterOnReceiver(String receiverJID) {
	filter = new AndFilter(new PacketTypeFilter(Message.class), new ToContainsFilter(
			receiverJID));
	listener = new PacketListener() {
		@Override
		public void processPacket(Packet packet) {
			if (packet instanceof Message) {
				final Message xmppMessage = (Message) packet;
				Thread msgProcessThread = new Thread() {
					public void run() {
						processIncomingMessage(xmppMessage);
					}
				};
				msgProcessThread.setDaemon(true);
				msgProcessThread.start();
			}
		}
	};

	connection.addPacketListener(listener, filter);
}
 
开发者ID:wso2-incubator,项目名称:iot-server-appliances,代码行数:30,代码来源:XMPPCommunicationHandler.java

示例12: setFilterOnSender

import org.jivesoftware.smack.packet.Packet; //导入依赖的package包/类
/**
 * Sets a filter for all the incoming XMPP-Messages on the Sender's JID (XMPP-Account ID).
 * Also creates a listener for the incoming messages and connects the listener to the
 * XMPPConnection alongside the set filter.
 *
 * @param senderJID the JID (XMPP-Account ID of the sender) to which the filter is to be set.
 */
protected void setFilterOnSender(String senderJID) {
	filter = new AndFilter(new PacketTypeFilter(Message.class), new FromContainsFilter(
			senderJID));
	listener = new PacketListener() {
		@Override
		public void processPacket(Packet packet) {
			if (packet instanceof Message) {
				final Message xmppMessage = (Message) packet;
				Thread msgProcessThread = new Thread() {
					public void run() {
						processIncomingMessage(xmppMessage);
					}
				};
				msgProcessThread.setDaemon(true);
				msgProcessThread.start();
			}
		}
	};

	connection.addPacketListener(listener, filter);
}
 
开发者ID:wso2-incubator,项目名称:iot-server-agents,代码行数:29,代码来源:XMPPCommunicationHandler.java

示例13: getReply

import org.jivesoftware.smack.packet.Packet; //导入依赖的package包/类
static public Packet getReply(Connection connection, Packet packet, long timeout)
	throws XMPPException
{
       PacketFilter responseFilter = new PacketIDFilter(packet.getPacketID());
       PacketCollector response = connection.createPacketCollector(responseFilter);
       
       connection.sendPacket(packet);

       // Wait up to a certain number of seconds for a reply.
       Packet result = response.nextResult(timeout);

       // Stop queuing results
       response.cancel();

       if (result == null) {
           throw new XMPPException("No response from server.");
       }
       else if (result.getError() != null) {
           throw new XMPPException(result.getError());
       }
       return result;
}
 
开发者ID:CJC-ivotten,项目名称:androidPN-client.,代码行数:23,代码来源:SyncPacketSend.java

示例14: save

import org.jivesoftware.smack.packet.Packet; //导入依赖的package包/类
/**
 * Save this vCard for the user connected by 'connection'. Connection should be authenticated
 * and not anonymous.<p>
 * <p/>
 * NOTE: the method is asynchronous and does not wait for the returned value.
 *
 * @param connection the Connection to use.
 * @throws XMPPException thrown if there was an issue setting the VCard in the server.
 */
public void save(Connection connection) throws XMPPException {
    checkAuthenticated(connection, true);

    setType(IQ.Type.SET);
    setFrom(connection.getUser());
    PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(getPacketID()));
    connection.sendPacket(this);

    Packet response = collector.nextResult(SmackConfiguration.getPacketReplyTimeout());

    // Cancel the collector.
    collector.cancel();
    if (response == null) {
        throw new XMPPException("No response from server on status set.");
    }
    if (response.getError() != null) {
        throw new XMPPException(response.getError());
    }
}
 
开发者ID:CJC-ivotten,项目名称:androidPN-client.,代码行数:29,代码来源:VCard.java

示例15: nextPacket

import org.jivesoftware.smack.packet.Packet; //导入依赖的package包/类
/**
 * Returns the next available packet from the queue for writing.
 *
 * @return the next packet for writing.
 */
private Packet nextPacket() {
    Packet packet = null;
    // Wait until there's a packet or we're done.
    while (!done && (packet = queue.poll()) == null) {
        try {
            synchronized (queue) {
                queue.wait();
            }
        }
        catch (InterruptedException ie) {
            // Do nothing
        }
    }
    return packet;
}
 
开发者ID:CJC-ivotten,项目名称:androidPN-client.,代码行数:21,代码来源:PacketWriter.java


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