Services
Services
Services are really easy to create and bind to http/upnp in a running agent. Then you can invoke them in a number of ways:
/** simplest service example */ @SoaService (name="simplest", descr="simplest service", bindings=Array("http")) class SimplestService extends AgentService { @SoaMethod (descr="well, it says \"hello\"") @SoaStreamable (mime="text") // otherwise it gets wrapped in an html <body> with CSS and everything def sayhi (out:DrawStream) = out write "hello" } /** test service samples, complete with bindings */ class TestSimpleService extends razie.RazUnit { var agent:razie.SimpleAgent = null override def setUp = { // the "secret" is the url path prefix, i.e. http://localhost:4446/secret/... LightAuth.init(new LightAuth("secret")) agent = razie.SimpleAgent.local("4446") agent register new SimplestService } // local call - you need to be in the same context to be local def test1 = expect ("hello") { agent inContext { val action = razie.Service ("simplest").action ("sayhi") (action act null).asInstanceOf[String] } } // remote call def test2 = expect ("hello") { val action = razie.Service (agent.getHandle, "simplest").action ("sayhi") (action act null).asInstanceOf[String] } // remote call def test3 = expect ("hello") { val action = new ServiceActionToInvoke (agent.getHandle.url, "simplest", razie.AI("sayhi")) (action act null).asInstanceOf[String] } // remote call def test4 = expect ("hello") { val url = "http://localhost:4446/secret/simplest/sayhi" Comms.readUrl(url) } override def tearDown = { agent.onShutdown super.tearDown } }
Satisfied? There's more options for binding methods, including streaming, multiple parms, sinks etc, see LightSoa.