开发者

java.io.IOException: ... is an in valid chunk size

开发者 https://www.devze.com 2023-03-21 04:08 出处:网络
I am using Restlet framework and create a web service to return XML using DomRepresentation. Here is the code:

I am using Restlet framework and create a web service to return XML using DomRepresentation. Here is the code:

public Representation toXml(Hashtale theHashtable)
  {
    try
    {
      DomRepresentation a开发者_运维百科DomRepresentation = new DomRepresentation( MediaType.APPLICATION_XML );

      Document aDocument = aDomRepresentation.getDocument();

      Element aElementRoot = aDocument.createElement("root");

      aDocument.appendChild(aElementRoot);

      Element aElementProperties =
        aDocument.createElement("properties");

      aElementRoot.appendChild(aElementProperties);

      // Add nodes to the element

      aDocument.normalizeDocument();

      return aDomRepresentation;

    }
    catch (Exception aException)
    {
      return null;
    }
  }

I have also tried the TEXT_XML, APPLICATION_W3C_SCHEMA MediaType.

On the client side of Restlet, I use the following piece of code to retrieve and parse the xml:

  InputSource aInputSource = new InputSource(getResponseEntity().getStream());

  XMLReader aXmlReader = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");

  HtHandler ahtHandler = new HtHandler();

  aXmlReader.setContentHandler(ahtHandler);

  aXmlReader.parse(aInputSource);

  return ahtHandler.getResult();

HtHandler is a class that extends DefaultHandler.

Each time, I got this error message:

java.io.IOException: <encoding="UTF-8" standalone="no"?><root><properties><workflow_id>0</workflow_id><name>name</name><id>1</id></properties></root>> is an invalid chunk size
    at org.restlet.engine.http.io.ChunkedInputStream.readChunkSize(ChunkedInputStream.java:232)
    at org.restlet.engine.http.io.ChunkedInputStream.initializeChunk(ChunkedInputStream.java:161)
    at org.restlet.engine.http.io.ChunkedInputStream.canRead(ChunkedInputStream.java:97)
    at org.restlet.engine.http.io.ChunkedInputStream.read(ChunkedInputStream.java:182)

I have checked, most of the XMLs are parsed correctly. I don't know why, there is always one XML that is not parsed correctly, this XML has one more ">" at the end.

Any ideas would be very helpful!

Thanks in advance! Ikeforward


Here is a rough draft of the suggestion to log your .xml to a log file:

log4j.properties:

# Define the root logger with appender file
log4j.rootLogger = DEBUG, FILE
# Define the file appender
log4j.appender.FILE=org.apache.log4j.FileAppender
# Set the name of the file
log4j.appender.FILE.File=${log}/log.out    
# Set the immediate flush to true (default)
log4j.appender.FILE.ImmediateFlush=true    
# Set the threshold to debug mode
log4j.appender.FILE.Threshold=debug    
# Set the append to false, overwrite
log4j.appender.FILE.Append=false    
# Define the layout for file appender
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%m%n

Then, some java code like this:

import org.apache.log4j.Logger;
...        
    public void logTheXML(String[] args) {
        String xmlstring = arg[0];
        Logger logger =Logger.getLogger("FILE");
        logger.info("xml data\n" + xmlstring + "\n");
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消