diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/hoxt/packet/AbstractHttpOverXmpp.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/hoxt/packet/AbstractHttpOverXmpp.java index 4692e787b..7af56e8b2 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/hoxt/packet/AbstractHttpOverXmpp.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/hoxt/packet/AbstractHttpOverXmpp.java @@ -31,20 +31,25 @@ public abstract class AbstractHttpOverXmpp extends IQ { public static final String NAMESPACE = "urn:xmpp:http"; - protected AbstractHttpOverXmpp(String element) { - super(element, NAMESPACE); - } - private HeadersExtension headers; private Data data; protected String version; + protected AbstractHttpOverXmpp(String element, Builder, ?> builder) { + super(element, NAMESPACE); + this.headers = builder.headers; + this.data = builder.data; + this.version = builder.version; + } + protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) { IQChildElementXmlStringBuilder builder = getIQHoxtChildElementBuilder(xml); - builder.optAppend(headers.toXML()); - builder.optAppend(data.toXML()); - + builder.optAppend(headers); + /* data cannot be fed to optAppend */ + if (data != null) { + builder.optAppend(data.toXML()); + } return builder; } @@ -64,15 +69,6 @@ public abstract class AbstractHttpOverXmpp extends IQ { return version; } - /** - * Sets version attribute. - * - * @param version version attribute - */ - public void setVersion(String version) { - this.version = version; - } - /** * Returns Headers element. * @@ -82,15 +78,6 @@ public abstract class AbstractHttpOverXmpp extends IQ { return headers; } - /** - * Sets Headers element. - * - * @param headers Headers element - */ - public void setHeaders(HeadersExtension headers) { - this.headers = headers; - } - /** * Returns Data element. * @@ -101,16 +88,65 @@ public abstract class AbstractHttpOverXmpp extends IQ { } /** - * Sets Data element. + * A builder for XMPP connection configurations. + *
+ * See ConnectionConfiguration Buidler for more details. + *
* - * @param data Headers element + * @param the builder type parameter. + * @param+ * Representation of Data element. + *
* This class is immutable. */ public static class Data { @@ -150,7 +186,8 @@ public abstract class AbstractHttpOverXmpp extends IQ { } /** - * Representation of Text element.
+ * Representation of Text element. + *
* This class is immutable. */ public static class Text implements NamedElement { @@ -193,7 +230,8 @@ public abstract class AbstractHttpOverXmpp extends IQ { } /** - * Representation of Base64 element.
+ * Representation of Base64 element. + *
* This class is immutable. */ public static class Base64 implements NamedElement { @@ -236,7 +274,8 @@ public abstract class AbstractHttpOverXmpp extends IQ { } /** - * Representation of Xml element.
+ * Representation of Xml element. + *
* This class is immutable. */ public static class Xml implements NamedElement { @@ -279,7 +318,8 @@ public abstract class AbstractHttpOverXmpp extends IQ { } /** - * Representation of ChunkedBase64 element.
+ * Representation of ChunkedBase64 element. + *
* This class is immutable. */ public static class ChunkedBase64 implements NamedElement { @@ -321,7 +361,8 @@ public abstract class AbstractHttpOverXmpp extends IQ { } /** - * Representation of Ibb element.
+ * Representation of Ibb element. + *
* This class is immutable.
*/
public static class Ibb implements NamedElement {
diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/hoxt/packet/HttpOverXmppReq.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/hoxt/packet/HttpOverXmppReq.java
index c13bf46df..9f92615de 100644
--- a/smack-experimental/src/main/java/org/jivesoftware/smackx/hoxt/packet/HttpOverXmppReq.java
+++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/hoxt/packet/HttpOverXmppReq.java
@@ -24,15 +24,18 @@ import org.jivesoftware.smack.util.StringUtils;
* @author Andriy Tsykholyas
* @see XEP-0332: HTTP over XMPP transport
*/
-public class HttpOverXmppReq extends AbstractHttpOverXmpp {
+public final class HttpOverXmppReq extends AbstractHttpOverXmpp {
public static final String ELEMENT = "req";
-
- public HttpOverXmppReq(HttpMethod method, String resource) {
- super(ELEMENT);
- this.method = method;
- this.resource = resource;
+ private HttpOverXmppReq(Builder builder) {
+ super(ELEMENT, builder);
+ this.method = builder.method;
+ this.resource = builder.resource;
+ this.maxChunkSize = builder.maxChunkSize;
+ this.ibb = builder.ibb;
+ this.jingle = builder.jingle;
+ this.sipub = builder.sipub;
setType(Type.set);
}
@@ -40,12 +43,12 @@ public class HttpOverXmppReq extends AbstractHttpOverXmpp {
private String resource;
// TODO: validate: xs:minInclusive value='256' xs:maxInclusive value='65536'
- private int maxChunkSize = 0; // 0 means not set
+ private int maxChunkSize; // 0 means not set
- private boolean sipub = true;
+ private boolean sipub;
- private boolean ibb = true;
- private boolean jingle = true;
+ private boolean ibb;
+ private boolean jingle;
@Override
protected IQChildElementXmlStringBuilder getIQHoxtChildElementBuilder(IQChildElementXmlStringBuilder builder) {
@@ -96,15 +99,6 @@ public class HttpOverXmppReq extends AbstractHttpOverXmpp {
return maxChunkSize;
}
- /**
- * Sets maxChunkSize attribute.
- *
- * @param maxChunkSize maxChunkSize attribute
- */
- public void setMaxChunkSize(int maxChunkSize) {
- this.maxChunkSize = maxChunkSize;
- }
-
/**
* Returns sipub attribute.
*
@@ -114,15 +108,6 @@ public class HttpOverXmppReq extends AbstractHttpOverXmpp {
return sipub;
}
- /**
- * Sets sipub attribute.
- *
- * @param sipub sipub attribute
- */
- public void setSipub(boolean sipub) {
- this.sipub = sipub;
- }
-
/**
* Returns ibb attribute.
*
@@ -132,15 +117,6 @@ public class HttpOverXmppReq extends AbstractHttpOverXmpp {
return ibb;
}
- /**
- * Sets ibb attribute.
- *
- * @param ibb ibb attribute
- */
- public void setIbb(boolean ibb) {
- this.ibb = ibb;
- }
-
/**
* Returns jingle attribute.
*
@@ -150,12 +126,119 @@ public class HttpOverXmppReq extends AbstractHttpOverXmpp {
return jingle;
}
+ public static Builder builder() {
+ return new Builder();
+ }
+
/**
- * Sets jingle attribute.
- *
- * @param jingle jingle attribute
+ * A configuration builder for HttpOverXmppReq. Use {@link HttpOverXmppReq#builder()} to obtain a new instance and
+ * {@link #build} to build the configuration.
*/
- public void setJingle(boolean jingle) {
- this.jingle = jingle;
+ public static final class Builder extends AbstractHttpOverXmpp.Builder