KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > communication > sms > provider > prodat > ProdatMessengerImpl


1 /**
2  * Copyright 2001-2004 The eXo platform SARL All rights reserved.
3  * Please look at license.txt in info directory for more license detail.
4  **/

5 package org.exoplatform.services.communication.sms.provider.prodat;
6
7 import java.util.Iterator JavaDoc;
8 import org.exoplatform.container.PortalContainer;
9 import org.exoplatform.services.communication.sms.SmsMonitorService;
10 import org.exoplatform.services.communication.sms.common.CommunicationError;
11 import org.exoplatform.services.communication.sms.common.ResponseException;
12 import org.exoplatform.services.communication.sms.model.*;
13 import org.exoplatform.services.communication.sms.provider.*;
14 import org.exoplatform.services.communication.sms.util.ClientHttpSocket;
15 import org.exoplatform.services.communication.sms.util.ClientSocket;
16
17
18
19 /**
20  * @author Ove Ranheim (oranheim@yahoo.no)
21  * @since Jun 17, 2004 8:09:31 PM
22  */

23 public class ProdatMessengerImpl implements Messenger {
24     
25     protected Provider _provider;
26     protected SmsMonitorService _monitor;
27     
28     
29     public ProdatMessengerImpl(Provider provider) {
30         _provider = provider;
31         PortalContainer manager = PortalContainer.getInstance();
32         _monitor = (SmsMonitorService) manager.getComponentInstanceOfType(SmsMonitorService.class);
33     }
34     
35     protected void statusSending(Messages messages) {
36         for(Iterator JavaDoc i = messages.iterator(); i.hasNext(); ) {
37             Message m = (Message) i.next();
38             for(Iterator JavaDoc j = m.getRecipients().iterator(); j.hasNext(); ) {
39                 Recipient r = (Recipient) j.next();
40                 r.setStatus(MessageStatus.SENDING);
41                 _monitor.incCountMessages();
42             }
43         }
44     }
45     
46     public void service(SmsRequest request, SmsResponse response) throws CommunicationError, ResponseException {
47         Operator operator = _provider.getOperator();
48         SmsMethod method = operator.getMethod();
49         String JavaDoc host = operator.getHost();
50         int port = Integer.parseInt(operator.getPort());
51         String JavaDoc xml = null;
52         
53         if (method.equals(SmsMethod.SOCKET_CLIENT)) {
54             ClientSocket socket = new ClientSocket(host, port);
55             statusSending(request.getMessages());
56             xml = socket.sendMessage(request.getPayload());
57         } else if (method.equals(SmsMethod.HTTP_CLIENT)) {
58             ClientHttpSocket http = new ClientHttpSocket(host, port, operator.getUsername(), operator.getPassword());
59             statusSending(request.getMessages());
60             xml = http.sendMessage(request.getPayload());
61         }
62         
63         if (xml == null) throw new CommunicationError("Unknown method to service in prodat messenger");
64
65         response.setResult(xml);
66         response.translate();
67     }
68     
69 }
70
Popular Tags