You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by Javier Valdes <ja...@gmail.com> on 2008/07/03 13:18:06 UTC

Problem with encoding

Hi,

We have made our own binding component and we have a problem with the
encoding. We are using Servicemix 3.2.1

The message that we received used ISO-8859-1, and our code is this:

********************************************************************************************

protected void processMessage (InputStream entrada, int socketId, int[]
eofDelim)
        throws Exception
    {
        InOnly exchange = getExchangeFactory().createInOnlyExchange();
        configureExchangeTarget(exchange);
        NormalizedMessage message = exchange.createMessage();
        message.setProperty("socketId", Integer.valueOf(socketId));
        exchange.setInMessage(message);

        String messageContent = readMessage();

        message.setContent(new StreamSource(new
StringReader(messageContent)));

        try
       {
               sendSync(exchange);
       }

        catch (Exception e)
        {
            mLogger.error("We had an exception in Socket Reader: " + e);
            e.printStackTrace();
            return;
        }
    }
********************************************************************************************

Where readMessage read the message content from a socket. We have debuged
the code and the messageContent is readed correctly (with the correct
ISO-8859-1 encoding) with this header:

<?xml version='1.0' encoding='ISO-8859-1'?>

When we set the content of the NormalizedMessage the content is still
correct, with the same xml header. But the exchange has this header (and the
message is sended to the bus in this way):

<?xml version="1.0" encoding="UTF-8"?>

We have set the charset to ISO-8859-1 in the servicemix.properties files but
we have the same problem.

How can we fix this problem?

Thanks

Re: Problem with encoding

Posted by Guillaume Nodet <gn...@gmail.com>.
Btw, maybe you could try with a new StringSource(src) instead of new
StreamSource(new StringReader(src))

On Thu, Jul 3, 2008 at 3:55 PM, Guillaume Nodet <gn...@gmail.com> wrote:
> How did you check the header in the exchange ?
> Did you use exchange.toString() or something like that ?  The encoding
> may have been lost in the process of making the exchange re-readable.
>
> On Thu, Jul 3, 2008 at 3:29 PM, Javier Valdes
> <ja...@gmail.com> wrote:
>> We think that there is no problem with the StreamSource. When we debuged we
>> see that the message was correct except in the MessageExchange (InOnly
>> exchange).
>>
>> Thanks
>>
>> 2008/7/3 Guillaume Nodet <gn...@gmail.com>:
>>
>>> Doesn't the StreamSource has a way to set the content encoding for the
>>> given stream ?
>>>
>>> On Thu, Jul 3, 2008 at 1:18 PM, Javier Valdes
>>> <ja...@gmail.com> wrote:
>>> > Hi,
>>> >
>>> > We have made our own binding component and we have a problem with the
>>> > encoding. We are using Servicemix 3.2.1
>>> >
>>> > The message that we received used ISO-8859-1, and our code is this:
>>> >
>>> >
>>> ********************************************************************************************
>>> >
>>> > protected void processMessage (InputStream entrada, int socketId, int[]
>>> > eofDelim)
>>> >        throws Exception
>>> >    {
>>> >        InOnly exchange = getExchangeFactory().createInOnlyExchange();
>>> >        configureExchangeTarget(exchange);
>>> >        NormalizedMessage message = exchange.createMessage();
>>> >        message.setProperty("socketId", Integer.valueOf(socketId));
>>> >        exchange.setInMessage(message);
>>> >
>>> >        String messageContent = readMessage();
>>> >
>>> >        message.setContent(new StreamSource(new
>>> > StringReader(messageContent)));
>>> >
>>> >        try
>>> >       {
>>> >               sendSync(exchange);
>>> >       }
>>> >
>>> >        catch (Exception e)
>>> >        {
>>> >            mLogger.error("We had an exception in Socket Reader: " + e);
>>> >            e.printStackTrace();
>>> >            return;
>>> >        }
>>> >    }
>>> >
>>> ********************************************************************************************
>>> >
>>> > Where readMessage read the message content from a socket. We have debuged
>>> > the code and the messageContent is readed correctly (with the correct
>>> > ISO-8859-1 encoding) with this header:
>>> >
>>> > <?xml version='1.0' encoding='ISO-8859-1'?>
>>> >
>>> > When we set the content of the NormalizedMessage the content is still
>>> > correct, with the same xml header. But the exchange has this header (and
>>> the
>>> > message is sended to the bus in this way):
>>> >
>>> > <?xml version="1.0" encoding="UTF-8"?>
>>> >
>>> > We have set the charset to ISO-8859-1 in the servicemix.properties files
>>> but
>>> > we have the same problem.
>>> >
>>> > How can we fix this problem?
>>> >
>>> > Thanks
>>> >
>>>
>>>
>>>
>>> --
>>> Cheers,
>>> Guillaume Nodet
>>> ------------------------
>>> Blog: http://gnodet.blogspot.com/
>>>
>>
>
>
>
> --
> Cheers,
> Guillaume Nodet
> ------------------------
> Blog: http://gnodet.blogspot.com/
>



-- 
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/

Re: Problem with encoding

Posted by Javier Valdes <ja...@gmail.com>.
So, the encoding may have been lost in the process of making the exchange
re-readable. Does it mean that a default encoding (UTF-8) it is used?

Is there any way to avoid the encoding lost? Why is the encoding lost?

Thanks

2008/7/3 Guillaume Nodet <gn...@gmail.com>:

> How did you check the header in the exchange ?
> Did you use exchange.toString() or something like that ?  The encoding
> may have been lost in the process of making the exchange re-readable.
>
> On Thu, Jul 3, 2008 at 3:29 PM, Javier Valdes
> <ja...@gmail.com> wrote:
> > We think that there is no problem with the StreamSource. When we debuged
> we
> > see that the message was correct except in the MessageExchange (InOnly
> > exchange).
> >
> > Thanks
> >
> > 2008/7/3 Guillaume Nodet <gn...@gmail.com>:
> >
> >> Doesn't the StreamSource has a way to set the content encoding for the
> >> given stream ?
> >>
> >> On Thu, Jul 3, 2008 at 1:18 PM, Javier Valdes
> >> <ja...@gmail.com> wrote:
> >> > Hi,
> >> >
> >> > We have made our own binding component and we have a problem with the
> >> > encoding. We are using Servicemix 3.2.1
> >> >
> >> > The message that we received used ISO-8859-1, and our code is this:
> >> >
> >> >
> >>
> ********************************************************************************************
> >> >
> >> > protected void processMessage (InputStream entrada, int socketId,
> int[]
> >> > eofDelim)
> >> >        throws Exception
> >> >    {
> >> >        InOnly exchange = getExchangeFactory().createInOnlyExchange();
> >> >        configureExchangeTarget(exchange);
> >> >        NormalizedMessage message = exchange.createMessage();
> >> >        message.setProperty("socketId", Integer.valueOf(socketId));
> >> >        exchange.setInMessage(message);
> >> >
> >> >        String messageContent = readMessage();
> >> >
> >> >        message.setContent(new StreamSource(new
> >> > StringReader(messageContent)));
> >> >
> >> >        try
> >> >       {
> >> >               sendSync(exchange);
> >> >       }
> >> >
> >> >        catch (Exception e)
> >> >        {
> >> >            mLogger.error("We had an exception in Socket Reader: " +
> e);
> >> >            e.printStackTrace();
> >> >            return;
> >> >        }
> >> >    }
> >> >
> >>
> ********************************************************************************************
> >> >
> >> > Where readMessage read the message content from a socket. We have
> debuged
> >> > the code and the messageContent is readed correctly (with the correct
> >> > ISO-8859-1 encoding) with this header:
> >> >
> >> > <?xml version='1.0' encoding='ISO-8859-1'?>
> >> >
> >> > When we set the content of the NormalizedMessage the content is still
> >> > correct, with the same xml header. But the exchange has this header
> (and
> >> the
> >> > message is sended to the bus in this way):
> >> >
> >> > <?xml version="1.0" encoding="UTF-8"?>
> >> >
> >> > We have set the charset to ISO-8859-1 in the servicemix.properties
> files
> >> but
> >> > we have the same problem.
> >> >
> >> > How can we fix this problem?
> >> >
> >> > Thanks
> >> >
> >>
> >>
> >>
> >> --
> >> Cheers,
> >> Guillaume Nodet
> >> ------------------------
> >> Blog: http://gnodet.blogspot.com/
> >>
> >
>
>
>
> --
> Cheers,
> Guillaume Nodet
> ------------------------
> Blog: http://gnodet.blogspot.com/
>

Re: Problem with encoding

Posted by Guillaume Nodet <gn...@gmail.com>.
How did you check the header in the exchange ?
Did you use exchange.toString() or something like that ?  The encoding
may have been lost in the process of making the exchange re-readable.

On Thu, Jul 3, 2008 at 3:29 PM, Javier Valdes
<ja...@gmail.com> wrote:
> We think that there is no problem with the StreamSource. When we debuged we
> see that the message was correct except in the MessageExchange (InOnly
> exchange).
>
> Thanks
>
> 2008/7/3 Guillaume Nodet <gn...@gmail.com>:
>
>> Doesn't the StreamSource has a way to set the content encoding for the
>> given stream ?
>>
>> On Thu, Jul 3, 2008 at 1:18 PM, Javier Valdes
>> <ja...@gmail.com> wrote:
>> > Hi,
>> >
>> > We have made our own binding component and we have a problem with the
>> > encoding. We are using Servicemix 3.2.1
>> >
>> > The message that we received used ISO-8859-1, and our code is this:
>> >
>> >
>> ********************************************************************************************
>> >
>> > protected void processMessage (InputStream entrada, int socketId, int[]
>> > eofDelim)
>> >        throws Exception
>> >    {
>> >        InOnly exchange = getExchangeFactory().createInOnlyExchange();
>> >        configureExchangeTarget(exchange);
>> >        NormalizedMessage message = exchange.createMessage();
>> >        message.setProperty("socketId", Integer.valueOf(socketId));
>> >        exchange.setInMessage(message);
>> >
>> >        String messageContent = readMessage();
>> >
>> >        message.setContent(new StreamSource(new
>> > StringReader(messageContent)));
>> >
>> >        try
>> >       {
>> >               sendSync(exchange);
>> >       }
>> >
>> >        catch (Exception e)
>> >        {
>> >            mLogger.error("We had an exception in Socket Reader: " + e);
>> >            e.printStackTrace();
>> >            return;
>> >        }
>> >    }
>> >
>> ********************************************************************************************
>> >
>> > Where readMessage read the message content from a socket. We have debuged
>> > the code and the messageContent is readed correctly (with the correct
>> > ISO-8859-1 encoding) with this header:
>> >
>> > <?xml version='1.0' encoding='ISO-8859-1'?>
>> >
>> > When we set the content of the NormalizedMessage the content is still
>> > correct, with the same xml header. But the exchange has this header (and
>> the
>> > message is sended to the bus in this way):
>> >
>> > <?xml version="1.0" encoding="UTF-8"?>
>> >
>> > We have set the charset to ISO-8859-1 in the servicemix.properties files
>> but
>> > we have the same problem.
>> >
>> > How can we fix this problem?
>> >
>> > Thanks
>> >
>>
>>
>>
>> --
>> Cheers,
>> Guillaume Nodet
>> ------------------------
>> Blog: http://gnodet.blogspot.com/
>>
>



-- 
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/

Re: Problem with encoding

Posted by Javier Valdes <ja...@gmail.com>.
We think that there is no problem with the StreamSource. When we debuged we
see that the message was correct except in the MessageExchange (InOnly
exchange).

Thanks

2008/7/3 Guillaume Nodet <gn...@gmail.com>:

> Doesn't the StreamSource has a way to set the content encoding for the
> given stream ?
>
> On Thu, Jul 3, 2008 at 1:18 PM, Javier Valdes
> <ja...@gmail.com> wrote:
> > Hi,
> >
> > We have made our own binding component and we have a problem with the
> > encoding. We are using Servicemix 3.2.1
> >
> > The message that we received used ISO-8859-1, and our code is this:
> >
> >
> ********************************************************************************************
> >
> > protected void processMessage (InputStream entrada, int socketId, int[]
> > eofDelim)
> >        throws Exception
> >    {
> >        InOnly exchange = getExchangeFactory().createInOnlyExchange();
> >        configureExchangeTarget(exchange);
> >        NormalizedMessage message = exchange.createMessage();
> >        message.setProperty("socketId", Integer.valueOf(socketId));
> >        exchange.setInMessage(message);
> >
> >        String messageContent = readMessage();
> >
> >        message.setContent(new StreamSource(new
> > StringReader(messageContent)));
> >
> >        try
> >       {
> >               sendSync(exchange);
> >       }
> >
> >        catch (Exception e)
> >        {
> >            mLogger.error("We had an exception in Socket Reader: " + e);
> >            e.printStackTrace();
> >            return;
> >        }
> >    }
> >
> ********************************************************************************************
> >
> > Where readMessage read the message content from a socket. We have debuged
> > the code and the messageContent is readed correctly (with the correct
> > ISO-8859-1 encoding) with this header:
> >
> > <?xml version='1.0' encoding='ISO-8859-1'?>
> >
> > When we set the content of the NormalizedMessage the content is still
> > correct, with the same xml header. But the exchange has this header (and
> the
> > message is sended to the bus in this way):
> >
> > <?xml version="1.0" encoding="UTF-8"?>
> >
> > We have set the charset to ISO-8859-1 in the servicemix.properties files
> but
> > we have the same problem.
> >
> > How can we fix this problem?
> >
> > Thanks
> >
>
>
>
> --
> Cheers,
> Guillaume Nodet
> ------------------------
> Blog: http://gnodet.blogspot.com/
>

Re: Problem with encoding

Posted by Guillaume Nodet <gn...@gmail.com>.
Doesn't the StreamSource has a way to set the content encoding for the
given stream ?

On Thu, Jul 3, 2008 at 1:18 PM, Javier Valdes
<ja...@gmail.com> wrote:
> Hi,
>
> We have made our own binding component and we have a problem with the
> encoding. We are using Servicemix 3.2.1
>
> The message that we received used ISO-8859-1, and our code is this:
>
> ********************************************************************************************
>
> protected void processMessage (InputStream entrada, int socketId, int[]
> eofDelim)
>        throws Exception
>    {
>        InOnly exchange = getExchangeFactory().createInOnlyExchange();
>        configureExchangeTarget(exchange);
>        NormalizedMessage message = exchange.createMessage();
>        message.setProperty("socketId", Integer.valueOf(socketId));
>        exchange.setInMessage(message);
>
>        String messageContent = readMessage();
>
>        message.setContent(new StreamSource(new
> StringReader(messageContent)));
>
>        try
>       {
>               sendSync(exchange);
>       }
>
>        catch (Exception e)
>        {
>            mLogger.error("We had an exception in Socket Reader: " + e);
>            e.printStackTrace();
>            return;
>        }
>    }
> ********************************************************************************************
>
> Where readMessage read the message content from a socket. We have debuged
> the code and the messageContent is readed correctly (with the correct
> ISO-8859-1 encoding) with this header:
>
> <?xml version='1.0' encoding='ISO-8859-1'?>
>
> When we set the content of the NormalizedMessage the content is still
> correct, with the same xml header. But the exchange has this header (and the
> message is sended to the bus in this way):
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> We have set the charset to ISO-8859-1 in the servicemix.properties files but
> we have the same problem.
>
> How can we fix this problem?
>
> Thanks
>



-- 
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/