users@jersey.java.net

Re: [Jersey] entities encoding issues in the response

From: Arul Dhesiaseelan <arul_at_fluxcorp.com>
Date: Thu, 15 May 2008 11:21:09 -0600

Paul,

I see these 2 errors when I started the REST service. My REST service
invokes a CXF JAX-WS Service.

org.apache.cxf.interceptor.Fault: Could not create XMLStreamReader
(input was of
 encoding UTF-8).
        at
org.apache.cxf.interceptor.StaxInInterceptor.handleMessage(StaxInInte
rceptor.java:83)
        at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseIntercept
orChain.java:221)
        at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:429)
        at
org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleR
esponse(HTTPConduit.java:1988)
        at
org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(H
TTPConduit.java:1824)
        at
org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:6
6)
        at
org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:583)

        at
org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndi
ngInterceptor.handleMessage(MessageSenderInterceptor.java:62)
        at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseIntercept
orChain.java:221)
        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:276)
        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:222)
        at
org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
        at
org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:17
7)

.................

Caused by: com.ctc.wstx.exc.WstxIOException: Invalid UTF-8 start byte
0xfc (at c
har #4, byte #-1)
        at
com.ctc.wstx.stax.WstxInputFactory.doCreateSR(WstxInputFactory.java:5
48)
        at
com.ctc.wstx.stax.WstxInputFactory.createSR(WstxInputFactory.java:604
)
        at
com.ctc.wstx.stax.WstxInputFactory.createSR(WstxInputFactory.java:629
)
        at
com.ctc.wstx.stax.WstxInputFactory.createXMLStreamReader(WstxInputFac
tory.java:324)
        at
org.apache.cxf.interceptor.StaxInInterceptor.handleMessage(StaxInInte
rceptor.java:81)
        ... 75 more
Caused by: java.io.CharConversionException: Invalid UTF-8 start byte
0xfc (at ch
ar #4, byte #-1)
        at
com.ctc.wstx.io.UTF8Reader.reportInvalidInitial(UTF8Reader.java:302)
        at com.ctc.wstx.io.UTF8Reader.read(UTF8Reader.java:188)
        at
com.ctc.wstx.io.ReaderBootstrapper.initialLoad(ReaderBootstrapper.jav
a:245)
        at
com.ctc.wstx.io.ReaderBootstrapper.bootstrapInput(ReaderBootstrapper.
java:132)
        at
com.ctc.wstx.stax.WstxInputFactory.doCreateSR(WstxInputFactory.java:5
43)
        ... 79 more

Thanks!
Arul

Paul Sandoz wrote:
> Arul Dhesiaseelan wrote:
>> Hi Paul,
>>
>> Thanks for the help.
>>
>> Do you think if this would work?
>
> Only one way to really find out and that is to build and run it :-)
>
> You don't need to use a string writer, do this:
>
> public void writeTo(CellType cellType,
> Class<?> type, Type genericType, Annotation annotations[],
> MediaType mediaType, MultivaluedMap<String, Object> headers,
> OutputStream out) throws IOException {
> try {
> JAXBContext jc = JAXBContext.newInstance(CellType.class);
> Marshaller marshaller = jc.createMarshaller();
> XMLStreamWriter swImpl =
> XMLOutputFactory.newInstance().createXMLStreamWriter(out);
> XMLStreamWriter sw = new MyStreamWriter(swImpl);
> marshaller.marshal(cellType, sw);
> } catch (XMLStreamException xse) {
> System.out.println(xse.getMessage());
> } catch (JAXBException je) {
> System.out.println(je.getMessage());
> }
>
> Plus you might consider moving the JAXBContext to the constructor and
> use a field, as these things are expensive to create.
>
> Paul.