Java Code Examples for org.xmpp.packet.Message#setThread()

The following examples show how to use org.xmpp.packet.Message#setThread() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Test
public void shouldNotStoreEmptyChatMessagesWithOnlyChatStatesAndThread() {
    Message message = new Message();
    message.setType(Message.Type.chat);
    message.setThread("1234");
    PacketExtension chatState = new PacketExtension("composing", "http://jabber.org/protocol/chatstates");
    message.addExtension(chatState);
    assertFalse(OfflineMessageStore.shouldStoreMessage(message));
}
 
Example 2
Source Project: Whack   File: WeatherComponent.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Handle the receied packet and answer the weather information of the requested station id.
 * The request must be made using Message packets where the body of the message should be the
 * station id.<p>
 *
 * Note: I don't know the list of valid station ids so if you find the list please send it to me
 * so I can add it to this example.
 *
 * @param packet the Message requesting information about a certain station id.
 */
public void processPacket(Packet packet) {
    System.out.println("Received package:"+packet.toXML());
    // Only process Message packets
    if (packet instanceof Message) {
        // Get the requested station to obtain it's weather information
        Message message = (Message) packet;
        String station = message.getBody();
        // Send the request and get the weather information
        Metar metar = Weather.getMetar(station, 5000);

        // Build the answer
        Message reply = new Message();
        reply.setTo(message.getFrom());
        reply.setFrom(message.getTo());
        reply.setType(message.getType());
        reply.setThread(message.getThread());

        // Append the discovered information if something was found
        if (metar != null) {
            StringBuilder sb = new StringBuilder();
            sb.append("station id : " + metar.getStationID());
            sb.append("\rwind dir   : " + metar.getWindDirection() + " degrees");
            sb.append("\rwind speed : " + metar.getWindSpeedInMPH() + " mph, " +
                                                 metar.getWindSpeedInKnots() + " knots");
            if (!metar.getVisibilityLessThan()) {
                sb.append("\rvisibility : " + metar.getVisibility() + " mile(s)");
            } else {
                sb.append("\rvisibility : < " + metar.getVisibility() + " mile(s)");
            }

            sb.append("\rpressure   : " + metar.getPressure() + " in Hg");
            sb.append("\rtemperaturePrecise: " +
                               metar.getTemperaturePreciseInCelsius() + " C, " +
                               metar.getTemperaturePreciseInFahrenheit() + " F");
            sb.append("\rtemperature: " +
                               metar.getTemperatureInCelsius() + " C, " +
                               metar.getTemperatureInFahrenheit() + " F");
            sb.append("\rtemperatureMostPrecise: " +
                               metar.getTemperatureMostPreciseInCelsius() + " C, " +
                               metar.getTemperatureMostPreciseInFahrenheit() + " F");
            reply.setBody(sb.toString());
        }
        else {
            // Answer that the requested station id does not exist
            reply.setBody("Unknown station ID");
        }

        // Send the response to the sender of the request
        try {
            ComponentManagerFactory.getComponentManager().sendPacket(this, reply);
        } catch (ComponentException e) {
            e.printStackTrace();
        }
    }
}
 
Example 3
Source Project: Whack   File: WeatherComponent.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Handle a receied message and answer the weather information of the requested station id.
 * The request must be made using Message packets where the body of the message should be the
 * station id.<p>
 *
 * Note: I don't know the list of valid station ids so if you find the list please send it to me
 * so I can add it to this example.
 *
 * @param message the Message requesting information about a certain station id.
 */
@Override
protected void handleMessage(Message message) {
    System.out.println("Received message:"+message.toXML());
    // Get the requested station to obtain it's weather information
    String station = message.getBody();
    // Send the request and get the weather information
    Metar metar = Weather.getMetar(station, 5000);

    // Build the answer
    Message reply = new Message();
    reply.setTo(message.getFrom());
    reply.setFrom(message.getTo());
    reply.setType(message.getType());
    reply.setThread(message.getThread());

    // Append the discovered information if something was found
    if (metar != null) {
        StringBuilder sb = new StringBuilder();
        sb.append("station id : " + metar.getStationID());
        sb.append("\rwind dir   : " + metar.getWindDirection() + " degrees");
        sb.append("\rwind speed : " + metar.getWindSpeedInMPH() + " mph, " +
                                             metar.getWindSpeedInKnots() + " knots");
        if (!metar.getVisibilityLessThan()) {
            sb.append("\rvisibility : " + metar.getVisibility() + " mile(s)");
        }
        else {
            sb.append("\rvisibility : < " + metar.getVisibility() + " mile(s)");
        }

        sb.append("\rpressure   : " + metar.getPressure() + " in Hg");
        sb.append("\rtemperaturePrecise: " +
                           metar.getTemperaturePreciseInCelsius() + " C, " +
                           metar.getTemperaturePreciseInFahrenheit() + " F");
        sb.append("\rtemperature: " +
                           metar.getTemperatureInCelsius() + " C, " +
                           metar.getTemperatureInFahrenheit() + " F");
        sb.append("\rtemperatureMostPrecise: " +
                           metar.getTemperatureMostPreciseInCelsius() + " C, " +
                           metar.getTemperatureMostPreciseInFahrenheit() + " F");
        reply.setBody(sb.toString());
    }
    else {
        // Answer that the requested station id does not exist
        reply.setBody("Unknown station ID");
    }

    // Send the response to the sender of the request
    send(reply);
}