• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * $RCSfile$
3  * $Revision$
4  * $Date$
5  *
6  * Copyright 2009 Jive Software.
7  *
8  * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 package org.jivesoftware.smack;
22 
23 import java.net.URI;
24 import java.net.URISyntaxException;
25 
26 import org.jivesoftware.smack.ConnectionConfiguration;
27 import org.jivesoftware.smack.proxy.ProxyInfo;
28 
29 /**
30  * Configuration to use while establishing the connection to the XMPP server via
31  * HTTP binding.
32  *
33  * @see BOSHConnection
34  * @author Guenther Niess
35  */
36 public class BOSHConfiguration extends ConnectionConfiguration {
37 
38     private boolean ssl;
39     private String file;
40 
BOSHConfiguration(String xmppDomain)41     public BOSHConfiguration(String xmppDomain) {
42         super(xmppDomain, 7070);
43         setSASLAuthenticationEnabled(true);
44         ssl = false;
45         file = "/http-bind/";
46     }
47 
BOSHConfiguration(String xmppDomain, int port)48     public BOSHConfiguration(String xmppDomain, int port) {
49         super(xmppDomain, port);
50         setSASLAuthenticationEnabled(true);
51         ssl = false;
52         file = "/http-bind/";
53     }
54 
55     /**
56      * Create a HTTP Binding configuration.
57      *
58      * @param https true if you want to use SSL
59      *             (e.g. false for http://domain.lt:7070/http-bind).
60      * @param host the hostname or IP address of the connection manager
61      *             (e.g. domain.lt for http://domain.lt:7070/http-bind).
62      * @param port the port of the connection manager
63      *             (e.g. 7070 for http://domain.lt:7070/http-bind).
64      * @param filePath the file which is described by the URL
65      *             (e.g. /http-bind for http://domain.lt:7070/http-bind).
66      * @param xmppDomain the XMPP service name
67      *             (e.g. domain.lt for the user alice@domain.lt)
68      */
BOSHConfiguration(boolean https, String host, int port, String filePath, String xmppDomain)69     public BOSHConfiguration(boolean https, String host, int port, String filePath, String xmppDomain) {
70         super(host, port, xmppDomain);
71         setSASLAuthenticationEnabled(true);
72         ssl = https;
73         file = (filePath != null ? filePath : "/");
74     }
75 
76     /**
77      * Create a HTTP Binding configuration.
78      *
79      * @param https true if you want to use SSL
80      *             (e.g. false for http://domain.lt:7070/http-bind).
81      * @param host the hostname or IP address of the connection manager
82      *             (e.g. domain.lt for http://domain.lt:7070/http-bind).
83      * @param port the port of the connection manager
84      *             (e.g. 7070 for http://domain.lt:7070/http-bind).
85      * @param filePath the file which is described by the URL
86      *             (e.g. /http-bind for http://domain.lt:7070/http-bind).
87      * @param proxy the configuration of a proxy server.
88      * @param xmppDomain the XMPP service name
89      *             (e.g. domain.lt for the user alice@domain.lt)
90      */
BOSHConfiguration(boolean https, String host, int port, String filePath, ProxyInfo proxy, String xmppDomain)91     public BOSHConfiguration(boolean https, String host, int port, String filePath, ProxyInfo proxy, String xmppDomain) {
92         super(host, port, xmppDomain, proxy);
93         setSASLAuthenticationEnabled(true);
94         ssl = https;
95         file = (filePath != null ? filePath : "/");
96     }
97 
isProxyEnabled()98     public boolean isProxyEnabled() {
99         return (proxy != null && proxy.getProxyType() != ProxyInfo.ProxyType.NONE);
100     }
101 
getProxyInfo()102     public ProxyInfo getProxyInfo() {
103         return proxy;
104     }
105 
getProxyAddress()106     public String getProxyAddress() {
107         return (proxy != null ? proxy.getProxyAddress() : null);
108     }
109 
getProxyPort()110     public int getProxyPort() {
111         return (proxy != null ? proxy.getProxyPort() : 8080);
112     }
113 
isUsingSSL()114     public boolean isUsingSSL() {
115         return ssl;
116     }
117 
getURI()118     public URI getURI() throws URISyntaxException {
119         if (file.charAt(0) != '/') {
120             file = '/' + file;
121         }
122         return new URI((ssl ? "https://" : "http://") + getHost() + ":" + getPort() + file);
123     }
124 }
125