导航:首页 > 编程语言 > wsdl2javaspring

wsdl2javaspring

发布时间:2023-01-18 00:49:04

① 如何用java调用cxf webservice接口

java调用cxf webservice接口可以自动生成的。
一:先下载CXF程序
二:在命令行下进入cxf下的bin目录
三:执行下面版命令:
wsdl2java -frontend jaxws21 -p com.webservice.cxfclient.sayhello -d src -all http://172.16.66.6:10000/test/sayHello?wsdl
四:点击权com.webservice.cxfclient右键,把生成的文件导入到工程中来。

② 如何将 webservice 部署 osb

1、jar包冲突

对照着wsdl,很快就手写好了客户端和服务端的代码,包括接口和领域模型。然后配一配cxf和spring的集成,搭了一个桩,一下就弄好了

可是将这部分代码放到项目里验证,用cxf2.5.2.jar替换了cxf2.0.13,就抛异常了:java.lang.IncompatibleClassChangeError: Implementing class

2、jar包升级后,旧功能不好用

好不容易定位出来,原来是2个版本的cxf所依赖的jar包是不同的,将相关的jar包也替换之后,发布成功了。可是系统中原来的几个老功能坏了,看来cxf的版本不能随便替换

3、jar包回退后,新功能不好用

于是又把cxf2.0.13替换了回去,这次老功能是可以了,我们新开发的web service也发布起来了,可是调用的时候报异常:
java.lang.IllegalArgumentException: object is not an instance of declaring class

后来发现,是cxf2.0.13和cxf2.5.2的配置文件的写法不同,改了一下以后,调用成功了

这3个问题的解决方法,见http://kyfxbl.iteye.com/blog/1467354

4、spring注入异常

当我们往服务端web service里注入业务逻辑组件,或者往业务逻辑组件里注入web service客户端接口时,依赖注入经常发生一些奇怪的问题,经常声明的bean找不到什么的

最后通过各种方式解决了,详情见http://kyfxbl.iteye.com/blog/1470923

不过还是遗留了一些问题没想通,以后再慢慢研究

5、根据wsdl手写的代码不好使

由于客户提供的wsdl比较复杂,手写的代码联调不通,最终还是只能用wsdl2java工具来做反向生成

6、用wsdl2java生成的代码,发布失败

生成了代码以后,发布又失败了,报了以下异常
Schema name conflict in collection. Namespace:xxxxxx

又花了1天时间解决了这个问题,详情见http://kyfxbl.iteye.com/blog/1483953

7、https证书问题

经过上面几个步骤,web service是发布起来了,通过http可以调通,但是客户要求用https协议来走,而且要求是双向认证。大家对https都不熟悉,这块花了3天时间才做出来,可以说是最困难的一步

8、实际联调时,客户端校验不通过

搞定了https协议问题之后,终于能业务联调了,可是失败了,客户系统那边报
Error code 'BEA-382505'. OSB Validate action failed validation: Expected element 'requestHeader' instead of 'requestBody' here in element XXX

定位发现原来是我们发送请求的时候,只填写了RequestBody的内容,以为不重要就没有填写RequestHead的内容,所以客户那边校验没通过

把这块改完以后,就OK了

总结一下:

1、开发新功能时,尽量在现有的jar包基础上开发。因为如果用与实际环境不同的jar包,很难保证不会出现jar包冲突,或者影响现有功能的问题

2、根据wsdl手写代码不是那么容易的,对于比较复杂的wsdl,还是用wsdl2java工具会比较保险

3、用spring配置文件来配置cxf还是很容易的,但是当集成spring和cxf的时候,依赖注入要特别小心,会有一些很异常的情况。这块的原因我现在还没有搞清楚

③ 如何用WSDL4J构建Spring+AXIS自动创建的Web service对应客户端

pache项目WSDL4J则是根据WSDL的XML文档就可以自动生成Web service的客户端代码,这样的话,构建web service服务端和客户端都显得没有多少手工编码了。其实WSDL4J也是可以生成服务端代码的,可是手工编写WSDL还不如用AXIS自动生成来得快。
用WSDL4J创建客户端代码的命令如下:
java -cp %AXIS_CLASSPATH% java org.apache.axis.wsdl.WSDL2Java -o DIR_NAME -p PACKAGE_NAME me?wsdl
其中AXIS_CLASSPATH应该包括axis.jar,commons-discovery.jar,commons-logging.jar,jaxrpc.jar,log4j.jar,saaj.jar,wsdl4j.jar,activation.jar,mail.jar。
该命令会在所指定目录下创建JAVA包,里面有[web_service]Locator.java, [web_service].java, [web_service]PortType.java, [web_service]SOAP11BindingStub.java,[web_service]SOAP12BindingStub.java,以及方法中所有涉及的参数bean等。

④ springmvc框架如何实现像webservice一样通过wsdl2Java生成客户端代码

在用到web service时,如果是调用自己开发的web service还好,可以有一个方法的接口或参数对象实体类什么的,但如果是调用第三方的服务,除了得到web service服务地址的wsdl文档外,没有任何实质性编码的东西,写原生调用太麻烦,这时就需要自己写一个方法的接口类。

这个,目前已经有比较成熟的工具,可以自动生成,下面作一下简单的介绍。

apache的wsdl2java工具,目前貌似CXF和axis各有一套,使用方式大同小异,但生成的代码会有所区别,这时说的是CXF提供的wsdl2java工具。

wsdl2java用法:

wsdl2java -p com -d src -all aa.wsdl

-p 指定其wsdl的命名空间,也就是要生成代码的包名:

-d 指定要产生代码所在目录

-client 生成客户端测试web service的代码

-server 生成服务器启动web service的代码

-impl 生成web service的实现代码

-ant 生成build.xml文件

-all 生成所有开始端点代码:types,service proxy,,service interface, server mainline, client mainline, implementation object, and an Ant build.xml file.

详细用法见:http://cwiki.apache.org/CXF20DOC/wsdl-to-java.html

一开始使用了CXF的这套工具,发现不是很方便,毕竟依赖CXF提供的工具jar包,个人不是很喜欢用。

后来发现JDK居然也自带了对web service生成java代码的功能,貌似1.6版本开始的,试用后发现效果十分不错,果断投入它的怀抱。下面作下简单的介绍,以备忘。

打开jdk下的bin目录 看下能否找到"wsimport.exe"这个文件

一般情况下都会有

如果没有则说明你的JDK不支持这个功能

然后在DOS窗口下输入wsimport 敲回车

如果提示错误的话 说明你的JDK环境变量还没有配好

一句话总结,如果你在dos窗口下输入wsimport正常,就可以

如果OK的话 输入以下命令就可以将wsdl文件生成java文件了

wsimporthttp://127.0.0.1/TicketMobile/services/Cococ?wsdl -keep -p com.llg.ws2 -s g:/ws

参数说明

wsimport 这个是必须的 该工具的名称

http://127.0.0.1/TicketMobile/services/Cococ?wsdl wsdl文件

-keep 是否生成源文件

-p com.llg.ws2 生成后的java包名

-s g:/ws 生成后放哪个目录

但是前几天,在对一个第三方提供的web service使用该工具生成java代码的时候,居然出错了,网上查找后终于找到原因。

使用cxf wsdl2java或javax wsimport工具的时候,可能会遇到关于生成的Response类文件名冲突的问题

Console代码

⑤ 求关于JAVA WEB的英文资料

真的吗??
那你去 http://en.wikipedia.org/wiki/Main_Page
然后在左边的搜索栏搜索 JAVA WEB
会出来一溜关于JAVA WEB的 我给你的是第一个
关于JAVA WEB START 的
去这个网站一看就一目了然了

http://en.wikipedia.org/wiki/Java_web_start

一定比我说的好
我给的网站差不多有20000字。。
这里还有 一小篇

Java Web Services Tools
by Madan Revoor, in Editorials - Sat, Feb 24th 2007 00:00 PDT

Web Service tools in Java are into their third generation now. Web services were introced with the hype of a loosely coupled technology for inter-connecting disparate endpoint systems. But they are, in fact, suffering from their tight coupling based on the WSDL data specifications and data types. Most of the current tools offer quick solutions to expose existing code as web services, but none offer a simple, yet intuitive and full-featured client.

--------------------------------------------------------------------------------
Copyright notice: All reader-contributed material on freshmeat.net is the property and responsibility of its author; for reprint rights, please contact the author directly.
--------------------------------------------------------------------------------

This article focuses on the Java-based Web Service APIs and compares some of the most commonly available tools, like Axis1.x, Axis2, XFire, WSIF, and SAAJ, along with stating the necessity for a Java Reflection-like API for Web Services based on WSDL that can retrieve the port type, operation name, service namespace, service style, method parameters, return types, Java data mappings, etc.

The first question that might pop into everyone's mind might be about Apache WSIF. Though WSIF mainly focuses on using the meta-information available in the WSDL, it doesn't offer a solution to directly work with the actual underlying XML message for a SOAP-based WSDL service. Also, it can look up the default port type and create default input and output messages for a specific operation, yet it does not offer a full-fledged Reflection API-like lookup for any and every piece of meta-information in the WSDL. Such a dynamic lookup can be used to check for available operations and exposed services at runtime and invoke them appropriately.

Also, as organizations look forward to web services as high-volume, transaction-capable, reliable, and interoperable workhorses, the ability to turn off Java object binding becomes highly desirable. This would be handy especially in scenarios in which the application is just a broker to a web service, and the actual data consumers are elsewhere. WSIF also depends on stubs generated from the Apache Axis WSDL2Java tool.

Apache SOAP was based on DOM and had to maintain the entire XML tree in memory, and hence was not suited to handle data-intensive services. Though Axis1.x (which was developed from Apache SOAP) was based on SAX and has enjoyed huge success in many corporate procts, it also has a serious flaw with web services that serve out huge XML content. It failed miserably in handling huge XML-based transactions, since the SAX-based parsing was tightly coupled to Java object binding. Thus, even though the SAX parsing could handle huge XML data efficiently, the data had to be stored in memory by generating and mapping to POJOs via its type mapping registry mechanism, coupled with its serializers and deserializers. It did not allow for a direct method to deal with the XML content transparently. There was no way one could turn off the generation of objects and deal with the XML content in a memory-efficient manner. Though it offered handlers and handler chaining mechanisms that could subscribe to receive the XML request/response message content, the object binding was mandatory, and each handler was presented with its own local of the message, which all added up to memory woes and hindered performance. However, Axis1.x has a very good WSDL parser tool called WSDL2Java, though it does not expose a complete set of APIs that clients can use to look up datatypes, method parameters, and their XML name tags or return parameters.

Axis2 is a complete re-architecture of Axis1.x from the ground up to address these issues. It is based on the new StAX (Streaming API for XML) and is poised to perform better than Axis1.x because of the advantages offered by StAX-based pull parsing. It provides more XML-oriented approaches and has a good Object Model named AXIOM that revolves around StAX to provide partial or deferred building support. This dependence on StAX allows it to boast of a low memory footprint. It also does not depend on storing the entire XML content in object forms in memory. It has support for plugable data bindings, and either SOAP or Java transport mechanisms can be used. However, one flaw with Axis2 is that it also does not allow a transparent and efficient method to dynamically invoke web services like WSIF, nor any lookup methods based on the WSDL.

SAAJ1.3 from Sun is a reliable SOAP messaging API. However, it does not deal with other Java-based transport mechanisms like JMS, RPC, etc., as Axis2 does. It's surprising that SAAJ offers much better performance than most of the Axis clients, though it offers a DOM-based API.

XFire has been developed by the Codehaus team as an alternative option to Axis1.x (at the same time that Axis2 was envisioned and drafted) to improve performance, along with the goals of catering to SOAP1.2 and being WS-I 1.1 compliant. It has an embedded HTTP server (Embedded XFire HTTP Service) and can be used to easily expose Java methods as web service endpoints with easy integration in Spring. It is also based on the current generation of pull parsers and incorporates StAX. However, XFire does not support encoded RPC-style services, and is yet to support dynamic clients (which might be featured in the next release).

Conclusion
Though the performance aspects of current Java web service tools are pepped up by the use of XML pull-based parsers like StAX and a more XML-oriented approach with optional object endpoints, the missing link in Java-based web service tools is good Reflection API-like dynamic WSDL parsing capability. It could be used to provide a handle to the meta-information available on the WSDL at runtime for clients. A mix of WSIF-like (with a more extensive WSDL parser) and Axis2-like StAX-based functionality is desired. It should not only offer a lot of possibilities like handling of small changes on the web service specification (WSDL) at runtime (an open issue would be to decide which changes are small and which can be handled), but empower clients at times to even ward off a complete rebuild and code changes. Another great feature would be to allow the clients to choose between options to turn on/off the WSDL parser and cache the WSDL metadata, as it need not affect the performance every time a call to the WSDL reflection API is made. This would be useful when the web service definition is not static and is in development or re-evolving stages, so that clients do not need to wait for the final release, but can continue with their development and testing. It would also lend much flexibility to the client design, as it could transparently decide which WSDL-exposed operation to choose or which transport protocol to use at runtime. Let's hope such a tool with the best features of all existing APIs will soon be released.

⑥ Java学习路线

java的学习内容很多,涵盖较多方面,这里大致分为几个阶段提供给你参考。
一、预科学习:
HTML5:HTML5标签入门、HTML5表格、表单
CSS3:CSS3选择器和简单属性、CSS3定位和布局、CSS3复杂选择器和高级属性
数据库:mysql数据库安装和数据操作、约束和简单查询、复杂查询、数据库设计、oracle的安装与数据操作、oracle与mysql的对比学习

二、JavaSE
Java语言基础、程序逻辑:环境配置和第一个语言程序-HelloWorld 变量运算符 条件和循环 方法和数组
Java面向对象:面向对象入门 面向对象应用_管理系统类 Java常用类、String相关、算法相关 面向对象深入(重载、this、static )继承(重写、super、初始化顺序) 多态(抽象类和接口、final、克隆和比较接口 设计模式、对象和类的生命周期)
API:异常、日志 集合 集合工具类和泛型 IO JDBC基础线程 网络编程 反射 NIO Junit
Java面向对象思想:设计模式 面向对象原则
Java底层理论:集合底层 性能监控工具 反编 JUC

三、Java web
web基础:TOMCAT/WEB程序结构/HTTP协议 Servlet基础入门、servlet作用域(cookie、session、ServletContext)、 Cookie和Session 、Servlet的交互/jsP原理及运用、 JavaBean/EL/JSTL/MVC思想 、JSP+Servlet+JDBC综合练习、Session购物车案例/验证码/防止表单重复提交、监听器过滤器
第三方工具包:连接池、事务、分页、文件上传下载、Dom4j/Log4j/Log back
JavaScript和jQuery框架技术:JS入门和DOM基础 、DOM模型深入 、jQ基础、 jQ操作DOM
MVC动态Web开发技术:自定义MVC框架、DAO框架、前端框架(layUI)
Web开发高级运用:tomcat server服务器配置 、nginx使用、 jetty配置
网络编程:网络原理、HTTP协议基础、Linux操作系统、云服务搭建

四、SSM框架
Spring框架、SpringMVC框架、MyBatis框架:mybatis入门、 配置文件详解和动态sql的使用、 mybatis管理关系映射和延迟加载、 查询缓存和逆向工程 、Spring入门和集成、myBatis SpringMVC入门 、SSM集成、 Spring配置详解 、Spring AOP、 Spring事务配置 、SpringMVC高级功能 、SpringMVC原理

五、前沿技术
高可用、高并发、高扩展:Spring Boot 、缓存 、分布式 、全文索引、 服务中间件、 myCat、 云服务 、人脸识别 、语言识别 、JVM底层+优化

希望能够帮到你!!!

⑦ Java开发的学习内容都有哪些

java学习内容你可以参考以下:

一、JavaEE基础

Java基础语法、面向对象、核心类库、集合、异常、IO、线程、JDK新特性;

二、JavaWeb开发

前端技术、数据库、JAVA数据库操作、软件服务器及服务器相关技术、动态网页JSP、AJAX;

三、Java高级框架

SpringMVC、MyBatis、Spring、MySQL高级、Linux&Redis&Nginx、Maven;

四、大型微服务分布式项目实战

SpringBoot、SpringCloud、Git、Dubbo、Zookeeper、AngularJS、Spring Security、BCrypt加密、FastDFS、分布式事务处理、Redis Cluster、Solr、SolrCloud、Freemarker、JMS、短信发送平台、SSO解决方案、CORS、Twitter的Snowflake、SpringTask、Maven Profile、MongoDB简介、MyCat、Docker、Jenkins;

五、微服务大型项目实战

⑧ 谁遇到过在Tomcat下面部署的CXF出现这样的错误

详细介绍了在tomcat容器中创建、发布和访问CXF服务的步骤和各种方法。一、服务器端1.添加CXF包1)基本包:commons-logging-1.1.1.jargeronimo-activation_1.1_spec-1.0.2.jargeronimo-annotation_1.0_spec-1.1.1.jargeronimo-javamail_1.4_spec-1.6.jargeronimo-jaxws_2.1_spec-1.0.jargeronimo-servlet_2.5_spec-1.2.jargeronimo-stax-api_1.0_spec-1.0.1.jargeronimo-ws-metadata_2.0_spec-1.1.2.jarjaxb-api-2.1.jarjaxb-impl-2.1.12.jarjetty-6.1.21.jarjetty-util-6.1.21.jarneethi-2.0.4.jarsaaj-api-1.3.jarsaaj-impl-1.3.2.jarwsdl4j-1.6.2.jarwstx-asl-3.2.8.jarxml-resolver-1.2.jarXmlSchema-1.4.5.jar2)jsf和jstl(非必要,用MyEclipse创建WebProject时会自动加入,无须再添加)jsf-api.jarjsf-impl.jarjstl-1.2.jar3)cxfcxf-2.2.4.jar4)Springjars,为XMLConfiguration添加Spring支持。aopalliance-1.0.jarspring-core-2.5.5.jarspring-beans-2.5.5.jarspring-context-2.5.5.jarspring-web-2.5.5.jar2.服务接口及实现1)接口类,如HelloWorld.java:packagecxf.test;importjavax.jws.WebService;@{//一个简单的方法,返回一个字符串Stringsay(Stringhello);}2)实现类,如HelloWorldImpl.java:packagecxf.test;importjavax.jws.WebService;//WebService实现类.//使用@WebService指向Interface定义类即可.@WebService(endpointInterface="cxf.test.HelloWorld"){publicStringsay(Stringhello){return"hello"+hello;}}3.服务配置1)web.xmlcontextConfigLocationWEB-INF/beans.xmlorg.springframework.web.context..apache.cxf.transport.servlet.CXFServletCXFServlet/services/*2)beans.xml注:服务无需诸如index.jsp之类的配置,MyEclipse自动加入的可删除,对服务及配置无任何影响。4.服务发布(到Tomcat)方法一:通过MyEclipse发布点击工具栏图标,或者右键单击项目→MyEclipse→。方法二:使用Ant。二、客户端创建WebProject,执行下列步骤即可。无须设置web.xml。1.添加CXF包针对不同的方法,需要的包不尽相同。如下面“3.服务调用”的方法三,需要如下包:commons-logging-1.1.1.jarcxf-2.2.4.jarneethi-2.0.4.jarspring-core-2.5.5.jarspring-beans-2.5.5.jarspring-context-2.5.5.jarwsdl4j-1.6.2.jarXmlSchema-1.4.5.jar2.获取服务服务接口类(类似于C/C++中的.h头文件)方法一:直接从原项目中这当然是最简单的方法,也是最“难”的方法(如果服务不是自己做的,显然没法获得)。方法二:从wsdl文档中生成。需要先安装cxf程序包。生成步骤如下:1)安装cxf,设置环境变量,如:D:/Apache/apache-cxf-2.2.4;同时,PATH后加上“;%CXF_HOME%/bin”(可选)。wsdl2java的用法如下:wsdl2java–p包名–d目录名wsdl路径如:wsdl2java–pdemo.service.client–de:/srchtt://localhost:8080/helloWorld?wsdl-p指定其wsdl的命名空间,也就是要生成代码的包名-d指定要产生代码所在目录-client生成客户端测试webservice的代码-server生成服务器启动webservice的代码-impl生成webservice的实现代码-ant生成build.xml文件-compile生成代码后编译-quient静默模式,不输出警告与错误信息-all生成所有开始端点代码:types,serviceproxy,serviceinterface,servermainline,clientmainline,implementationobject,andanAntbuild.xmlfile.2)执行wsdl2java批处理程序,如:wsdl2java-pcxf.test-dd:/src-{_NAME=newQName("","HelloWorld");//首参为接口实现类包名的反缀privatestaticfinalQNamePORT_NAME=newQName("","HelloWorldPort");privateClient(){}publicstaticvoidmain(Stringargs[])throwsException{Serviceservice=Service.create(SERVICE_NAME);//="HelloWorld";//AddaporttotheServiceservice.addPort(PORT_NAME,SOAPBinding.SOAP11HTTP_BINDING,endpointAddress);HelloWorldhw=service.getPort(HelloWorld.class);System.out.println(hw.say("World"));}}方法二:使用较下层的代码更加精确的控制程序的行为,如:packagecxf.test;importorg.apache.cxf.jaxws.JaxWsProxyFactoryBean;importcxf.test.HelloWorld;//{privateClient(){}publicstaticvoidmain(Stringargs[])throwsException{=newJaxWsProxyFactoryBean();factoryBean.getInInterceptors().add(newLoggingInInterceptor());(可选)factoryBean.getOutInterceptors().add(newLoggingOutInterceptor());(可选)factoryBean.setServiceClass(cxf.test.HelloWorld.class);factoryBean.setAddress("HelloWorld");HelloWorldclient=(HelloWorld)factoryBean.create();System.out.println(client.say("God"));System.exit(0);}}备注:LoggingInInterceptor和LoggingOutInterceptor是日志拦截器,用于输入和输出时显示日志。使用与否并不影响程序的行为。方法三:使用Spring,例如:packagecxf.test;importorg.springframework.context.support.;importcxf.test.HelloWorld;//{privateClient(){}publicstaticvoidmain(Stringargs[])throwsException{context=new(newString[]{"cxf/test/client-beans.xml"});HelloWorldclient=(HelloWorld)context.getBean("client");Stringresponse=client.say("Joe");System.out.println("Response:"+response);System.exit(0);}}注意:要想使用Spring来完成,在cxf.test包中必须有client-beans.xml存在,内容如下:4.执行RunAsJavaApplication

⑨ 如何在Tomcat中创建,发布和访问基于CXF的服务

详细介绍了在tomcat容器中创建、发布和访问CXF服务的步骤和各种方法。
一、服务器端
1.添加CXF包
1)基本包:
commons-logging-1.1.1.jar
geronimo-activation_1.1_spec-1.0.2.jar
geronimo-annotation_1.0_spec-1.1.1.jar
geronimo-javamail_1.4_spec-1.6.jar
geronimo-jaxws_2.1_spec-1.0.jar
geronimo-servlet_2.5_spec-1.2.jar
geronimo-stax-api_1.0_spec-1.0.1.jar
geronimo-ws-metadata_2.0_spec-1.1.2.jar
jaxb-api-2.1.jar
jaxb-impl-2.1.12.jar
jetty-6.1.21.jar
jetty-util-6.1.21.jar
neethi-2.0.4.jar
saaj-api-1.3.jar
saaj-impl-1.3.2.jar
wsdl4j-1.6.2.jar
wstx-asl-3.2.8.jar
xml-resolver-1.2.jar
XmlSchema-1.4.5.jar
2)jsf和jstl(非必要,用MyEclipse创建Web Project时会自动加入,无须再添加)
jsf-api.jar
jsf-impl.jar
jstl-1.2.jar
3)cxf
cxf-2.2.4.jar
4)Spring jars,为XML Configuration添加Spring支持。
aopalliance-1.0.jar
spring-core-2.5.5.jar
spring-beans-2.5.5.jar
spring-context-2.5.5.jar
spring-web-2.5.5.jar

2.服务接口及实现
1)接口类,如HelloWorld.java:
package cxf.test;
import javax.jws.WebService;
@WebService
public interface HelloWorld
{
// 一个简单的方法,返回一个字符串
String say(String hello);
}
2)实现类,如HelloWorldImpl.java:
package cxf.test;
import javax.jws.WebService;
// WebService实现类.
// 使用@WebService指向Interface定义类即可.
@WebService(endpointInterface = "cxf.test.HelloWorld")
public class HelloWorldImpl implements HelloWorld
{
public String say(String hello)
{
return "hello " + hello;
}
}

3.服务配置
1)web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/beans.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>
org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
</web-app>
2)beans.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jaxws:endpoint id="webServiceHelloWorld"
address="/HelloWorld"
implementor="cxf.test.HelloWorldImpl"/>
</beans>
注:服务无需诸如index.jsp之类的配置,MyEclipse自动加入的可删除,对服务及配置无任何影响。
4.服务发布(到Tomcat)
方法一:通过MyEclipse发布
点击工具栏 图标,或者右键单击项目 → MyEclipse → Add and Remove Project Deployments。
方法二:使用Ant。

二、客户端
创建Web Project,执行下列步骤即可。无须设置web.xml。
1.添加CXF包
针对不同的方法,需要的包不尽相同。如下面“3.服务调用”的方法三,需要如下包:
commons-logging-1.1.1.jar
cxf-2.2.4.jar
neethi-2.0.4.jar
spring-core-2.5.5.jar
spring-beans-2.5.5.jar
spring-context-2.5.5.jar
wsdl4j-1.6.2.jar
XmlSchema-1.4.5.jar
2.获取服务服务接口类(类似于C/C++中的.h头文件)
方法一:直接从原项目中
这当然是最简单的方法,也是最“难”的方法(如果服务不是自己做的,显然没法获得)。
方法二:从wsdl文档中生成。
需要先安装cxf程序包。生成步骤如下:
1) 安装cxf,设置环境变量,如:D:/Apache/apache-cxf-2.2.4;同时,PATH后加上“;%CXF_HOME%/bin”(可选)。wsdl2java的用法如下:
wsdl2java –p 包名 –d 目录名 wsdl路径
如:wsdl2java –p demo.service.client –d e:/src htt://localhost:8080/helloWorld?wsdl
-p 指定其wsdl的命名空间,也就是要生成代码的包名
-d 指定要产生代码所在目录
-client 生成客户端测试web service的代码
-server 生成服务器启动web service的代码
-impl 生成web service的实现代码
-ant 生成build.xml文件
-compile 生成代码后编译
-quient 静默模式,不输出警告与错误信息
-all 生成所有开始端点代码:types,service proxy,service interface, server mainline, client mainline, implementation object, and an Ant build.xml file.
2) 执行wsdl2java批处理程序,如:
wsdl2java -p cxf.test -d d:/src -server http://localhost:8080/CXFTomcat/services/ HelloWorld?wsdl
3) 将java接口类导入项目。
上一步生成的java类文件很多,一般的应用中只要将说明接口的那个类文件导入项目即可,如上例生成的HelloWorld.java文件。
3.服务调用
方法一:使用jws的高层封装,如:
package cxf.test;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.soap.SOAPBinding;
import cxf.test.HelloWorld; // necessary
public final class Client {
private static final QName SERVICE_NAME
= new QName("http://test.cxf/", "HelloWorld"); // 首参为接口实现类包名的反缀
private static final QName PORT_NAME
= new QName("http://test.cxf/", "HelloWorldPort");
private Client() { }
public static void main(String args[]) throws Exception {
Service service = Service.create(SERVICE_NAME);
// Endpoint Address
String endpointAddress = "http://localhost:8080/CXFTomcat/services/HelloWorld";
// Add a port to the Service
service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);
HelloWorld hw = service.getPort(HelloWorld.class);
System.out.println(hw.say("World"));
}
}
方法二:使用较下层的代码更加精确的控制程序的行为,如:
package cxf.test;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import cxf.test.HelloWorld; // necessary
public final class Client {
private Client() { }
public static void main(String args[]) throws Exception {
JaxWsProxyFactoryBean factoryBean = new JaxWsProxyFactoryBean();
factoryBean.getInInterceptors().add(new LoggingInInterceptor());(可选)
factoryBean.getOutInterceptors().add(new LoggingOutInterceptor());(可选)
factoryBean.setServiceClass(cxf.test.HelloWorld.class);
factoryBean.setAddress("http://localhost:8080/CXFTomcat/services/HelloWorld");
HelloWorld client = (HelloWorld)factoryBean.create();
System.out.println(client.say("God"));
System.exit(0);
}
}
备注:LoggingInInterceptor和LoggingOutInterceptor是日志拦截器,用于输入和输出时显示日志。使用与否并不影响程序的行为。
方法三:使用Spring,例如:
package cxf.test;
import org.springframework.context.support.;
import cxf.test.HelloWorld; // necessary
public final class Client {
private Client() { }
public static void main(String args[]) throws Exception {
context = new (new String[] {"cxf/test/client-beans.xml"});
HelloWorld client = (HelloWorld)context.getBean("client");
String response = client.say("Joe");
System.out.println("Response: " + response);
System.exit(0);
}
}
注意:要想使用Spring来完成,在cxf.test包中必须有client-beans.xml存在,内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schema/jaxws.xsd">
<bean id="client" class="cxf.test.HelloWorld"
factory-bean="clientFactory" factory-method="create"/>
<bean id="clientFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
<property name="serviceClass" value="cxf.test.HelloWorld"/>
<property name="address" value="http://localhost:8080/CXFTomcat/services/HelloWorld"/>
</bean>
</beans>
4.执行
Run As Java Application

⑩ 学习Java的最佳路线

说到学习Java,我们今天就来说说Java开发需要学习的内容,说说java学习路线,说说Java学习的课程内容。
Java学习大致分为四大阶段,具体内容如下:
第一阶段——Java基础
Java的学习内容从计算机基本概念,DOS命令开始,为你入门编程语言扫盲,什么是程序,如何配置Java开发环境,Java编程的过程是怎样的,Java有什么物特点,程序是如何运行的,这些你都可以在这里得到答案。
Java编程的基础语法,共分为10个知识点,我们将学习变量,基本数据类型,进制,转义字符,运算符,分支语句和循环语句等,以达到训练基础语法和逻辑能力的目的。还有对数组、面向对象和异常处理等。
第二阶段——JavaWeb
Web前端开发基础和框架、Servlet和JSP在Web后端的应用、Web后端开发相关专题、MVC和分层架构以及项目开发流程及CASE工具的使用等。
第三阶段——Java框架
框架是程序中另一种存储数据的方式,比直接使用数组来存储更加的灵活,在项目中应用十分广泛。同时,框架整合开发(SSH/SSS)、RESTful架构和移动端接口设计、第三方接口和在线支付功能、网站安全和Spring Security应用实战、复杂用户交互处理和Spring Web Flow的应用、MyBatis的应用和SSM整合,我们将深入研究其中涉及到的数据结构和算法,对学员的技术深度有了一个质的提升。
第四阶段——Java+云数据
亿级并发架构演进、Linux基础、搭建tomcat环境以实战演练,企业真实项目供学员应用学习,进行知识体系的“二次学习”。
其实学习Java技术,大可参考此学习路线,该学习路线对从零基础小白到Java初级开发工程师,Java高级开发工程师,后面的Java大神级开发工程师都有一个明确清晰的指导。

阅读全文

与wsdl2javaspring相关的资料

热点内容
dos看图工具 浏览:15
微信直接加为好友 浏览:467
可以用微信传送的文件app 浏览:294
pdf文件解析乱码 浏览:479
光照无关图代码 浏览:688
Linux读写文件前八位 浏览:597
word如何绘制饼状图 浏览:172
w7系统搜索文件夹 浏览:618
java线程变量 浏览:854
苹果电脑word是只读文件 浏览:691
ps5国行备份文件大小 浏览:754
linux恢复删除文件命令 浏览:805
win10家庭版打不开qq文件 浏览:794
女生来例假有哪个app比较好 浏览:66
调用后台接口为什么不显示数据 浏览:363
js判断重复 浏览:422
联通如何切换到网络电视 浏览:191
学编程的优势哪里靠谱 浏览:939
沟通文件 浏览:267
水准测量平差程序 浏览:78

友情链接