| @@ -1,11 +1,7 @@ | |||||
| package altk.comm.engine; | package altk.comm.engine; | ||||
| import java.io.ByteArrayInputStream; | |||||
| import java.io.CharArrayReader; | |||||
| import java.io.IOException; | import java.io.IOException; | ||||
| import java.io.InputStream; | import java.io.InputStream; | ||||
| import java.nio.ByteBuffer; | |||||
| import java.nio.CharBuffer; | |||||
| import java.nio.charset.Charset; | import java.nio.charset.Charset; | ||||
| import java.nio.charset.CharsetDecoder; | import java.nio.charset.CharsetDecoder; | ||||
| import java.nio.charset.CodingErrorAction; | import java.nio.charset.CodingErrorAction; | ||||
| @@ -86,7 +82,7 @@ public abstract class XMLDOMBroadcast extends Broadcast | |||||
| // parse request into multiple BroadcastSMS pass then to Dispatcher | // parse request into multiple BroadcastSMS pass then to Dispatcher | ||||
| Document xmlDoc; | |||||
| Document xmlDoc = null; | |||||
| try | try | ||||
| { | { | ||||
| InputStream inb; | InputStream inb; | ||||
| @@ -102,28 +98,16 @@ public abstract class XMLDOMBroadcast extends Broadcast | |||||
| inb = request.getInputStream(); | inb = request.getInputStream(); | ||||
| } | } | ||||
| int contentLength = request.getContentLength(); | int contentLength = request.getContentLength(); | ||||
| CommonLogger.activity.info("Receiving " + contentLength + " bytes of data"); | 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. | // Clean content off bad UTF-8 characters. | ||||
| Charset utf8Charset = Charset.forName("UTF-8"); | Charset utf8Charset = Charset.forName("UTF-8"); | ||||
| CharsetDecoder utf8Decoder = utf8Charset.newDecoder(); | CharsetDecoder utf8Decoder = utf8Charset.newDecoder(); | ||||
| utf8Decoder.onMalformedInput(CodingErrorAction.REPLACE).onUnmappableCharacter(CodingErrorAction.REPLACE); | 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) | catch (SAXException e) | ||||
| { | { | ||||