2

Xml 模板:

@(product: models.Product, productComponents: List[models.ProductComponent])
<product>
  <name>@product.name</name>
  <tomcatLocation>@product.tomcatLocation</tomcatLocation>
  <productComponents>
    @for(productComponent <- productComponents) {
     <component>
       <name>@productComponent.name</name>
       <packageName>@productComponent.packageName</packageName>
       <buildPath>@productComponent.buildPath</buildPath>
       <packageFormat>@productComponent.packageFormat</packageFormat>
       <versionAction>@productComponent.versionAction</versionAction>
       <versionFilePath>@productComponent.versionFilePath</versionFilePath>
       <versionCommand>@productComponent.versionCommand</versionCommand>
     </component>
    }
  </productComponents>
</product>

控制器动作:

public static Result upgradeProduct(String serverId, String productId) throws InterruptedException
  {
      models.Server server = models.Server.retrieveById(Long.parseLong(serverId));
      models.Product product = models.Product.retrieveById(Long.parseLong(productId));

      List<models.ProductComponent> productComponents = 
              models.ProductComponent.retrieveByProductId(Long.parseLong(productId));

      Xml renderedXmlPage = upgradeService.render(product, productComponents);

      Promise<WS.Response> upgradeStatus = 
              WS.url("http://" + server.hostIp + ":8085/upgradeProduct").setHeader("Content-Type", "text/xml").post(
                      renderedXmlPage.toString());

      String testMessage = upgradeStatus.get().getBody();

      return TODO;
  }

网络服务:

public static Result upgradeProduct()
{
  return async( WS.url(MAIN_URL).get().map(
          new Function<WS.Response, Result>() {
            public Result apply(WS.Response response)
            {
                try
                {
                    Document doc = response.asXml();
                    return ok("I WORKED");
                }
                catch(RuntimeException e)
                {
                    return ok("Error" + e.getMessage()+ "\n");
                }

            }
          })
        );
}

当我运行此操作时,会引发以下运行时异常

“Errorjava.lang.RuntimeException:org.xml.sax.SAXParseException;lineNumber:1;columnNumber:1;文件过早结束。”。

此异常在“Document doc = response.asXml();”处引发。我不知道为什么会出现这种情况?非常感谢任何帮助谢谢!

Stack Trace: 
play.libs.WS$Response.asXml(WS.java:332)
controllers.Service$1.apply(Service.java:40)
controllers.Service$1.apply(Service.java:35)
play.libs.F$Promise$2.apply(F.java:111)
play.api.libs.concurrent.STMPromise$$anonfun$map$1$$anonfun$apply$9.apply(Promise.scala:185)
scala.util.control.Exception$Catch$$anonfun$either$1.apply(Exception.scala:110)
scala.util.control.Exception$Catch$$anonfun$either$1.apply(Exception.scala:110)
scala.util.control.Exception$Catch.apply(Exception.scala:88)
scala.util.control.Exception$Catch.either(Exception.scala:110)
play.api.libs.concurrent.STMPromise.redeem(Promise.scala:166)
play.api.libs.concurrent.STMPromise$$anonfun$map$1.apply(Promise.scala:185)
play.api.libs.concurrent.STMPromise$$anonfun$map$1.apply(Promise.scala:184)
play.api.libs.concurrent.STMPromise$PromiseInvoker$$anonfun$receive$1.apply(Promise.scala:10    4)
play.api.libs.concurrent.STMPromise$PromiseInvoker$$anonfun$receive$1.apply(Promise.scala:10    3)
akka.actor.Actor$class.apply(Actor.scala:290)
play.api.libs.concurrent.STMPromise$PromiseInvoker.apply(Promise.scala:101)
akka.actor.ActorCell.invoke(ActorCell.scala:617)
akka.dispatch.Mailbox.processMailbox(Mailbox.scala:179)
akka.dispatch.Mailbox.run(Mailbox.scala:161)
akka.dispatch.ForkJoinExecutorConfigurator$MailboxExecutionTask.exec(AbstractDispatcher.scala:505)
akka.jsr166y.ForkJoinTask.doExec(ForkJoinTask.java:259)
akka.jsr166y.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:997)
akka.jsr166y.ForkJoinPool.runWorker(ForkJoinPool.java:1495)
akka.jsr166y.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104)
4

3 回答 3

1

如果我错了,请纠正我,但看起来您并没有从服务返回您的 xml 文档!?相反,您返回“I WORKED”,这将不会解析为 xml,并且解析器将抛出异常。

于 2012-04-25T21:02:43.687 回答
0

除了开始时没有任何 XML 输入的明显情况外,有时在您的代码第二次尝试读取 ajavax.xml.transform.Source或 a时也会引发此错误javax.xml.transform.sax.SAXSource。第一次一切运行正常,但第二次字节已被消耗,你会得到那个异常。至少我是如何遇到它的,在这种情况下,我只是Source重新创建 - 我不知道这是否适用于您的特定情况。

于 2013-06-21T10:43:51.747 回答
0

在服务中,您通过WS外部 URL ( MAIN_URL) 调用并使用在线响应:

Document doc = response.asXml();

该错误意味着您正在调用的服务 ( MAIN_URL) 未返回 XML。

顺便说一句,您的控制器具有TODO作为返回值,我不确定这是否是您想要的,因为您似乎在控制器中有工作代码。

于 2012-05-02T08:55:31.783 回答