001/** 002 * 003 * Copyright 2003-2005 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.packet; 019 020/** 021 * Represents a stream error packet. Stream errors are unrecoverable errors where the server 022 * will close the unrelying TCP connection after the stream error was sent to the client. 023 * These is the list of stream errors as defined in the XMPP spec:<p> 024 * 025 * <table border=1> 026 * <tr><td><b>Code</b></td><td><b>Description</b></td></tr> 027 * <tr><td> bad-format </td><td> the entity has sent XML that cannot be processed </td></tr> 028 * <tr><td> unsupported-encoding </td><td> the entity has sent a namespace prefix that is 029 * unsupported </td></tr> 030 * <tr><td> bad-namespace-prefix </td><td> Remote Server Timeout </td></tr> 031 * <tr><td> conflict </td><td> the server is closing the active stream for this entity 032 * because a new stream has been initiated that conflicts with the existing 033 * stream. </td></tr> 034 * <tr><td> connection-timeout </td><td> the entity has not generated any traffic over 035 * the stream for some period of time. </td></tr> 036 * <tr><td> host-gone </td><td> the value of the 'to' attribute provided by the initiating 037 * entity in the stream header corresponds to a hostname that is no longer hosted by 038 * the server. </td></tr> 039 * <tr><td> host-unknown </td><td> the value of the 'to' attribute provided by the 040 * initiating entity in the stream header does not correspond to a hostname that is 041 * hosted by the server. </td></tr> 042 * <tr><td> improper-addressing </td><td> a stanza sent between two servers lacks a 'to' 043 * or 'from' attribute </td></tr> 044 * <tr><td> internal-server-error </td><td> the server has experienced a 045 * misconfiguration. </td></tr> 046 * <tr><td> invalid-from </td><td> the JID or hostname provided in a 'from' address does 047 * not match an authorized JID. </td></tr> 048 * <tr><td> invalid-namespace </td><td> the streams namespace name is invalid. </td></tr> 049 * <tr><td> invalid-xml </td><td> the entity has sent invalid XML over the stream. </td></tr> 050 * <tr><td> not-authorized </td><td> the entity has attempted to send data before the 051 * stream has been authenticated </td></tr> 052 * <tr><td> policy-violation </td><td> the entity has violated some local service 053 * policy. </td></tr> 054 * <tr><td> remote-connection-failed </td><td> Rthe server is unable to properly connect 055 * to a remote entity. </td></tr> 056 * <tr><td> resource-constraint </td><td> Rthe server lacks the system resources necessary 057 * to service the stream. </td></tr> 058 * <tr><td> restricted-xml </td><td> the entity has attempted to send restricted XML 059 * features. </td></tr> 060 * <tr><td> see-other-host </td><td> the server will not provide service to the initiating 061 * entity but is redirecting traffic to another host. </td></tr> 062 * <tr><td> system-shutdown </td><td> the server is being shut down and all active streams 063 * are being closed. </td></tr> 064 * <tr><td> undefined-condition </td><td> the error condition is not one of those defined 065 * by the other conditions in this list. </td></tr> 066 * <tr><td> unsupported-encoding </td><td> the initiating entity has encoded the stream in 067 * an encoding that is not supported. </td></tr> 068 * <tr><td> unsupported-stanza-type </td><td> the initiating entity has sent a first-level 069 * child of the stream that is not supported. </td></tr> 070 * <tr><td> unsupported-version </td><td> the value of the 'version' attribute provided by 071 * the initiating entity in the stream header specifies a version of XMPP that is not 072 * supported. </td></tr> 073 * <tr><td> not-well-formed </td><td> the initiating entity has sent XML that is not 074 * well-formed. </td></tr> 075 * </table> 076 * 077 * @author Gaston Dombiak 078 */ 079public class StreamError { 080 081 public static final String NAMESPACE = "urn:ietf:params:xml:ns:xmpp-streams"; 082 083 private String code; 084 private String text; 085 086 public StreamError(String code) { 087 super(); 088 this.code = code; 089 } 090 091 public StreamError(String code, String text) { 092 this(code); 093 this.text = text; 094 } 095 096 /** 097 * Returns the error code. 098 * 099 * @return the error code. 100 */ 101 public String getCode() { 102 return code; 103 } 104 105 /** 106 * Returns the error text, which may be null. 107 * 108 * @return the error text. 109 */ 110 public String getText() { 111 return text; 112 } 113 114 public String toString() { 115 StringBuilder txt = new StringBuilder(); 116 txt.append("stream:error (").append(code).append(")"); 117 if (text != null) txt.append(" text: ").append(text); 118 return txt.toString(); 119 } 120}