View Javadoc

    1   package org.codehaus.xfire.xmpp;
    2
    3   import java.io.StringReader;
    4
    5   import javax.xml.stream.XMLStreamReader;
    6
    7   import org.apache.commons.logging.Log;
    8   import org.apache.commons.logging.LogFactory;
    9   import org.codehaus.xfire.MessageContext;
    10  import org.codehaus.xfire.XFire;
    11  import org.codehaus.xfire.exchange.InMessage;
    12  import org.codehaus.xfire.service.Service;
    13  import org.codehaus.xfire.util.STAXUtils;
    14  import org.jivesoftware.smack.PacketListener;
    15  import org.jivesoftware.smack.packet.Packet;
    16
    17  /***
    18   * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
    19   */
    20  public class ChannelPacketListener
    21      implements PacketListener
    22  {
    23      private static Log log = LogFactory.getLog(ChannelPacketListener.class);
    24
    25      private XMPPChannel channel;
    26
    27      public static final String PACKET = "xmpp.packet";
    28
    29      private XFire xfire;
    30
    31      public ChannelPacketListener(XFire xfire, XMPPChannel channel)
    32      {
    33          this.xfire = xfire;
    34          this.channel = channel;
    35      }
    36
    37      /***
    38       * @param packet
    39       */
    40      public void processPacket(Packet packet)
    41      {
    42          if (log.isDebugEnabled())
    43              log.debug("Got packet: " + packet.getClass().getName());
    44
    45          if(!(packet instanceof SoapEnvelopePacket))
    46              // Just discard the packet?
    47              return;
    48
    49          SoapEnvelopePacket soapPacket = (SoapEnvelopePacket) packet;
    50
    51          String to = packet.getTo();
    52          String serviceName = to.substring(to.indexOf('/')+1);
    53          Service service = xfire.getServiceRegistry().getService(serviceName);
    54
    55          XMLStreamReader reader = STAXUtils.createXMLStreamReader(new StringReader(soapPacket.getChildElementXML()));
    56          InMessage message = new InMessage(reader, to);
    57
    58          MessageContext context = new MessageContext();
    59          context.setProperty(PACKET, packet);
    60          context.setXFire(xfire);
    61          context.setService(service);
    62
    63          channel.receive(context, message);
    64      }
    65  }