Commit 31e93b66 authored by guus's avatar guus

OF-524: Send a stream:error before closing a connection.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@12980 b35dd754-fafc-0310-a699-88a17e54d16e
parent 681d8788
......@@ -36,6 +36,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
import org.xmpp.packet.StreamError;
/**
* A ConnectionHandler is responsible for creating new sessions, destroying sessions and delivering
......@@ -137,8 +138,18 @@ public abstract class ConnectionHandler extends IoHandlerAdapter {
// TODO Verify if there were packets pending to be sent and decide what to do with them
Log.debug("ConnectionHandler: ",cause);
}
else if (cause instanceof XMLNotWellFormedException) {
Log.warn("Closing session due to malformed XML: " + session, cause);
final Connection connection = (Connection) session.getAttribute(CONNECTION);
final StreamError error = new StreamError(StreamError.Condition.xml_not_well_formed);
connection.deliverRawText(error.toXML());
session.close();
}
else if (cause instanceof ProtocolDecoderException) {
Log.warn("Closing session due to exception: " + session, cause);
final Connection connection = (Connection) session.getAttribute(CONNECTION);
final StreamError error = new StreamError(StreamError.Condition.internal_server_error);
connection.deliverRawText(error.toXML());
session.close();
}
else {
......
......@@ -155,11 +155,11 @@ class XMLLightweightParser {
/*
* Method that add a message to the list and reinit parser.
*/
protected void foundMsg(String msg) throws Exception {
protected void foundMsg(String msg) throws XMLNotWellFormedException {
// Add message to the complete message list
if (msg != null) {
if (hasIllegalCharacterReferences(msg)) {
throw new Exception("Illegal character reference found in: " + msg);
throw new XMLNotWellFormedException("Illegal character reference found in: " + msg);
}
msgs.add(msg);
}
......@@ -205,7 +205,7 @@ class XMLLightweightParser {
if (ch < 0x20 && ch != 0x9 && ch != 0xA && ch != 0xD && ch != 0x0) {
//Unicode characters in the range 0x0000-0x001F other than 9, A, and D are not allowed in XML
//We need to allow the NULL character, however, for Flash XMLSocket clients to work.
throw new Exception("Disallowed character");
throw new XMLNotWellFormedException("Character is invalid in: " + ch);
}
if (isHighSurrogate) {
if (Character.isLowSurrogate(ch)) {
......
/**
* $Revision: $
* $Date: $
*
* Copyright (C) 2005-2008 Jive Software. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.openfire.nio;
/**
* An Exception indicating that evaluated content is not valid XML.
*
* @author Guus der Kinderen, guus.der.kinderen@gmail.com
*/
public class XMLNotWellFormedException extends Exception {
private static final long serialVersionUID = 1L;
public XMLNotWellFormedException() {
super();
}
public XMLNotWellFormedException(String message, Throwable cause) {
super(message, cause);
}
public XMLNotWellFormedException(String message) {
super(message);
}
public XMLNotWellFormedException(Throwable cause) {
super(cause);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment