2014-02-19 20:06:30 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2014-05-15 15:04:46 +02:00
|
|
|
package org.jivesoftware.smack.bosh;
|
2014-02-19 20:06:30 +01:00
|
|
|
|
|
|
|
import java.net.URI;
|
|
|
|
import java.net.URISyntaxException;
|
|
|
|
|
|
|
|
import org.jivesoftware.smack.ConnectionConfiguration;
|
|
|
|
import org.jivesoftware.smack.proxy.ProxyInfo;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Configuration to use while establishing the connection to the XMPP server via
|
|
|
|
* HTTP binding.
|
|
|
|
*
|
2014-04-09 12:16:44 +02:00
|
|
|
* @see XMPPBOSHConnection
|
2014-02-19 20:06:30 +01:00
|
|
|
* @author Guenther Niess
|
|
|
|
*/
|
2015-04-06 10:45:12 +02:00
|
|
|
public final class BOSHConfiguration extends ConnectionConfiguration {
|
2014-02-19 20:06:30 +01:00
|
|
|
|
2014-11-09 18:30:16 +01:00
|
|
|
private final boolean https;
|
|
|
|
private final String file;
|
2014-02-19 20:06:30 +01:00
|
|
|
|
2014-12-17 17:01:53 +01:00
|
|
|
private BOSHConfiguration(Builder builder) {
|
2014-11-09 18:30:16 +01:00
|
|
|
super(builder);
|
|
|
|
https = builder.https;
|
|
|
|
if (builder.file.charAt(0) != '/') {
|
|
|
|
file = '/' + builder.file;
|
|
|
|
} else {
|
|
|
|
file = builder.file;
|
|
|
|
}
|
2014-02-19 20:06:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2014-11-09 18:30:16 +01:00
|
|
|
public boolean isUsingHTTPS() {
|
|
|
|
return https;
|
2014-02-19 20:06:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public URI getURI() throws URISyntaxException {
|
2014-11-09 18:30:16 +01:00
|
|
|
return new URI((https ? "https://" : "http://") + this.host + ":" + this.port + file);
|
|
|
|
}
|
|
|
|
|
2014-12-17 17:01:53 +01:00
|
|
|
public static Builder builder() {
|
|
|
|
return new Builder();
|
2014-11-09 18:30:16 +01:00
|
|
|
}
|
|
|
|
|
2015-04-06 10:45:12 +02:00
|
|
|
public static final class Builder extends ConnectionConfiguration.Builder<Builder, BOSHConfiguration> {
|
2014-11-09 18:30:16 +01:00
|
|
|
private boolean https;
|
|
|
|
private String file;
|
|
|
|
|
2014-12-17 17:01:53 +01:00
|
|
|
private Builder() {
|
2014-02-19 20:06:30 +01:00
|
|
|
}
|
2014-11-09 18:30:16 +01:00
|
|
|
|
2014-12-17 17:01:53 +01:00
|
|
|
public Builder setUseHttps(boolean useHttps) {
|
2014-11-09 18:30:16 +01:00
|
|
|
https = useHttps;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2014-12-17 17:01:53 +01:00
|
|
|
public Builder useHttps() {
|
2014-11-09 18:30:16 +01:00
|
|
|
return setUseHttps(true);
|
|
|
|
}
|
|
|
|
|
2014-12-17 17:01:53 +01:00
|
|
|
public Builder setFile(String file) {
|
2014-11-09 18:30:16 +01:00
|
|
|
this.file = file;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public BOSHConfiguration build() {
|
|
|
|
return new BOSHConfiguration(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-12-17 17:01:53 +01:00
|
|
|
protected Builder getThis() {
|
2014-11-09 18:30:16 +01:00
|
|
|
return this;
|
2014-03-20 16:56:58 +01:00
|
|
|
}
|
2014-02-19 20:06:30 +01:00
|
|
|
}
|
|
|
|
}
|