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