001/** 002 * 003 * Copyright 2009 Jive Software. 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package org.jivesoftware.smack.bosh; 019 020import java.net.URI; 021import java.net.URISyntaxException; 022 023import org.jivesoftware.smack.ConnectionConfiguration; 024import org.jivesoftware.smack.proxy.ProxyInfo; 025 026/** 027 * Configuration to use while establishing the connection to the XMPP server via 028 * HTTP binding. 029 * 030 * @see XMPPBOSHConnection 031 * @author Guenther Niess 032 */ 033public class BOSHConfiguration extends ConnectionConfiguration { 034 035 private final boolean https; 036 private final String file; 037 038 private BOSHConfiguration(Builder builder) { 039 super(builder); 040 https = builder.https; 041 if (builder.file.charAt(0) != '/') { 042 file = '/' + builder.file; 043 } else { 044 file = builder.file; 045 } 046 } 047 048 public boolean isProxyEnabled() { 049 return (proxy != null && proxy.getProxyType() != ProxyInfo.ProxyType.NONE); 050 } 051 052 public ProxyInfo getProxyInfo() { 053 return proxy; 054 } 055 056 public String getProxyAddress() { 057 return (proxy != null ? proxy.getProxyAddress() : null); 058 } 059 060 public int getProxyPort() { 061 return (proxy != null ? proxy.getProxyPort() : 8080); 062 } 063 064 public boolean isUsingHTTPS() { 065 return https; 066 } 067 068 public URI getURI() throws URISyntaxException { 069 return new URI((https ? "https://" : "http://") + this.host + ":" + this.port + file); 070 } 071 072 public static Builder builder() { 073 return new Builder(); 074 } 075 076 public static class Builder extends ConnectionConfiguration.Builder<Builder, BOSHConfiguration> { 077 private boolean https; 078 private String file; 079 080 private Builder() { 081 } 082 083 public Builder setUseHttps(boolean useHttps) { 084 https = useHttps; 085 return this; 086 } 087 088 public Builder useHttps() { 089 return setUseHttps(true); 090 } 091 092 public Builder setFile(String file) { 093 this.file = file; 094 return this; 095 } 096 097 @Override 098 public BOSHConfiguration build() { 099 return new BOSHConfiguration(this); 100 } 101 102 @Override 103 protected Builder getThis() { 104 return this; 105 } 106 } 107}