1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-06-14 15:44:49 +02:00
Smack/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/BOSHConfiguration.java
Florian Schmaus 4c76f2652d Reworked OSGi support of Smack (SMACK-343)
Because of OSGi, no subproject of Smack (which is the same as a OSGi
bundle) must export a package that is already exported by another
subproject.

Therefore it was necessary to move the TCP and BOSH code into their own
packages: org.jivesoftware.smack.(tcp|bosh).

OSGi classloader restrictions also made it necessary to create a
Declarative Service for smack-extensions, smack-experimental and
smack-lagacy (i.e. smack subprojects which should be initialized), in
order to initialize them accordingly, as smack-core is, when used in a
OSGi environment, unable to load and initialize classes from other smack
bundles. OSGi's "Service Component Runtime" (SCR) will now take care of
running the initialization code of the particular Smack bundle by
activating its Declarative Service.

That is also the reason why most initialization related method now have an
additional classloader argument.

Note that due the refactoring, some ugly changes in XMPPTCPConnection
and its PacketReader and PacketWriter where necessary.
2014-05-15 16:09:37 +02:00

129 lines
4.2 KiB
Java

/**
*
* Copyright 2009 Jive Software.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smack.bosh;
import java.net.URI;
import java.net.URISyntaxException;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.proxy.ProxyInfo;
import org.jivesoftware.smack.util.dns.HostAddress;
/**
* Configuration to use while establishing the connection to the XMPP server via
* HTTP binding.
*
* @see XMPPBOSHConnection
* @author Guenther Niess
*/
public class BOSHConfiguration extends ConnectionConfiguration {
private boolean ssl;
private String file;
public BOSHConfiguration(String xmppDomain) {
super(xmppDomain, 7070);
ssl = false;
file = "/http-bind/";
}
public BOSHConfiguration(String xmppDomain, int port) {
super(xmppDomain, port);
ssl = false;
file = "/http-bind/";
}
/**
* Create a HTTP Binding configuration.
*
* @param https true if you want to use SSL
* (e.g. false for http://domain.lt:7070/http-bind).
* @param host the hostname or IP address of the connection manager
* (e.g. domain.lt for http://domain.lt:7070/http-bind).
* @param port the port of the connection manager
* (e.g. 7070 for http://domain.lt:7070/http-bind).
* @param filePath the file which is described by the URL
* (e.g. /http-bind for http://domain.lt:7070/http-bind).
* @param xmppDomain the XMPP service name
* (e.g. domain.lt for the user alice@domain.lt)
*/
public BOSHConfiguration(boolean https, String host, int port, String filePath, String xmppDomain) {
super(host, port, xmppDomain);
ssl = https;
file = (filePath != null ? filePath : "/");
}
/**
* Create a HTTP Binding configuration.
*
* @param https true if you want to use SSL
* (e.g. false for http://domain.lt:7070/http-bind).
* @param host the hostname or IP address of the connection manager
* (e.g. domain.lt for http://domain.lt:7070/http-bind).
* @param port the port of the connection manager
* (e.g. 7070 for http://domain.lt:7070/http-bind).
* @param filePath the file which is described by the URL
* (e.g. /http-bind for http://domain.lt:7070/http-bind).
* @param proxy the configuration of a proxy server.
* @param xmppDomain the XMPP service name
* (e.g. domain.lt for the user alice@domain.lt)
*/
public BOSHConfiguration(boolean https, String host, int port, String filePath, ProxyInfo proxy, String xmppDomain) {
super(host, port, xmppDomain, proxy);
ssl = https;
file = (filePath != null ? filePath : "/");
}
public boolean isProxyEnabled() {
return (proxy != null && proxy.getProxyType() != ProxyInfo.ProxyType.NONE);
}
public ProxyInfo getProxyInfo() {
return proxy;
}
public String getProxyAddress() {
return (proxy != null ? proxy.getProxyAddress() : null);
}
public int getProxyPort() {
return (proxy != null ? proxy.getProxyPort() : 8080);
}
public boolean isUsingSSL() {
return ssl;
}
public URI getURI() throws URISyntaxException {
if (file.charAt(0) != '/') {
file = '/' + file;
}
String host;
int port;
if (hostAddresses != null) {
HostAddress hostAddress = hostAddresses.get(0);
host = hostAddress.getFQDN();
port = hostAddress.getPort();
} else {
host = getServiceName();
port = 80;
}
return new URI((ssl ? "https://" : "http://") + host + ":" + port + file);
}
}