View Javadoc

1   package org.codehaus.xfire.xmpp;
2   
3   import org.apache.commons.logging.Log;
4   import org.apache.commons.logging.LogFactory;
5   import org.codehaus.xfire.XFire;
6   import org.codehaus.xfire.XFireRuntimeException;
7   import org.codehaus.xfire.service.Service;
8   import org.codehaus.xfire.transport.AbstractWSDLTransport;
9   import org.codehaus.xfire.transport.Channel;
10  import org.codehaus.xfire.transport.DefaultEndpoint;
11  import org.codehaus.xfire.transport.Transport;
12  import org.codehaus.xfire.wsdl11.WSDL11Transport;
13  
14  /***
15   * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
16   */
17  public class XMPPTransport
18      extends AbstractWSDLTransport
19      implements Transport, WSDL11Transport
20  {
21      private static final Log log = LogFactory.getLog(XMPPTransport.class);
22      
23      public final static String NAME = "XMPP";
24      public final static String XMPP_TRANSPORT_NS = "http://jabber.org/protocol/soap";
25  
26      private XFire xfire;
27      private String username;
28      private String password;
29      private String server;
30      private String id;
31      
32      public XMPPTransport(XFire xfire, String server, String username, String password)
33      {
34          this.username = username;
35          this.password = password;
36          this.server = server;
37          this.xfire = xfire;
38          
39          this.id = username + "@" + server;
40          
41          // Make sure the SoapIQProvider class has been loaded so
42          // our IQ provider is registered.
43          new SoapIQProvider();
44          
45          addFaultHandler(new XMPPFaultHandler());
46      }
47  
48      /***
49       * Gets the transport name. @see NAME.
50       */
51      public String getName()
52      {
53          return NAME;
54      }
55  
56      /***
57       * @param service
58       * @return
59       */
60      public String getServiceURL(Service service)
61      {
62          try
63          {
64              return id + "/" + service.getName();
65          }
66          catch (Exception e)
67          {
68              throw new XFireRuntimeException("Couldn't create the channel.", e);
69          }
70      }
71  
72      /***
73       * @param service
74       * @return
75       */
76      public String getTransportURI(Service service)
77      {
78          return XMPP_TRANSPORT_NS;
79      }
80  
81      protected Channel createNewChannel(String uri)
82      {
83          log.debug("Creating new channel for uri: " + uri);
84          
85          XMPPChannel c = new XMPPChannel(uri, this);
86          c.setEndpoint(new DefaultEndpoint());
87  
88          return c;
89      }
90  
91      protected String getUriPrefix()
92      {
93          return id;
94      }
95  
96      public String getPassword()
97      {
98          return password;
99      }
100     
101     public XFire getXFire()
102     {
103         return xfire;
104     }
105 
106     public String getServer()
107     {
108         return server;
109     }
110 
111     public String getUsername()
112     {
113         return username;
114     }
115 
116     public String[] getKnownUriSchemes()
117     {
118         return new String[] { "xmpp://" };
119     }
120 
121 }