简单的XML框架 - 奇怪的错误

时间:2012-03-12 23:14:51

标签: java xml-parsing jersey simple-framework

我在Jersey REST应用程序中使用Simple XML Framework,我突然遇到了很多奇怪的例外:

at org.simpleframework.xml.stream.PrefixResolver.getPrefix(PrefixResolver.java:123)
at org.simpleframework.xml.stream.PrefixResolver.resolvePrefix(PrefixResolver.java:183)
at org.simpleframework.xml.stream.PrefixResolver.getPrefix(PrefixResolver.java:123)
at org.simpleframework.xml.stream.PrefixResolver.resolvePrefix(PrefixResolver.java:183)
at org.simpleframework.xml.stream.PrefixResolver.getPrefix(PrefixResolver.java:123)

(上面的错误重复了一百次......并在下面继续)

SEVERE: Exception mapper com.sun.jersey.server.impl.ejb.EJBExceptionMapper@da1be4   for Throwable javax.ejb.EJBException threw a RuntimeException when attempting to obtain the     response
SEVERE: Mapped exception to response: 500 (Internal Server Error)
java.lang.ClassCastException: java.lang.StackOverflowError cannot be cast to    java.lang.Exception
    at javax.ejb.EJBException.getCausedByException(EJBException.java:91)
    at  com.sun.jersey.server.impl.ejb.EJBExceptionMapper.toResponse(EJBExceptionMapper.java:63)
    at  com.sun.jersey.server.impl.ejb.EJBExceptionMapper.toResponse(EJBExceptionMapper.java:54)
    at  com.sun.jersey.spi.container.ContainerResponse.mapException(ContainerResponse.java:452)
    at  com.sun.jersey.spi.container.ContainerResponse.mapMappableContainerException(ContainerRespo nse.java:400)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1404)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)

这是它试图解析的XML(但有时它可以工作,有时不工作):

<shoppinglistItem>
   <id>0</id>
   <article>
      <id>17</id>
      <name>Brunch</name>
      <price>0.99</price>
      <description>Brunch Brotaufstrich...</description>
      <picture>...</picture>
      <ean>125</ean>
      <substances class="java.util.ArrayList"/>
      <comments class="java.util.ArrayList"/>
      <ratings class="java.util.ArrayList"/>
      <stores class="java.util.ArrayList"/>
   </article>
   <count>1</count>
</shoppinglistItem>

如果有人能给我一个暗示,我会很高兴的! = / 我真的很生气......

2 个答案:

答案 0 :(得分:0)

好的,我到目前为止唯一的解决方案是改变模型 - .- (SimpleXML邮件列表也没有提示或解决方案......)

答案 1 :(得分:0)

我遇到了同样的问题。原因是SimpleXML显然无法序列化Exception类。我还没有解决这个问题,但我会尝试将此报告为SimpleXML的错误。这再现了例外:

public class MainClass {
  public static void main(String[] args) throws Exception {
    SomeClass someClass = new SomeClass();
    someClass.exception = new Exception();

    StringWriter stringWriter = new StringWriter();
    new Persister().write(someClass, stringWriter); // <<< Bam!

    System.out.println(stringWriter.toString());
  }  

  public static class SomeClass {
    private Exception exception;        
  }
}