【问题标题】:Errors with using Scalaxb for code generation使用 Scalaxb 生成代码的错误
【发布时间】:2015-11-11 14:14:47
【问题描述】:

我不得不为其中一个实现摆弄一个 WSDL 文档,然后我遇到了 Scalaxb!我现在正在尝试从我拥有的 WSDL 文件中生成一些 scala 类,并且正如预期的那样,我遇到了一些问题:

这是 WSDL 文件的 sn-p:

<?xml version="1.0" encoding="UTF-8" ?>
<wsdl:definitions
 xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
 xmlns:tns="http://www.myservice.com/MyServices/2012/06/18/"
 xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
 xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
 xmlns:s="http://www.w3.org/2001/XMLSchema"
 name="MyServices"
 targetNamespace="http://www.myservice.com/MyServices/2012/06/18/">
<wsdl:types>
 <s:schema elementFormDefault="qualified" targetNamespace="http://www.myservice.com/MyServices/2012/06/18/">
  <s:complexType name="UserCredentials">
   <s:sequence>
    <s:element name="UserName" type="s:string" />
    <s:element name="Password" type="s:string" />
   </s:sequence>
  </s:complexType>
  <s:element name="UserCredentials" type="tns:UserCredentials" />
  <s:complexType name="AnotherComplexType" >
   <s:sequence>
    <s:element name="Index" type="s:int" />
    <s:element name="Name" type="s:string" />
    <s:element name="Status" type="s:boolean" />
   </s:sequence>
  </s:complexType>
  ....

假设 WSDL 文件的其余部分完全没有问题,当我尝试编译项目时,我遇到了以下错误:

[error] /Users/joe/Desktop/scalaxb-soap-example/target/scala-2.11/src_managed/main/sbt-scalaxb/myservice/xmlprotocol.scala:1542: not found: value userCredentials
[error]             scalaxb.toXML(userCredentials, Some("http://www.myservice.com/MyServices/2012/06/18/"), "UserCredentials", defaultScope), defaultScope, baseAddress, "POST", Some(new java.net.URI("http://1.1.1.1/cgi-bin/cgi.cgi?WebService=SetGPTimerChannel"))).transform({ case (header, body) => 
[error]                           ^
[error] /Users/joe/Desktop/scalaxb-soap-example/target/scala-2.11/src_managed/main/sbt-scalaxb/myservice/xmlprotocol.scala:1544: value toSeq is not a member of Any
[error]               scala.xml.Elem(null, "Body", scala.xml.Null, defaultScope, true, body.toSeq: _*)
[error]                                                                                     ^
[error] /Users/joe/Desktop/scalaxb-soap-example/target/scala-2.11/src_managed/main/sbt-scalaxb/myservice/xmlprotocol.scala:1551: not found: value userCredentials
[error]             scalaxb.toXML(userCredentials, Some("http://www.myservice.com/MyServices/2012/06/18/"), "UserCredentials", defaultScope), defaultScope, baseAddress, "POST", Some(new java.net.URI("http://1.1.1.1/cgi-bin/cgi.cgi?WebService=SomeServiceCall"))).transform({ case (header, body) => 
[error]                           ^
[error] /Users/joe/Desktop/scalaxb-soap-example/target/scala-2.11/src_managed/main/sbt-scalaxb/myservice/xmlprotocol.scala:1553: value toSeq is not a member of Any
[error]               scala.xml.Elem(null, "Body", scala.xml.Null, defaultScope, true, body.toSeq: _*)
[error]                                                                                     ^

任何想法我面临这个问题是什么以及为什么?这是我的 build.sbt:

import ScalaxbKeys._

val scalaXml = "org.scala-lang.modules" %% "scala-xml" % "1.0.2"
val scalaParser = "org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.1"
val dispatchV = "0.11.1" // change this to appropriate dispatch version
val dispatch = "net.databinder.dispatch" %% "dispatch-core" % dispatchV

organization := "com.eon"

name := "scalaxb-myservice-sample"

scalaVersion := "2.11.6"

scalaxbSettings

packageName in (Compile, scalaxb) := "rdmservice"

dispatchVersion in (Compile, scalaxb) := dispatchV

async in (Compile, scalaxb) := true

sourceGenerators in Compile <+= scalaxb in Compile

libraryDependencies ++= Seq(scalaXml, scalaParser, dispatch)

【问题讨论】:

  • 你看过生成的源码了吗?大概你“摆弄”了 userCredentials 对象。你能在任何地方找到它的定义吗?看起来应该大写。
  • 不!它在任何地方都找不到定义!但它正在生成,所以我无法控制它是否是大写字母!
  • 其他类型都生成了吗? scalaxb 是否会产生任何警告/错误?
  • 不,没有任何警告或类似情况!
  • 所有其他类型都在生成吗?如果是这样,那就太奇怪了。我会提交一份带有 wsdl 链接的错误报告。

标签: web-services scala soap wsdl scalaxb


【解决方案1】:

如果您只需要生成 WSDL 客户端代码,使用scalaxb 可能有点过分。作为一个选项,您可以使用 wsimport 包装为一个简单的 SBT 任务,该任务将在主代码编译之前执行。除了减少一种依赖之外,它还可以保持您的存储库的原始状态,并将其从提交生成的样板 Java 代码中解放出来。如果有人感兴趣,这里是一个示例模板项目:https://github.com/sainnr/sbt-scala-wsdl-template

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-07
    • 2017-12-19
    • 1970-01-01
    • 2021-07-06
    • 2015-05-20
    • 1970-01-01
    相关资源
    最近更新 更多