使用Eclipse3.2.1+STP.0.4.0+Apache Tuscany开发SCA的Java组件(2)代码篇
2008-10-25 15:35
751 查看
四、编辑服务端代码
1、项目建成后,包含一些文件。
在src目录下相应包内有:HelloWorld.java、HelloWorldImpl.java和HelloWorldServer.java三个文件;
在META-INF/sca目录下有default.scdl文件;
在bin目录下有HelloWorld_sca.jar文件。如图所示:
2、修改HelloWorld.java文件
原文件为:
package org.eclipse.stp.test;
import org.osoa.sca.annotations.Remotable;
import org.osoa.sca.annotations.Service;
@Service()
@Remotable()
public interface HelloWorld {
}
修改为:
package org.eclipse.stp.test;
import org.osoa.sca.annotations.Remotable;
import org.osoa.sca.annotations.Service;
@Service()
@Remotable()
public interface HelloWorld {
public void sayHello(String value);
}
3、修改HelloWorldImpl.java文件
第一步、增加sayHello()方法
原文件为:
package org.eclipse.stp.test;
import org.osoa.sca.annotations.Service;
import org.osoa.sca.annotations.OneWay;
@Service(org.eclipse.stp.test.HelloWorld.class)
public class HelloWorldImpl implements HelloWorld {
}
修改为:(*注意:并没有完全修改完毕,这里只是手工添加了一个方法)
package org.eclipse.stp.test;
import org.osoa.sca.annotations.Service;
import org.osoa.sca.annotations.Session;
@Session()
@Service(org.eclipse.stp.test.HelloWorld.class)
public class HelloWorldImpl implements HelloWorld {
public void sayHello(String value){
System.out.println("Hello "+ value);
}
}
第二步、利用工具为sayHello方法添加注释 Annotation
选中HelloWorldImpl.java中的sayHello方法名称,在Annotation view中会显示如图的信息将红色的OneWay设置成true。
图(1)选中方法。(下图)
图(2)设置OneWay值为true。(下图)
图(3)代码同步完成注释添加。(下图)
第三步、利用工具为HelloWorldImpl类添加注释 Annotation
选中HelloWorldImpl名,如图示:
最后,代码修改完毕,如下:
package org.eclipse.stp.test;
import org.osoa.sca.annotations.Service;
import org.osoa.sca.annotations.OneWay;
import org.osoa.sca.annotations.Session;
@Session(maxIdleTime="30")
@Service(org.eclipse.stp.test.HelloWorld.class)
public class HelloWorldImpl implements HelloWorld {
@OneWay()
public void sayHello(String value){
System.out.println("Hello "+ value);
}
}
五、创建客户端代码
第一步、新建java project ,选中Java Project,Next
输入项目名称为:HelloWorldRMIClient,其他保持默认值,Next.
Java Settings也保持默认值,Finish.
第二步、创建一个新的Interface。文件如下:
package org.eclipse.stp.test;
import java.rmi.Remote;
public interface HelloWorld extends Remote {
public void sayHello(String value);
}
第三步、创建一个新的Class。文件如下:
package org.eclipse.stp.test;
import java.rmi.Naming;
public class HelloWorldRMIClient {
public static void main(String[] args) {
try{
HelloWorld service =(HelloWorld)Naming.lookup("rmi://localhost:1099/HelloWorldRemoteService");
service.sayHello("Welcome to SOA World !");
}catch(Exception e){
e.printStackTrace();
}
}
}
代码中,HelloWorld是继承了远程接口的本地接口。
rmi信息参照:default.scdl文件中的rmi:binding.rmi内容,default.scdl内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:rmi="http://incubator.apache.org/tuscany/xmlns/binding/rmi/1.0-incubator-M2" name="HelloWorldComposite">
<component name="HelloWorldComponent">
<implementation.java class="org.eclipse.stp.test.HelloWorldImpl"/>
</component>
<service name="HelloWorldService">
<interface.java interface="org.eclipse.stp.test.HelloWorld"/>
<rmi:binding.rmi host="localhost" port="1099" serviceName="HelloWorldRemoteService"/>
<reference>HelloWorldComponent</reference>
</service>
</composite>
<待续>
1、项目建成后,包含一些文件。
在src目录下相应包内有:HelloWorld.java、HelloWorldImpl.java和HelloWorldServer.java三个文件;
在META-INF/sca目录下有default.scdl文件;
在bin目录下有HelloWorld_sca.jar文件。如图所示:
2、修改HelloWorld.java文件
原文件为:
package org.eclipse.stp.test;
import org.osoa.sca.annotations.Remotable;
import org.osoa.sca.annotations.Service;
@Service()
@Remotable()
public interface HelloWorld {
}
修改为:
package org.eclipse.stp.test;
import org.osoa.sca.annotations.Remotable;
import org.osoa.sca.annotations.Service;
@Service()
@Remotable()
public interface HelloWorld {
public void sayHello(String value);
}
3、修改HelloWorldImpl.java文件
第一步、增加sayHello()方法
原文件为:
package org.eclipse.stp.test;
import org.osoa.sca.annotations.Service;
import org.osoa.sca.annotations.OneWay;
@Service(org.eclipse.stp.test.HelloWorld.class)
public class HelloWorldImpl implements HelloWorld {
}
修改为:(*注意:并没有完全修改完毕,这里只是手工添加了一个方法)
package org.eclipse.stp.test;
import org.osoa.sca.annotations.Service;
import org.osoa.sca.annotations.Session;
@Session()
@Service(org.eclipse.stp.test.HelloWorld.class)
public class HelloWorldImpl implements HelloWorld {
public void sayHello(String value){
System.out.println("Hello "+ value);
}
}
第二步、利用工具为sayHello方法添加注释 Annotation
选中HelloWorldImpl.java中的sayHello方法名称,在Annotation view中会显示如图的信息将红色的OneWay设置成true。
图(1)选中方法。(下图)
图(2)设置OneWay值为true。(下图)
图(3)代码同步完成注释添加。(下图)
第三步、利用工具为HelloWorldImpl类添加注释 Annotation
选中HelloWorldImpl名,如图示:
最后,代码修改完毕,如下:
package org.eclipse.stp.test;
import org.osoa.sca.annotations.Service;
import org.osoa.sca.annotations.OneWay;
import org.osoa.sca.annotations.Session;
@Session(maxIdleTime="30")
@Service(org.eclipse.stp.test.HelloWorld.class)
public class HelloWorldImpl implements HelloWorld {
@OneWay()
public void sayHello(String value){
System.out.println("Hello "+ value);
}
}
五、创建客户端代码
第一步、新建java project ,选中Java Project,Next
输入项目名称为:HelloWorldRMIClient,其他保持默认值,Next.
Java Settings也保持默认值,Finish.
第二步、创建一个新的Interface。文件如下:
package org.eclipse.stp.test;
import java.rmi.Remote;
public interface HelloWorld extends Remote {
public void sayHello(String value);
}
第三步、创建一个新的Class。文件如下:
package org.eclipse.stp.test;
import java.rmi.Naming;
public class HelloWorldRMIClient {
public static void main(String[] args) {
try{
HelloWorld service =(HelloWorld)Naming.lookup("rmi://localhost:1099/HelloWorldRemoteService");
service.sayHello("Welcome to SOA World !");
}catch(Exception e){
e.printStackTrace();
}
}
}
代码中,HelloWorld是继承了远程接口的本地接口。
rmi信息参照:default.scdl文件中的rmi:binding.rmi内容,default.scdl内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:rmi="http://incubator.apache.org/tuscany/xmlns/binding/rmi/1.0-incubator-M2" name="HelloWorldComposite">
<component name="HelloWorldComponent">
<implementation.java class="org.eclipse.stp.test.HelloWorldImpl"/>
</component>
<service name="HelloWorldService">
<interface.java interface="org.eclipse.stp.test.HelloWorld"/>
<rmi:binding.rmi host="localhost" port="1099" serviceName="HelloWorldRemoteService"/>
<reference>HelloWorldComponent</reference>
</service>
</composite>
<待续>
相关文章推荐
- 使用Eclipse3.2.1+STP.0.4.0+Apache Tuscany开发SCA的Java组件(2)代码篇
- 使用Eclipse3.2.1+STP.0.4.0+Apache Tuscany开发SCA的Java组件(3)运行篇
- 使用Eclipse3.2.1+STP.0.4.0+Apache Tuscany开发SCA的Java组件(3)运行篇
- 使用Eclipse3.2.1+STP.0.4.0+Apache Tuscany开发SCA的Java组件(4)安装运行错误问题修正篇
- 使用Eclipse3.2.1+STP.0.4.0+Apache Tuscany开发SCA的Java组件(1)设置篇
- 使用Eclipse3.2.1+STP.0.4.0+Apache Tuscany开发SCA的Java组件(1)设置篇
- 使用Eclipse3.2.1+STP.0.4.0+Apache Tuscany开发SCA的Java组件(4)安装运行错误问题修正篇
- 阿里巴巴Java开发手册及Java代码规约扫描eclipse和IDEA插件使用方法
- 使用Eclipse-Maven-git做Java开发(12)--使用osc的git服务托管代码
- 关于如何使用eclipse开发工具写java代码
- 使用Eclipse-Maven-git做Java开发(13)--导入git仓库的代码到eclipse
- Atitit.uml2 api 的编程代码实现设计uml开发 使用eclipse jar java 版本
- java开发环境eclipse的使用(模块代码折叠、可视化开发插件、生成Jar插件)
- 阿里开发的Java代码规约扫描eclipse插件安装和使用方法
- 使用Eclipse开发能够在 LoadRunner 中运行的Java代码
- Lombok — Java代码自动生成 开发利器 Eclipse for Mac
- 使用Eclipse运行Java代码调用JDBC读写MySQL中文变成问号的终极解决办法
- 在windows开发环境中,java代码中使用linux格式路径的方法需要注意的问题
- 搭建java开发环境+配置tomcat+使用eclipse______软件开发-JAVA
- 阿里巴巴Java开发手册及Java代码规约扫描eclipse和IDEA插件