001/** 002 * 003 * Copyright 2014 Andriy Tsykholyas 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 */ 017package org.jivesoftware.smackx.hoxt.packet; 018 019import org.jivesoftware.smack.util.Objects; 020 021/** 022 * Represents Resp IQ packet. 023 * 024 * @author Andriy Tsykholyas 025 * @see <a href="http://xmpp.org/extensions/xep-0332.html">XEP-0332: HTTP over XMPP transport</a> 026 */ 027public final class HttpOverXmppResp extends AbstractHttpOverXmpp { 028 029 public static final String ELEMENT = "resp"; 030 031 private HttpOverXmppResp(Builder builder) { 032 super(ELEMENT, builder); 033 this.statusCode = Objects.requireNonNull(builder.statusCode, "statusCode must not be null"); 034 this.statusMessage = builder.statusMessage; 035 } 036 037 private final int statusCode; 038 private final String statusMessage; 039 040 @Override 041 protected IQChildElementXmlStringBuilder getIQHoxtChildElementBuilder(IQChildElementXmlStringBuilder builder) { 042 builder.attribute("version", getVersion()); 043 builder.attribute("statusCode", statusCode); 044 builder.optAttribute("statusMessage", statusMessage); 045 builder.rightAngleBracket(); 046 return builder; 047 } 048 049 /** 050 * Returns statusCode attribute. 051 * 052 * @return statusCode attribute 053 */ 054 public int getStatusCode() { 055 return statusCode; 056 } 057 058 /** 059 * Returns statusMessage attribute. 060 * 061 * @return statusMessage attribute 062 */ 063 public String getStatusMessage() { 064 return statusMessage; 065 } 066 067 public static Builder builder() { 068 return new Builder(); 069 } 070 071 /** 072 * A configuration builder for HttpOverXmppReq. Use {@link HttpOverXmppResp#builder()} to obtain a new instance and 073 * {@link #build} to build the configuration. 074 */ 075 public static final class Builder extends AbstractHttpOverXmpp.Builder<Builder, HttpOverXmppResp> { 076 077 private int statusCode = 200; 078 private String statusMessage = null; 079 080 private Builder() { 081 } 082 083 /** 084 * Sets statusCode attribute. 085 * 086 * @param statusCode statusCode attribute 087 * 088 * @return the builder 089 */ 090 public Builder setStatusCode(int statusCode) { 091 this.statusCode = statusCode; 092 return this; 093 } 094 095 /** 096 * Sets statusMessage attribute. 097 * 098 * @param statusMessage statusMessage attribute 099 * 100 * @return the builder 101 */ 102 public Builder setStatusMessage(String statusMessage) { 103 this.statusMessage = statusMessage; 104 return this; 105 106 } 107 108 @Override 109 public HttpOverXmppResp build() { 110 return new HttpOverXmppResp(this); 111 } 112 113 @Override 114 protected Builder getThis() { 115 return this; 116 } 117 } 118 119}