智慧城市栅格操作系统-服务封装说明书V1.2.12084

图3.2.4[2]结果时,表示成功生成。

3.2.4[2] 编译结果

此时,在Eclipse左侧的区域此项目的目录如图3.2.4[3]所示:

3.2.4[3] 工程目录

至此为止,gar包生成结束,剩下的就是如何将其部署到容器中了。

3.5    部署网格服务

使用GDT插件在Eclipse下开发网格服务后,部署起来则相对简单了不少。选中刚刚生成的gar包,右键Grid→Deploy(GT4 local container),如图3.2.5[1]所示:

3.2.5[1] 部署过程

部署成功后,还需要验证一下此网格服务是否已存在于容器当中并能够查询其相关信息了。步骤如下:

1、启动数据库,如图3.2.5[2]所示。

3.2.5[2] 启动数据库

注册数据配置信息:

 

2、按【win】+【r】键进入运行界面,输入cmd进入DOS环境。,输入globus-start-container –nosec,开启容器,如图3.2.5[3]所示。

3.2.5[3] 查询结果

通过以上的验证,已经足以证明所开发的网格服务DatabaseService已经成功部署到容器中。

 

3.6    开发过程中要注意的问题

1、如果包装的是已经开发好的业务逻辑,则要把业务逻辑用到的库文件(jar包)拷贝到工程根目录下的lib文件夹中。这样,在部署服务的时候这些jar文件会被自动拷贝到GT容器中的lib里,服务才能正常运行。

2、编写服务时为变量和接口起的名字要规范,不能与某些环境保留的名字相冲突。

4    服务调用

服务调用有两种环境,一种是在本工程的目录下编写客户端进行调用,另一种就是在不同的工程目录下甚至是在不同的操作系统环境中进行调用。

4.1    在相同的工程目录下调用

GDT会自动为服务生成一个客户端,但是这个客户端可能不符合我们的需要,因此需要重新编写客户端,在编写客户端时我们可以把系统自动生成的客户端作为参考。客户端主要是验证其中定义的各种操作是否可以正常使用。客户端程序DatabaseClient.java文件内容如下:

public
class DatabaseClient implements DatabaseNamespaces

{

    public
static
void main(String[] args)

        {

            try

            {

            String[] res = null;

            res = Selectfrommaterial(“00001”);

            //res = Selectfromsc(“000001001″,”Rectangle”);

            //res = Selectfromscandmaterial(“00001″,”000000000″,”Triangle”);

            if (res!=null)

            {

                for(int i=0;i<res.length;i++)

                 System.out.println(res[i]);

            }else {

System.out.print(“res is null!”);

        };

            }

            catch(Exception e)

            {

                e.printStackTrace();

            }

        }

        public
static String[] Selectfrommaterial(String type){ //
对应于接口1的函数

            DatabaseServiceAddressingLocator locator = new DatabaseServiceAddressingLocator();

            String[] result = null;

            try{

                 String serviceURI = “http://127.0.0.1:8080/wsrf/services/DatabaseService”;

                     EndpointReferenceType endpoint = new EndpointReferenceType();

                     endpoint.setAddress(new Address(serviceURI));

                     DatabasePortType data = locator.getDatabasePortTypePort(endpoint);

                     Findexpfrommaterial f = new Findexpfrommaterial();

                     f.setType(type);

                     FindexpfrommaterialResponse s =data.findexpfrommaterial(f);

                     result = s.getFindexpfrommaterialReturn();

                }catch(Exception e){

                    e.printStackTrace();

                }

                return result;

            }

        public
static String[] Selectfromsc(String type,String dimension){ //
对应于接口2的函数

            DatabaseServiceAddressingLocator locator = new DatabaseServiceAddressingLocator();

            String[] result = null;

            try{

                 String serviceURI = “http://127.0.0.1:8080/wsrf/services/DatabaseService”;

                     EndpointReferenceType endpoint = new EndpointReferenceType();

                     endpoint.setAddress(new Address(serviceURI));

                     DatabasePortType data = locator.getDatabasePortTypePort(endpoint);

                     Findexpfromsc f = new Findexpfromsc();

                     f.setType(type);

                     f.setDimension(dimension);

                     FindexpfromscResponse s =data.findexpfromsc(f);

                     result = s.getFindexpfromscReturn();

                }catch(Exception e){

                    e.printStackTrace();

                }

                return result;

            }

        public
static String[] Selectfromscandmaterial(String materialtype,String sctype,String scdimension){

         //对应于接口3的函数

        DatabaseServiceAddressingLocator locator = new DatabaseServiceAddressingLocator();

        String[] result = null;

        try{

             String serviceURI = “http://127.0.0.1:8080/wsrf/services/DatabaseService”;//服地址

             EndpointReferenceType endpoint = new EndpointReferenceType();//生成端点引用

             endpoint.setAddress(new Address(serviceURI));

             DatabasePortType data = locator.getDatabasePortTypePort(endpoint);//根据端点引用的引用

             Findexpfromscandmaterial f = new Findexpfromscandmaterial();//求参数

             f.setMaterialtype(materialtype);

             f.setSctype(sctype);

             f.setScdimension(scdimension);

             FindexpfromscandmaterialResponse s =data.findexpfromscandmaterial(f);//用服接口

                 result = s.getFindexpfromscandmaterialReturn();

            }catch(Exception e){

                e.printStackTrace();

            }

            return result;

        }

}

运行客户端程序DatabaseClient.java,在Console工作区运行结果如图3.4所示:

3.4 异地调用服务结果显示

如上图所示,数据库的查询成功,则证明服务的调用成功,同时也说明网格服务DatabaseService的开发成功完成。

针对不同的服务资源模式,客户端会有不同的编写方法。如果服务类型为Singleton的话,则只需要获得服务的引用然后调用接口即可;如果服务类型是Simple和Factory的话,就必须先创建资源然后再调用接口。


 

以下文章点击率最高

Loading…

     

如果这文章对你有帮助,请扫左上角微信支付-支付宝,给于打赏,以助博客运营

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注