BlazeDS 未将 Scala 类转换为 AMF

发布于 2025-01-01 12:17:52 字数 1952 浏览 1 评论 0原文

我是 Scala 和 BlazeDS 的新手。我正在尝试编写一个非常简单的应用程序,其中 flex 会调用一个名为 getBook 的方法,并且 Scala 服务返回一个 Book 对象。不涉及数据库。我所做的就是创建一个新的 Book 实例并将其返回。

我的问题是我没有在 Flex 上获得有效的 Book 对象作为响应。我在这里添加了代码。

Scala Book (scalaDemo.vo.Book.scala)

package scalaDemo.vo

case class Book (id:Long,name:String,authors:String) 

Scala Service (scalaDemo.GreetingService.scala)

    package scalaDemo
    import scalaDemo.vo.Book

    class GreetingService {

      def sayHello = "Hello, World!"

      def getBook (name:String):Book = new Book (10,name,"author")
    }

Flex Side Book (vo.Book.as)

package vo
{
        [RemoteClass(alias="scalaDemo.vo.Book")]
        public class Book
        {
                public var id:Number;
                public var name:String;
                public var authors:String;
        }
}

GreetingService.as

package services
{
    import mx.rpc.AsyncResponder;
    import mx.rpc.AsyncToken;
    import mx.rpc.remoting.RemoteObject;

    public class GreetingService
    {
        protected var ro : RemoteObject = new RemoteObject ("greetingService");

        public function sayHello (responder:AsyncResponder) : void {
            var token : AsyncToken = ro.sayHello();

            token.addResponder(responder);
        }

        public function getBook (name:String,responder:AsyncResponder) : void {
            var token : AsyncToken = ro.getBook(name);

            token.addResponder(responder);
        }

    }
}

remoting-config.xml

<destination id="greetingService">
    <properties>
        <source>scalaDemo.GreetingService</source>
        <scope>application</scope>
    </properties>
</destination>

我已将 scala 类放置在 tomcat/webapps/blazeds 下/WEB-INF/classes (我正在使用 blazeds 交钥匙服务器)

请帮助我。

I'm new to Scala and BlazeDS. I am trying to write a very simple application where flex would call a method called getBook and the Scala service returns a Book object. There's no database involved. All I am doing is that I'm creating a new Instance of Book and returning it.

My problem is that I don't get a valid Book object on Flex as response. I'm including the code here.

Scala Book (scalaDemo.vo.Book.scala)

package scalaDemo.vo

case class Book (id:Long,name:String,authors:String) 

Scala Service (scalaDemo.GreetingService.scala)

    package scalaDemo
    import scalaDemo.vo.Book

    class GreetingService {

      def sayHello = "Hello, World!"

      def getBook (name:String):Book = new Book (10,name,"author")
    }

Flex Side Book (vo.Book.as)

package vo
{
        [RemoteClass(alias="scalaDemo.vo.Book")]
        public class Book
        {
                public var id:Number;
                public var name:String;
                public var authors:String;
        }
}

GreetingService.as

package services
{
    import mx.rpc.AsyncResponder;
    import mx.rpc.AsyncToken;
    import mx.rpc.remoting.RemoteObject;

    public class GreetingService
    {
        protected var ro : RemoteObject = new RemoteObject ("greetingService");

        public function sayHello (responder:AsyncResponder) : void {
            var token : AsyncToken = ro.sayHello();

            token.addResponder(responder);
        }

        public function getBook (name:String,responder:AsyncResponder) : void {
            var token : AsyncToken = ro.getBook(name);

            token.addResponder(responder);
        }

    }
}

remoting-config.xml

<destination id="greetingService">
    <properties>
        <source>scalaDemo.GreetingService</source>
        <scope>application</scope>
    </properties>
</destination>

I have placed the scala classes under tomcat/webapps/blazeds/WEB-INF/classes (I am using blazeds turnkey server)

Please help me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑梦风尘 2025-01-08 12:17:52

好的。这就是我出错的地方。对不起,BlazeDS。我没有责怪你。

这就是我在 Scala 中定义 Book 类的方式(错误的方式)

package scalaDemo.vo
case class Book (id:Long,name:String,authors:String) 

对于 BlazeDS 序列化的 Scala 对象,我们需要确保两件事。

  • 类的每个属性前面都应该有注解 @BeanProperty
  • 类的每个属性都应该声明为 var

下面是 scalaDemo.Book< 的正确定义/code> 我在问题中提到的。

package scalaDemo.vo
import scala.reflect.BeanProperty

case class Book (
    @BeanProperty
    var id:Long,
    @BeanProperty
    var name:String,
    @BeanProperty
    var authors:String) 

Daniel C.Sorbal 感谢您的关注。现在我的下一个任务是让 Hibernate 与 Scala 对话。

Ok. This is where I went wrong. I'm sorry BlazeDS. I blamed you for nothing.

This was how I defined my Book Class in Scala (the wrong way)

package scalaDemo.vo
case class Book (id:Long,name:String,authors:String) 

For a Scala object to be serialized by BlazeDS we need to make sure of 2 things.

  • Each attribute of the class should be preceded by the Annotation @BeanProperty
  • Each attribute of the class should be declared as var

Here is the correct definition of scalaDemo.Book that I mentioned in my question.

package scalaDemo.vo
import scala.reflect.BeanProperty

case class Book (
    @BeanProperty
    var id:Long,
    @BeanProperty
    var name:String,
    @BeanProperty
    var authors:String) 

Daniel C. Sorbal thank you for you interest. Now my next task would be to get Hibernate talking to Scala.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文