2008-05-07
使用Tuscany,建立web services
关键字: tuscany
Tuscany-ws项目
摘要》
使用Tuscany创建Web services服务
一:安装Tuscany的Eclipse plugin
启动Eclipse后,菜单Help->Software Updates->Find and Install
选择Searh for new features to install ,然后执行New Remote Site
名字:Tusany
URL:http://people.apache.org/~jsdelfino/tuscany/tools/updatesite/*
Remote site ,完成即可
…
安装完成后,重启eclipse
二:建立Java Project
Tuscany-ws
由于插件已经加入开发工具,因此可以自行建立一个User Library资源,供以引用;
>>一:源代码文件HelloWorld.java
package com.spsoft.tuscany.ws.helloworld;
import org.osoa.sca.annotations.Remotable;
@Remotable
public interface HelloWorld{
String sayHello(String name);
}
>>二:源代码文件HelloWorldImpl.java
package com.spsoft.tuscany.ws.helloworld;
public class HelloWorldImpl implements HelloWorld{
Public String sayHello(String name){
Return “Hello:”+name;
}
}
>>三:helloworld.composite建立在src下
<?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://helloworld.ws.tuscany.spsoft.com.cn"
name="helloworld">
<component name="HelloWorldComponent">
<implementation.java class=" com.spsoft.tuscany.ws.helloworld.HelloWorldImpl"/>
<service name="HelloWorld">
<binding.ws uri="http://localhost:9080/HelloWorld"/>
</service>
</component>
</composite>
>>四:建立启动web services的服务类
package com.spsoft.tuscany.ws.helloworld;
import java.io.IOException;
import org.apache.tuscany.sca.host.embedded.SCADomain;
public class HelloWorldServer {
public static void main(String[] args) {
SCADomain scaDomain = SCADomain.newInstance("helloworld.composite");
try {
System.out
.println("HelloWorld server started (press enter to shutdown)");
System.in.read();
} catch (IOException e) {
e.printStackTrace();
}
scaDomain.close();
System.out.println("HelloWorld server stopped");
}
}
运行该类时,控制台将会看到以下信息:
2008-5-7 19:35:01 org.apache.tuscany.sca.http.jetty.JettyServer addServletMapping
信息: Added Servlet mapping: http://spsoft-35c9654c:9080/HelloWorld
HelloWorld server started (press enter to shutdown)
此时您可以通过访问
http://spsoft-35c9654c:9080/HelloWorld?wsdl
观看你的服务是否已经成功创建!
摘要》
使用Tuscany创建Web services服务
一:安装Tuscany的Eclipse plugin
启动Eclipse后,菜单Help->Software Updates->Find and Install
选择Searh for new features to install ,然后执行New Remote Site
名字:Tusany
URL:http://people.apache.org/~jsdelfino/tuscany/tools/updatesite/*
Remote site ,完成即可
…
安装完成后,重启eclipse
二:建立Java Project
Tuscany-ws
由于插件已经加入开发工具,因此可以自行建立一个User Library资源,供以引用;
>>一:源代码文件HelloWorld.java
package com.spsoft.tuscany.ws.helloworld;
import org.osoa.sca.annotations.Remotable;
@Remotable
public interface HelloWorld{
String sayHello(String name);
}
>>二:源代码文件HelloWorldImpl.java
package com.spsoft.tuscany.ws.helloworld;
public class HelloWorldImpl implements HelloWorld{
Public String sayHello(String name){
Return “Hello:”+name;
}
}
>>三:helloworld.composite建立在src下
<?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://helloworld.ws.tuscany.spsoft.com.cn"
name="helloworld">
<component name="HelloWorldComponent">
<implementation.java class=" com.spsoft.tuscany.ws.helloworld.HelloWorldImpl"/>
<service name="HelloWorld">
<binding.ws uri="http://localhost:9080/HelloWorld"/>
</service>
</component>
</composite>
>>四:建立启动web services的服务类
package com.spsoft.tuscany.ws.helloworld;
import java.io.IOException;
import org.apache.tuscany.sca.host.embedded.SCADomain;
public class HelloWorldServer {
public static void main(String[] args) {
SCADomain scaDomain = SCADomain.newInstance("helloworld.composite");
try {
System.out
.println("HelloWorld server started (press enter to shutdown)");
System.in.read();
} catch (IOException e) {
e.printStackTrace();
}
scaDomain.close();
System.out.println("HelloWorld server stopped");
}
}
运行该类时,控制台将会看到以下信息:
2008-5-7 19:35:01 org.apache.tuscany.sca.http.jetty.JettyServer addServletMapping
信息: Added Servlet mapping: http://spsoft-35c9654c:9080/HelloWorld
HelloWorld server started (press enter to shutdown)
此时您可以通过访问
http://spsoft-35c9654c:9080/HelloWorld?wsdl
观看你的服务是否已经成功创建!
评论
zwm
2008-05-07
采用XFire客户端调用
public static void main(String[] args) {
// TODO Auto-generated method stub
Service servModel = new ObjectServiceFactory().create(HelloWorld.class);
//
XFireProxyFactory factory = new XFireProxyFactory(XFireFactory
.newInstance().getXFire());
String wsUrl = "http://spsoft-35c9654c:9080/HelloWorld";
try {
HelloWorld srvc = (HelloWorld) factory.create(servModel, wsUrl);
System.out.println(srvc.sayHello("@author:zwm"));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Service servModel = new ObjectServiceFactory().create(HelloWorld.class);
//
XFireProxyFactory factory = new XFireProxyFactory(XFireFactory
.newInstance().getXFire());
String wsUrl = "http://spsoft-35c9654c:9080/HelloWorld";
try {
HelloWorld srvc = (HelloWorld) factory.create(servModel, wsUrl);
System.out.println(srvc.sayHello("@author:zwm"));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
发表评论
- 浏览: 56047 次
- 性别:

- 来自: 南京

- 详细资料
搜索本博客
最新评论
-
良好的编程风格是一门艺术 ...
com.company_name.project_name.bo.Message ...
-- by nwangwei -
DB2百万数据的测试
特别是内存很有关系,呵呵。www.mydb2.cn 上有一些不错的DB2性能和调 ...
-- by xzc -
DB2百万数据的测试
Genuine Intel(R)CPU 2160 @1.80GHZ 1.80 G ...
-- by zwm -
DB2百万数据的测试
应该有硬件信息吧。不同平台表现差别很大的
-- by feifei2001 -
使用Tuscany,建立web serv ...
采用XFire客户端调用 public static void main(Str ...
-- by zwm






评论排行榜