Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
Openfire
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Openfire
Commits
23d6aabc
Commit
23d6aabc
authored
Oct 30, 2015
by
Dave Cridland
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #346 from sco0ter/utf8
Use StandardCharsets.UTF_8 with Reader/Writer classes.
parents
1989f919
8b272c67
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
28 additions
and
29 deletions
+28
-29
AuditorImpl.java
...java/org/jivesoftware/openfire/audit/spi/AuditorImpl.java
+2
-1
HttpBindServlet.java
src/java/org/jivesoftware/openfire/http/HttpBindServlet.java
+1
-1
SocketConnection.java
src/java/org/jivesoftware/openfire/net/SocketConnection.java
+6
-10
ConnectionHandler.java
...java/org/jivesoftware/openfire/nio/ConnectionHandler.java
+3
-5
XMLLightweightParser.java
...a/org/jivesoftware/openfire/nio/XMLLightweightParser.java
+2
-2
LocalOutgoingServerSession.java
...software/openfire/session/LocalOutgoingServerSession.java
+6
-5
UpdateManager.java
src/java/org/jivesoftware/openfire/update/UpdateManager.java
+3
-2
XMLProperties.java
src/java/org/jivesoftware/util/XMLProperties.java
+3
-2
XMLWriter.java
src/java/org/jivesoftware/util/XMLWriter.java
+2
-1
No files found.
src/java/org/jivesoftware/openfire/audit/spi/AuditorImpl.java
View file @
23d6aabc
...
...
@@ -27,6 +27,7 @@ import java.io.FilenameFilter;
import
java.io.IOException
;
import
java.io.OutputStreamWriter
;
import
java.io.Writer
;
import
java.nio.charset.StandardCharsets
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Calendar
;
...
...
@@ -346,7 +347,7 @@ public class AuditorImpl implements Auditor {
currentAuditFile
=
tmpAuditFile
;
close
();
// always append to an existing file (after restart)
writer
=
new
BufferedWriter
(
new
OutputStreamWriter
(
new
FileOutputStream
(
currentAuditFile
,
true
),
"UTF-8"
));
writer
=
new
BufferedWriter
(
new
OutputStreamWriter
(
new
FileOutputStream
(
currentAuditFile
,
true
),
StandardCharsets
.
UTF_8
));
writer
.
write
(
"<jive xmlns=\"http://www.jivesoftware.org\">"
);
xmlWriter
=
new
org
.
jivesoftware
.
util
.
XMLWriter
(
writer
);
}
...
...
src/java/org/jivesoftware/openfire/http/HttpBindServlet.java
View file @
23d6aabc
...
...
@@ -415,7 +415,7 @@ public class HttpBindServlet extends HttpServlet {
byte
b
[]
=
new
byte
[
1024
];
int
length
;
while
(
inputStream
.
isReady
()
&&
(
length
=
inputStream
.
read
(
b
))
!=
-
1
)
{
buffer
.
append
(
new
String
(
b
,
0
,
length
,
"UTF-8"
));
buffer
.
append
(
new
String
(
b
,
0
,
length
,
StandardCharsets
.
UTF_8
));
}
}
...
...
src/java/org/jivesoftware/openfire/net/SocketConnection.java
View file @
23d6aabc
...
...
@@ -27,6 +27,7 @@ import java.io.Writer;
import
java.net.Socket
;
import
java.net.UnknownHostException
;
import
java.nio.channels.Channels
;
import
java.nio.charset.StandardCharsets
;
import
java.security.cert.Certificate
;
import
java.util.Collection
;
import
java.util.Date
;
...
...
@@ -65,11 +66,6 @@ public class SocketConnection implements Connection {
private
static
final
Logger
Log
=
LoggerFactory
.
getLogger
(
SocketConnection
.
class
);
/**
* The utf-8 charset for decoding and encoding XMPP packet streams.
*/
public
static
final
String
CHARSET
=
"UTF-8"
;
private
static
Map
<
SocketConnection
,
String
>
instances
=
new
ConcurrentHashMap
<
SocketConnection
,
String
>();
...
...
@@ -145,11 +141,11 @@ public class SocketConnection implements Connection {
// DANIELE: Modify socket to use channel
if
(
socket
.
getChannel
()
!=
null
)
{
writer
=
Channels
.
newWriter
(
ServerTrafficCounter
.
wrapWritableChannel
(
socket
.
getChannel
()),
CHARSET
);
ServerTrafficCounter
.
wrapWritableChannel
(
socket
.
getChannel
()),
StandardCharsets
.
UTF_8
.
newEncoder
(),
-
1
);
}
else
{
writer
=
new
BufferedWriter
(
new
OutputStreamWriter
(
ServerTrafficCounter
.
wrapOutputStream
(
socket
.
getOutputStream
()),
CHARSET
));
ServerTrafficCounter
.
wrapOutputStream
(
socket
.
getOutputStream
()),
StandardCharsets
.
UTF_8
));
}
this
.
backupDeliverer
=
backupDeliverer
;
xmlSerializer
=
new
XMLSocketWriter
(
writer
,
this
);
...
...
@@ -181,7 +177,7 @@ public class SocketConnection implements Connection {
// Start handshake
tlsStreamHandler
.
start
();
// Use new wrapped writers
writer
=
new
BufferedWriter
(
new
OutputStreamWriter
(
tlsStreamHandler
.
getOutputStream
(),
CHARSET
));
writer
=
new
BufferedWriter
(
new
OutputStreamWriter
(
tlsStreamHandler
.
getOutputStream
(),
StandardCharsets
.
UTF_8
));
xmlSerializer
=
new
XMLSocketWriter
(
writer
,
this
);
}
}
...
...
@@ -199,13 +195,13 @@ public class SocketConnection implements Connection {
ServerTrafficCounter
.
wrapOutputStream
(
socket
.
getOutputStream
()),
JZlib
.
Z_BEST_COMPRESSION
);
out
.
setFlushMode
(
JZlib
.
Z_PARTIAL_FLUSH
);
writer
=
new
BufferedWriter
(
new
OutputStreamWriter
(
out
,
CHARSET
));
writer
=
new
BufferedWriter
(
new
OutputStreamWriter
(
out
,
StandardCharsets
.
UTF_8
));
xmlSerializer
=
new
XMLSocketWriter
(
writer
,
this
);
}
else
{
ZOutputStream
out
=
new
ZOutputStream
(
tlsStreamHandler
.
getOutputStream
(),
JZlib
.
Z_BEST_COMPRESSION
);
out
.
setFlushMode
(
JZlib
.
Z_PARTIAL_FLUSH
);
writer
=
new
BufferedWriter
(
new
OutputStreamWriter
(
out
,
CHARSET
));
writer
=
new
BufferedWriter
(
new
OutputStreamWriter
(
out
,
StandardCharsets
.
UTF_8
));
xmlSerializer
=
new
XMLSocketWriter
(
writer
,
this
);
}
}
catch
(
IOException
e
)
{
...
...
src/java/org/jivesoftware/openfire/nio/ConnectionHandler.java
View file @
23d6aabc
...
...
@@ -33,6 +33,8 @@ import org.xmlpull.v1.XmlPullParserException;
import
org.xmlpull.v1.XmlPullParserFactory
;
import
org.xmpp.packet.StreamError
;
import
java.nio.charset.StandardCharsets
;
/**
* A ConnectionHandler is responsible for creating new sessions, destroying sessions and delivering
* received XML stanzas to the proper StanzaHandler.
...
...
@@ -43,10 +45,6 @@ public abstract class ConnectionHandler extends IoHandlerAdapter {
private
static
final
Logger
Log
=
LoggerFactory
.
getLogger
(
ConnectionHandler
.
class
);
/**
* The utf-8 charset for decoding and encoding Jabber packet streams.
*/
static
final
String
CHARSET
=
"UTF-8"
;
static
final
String
XML_PARSER
=
"XML-PARSER"
;
protected
static
final
String
HANDLER
=
"HANDLER"
;
protected
static
final
String
CONNECTION
=
"CONNECTION"
;
...
...
@@ -84,7 +82,7 @@ public abstract class ConnectionHandler extends IoHandlerAdapter {
@Override
public
void
sessionOpened
(
IoSession
session
)
throws
Exception
{
// Create a new XML parser for the new connection. The parser will be used by the XMPPDecoder filter.
final
XMLLightweightParser
parser
=
new
XMLLightweightParser
(
CHARSET
);
final
XMLLightweightParser
parser
=
new
XMLLightweightParser
(
StandardCharsets
.
UTF_8
);
session
.
setAttribute
(
XML_PARSER
,
parser
);
// Create a new NIOConnection for the new session
final
NIOConnection
connection
=
createNIOConnection
(
session
);
...
...
src/java/org/jivesoftware/openfire/nio/XMLLightweightParser.java
View file @
23d6aabc
...
...
@@ -113,8 +113,8 @@ class XMLLightweightParser {
PropertyEventDispatcher
.
addListener
(
new
PropertyListener
());
}
public
XMLLightweightParser
(
String
charset
)
{
encoder
=
Charset
.
forName
(
charset
)
.
newDecoder
()
public
XMLLightweightParser
(
Charset
charset
)
{
encoder
=
charset
.
newDecoder
()
.
onMalformedInput
(
CodingErrorAction
.
REPLACE
)
.
onUnmappableCharacter
(
CodingErrorAction
.
REPLACE
);
}
...
...
src/java/org/jivesoftware/openfire/session/LocalOutgoingServerSession.java
View file @
23d6aabc
...
...
@@ -24,6 +24,7 @@ import java.io.IOException;
import
java.io.InputStreamReader
;
import
java.net.InetSocketAddress
;
import
java.net.Socket
;
import
java.nio.charset.StandardCharsets
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.HashSet
;
...
...
@@ -272,7 +273,7 @@ public class LocalOutgoingServerSession extends LocalServerSession implements Ou
XMPPPacketReader
reader
=
new
XMPPPacketReader
();
reader
.
getXPPParser
().
setInput
(
new
InputStreamReader
(
socket
.
getInputStream
(),
CHARSET
));
StandardCharsets
.
UTF_8
));
// Get the answer from the Receiving Server
XmlPullParser
xpp
=
reader
.
getXPPParser
();
for
(
int
eventType
=
xpp
.
getEventType
();
eventType
!=
XmlPullParser
.
START_TAG
;)
{
...
...
@@ -401,7 +402,7 @@ public class LocalOutgoingServerSession extends LocalServerSession implements Ou
connection
.
deliverRawText
(
openingStream
.
toString
());
// Reset the parser to use the new secured reader
xpp
.
setInput
(
new
InputStreamReader
(
connection
.
getTLSStreamHandler
().
getInputStream
(),
CHARSET
));
xpp
.
setInput
(
new
InputStreamReader
(
connection
.
getTLSStreamHandler
().
getInputStream
(),
StandardCharsets
.
UTF_8
));
// Skip new stream element
for
(
int
eventType
=
xpp
.
getEventType
();
eventType
!=
XmlPullParser
.
START_TAG
;)
{
eventType
=
xpp
.
next
();
...
...
@@ -446,7 +447,7 @@ public class LocalOutgoingServerSession extends LocalServerSession implements Ou
ZInputStream
in
=
new
ZInputStream
(
connection
.
getTLSStreamHandler
().
getInputStream
());
in
.
setFlushMode
(
JZlib
.
Z_PARTIAL_FLUSH
);
xpp
.
setInput
(
new
InputStreamReader
(
in
,
CHARSET
));
xpp
.
setInput
(
new
InputStreamReader
(
in
,
StandardCharsets
.
UTF_8
));
// Skip the opening stream sent by the server
for
(
int
eventType
=
xpp
.
getEventType
();
eventType
!=
XmlPullParser
.
START_TAG
;)
{
...
...
@@ -551,7 +552,7 @@ public class LocalOutgoingServerSession extends LocalServerSession implements Ou
// Reset the parser
//xpp.resetInput();
// // Reset the parser to use the new secured reader
xpp
.
setInput
(
new
InputStreamReader
(
connection
.
getTLSStreamHandler
().
getInputStream
(),
CHARSET
));
xpp
.
setInput
(
new
InputStreamReader
(
connection
.
getTLSStreamHandler
().
getInputStream
(),
StandardCharsets
.
UTF_8
));
// Skip the opening stream sent by the server
for
(
int
eventType
=
xpp
.
getEventType
();
eventType
!=
XmlPullParser
.
START_TAG
;)
{
eventType
=
xpp
.
next
();
...
...
src/java/org/jivesoftware/openfire/update/UpdateManager.java
View file @
23d6aabc
...
...
@@ -29,6 +29,7 @@ import java.io.InputStream;
import
java.io.OutputStreamWriter
;
import
java.io.StringReader
;
import
java.io.Writer
;
import
java.nio.charset.StandardCharsets
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.HashMap
;
...
...
@@ -670,7 +671,7 @@ public class UpdateManager extends BasicModule {
file
.
delete
();
}
// Create new version.xml with returned data
try
(
Writer
writer
=
new
BufferedWriter
(
new
OutputStreamWriter
(
new
FileOutputStream
(
file
),
"UTF-8"
)))
{
try
(
Writer
writer
=
new
BufferedWriter
(
new
OutputStreamWriter
(
new
FileOutputStream
(
file
),
StandardCharsets
.
UTF_8
)))
{
OutputFormat
prettyPrinter
=
OutputFormat
.
createPrettyPrint
();
XMLWriter
xmlWriter
=
new
XMLWriter
(
writer
,
prettyPrinter
);
xmlWriter
.
write
(
xmlResponse
);
...
...
@@ -717,7 +718,7 @@ public class UpdateManager extends BasicModule {
file
.
delete
();
}
// Create new version.xml with returned data
writer
=
new
BufferedWriter
(
new
OutputStreamWriter
(
new
FileOutputStream
(
file
),
"UTF-8"
));
writer
=
new
BufferedWriter
(
new
OutputStreamWriter
(
new
FileOutputStream
(
file
),
StandardCharsets
.
UTF_8
));
OutputFormat
prettyPrinter
=
OutputFormat
.
createPrettyPrint
();
XMLWriter
xmlWriter
=
new
XMLWriter
(
writer
,
prettyPrinter
);
xmlWriter
.
write
(
xml
);
...
...
src/java/org/jivesoftware/util/XMLProperties.java
View file @
23d6aabc
...
...
@@ -35,6 +35,7 @@ import java.io.OutputStreamWriter;
import
java.io.Reader
;
import
java.io.StringReader
;
import
java.io.Writer
;
import
java.nio.charset.StandardCharsets
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Collections
;
...
...
@@ -113,7 +114,7 @@ public class XMLProperties {
* @throws IOException if an exception occurs when reading the stream.
*/
public
XMLProperties
(
InputStream
in
)
throws
IOException
{
try
(
Reader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
in
,
"UTF-8"
)))
{
try
(
Reader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
in
,
StandardCharsets
.
UTF_8
)))
{
buildDoc
(
reader
);
}
}
...
...
@@ -745,7 +746,7 @@ public class XMLProperties {
boolean
error
=
false
;
// Write data out to a temporary file first.
File
tempFile
=
new
File
(
file
.
getParentFile
(),
file
.
getName
()
+
".tmp"
);;
try
(
Writer
writer
=
new
BufferedWriter
(
new
OutputStreamWriter
(
new
FileOutputStream
(
tempFile
),
"UTF-8"
)))
{
try
(
Writer
writer
=
new
BufferedWriter
(
new
OutputStreamWriter
(
new
FileOutputStream
(
tempFile
),
StandardCharsets
.
UTF_8
)))
{
OutputFormat
prettyPrinter
=
OutputFormat
.
createPrettyPrint
();
XMLWriter
xmlWriter
=
new
XMLWriter
(
writer
,
prettyPrinter
);
xmlWriter
.
write
(
document
);
...
...
src/java/org/jivesoftware/util/XMLWriter.java
View file @
23d6aabc
...
...
@@ -8,6 +8,7 @@ import org.xml.sax.ext.LexicalHandler;
import
org.xml.sax.helpers.XMLFilterImpl
;
import
java.io.*
;
import
java.nio.charset.StandardCharsets
;
import
java.util.*
;
/**
...
...
@@ -91,7 +92,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
public
XMLWriter
()
throws
UnsupportedEncodingException
{
this
.
format
=
DEFAULT_FORMAT
;
this
.
writer
=
new
BufferedWriter
(
new
OutputStreamWriter
(
System
.
out
,
"UTF-8"
)
);
this
.
writer
=
new
BufferedWriter
(
new
OutputStreamWriter
(
System
.
out
,
StandardCharsets
.
UTF_8
)
);
this
.
autoFlush
=
true
;
namespaceStack
.
push
(
Namespace
.
NO_NAMESPACE
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment