Coverage Report - org.apache.camel.component.xmpp.XmppConsumer
 
Classes in this File Line Coverage Branch Coverage Complexity
XmppConsumer
0% 
0% 
0
 
 1  
 /**
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.camel.component.xmpp;
 18  
 
 19  
 import java.util.Iterator;
 20  
 
 21  
 import org.apache.camel.Processor;
 22  
 import org.apache.camel.impl.DefaultConsumer;
 23  
 import org.apache.commons.logging.Log;
 24  
 import org.apache.commons.logging.LogFactory;
 25  
 
 26  
 import org.jivesoftware.smack.PacketListener;
 27  
 import org.jivesoftware.smack.packet.Message;
 28  
 import org.jivesoftware.smack.packet.Packet;
 29  
 import org.jivesoftware.smack.packet.RosterPacket;
 30  
 
 31  
 /**
 32  
  * A {@link Consumer} which listens to XMPP packets
 33  
  * 
 34  
  * @version $Revision: 563665 $
 35  
  */
 36  
 public class XmppConsumer extends DefaultConsumer<XmppExchange> implements PacketListener {
 37  0
     private static final transient Log LOG = LogFactory.getLog(XmppConsumer.class);
 38  
     private final XmppEndpoint endpoint;
 39  
 
 40  
     public XmppConsumer(XmppEndpoint endpoint, Processor processor) {
 41  0
         super(endpoint, processor);
 42  0
         this.endpoint = endpoint;
 43  0
     }
 44  
 
 45  
     @Override
 46  
     protected void doStart() throws Exception {
 47  0
         super.doStart();
 48  0
         endpoint.getConnection().addPacketListener(this, endpoint.getFilter());
 49  0
     }
 50  
 
 51  
     @Override
 52  
     protected void doStop() throws Exception {
 53  0
         endpoint.getConnection().removePacketListener(this);
 54  0
         super.doStop();
 55  0
     }
 56  
 
 57  
     public void processPacket(Packet packet) {
 58  
 
 59  0
         if (packet instanceof Message) {
 60  0
             Message message = (Message)packet;
 61  0
             if (LOG.isDebugEnabled()) {
 62  0
                 LOG.debug("<<<< message: " + message.getBody());
 63  
             }
 64  0
             XmppExchange exchange = endpoint.createExchange(message);
 65  
             try {
 66  0
                 getProcessor().process(exchange);
 67  0
             } catch (Exception e) {
 68  
                 // TODO: what should we do when a processing failure occurs??
 69  0
                 e.printStackTrace();
 70  0
             }
 71  0
         } else if (packet instanceof RosterPacket) {
 72  0
             RosterPacket rosterPacket = (RosterPacket)packet;
 73  0
             if (LOG.isDebugEnabled()) {
 74  0
                 LOG.debug("Roster packet with : " + rosterPacket.getRosterItemCount() + " item(s)");
 75  0
                 Iterator rosterItems = rosterPacket.getRosterItems();
 76  0
                 while (rosterItems.hasNext()) {
 77  0
                     Object item = rosterItems.next();
 78  0
                     LOG.debug("Roster item: " + item);
 79  0
                 }
 80  
             }
 81  0
         } else {
 82  0
             if (LOG.isDebugEnabled()) {
 83  0
                 LOG.debug("<<<< ignored packet: " + packet);
 84  
             }
 85  
 
 86  
         }
 87  0
     }
 88  
 }