View Javadoc

1   package net.sf.orcus.sms.ubssms;
2   
3   import net.sf.orcus.sms.Sms;
4   import net.sf.orcus.sms.SmsServiceException;
5   import net.sf.orcus.sms.transport.TransportHandler;
6   import net.sf.orcus.sms.util.PropertyLoader;
7   
8   import org.apache.commons.httpclient.HttpMethod;
9   import org.apache.commons.httpclient.NameValuePair;
10  import org.apache.commons.httpclient.URI;
11  import org.apache.commons.httpclient.URIException;
12  import org.apache.commons.httpclient.methods.PostMethod;
13  import org.apache.commons.logging.Log;
14  import org.apache.commons.logging.LogFactory;
15  
16  /***
17   * This is an implementation of the <code>SmsService</code> which uses the 
18   * sms gate available internally at ubs. 
19   *
20   * @version $Revision: 1.2 $, $Date: 2005/11/19 23:19:49 $
21   * @author Pawel Kowalski
22   */
23  public class UbsSmsService extends HttpFormService {
24      
25      private final static Log LOG = LogFactory.getLog(UbsSmsService.class);
26  
27      public static final String DEFAULT_FORM_URI_STRING = "http://bw.smsgate.ubs.com/GmsgSend.pl";
28  
29      public final static String NUMBER_ID = "inNumber";
30  
31      public final static String MESSAGE_ID = "inMessage";
32  
33      public final static String PROVIDER_ID = "inProvider";
34  
35      public final static String PROVIDER_NATELD = "NatelD";
36  
37      /*** 
38       * The default, package visible ctor.
39       *
40       */
41      UbsSmsService() {
42          LOG.debug("UbsSmsService()");
43      }
44      
45      // ----------------------------------------------
46      // template method implementations
47      // ----------------------------------------------
48  
49      public HttpMethod getMethod() {
50          LOG.debug("getMethod()");
51          
52          HttpMethod aHttpMethod = new PostMethod();
53          return aHttpMethod;
54      }
55  
56      public NameValuePair[] getParameters(Sms aSms) {
57          LOG.debug("getParameters(" + aSms + ")");
58          
59          NameValuePair[] pairs = new NameValuePair[] {
60                  new NameValuePair(NUMBER_ID, aSms.getRecipient()),
61                  new NameValuePair(MESSAGE_ID, aSms.getMessage()),
62                  new NameValuePair(PROVIDER_ID, PROVIDER_NATELD), };
63          return pairs;
64      }
65  
66      public URI getFormUri() throws URIException {
67          LOG.debug("getFormUri()");
68          
69          String formUriString = PropertyLoader.getProperty(FORM_URI_PROPERTY,
70                  DEFAULT_FORM_URI_STRING);
71          URI formUri = new URI(formUriString, false); 
72          return formUri;
73      }
74  
75      public double getCredits() throws SmsServiceException {
76          LOG.debug("getCredits()");
77          
78          // there is no notion of credits in case of the UbsSmsService. 
79          
80          throw new UnsupportedOperationException("getCredits() not implemented for the UbsSmsService");
81      }
82  
83      public TransportHandler getTransport() {
84          LOG.debug("getTransport()");
85  
86          // FIXME: in this implementation of ths SmsService there is
87          // no need to implement the TransportHandler in its current
88          // form. How to augment or change the sms API?
89  
90          throw new UnsupportedOperationException("getTransport() not implemented for the UbsSmsService");
91      }
92  
93      public void setTransport(TransportHandler pTransport) {
94          LOG.debug("setTransport()");
95  
96          // FIXME: in this implementation of ths SmsService there is
97          // no need to implement the TransportHandler in its current
98          // form. How to augment or change the sms API?
99  
100         throw new UnsupportedOperationException("setTransport() not implemented for the UbsSmsService");
101 
102     }
103 
104 }