mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-16 01:02:06 +01:00
Merge pull request #280 from MarcelHeckel/bosh_connection_with_compression
Enables the HTTP compression in JBOSH
This commit is contained in:
commit
49b7e8b905
3 changed files with 23 additions and 32 deletions
|
@ -157,6 +157,8 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
|
||||||
if (config.isProxyEnabled()) {
|
if (config.isProxyEnabled()) {
|
||||||
cfgBuilder.setProxy(config.getProxyAddress(), config.getProxyPort());
|
cfgBuilder.setProxy(config.getProxyAddress(), config.getProxyPort());
|
||||||
}
|
}
|
||||||
|
cfgBuilder.setCompressionEnabled(config.isCompressionEnabled());
|
||||||
|
|
||||||
client = BOSHClient.create(cfgBuilder.build());
|
client = BOSHClient.create(cfgBuilder.build());
|
||||||
|
|
||||||
client.addBOSHClientConnListener(new BOSHConnectionListener());
|
client.addBOSHClientConnListener(new BOSHConnectionListener());
|
||||||
|
|
|
@ -125,6 +125,8 @@ public abstract class ConnectionConfiguration {
|
||||||
|
|
||||||
private final Set<String> enabledSaslMechanisms;
|
private final Set<String> enabledSaslMechanisms;
|
||||||
|
|
||||||
|
private final boolean compressionEnabled;
|
||||||
|
|
||||||
protected ConnectionConfiguration(Builder<?,?> builder) {
|
protected ConnectionConfiguration(Builder<?,?> builder) {
|
||||||
authzid = builder.authzid;
|
authzid = builder.authzid;
|
||||||
username = builder.username;
|
username = builder.username;
|
||||||
|
@ -162,6 +164,8 @@ public abstract class ConnectionConfiguration {
|
||||||
allowNullOrEmptyUsername = builder.allowEmptyOrNullUsername;
|
allowNullOrEmptyUsername = builder.allowEmptyOrNullUsername;
|
||||||
enabledSaslMechanisms = builder.enabledSaslMechanisms;
|
enabledSaslMechanisms = builder.enabledSaslMechanisms;
|
||||||
|
|
||||||
|
compressionEnabled = builder.compressionEnabled;
|
||||||
|
|
||||||
// If the enabledSaslmechanisms are set, then they must not be empty
|
// If the enabledSaslmechanisms are set, then they must not be empty
|
||||||
assert (enabledSaslMechanisms != null ? !enabledSaslMechanisms.isEmpty() : true);
|
assert (enabledSaslMechanisms != null ? !enabledSaslMechanisms.isEmpty() : true);
|
||||||
|
|
||||||
|
@ -440,8 +444,7 @@ public abstract class ConnectionConfiguration {
|
||||||
* @return true if the connection is going to use stream compression.
|
* @return true if the connection is going to use stream compression.
|
||||||
*/
|
*/
|
||||||
public boolean isCompressionEnabled() {
|
public boolean isCompressionEnabled() {
|
||||||
// Compression for non-TCP connections is always disabled
|
return compressionEnabled;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -513,6 +516,7 @@ public abstract class ConnectionConfiguration {
|
||||||
private boolean saslMechanismsSealed;
|
private boolean saslMechanismsSealed;
|
||||||
private Set<String> enabledSaslMechanisms;
|
private Set<String> enabledSaslMechanisms;
|
||||||
private X509TrustManager customX509TrustManager;
|
private X509TrustManager customX509TrustManager;
|
||||||
|
private boolean compressionEnabled = false;
|
||||||
|
|
||||||
protected Builder() {
|
protected Builder() {
|
||||||
if (SmackConfiguration.DEBUG) {
|
if (SmackConfiguration.DEBUG) {
|
||||||
|
@ -946,6 +950,21 @@ public abstract class ConnectionConfiguration {
|
||||||
return getThis();
|
return getThis();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets if the connection is going to use compression (default false).
|
||||||
|
*
|
||||||
|
* Compression is only activated if the server offers compression. With compression network
|
||||||
|
* traffic can be reduced up to 90%. By default compression is disabled.
|
||||||
|
*
|
||||||
|
* @param compressionEnabled if the connection is going to use compression on the HTTP level.
|
||||||
|
* @return a reference to this object.
|
||||||
|
*/
|
||||||
|
public B setCompressionEnabled(boolean compressionEnabled) {
|
||||||
|
this.compressionEnabled = compressionEnabled;
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public abstract C build();
|
public abstract C build();
|
||||||
|
|
||||||
protected abstract B getThis();
|
protected abstract B getThis();
|
||||||
|
|
|
@ -41,8 +41,6 @@ public final class XMPPTCPConnectionConfiguration extends ConnectionConfiguratio
|
||||||
*/
|
*/
|
||||||
public static int DEFAULT_CONNECT_TIMEOUT = 30000;
|
public static int DEFAULT_CONNECT_TIMEOUT = 30000;
|
||||||
|
|
||||||
private final boolean compressionEnabled;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How long the socket will wait until a TCP connection is established (in milliseconds).
|
* How long the socket will wait until a TCP connection is established (in milliseconds).
|
||||||
*/
|
*/
|
||||||
|
@ -50,23 +48,9 @@ public final class XMPPTCPConnectionConfiguration extends ConnectionConfiguratio
|
||||||
|
|
||||||
private XMPPTCPConnectionConfiguration(Builder builder) {
|
private XMPPTCPConnectionConfiguration(Builder builder) {
|
||||||
super(builder);
|
super(builder);
|
||||||
compressionEnabled = builder.compressionEnabled;
|
|
||||||
connectTimeout = builder.connectTimeout;
|
connectTimeout = builder.connectTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if the connection is going to use stream compression. Stream compression
|
|
||||||
* will be requested after TLS was established (if TLS was enabled) and only if the server
|
|
||||||
* offered stream compression. With stream compression network traffic can be reduced
|
|
||||||
* up to 90%. By default compression is disabled.
|
|
||||||
*
|
|
||||||
* @return true if the connection is going to use stream compression.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean isCompressionEnabled() {
|
|
||||||
return compressionEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How long the socket will wait until a TCP connection is established (in milliseconds). Defaults to {@link #DEFAULT_CONNECT_TIMEOUT}.
|
* How long the socket will wait until a TCP connection is established (in milliseconds). Defaults to {@link #DEFAULT_CONNECT_TIMEOUT}.
|
||||||
*
|
*
|
||||||
|
@ -91,20 +75,6 @@ public final class XMPPTCPConnectionConfiguration extends ConnectionConfiguratio
|
||||||
private Builder() {
|
private Builder() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets if the connection is going to use stream compression. Stream compression
|
|
||||||
* will be requested after TLS was established (if TLS was enabled) and only if the server
|
|
||||||
* offered stream compression. With stream compression network traffic can be reduced
|
|
||||||
* up to 90%. By default compression is disabled.
|
|
||||||
*
|
|
||||||
* @param compressionEnabled if the connection is going to use stream compression.
|
|
||||||
* @return a reference to this object.
|
|
||||||
*/
|
|
||||||
public Builder setCompressionEnabled(boolean compressionEnabled) {
|
|
||||||
this.compressionEnabled = compressionEnabled;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set how long the socket will wait until a TCP connection is established (in milliseconds).
|
* Set how long the socket will wait until a TCP connection is established (in milliseconds).
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue