让SOA落地,tuscany初体验

1 安装tuscany插件 http://archive.apache.org/dist/incubator/tuscany/java/sca/1.2-incubating/updatesite/
2 建立一个java项目hello
定义接口
package soasample;

import org.osoa.sca.annotations.Remotable;


@Remotable
public interface Hello {

String say(String name);
}

定义实现类
package soasample;

public class HelloImpl implements Hello {

@Override
public String say(String name) {
// TODO Auto-generated method stub
System.out.println("Hello-->"+ "hello:" + name);
return "hello:" + name;
}

}

定义文件hello.composite文件
<?xml version="1.0" encoding="UTF-8"?>
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
xmlns:t="http://tuscany.apache.org/xmlns/sca/1.0"
xmlns:c="http://hello" targetNamespace="http://hello" name="hello">
<component name="Hello">
<implementation.java class="soasample.HelloImpl"></implementation.java>
<service name="Hello">
<interface.java interface="soasample.Hello"></interface.java>
<binding.ws></binding.ws>
</service>
</component>
</composite>


3 建立一个java项目first
定义接口
package soasample;

import org.osoa.sca.annotations.Remotable;

@Remotable
public interface First {

String first();
}

定义实现
package soasample;

import org.osoa.sca.annotations.Reference;

public class FirstImpl implements First {

private Hello hello = null;

@Override
public String first() {
String say = hello.say("test");
System.out.println("First-->"+ say);
return say;
}

public Hello getHello() {
return hello;
}

@Reference
public void setHello(Hello hello) {
this.hello = hello;
}

}

定义文件first.composite文件
<?xml version="1.0" encoding="UTF-8"?>
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
xmlns:t="http://tuscany.apache.org/xmlns/sca/1.0"
xmlns:c="http://first"
targetNamespace="http://first"
name="first">
<component name="First">
<implementation.java class="soasample.FirstImpl">
</implementation.java>
<reference name="hello" target="Hello">
<interface.java interface="soasample.Hello"></interface.java>
<binding.ws uri="http://192.168.204.1:8100/Hello"/>
<!--此处ip端口不同,注意看控制台信息修改一下-->
</reference>
<service name="First">
<interface.java interface="soasample.First"></interface.java>
<binding.ws></binding.ws>
</service>
</component>
</composite>


4 启动,先启动hello项目,选中hello.composite文件 运行选择tuscany方式,启动好之后以同样方式启动first项目
你可以看到eclipse启动了3个控制台
OK,你可以以web service方式调用First,看看输出
hello控制台
Hello-->hello:test
first控制台
First-->hello:test
5 tuscany比spring等IOC容器更提升了一步,将协议层彻底分离
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值