MyEclipse+Axis2插件开发Web服务.docx

上传人:b****1 文档编号:10251497 上传时间:2023-05-24 格式:DOCX 页数:11 大小:182.70KB
下载 相关 举报
MyEclipse+Axis2插件开发Web服务.docx_第1页
第1页 / 共11页
MyEclipse+Axis2插件开发Web服务.docx_第2页
第2页 / 共11页
MyEclipse+Axis2插件开发Web服务.docx_第3页
第3页 / 共11页
MyEclipse+Axis2插件开发Web服务.docx_第4页
第4页 / 共11页
MyEclipse+Axis2插件开发Web服务.docx_第5页
第5页 / 共11页
MyEclipse+Axis2插件开发Web服务.docx_第6页
第6页 / 共11页
MyEclipse+Axis2插件开发Web服务.docx_第7页
第7页 / 共11页
MyEclipse+Axis2插件开发Web服务.docx_第8页
第8页 / 共11页
MyEclipse+Axis2插件开发Web服务.docx_第9页
第9页 / 共11页
MyEclipse+Axis2插件开发Web服务.docx_第10页
第10页 / 共11页
MyEclipse+Axis2插件开发Web服务.docx_第11页
第11页 / 共11页
亲,该文档总共11页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

MyEclipse+Axis2插件开发Web服务.docx

《MyEclipse+Axis2插件开发Web服务.docx》由会员分享,可在线阅读,更多相关《MyEclipse+Axis2插件开发Web服务.docx(11页珍藏版)》请在冰点文库上搜索。

MyEclipse+Axis2插件开发Web服务.docx

MyEclipse+Axis2插件开发Web服务

MyEclipse+Axis2插件开发WebService2011-06-14

Axis2插件的安装

代码生成工具  Axis2_Code_Generator

打包工具      Axis2_Service_Archiver

上述两个工具可以在http:

//apache.justdn.org/ws/axis2/tools/下载。

 需要注意的是,这两个工具都是针对Axis2具体的版本开发的。

也就是说,plug-in版本一定要与webapps下的项目axis2版本一致,否则服务不能被发布。

如果你之前下载的Axis2的版本为1.3,则选择1.3目录,然后,进入后选择如下两项的链接,下载即可。

安装方法

Axis2EclipseCodegenWizardInstallation

-----------------------------------------

1)ShutdownEclipseIDE,ifalreadyrunning.

2)PleaseremoveexistingAxis2CodegenWizardsinsideECLIPSE_HOME/pluginsdirectory.

3)copytheAxis2_Codegen_Wizard_foldertotheECLIPSE_HOME/pluginsdirectory.

4)StartEclipse.

5)Axis2wizardsareavailableatFile->new->other.[ ctl+n ]

Note:

TheAxis2codegenwizardelcipsepluginonlycompatiblewithEclipse3.1upwards.

 Axis2EclipseServiceArchiverWizardInstallation

--------------------------------------------------

1)ShutdownEclipseIDE,ifalreadyrunning.

2)Ifpreviousversionsofthesamepluginexists,

  pleaseremoveexistingAxis2ServiceArchiverWizardinsideECLIPSE_HOME/pluginsdirectory.

3)copytheAxis_Service_Archiver_foldertotheECLIPSE_HOME/pluginsdirectory.

4)StartEclipse.

5)Axis2wizardsareavailableatFile->new->other.[ ctl+n ]

安装完成后文件目录应该多了如下2个文件夹

重新启动eclipse可以在new->other下找到如下图所示axis2开发图表则安装成功。

安装完成后的快速上手:

启动MyEclipse,新建立一个WebApps(File->New->Project->WebProject),给ProjectName为SayHello,其他保持不改变。

创建WSDL文件

A.选择File->New-Other菜单,进入后找到MyEclipse->WebServices并选择WSDL.如下图:

B.点击下一步按钮,显示如下图:

C.选择“src”目录作为“Enterorselecttheparentfolder”的值,“Filename”值给定为SayHello.wsdl。

D.下一步》所有界面内容取默认值,Finish!

E.显示WSDL设计器的界面如下:

F.修改图中标红色的部分:

修改图中的NewOperation为SayHello;

修改input中parameters为SayHelloRequest;

修改output中parameters为SayHelloResponse;

修改完后如下图:

红色框内为变化的内容,WSDL文件修改完毕。

从WSDL生成Java代码

A.选择菜单“File->New->Other”,从对话框中选取“Axis2Wizards”下面的“Axis2CodeGenerator”.点击“Next”

B.进入下一个页面,保持“GeneratejavasourcecodefromWSDLfile”被选中,点击“Next”进入下一步。

C.点击“Browse”来选取存放在src目录下的SayHello.wsdl文件,“Next”进入下一步。

D.首先生成客户端代码和测试代码,设置如下:

E.下一步后,选择SayHellosrc目录,如下图:

Finish!

F.重复从A到C的步骤,然后生成服务端代码,设置如下:

后同E。

G.结束后,刷新项目,如图:

这是由于没有将Axis2的jar包放入classpath中以及源代码的package不为org.example.www.sayhello引起的。

H.修改包名为org.example.www.sayhello并从tomcat中的axis2web应用WEB-INF/lib目录中加载所有jar包到项目的classpath中。

I.在SayHelloTest.java中引入junit包。

服务端代码:

SayHello.java SayHelloResponse.java ExtensionMapper.java SayHelloMessageReceiverInOut.java SayHelloSkeleton.java

客户端代码:

SayHelloStub.javaSayHelloTest.java

编写业务代码

打开SayHelloSKeleton.java文件其中的方法如下:

public org.example.www.sayhello.SayHelloResponse SayHello(org.example.www.sayhello.SayHelloRequest param0)

{

// Todo fill this with the necessary business logic

throw new java.lang.UnsupportedOperationException();

}

 修改为:

public org.example.www.sayhello.SayHelloResponse SayHello(org.example.www.sayhello.SayHelloRequest request)

{

      SayHelloResponseresponse=newSayHelloResponse();//创建服务响应对象。

      response.setOut("Hi,"+request.getIn()+".Howareyou?

");

      //创建服务响应的具体消息,request.getIn()获取请求的消息。

       returnresponse;

  }

打包

A.选择菜单“File->New->Other”,从对话框中选取“Axis2Wizards”下面的“Axis2ServicesArchive”.点击“Next”进入下一个页面。

B.选择编译好的class文件所在目录(本项目应该是${SayHello}\WebRoot\WEB-INF\classes),“Next”进入下一步。

C.选择WSDL文件所在目录,此处为src目录下的SayHello.wsdl文件。

“Next”,再“Next”,选择services.xm文件,位于src\resources\services.xml。

D.点击“Next”,将记入最后一个页面,此处有两个选项,一个是输出目录一个是处处文件名称。

这里的输出文件名称给的是SayHello。

点击“Finish”完成。

部署

A.将打包好的文件SayHello.jar拷贝到Tomcat中已经部署的Axis2应用的WEB-INF/services目录下面。

B.打开浏览器,输入http:

//127.0.0.1:

8080/axis2,并点击其中的“services”链接可以看到SayHello已经被部署。

点击SayHello提供的连接可以看到与之对应的WSDL。

调用测试

A.修改SayHelloTest.java文件中的方法testSayHello的内容为:

publicvoidtestSayHello()throwsjava.lang.Exception{

  Stringurl="http:

//localhost:

8080/axis2/services/SayHello"; //指定服务的url。

  org.example.www.sayhello.SayHelloStubstub=neworg.example.www.sayhello.SayHelloStub(url);

  org.example.www.sayhello.SayHelloStub.SayHellorequest=(org.example.www.sayhello.SayHelloStub.SayHello)getTestObject(org.example.www.sayhello.SayHelloStub.SayHello.class);

  request.setIn("Teamlet");//向服务发送的请求

  System.out.println(stub.SayHello(request).getOut());//对于特定请求的响应。

  assertNotNull(stub.SayHello(request));

 }

 从菜单中选择“Run->Runas->JUnitTest完成测试!

可能出现的错误及解决方案

在生成代码最后一步出现的java.lang.错误解决

1)关闭eclipse

2)从"$AXIS2_HOME/lib/"复制"backport-util-concurrent-3.1.jar"到"$ECLIPSE_HOME/plugins/Axis2_Codegen_Wizard_1.3.0/lib/"

3)往"$ECLIPSE_HOME/plugins/Axis2_Codegen_Wizard_1.3.0/plugin.xml"插入如下配置

4)将"$ECLIPSE_HOME/plugins/Axis2_Codegen_Wizard_1.3.0/plugin.xml"中的版本号从"1.3.0"改为"1.4.0"

5)将eclipse的plugin文件夹的"Axis2_Codegen_Wizard_1.3.0"重命名为"Axis2_Codegen_Wizard_1.4.0"

6)再启动eclipse就OK了

 

--------------------

在使用codegen插件来从WSDL文件生成代码时,到了最后一步竟然出然了"Anerroroccurredwhilecompletingprocess-java.lang.reflect.InvocationTargetException"的错误,重试N次,结果依然,

从AXIS2的LIB库中复制"geronimo-stax-api_1.0_spec-1.0.1.jar"和"backport-util-concurrent-3.1.jar"文件到Codegen的lib目录中,同时修改plugin.xml文件,添加

到plugin.xml文件中,保存后重新启动Eclipse即可!

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 自然科学 > 化学

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2