L.S.,

You can get this exception when you're actually reading invalid bytes,
but in my experience you usually get this when you're reading XML as
UTF-8 while it has actually been creating with another encoding.  I'm
not entirely sure how this can happen with the snippet of code you're
showing us, Does the SOAPMessage with the System.out.println statement
look OK?  What OS are you running this on -- perhaps the underlying OS
uses another encoding by default?

Could you try rewriting the snippet using ServiceMix'
SourceTransformer class?  That one has been configured with a charset
of UTF-8 and has helper methods to help you create the Document from a
StringSource without having to work with the low-level byte streams
that might mess up the encoding.  Something like this:
  SourceTransformer transformer = new SourceTransformer();
  Document document = transformer.toDOMDocument(new StringSource(req));

Regards,

Gert Vanthienen
------------------------
Open Source SOA: http://fusesource.com
Blog: http://gertvanthienen.blogspot.com/



2009/11/16 lekkie <[email protected]>:
>
> I am trying to send a SOAP mesage over JMS and I got the following error msg:
>
>
> 12:37:55,792 | WARN  | enerContainer-25 | ResolverUtil                     |
> g.apache.camel.util.ResolverUtil  517 | Could not find class
> 'org/apache/activemq/camel/converter/ActiveMQConverter.class' in any
> classloaders: [BundleDelegatingClassLoader for [Service Consumer (JMS)
> (college-jms)]
>
> 12:37:56,401 | ERROR | -cxf-se-thread-2 | JBIDispatcherUtil                |
> e.servicemix.cxfse.CxfSeEndpoint  390 | error preparing message
> javax.xml.transform.TransformerException:
> com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException:
> Invalid byte 2 of 3-byte UTF-8 sequence.
>        at
> com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:756)
>
> 12:37:56,401 | ERROR | -cxf-se-thread-2 | CxfSeComponent                   |
> icemix.common.AsyncBaseLifeCycle  480 | Error processing exchange
> org.apache.servicemix.jbi.runtime.impl.inouti...@c7c991
> java.io.IOException:
> com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException:
> Invalid byte 2 of 3-byte UTF-8 sequence.
>        at
> org.apache.cxf.transport.jbi.JBIDispatcherUtil.dispatch(JBIDispatcherUtil.java:164)
>
> here is the xml data sent:
>
>            String req = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
>                        "<ser:NotifyPaymentRequest 
> xmlns:ser=\"http://services.com\";>"
> +
>                "<StudentNumber>91283123</StudentNumber>" +
>                "<TxnDateTime>20082734</TxnDateTime>" +
>                "<PINReceiptNumber>dgf322343</PINReceiptNumber>" +
>                "<StudentName>asdasd asds</StudentName>" +
>                "<AmountPaid>900</AmountPaid>" +
>                "<FeeName>sdfsdfd</FeeName>" +
>                "<Session>sdfdsf</Session>" +
>                "<Semester>asdsdfs</Semester>" +
>                "<PaymentReferenceNumber>safsdfd</PaymentReferenceNumber>" +
>                "<BankName>asfdsad</BankName>" +
>                "<BranchName>asdasd</BranchName>" +
>                "<CollegeName>asdas</CollegeName>" +
>                "</ser:NotifyPaymentRequest>";
>
> DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
>            factory.setNamespaceAware(true);
> byte reqXMLButes[] = req.getBytes();
>            ByteArrayInputStream byteArrayInputStream = new
> ByteArrayInputStream(reqXMLButes);
>
>            DocumentBuilder builder = factory.newDocumentBuilder();
>            Document document = builder.parse(byteArrayInputStream);
> //            Document document = builder.parse( new
> File("src/PaydirectNotifyPaymentRequest.xml") );
>            SOAPBody soapBody = soapMessage.getSOAPBody();
>            SOAPBodyElement docElement =  soapBody.addDocument(document);
>            soapMessage.saveChanges();
>            Message m =
> MessageTransformer.SOAPMessageIntoJMSMessage(soapMessage, sendSession);
>            System.out.println("Display the SOAP message"+m);
>            sender.send(m);
>
>
> kr.
>
>
> --
> View this message in context: 
> http://old.nabble.com/Invalid-byte-2-of-3-byte-UTF-8-sequence-tp26370700p26370700.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>
>

Reply via email to