|
|
|
@@ -1,11 +1,7 @@ |
|
|
|
package altk.comm.engine; |
|
|
|
|
|
|
|
import java.io.ByteArrayInputStream; |
|
|
|
import java.io.CharArrayReader; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.nio.ByteBuffer; |
|
|
|
import java.nio.CharBuffer; |
|
|
|
import java.nio.charset.Charset; |
|
|
|
import java.nio.charset.CharsetDecoder; |
|
|
|
import java.nio.charset.CodingErrorAction; |
|
|
|
@@ -86,7 +82,7 @@ public abstract class XMLDOMBroadcast extends Broadcast |
|
|
|
|
|
|
|
|
|
|
|
// parse request into multiple BroadcastSMS pass then to Dispatcher |
|
|
|
Document xmlDoc; |
|
|
|
Document xmlDoc = null; |
|
|
|
try |
|
|
|
{ |
|
|
|
InputStream inb; |
|
|
|
@@ -102,28 +98,16 @@ public abstract class XMLDOMBroadcast extends Broadcast |
|
|
|
inb = request.getInputStream(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int contentLength = request.getContentLength(); |
|
|
|
CommonLogger.activity.info("Receiving " + contentLength + " bytes of data"); |
|
|
|
byte[] byteContent = new byte[contentLength]; |
|
|
|
int offset = 0; |
|
|
|
int length = contentLength; |
|
|
|
int read; |
|
|
|
while (length > 0) |
|
|
|
{ |
|
|
|
read = inb.read(byteContent, offset, length); |
|
|
|
if (read < 0) break; |
|
|
|
offset += read; |
|
|
|
length -= read; |
|
|
|
} |
|
|
|
|
|
|
|
// Clean content off bad UTF-8 characters. |
|
|
|
Charset utf8Charset = Charset.forName("UTF-8"); |
|
|
|
CharsetDecoder utf8Decoder = utf8Charset.newDecoder(); |
|
|
|
utf8Decoder.onMalformedInput(CodingErrorAction.REPLACE).onUnmappableCharacter(CodingErrorAction.REPLACE); |
|
|
|
CharBuffer charContent = utf8Decoder.decode(ByteBuffer.wrap(byteContent)); |
|
|
|
CommonLogger.activity.info("Received: " + charContent); |
|
|
|
//Do not use this, as it can be killed by non UTF=8 chars: xmlDoc = builder.parse(new ByteArrayInputStream(byteContent), "UTF-8"); |
|
|
|
xmlDoc = builder.parse(new InputSource(new CharArrayReader(charContent.array()))); |
|
|
|
LoggingInputStreamReader ins = new LoggingInputStreamReader(inb, utf8Decoder); |
|
|
|
InputSource is = new InputSource(ins); |
|
|
|
xmlDoc = builder.parse(is); |
|
|
|
} |
|
|
|
catch (SAXException e) |
|
|
|
{ |
|
|
|
|