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