Coverage Report - org.apache.camel.component.xmpp.XmppPrivateChatProducer
 
Classes in this File Line Coverage Branch Coverage Complexity
XmppPrivateChatProducer
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 org.apache.camel.Exchange;
 20  
 import org.apache.camel.impl.DefaultProducer;
 21  
 import org.apache.commons.logging.Log;
 22  
 import org.apache.commons.logging.LogFactory;
 23  
 import org.jivesoftware.smack.Chat;
 24  
 import org.jivesoftware.smack.XMPPException;
 25  
 import org.jivesoftware.smack.packet.Message;
 26  
 
 27  
 /**
 28  
  * @version $Revision: 563665 $
 29  
  */
 30  
 public class XmppPrivateChatProducer extends DefaultProducer {
 31  0
     private static final transient Log LOG = LogFactory.getLog(XmppPrivateChatProducer.class);
 32  
     private final XmppEndpoint endpoint;
 33  
     private final String participant;
 34  
     private Chat chat;
 35  
 
 36  
     public XmppPrivateChatProducer(XmppEndpoint endpoint, String participant) {
 37  0
         super(endpoint);
 38  0
         this.endpoint = endpoint;
 39  0
         this.participant = participant;
 40  0
         if (participant == null) {
 41  0
             throw new IllegalArgumentException("No participant property specified");
 42  
         }
 43  0
     }
 44  
 
 45  
     public void process(Exchange exchange) {
 46  
         // TODO it would be nice if we could reuse the message from the exchange
 47  0
         Message message = chat.createMessage();
 48  0
         message.setTo(participant);
 49  0
         message.setFrom(endpoint.getUser());
 50  0
         message.setThread(exchange.getExchangeId());
 51  0
         message.setType(Message.Type.NORMAL);
 52  
 
 53  0
         endpoint.getBinding().populateXmppMessage(message, exchange);
 54  0
         if (LOG.isDebugEnabled()) {
 55  0
             LOG.debug(">>>> message: " + message.getBody());
 56  
         }
 57  
         try {
 58  0
             chat.sendMessage(message);
 59  0
         } catch (XMPPException e) {
 60  0
             throw new RuntimeXmppException(e);
 61  0
         }
 62  0
     }
 63  
 
 64  
     @Override
 65  
     protected void doStart() throws Exception {
 66  0
         super.doStart();
 67  0
         if (chat == null) {
 68  0
             chat = endpoint.getConnection().createChat(getParticipant());
 69  
         }
 70  0
     }
 71  
 
 72  
     @Override
 73  
     protected void doStop() throws Exception {
 74  0
         chat = null;
 75  0
         super.doStop();
 76  0
     }
 77  
 
 78  
     // Properties
 79  
     // -------------------------------------------------------------------------
 80  
     public Chat getChat() {
 81  0
         return chat;
 82  
     }
 83  
 
 84  
     public void setChat(Chat chat) {
 85  0
         this.chat = chat;
 86  0
     }
 87  
 
 88  
     public String getParticipant() {
 89  0
         return participant;
 90  
     }
 91  
 }