??xml version="1.0" encoding="utf-8" standalone="yes"?>精品福利免费观看,久久精品无码一区二区三区,欧美日韩美女视频http://www.aygfsteel.com/yuxh/category/48138.htmlwayzh-cnTue, 08 May 2012 20:59:54 GMTTue, 08 May 2012 20:59:54 GMT60Developing.Web.Services.with.Apache.CXF.and.Axis2 3rdhttp://www.aygfsteel.com/yuxh/archive/2011/10/24/361838.htmlyuxhyuxhSun, 23 Oct 2011 16:26:00 GMThttp://www.aygfsteel.com/yuxh/archive/2011/10/24/361838.htmlhttp://www.aygfsteel.com/yuxh/comments/361838.htmlhttp://www.aygfsteel.com/yuxh/archive/2011/10/24/361838.html#Feedback0http://www.aygfsteel.com/yuxh/comments/commentRss/361838.htmlhttp://www.aygfsteel.com/yuxh/services/trackbacks/361838.html1. Code first approach:可能不能完全发挥框架和web services的能量,但能完成目标。减了学习曲线Q不用非帔R彻了解web services概念Q只要对某个框架有一定了解就能完成Q务?br />2.Contract first approach:Ҏ服务先写WSDL文gQ写好之后用框架的工具把WSDL转换Z赖框架的代码?/p>

一  介绍

当客L调用你的web service的时候,他会发送一个消息过来(可能是soap 消息Q,如:

<foo:concatRequest>
<s1>abc</s1>
<s2>123</s2>
</foo:concatRequest>

q时候如果有一个{换器把这个soap消息转换成java对象Q然后调用你提供的java对象Q方法)的话会是非常方便的。几个最行的库是充当了这U{换器功能Q比如CXF, Axis2 Q?Metro Qjdk6自带的有Q?/p>

手动创徏WSDL文g比较Ҏ出错Q可以用eclipseq行可视化编辑?/p>

?生成服务代码

像CXFq样?web service库可以创{换器把进来的SOAP 消息转换为Java对象Q然后作为参Cl方法。生成这些代码,只需创徏一个mainQ?/p>

1 CXF方式Q?/p>

public static void main(String[] args) { WSDLToJava.main(new String[] { "-server", "-d", "src/main/java", "src/main/resources/SimpleService.wsdl" }); System.out.println("Done!"); }

q行后会生成service endpoint interfaceQSEIQ,我们再写一个类Q比如SimpleServiceImplQ来实现q个接口Q写入自q业务。还会生成传入消息对应的java对象。同时生成一个服务器c:

public class SimpleService_P1_Server { protected SimpleService_P1_Server() throws Exception { System.out.println("Starting Server"); Object implementor = new SimpleServiceImpl(); String address = "http://localhost:8080/ss/p1"; Endpoint.publish(address, implementor); } public static void main(String args[]) throws Exception { new SimpleService_P1_Server(); System.out.println("Server ready..."); Thread.sleep(5 * 60 * 1000); System.out.println("Server exiting"); System.exit(0); } }

q行q个cM的web service可以服务了?/p>

2 Axis2 方式

用类似的写mainҎQ或者配|eclipse的axis2插g可生成:在WSDL文g上,右键->web service->generate java bean skeleton

界面的上半部分针Ҏ务端Q可以根据需要调整生成的U别Q下半部分是生成客户端。具体的U别可参考eclipse的帮助文档。一路下一步,最后根据命名空间生成包路径的文Ӟ里面有XXSkeletonInterface.java 文gQ如果生成的时候选择了生成接口的话)Q还有一个XXSkeleton实现了这个接口,也是我们需要修改这部分代码完成我们业务的地斏V实际上有一个XXMessageReceiverInOut.java的类接收h的消息,q调用XXSkeletonInterface。用eclipse的axis2插g的时候,会自动在web-inf文g夹下生成service\xx(你的wsdl服务?Q这下面q要一个meta-inf文g夹装有wsd文g和一个services.xml配置文g。services.xml文g可配|包括XXMessageReceiverInOutcd内的选项?br />

?生成客户端代?/p>

Z调用q些web serviceQ同样可以用CXFq些库来生成在客Lq行的{换器Q称为service stubQ。当调用stub里的Ҏ的时候,他会把你的数?对象 转换为正的XML格式Q然后发送给真正的web service。当他收到响应的时候,又会把XML转回Java?/p>

1 CXF 方式

和生成服务器端类|使用Ҏ

WSDLToJava.main(new String[] {
"-client",
"-d", "src/main/java",
"src/main/resources/SimpleService.wsdl" });

q行后会生成客户端代码:

public final class SimpleService_P1_Client { private static final QName SERVICE_NAME = new QName("http://ttdev.com/ss", "SimpleService"); private SimpleService_P1_Client() {} public static void main(String args[]) throws Exception { URL wsdlURL = SimpleService_Service.WSDL_LOCATION; if (args.length > 0) { File wsdlFile = new File(args[0]); try { if (wsdlFile.exists()) { wsdlURL = wsdlFile.toURI().toURL(); } else { wsdlURL = new URL(args[0]); } } catch (MalformedURLException e) { e.printStackTrace(); } } SimpleService_Service ss = new SimpleService_Service(wsdlURL, SERVICE_NAME); SimpleService port = ss.getP1(); { System.out.println("Invoking concat..."); com.ttdev.ss.ConcatRequest _concat_parameters = null; java.lang.String _concat__return = port.concat(_concat_parameters); System.out.println("concat.result=" + _concat__return); } System.exit(0); } }

SimpleService_Service是创建的service stubQ他模拟了客L的服务。我们需要修改这个类中的_concat_parameters部分Q加入参敎ͼ

com.ttdev.ss.ConcatRequest _concat_parameters = new ConcatRequest();
_concat_parameters.setS1("abc");
_concat_parameters.setS2("123");

现在可以运行客L代码了。SEI中有一些注解,可以修改Q不l说?/p>

 

2 Axis2 方式
和生成服务端cMQ利用eclipse插g直接生成Q包路径cMQ有一个XXStubc,q个c里面有包括h和应{消息在内的内部cR用的时候,先对h消息参数cL业务需求赋|最后调用Stub的请求方法。可以用Stub的构造函数指定目标endpoint?p> 



yuxh 2011-10-24 00:26 发表评论
]]>
RCP与Document风格http://www.aygfsteel.com/yuxh/archive/2011/10/08/360224.htmlyuxhyuxhSat, 08 Oct 2011 13:47:00 GMThttp://www.aygfsteel.com/yuxh/archive/2011/10/08/360224.htmlhttp://www.aygfsteel.com/yuxh/comments/360224.htmlhttp://www.aygfsteel.com/yuxh/archive/2011/10/08/360224.html#Feedback0http://www.aygfsteel.com/yuxh/comments/commentRss/360224.htmlhttp://www.aygfsteel.com/yuxh/services/trackbacks/360224.html有两USOAP message风格Q?em>document ?em>RPCQ?/em>他们定义了SOAP message body的格式。用document风格Ӟ包括wrapped和unwrappedQ,在wsdl中有一个非I的types部分Q这个部分用XML Schema language定义了web service要用到的cd?em>wsgen工具从SIBQ有SEIp够了Q中生成与XSD对应的javacR用java代码生成WSDL文g的时候需要一些javac,wsgen工具可以生成q些Javac,生成的这些javac被UCؓwsgen artifactsQ底层的JWScd会用到这些类Q特别是JAX-Bpd的包Q会用来转换(marshal)javacd?that is, Java in-memory objects)为XMLcd的XML实例Q满XML Schema document的XML文档实例Q,

The inverse operation is used to convert (unmarshal) an XML document instance to an in-memory
object, an object of a Java type or a comparable type in some other language。因?em>wsgen工具生成的artifactsQ支持了Java为基的web service的互操作性。JAX-Bcd提供了Java和XSDcd转换的底层支持?/p>

For the most part, the wsgen utility can be used without our bothering to inspect the artifacts that it produces. For the most part, JAX-B remains unseen infrastructure.

wsgen artifacts实际上是wsdl message的数据类型,他们和XML Schema typel定Q每个message的XML Schema types从这些javacd得来的。注Q在当前的jdk1.6.24中,已经融入wsgen自动生成的过E,不需手动调用?/p>

wsgen工具可用来生成wsdl文gQ如Q? wsgen -cp "." -wsdl ch01.ts.TimeServerImpl 。这为TimeServer服务生成了wsdl。用wsgen生成的wsdl和通过讉K发布的服务生成的wsdl 有个很大的区别:wsgen生成的没有endpoint,因ؓq个URL是在发布服务的时候决定的。其他地方两个wsdl是相同的?/p>

wsimport(以前叫wsdl2java?java2wsdl更Ş?em>)工具可用WSDL生成用来帮助写客L的artifacts .

1 先契U再~码方式
一个例子:得到一个tempConvert.wsdl文gQ用命?wsimport -keep -p ch02.tc tempConvert.wsdl Q命令根据wsdl的portType生成一个SEIc,把SEI的interface换ؓclassQ再把方法改为实现就可变为SIB。把该SIB发布Q再使用命owsimport -keep -p clientTC http://localhost:5599/tc?wsdlQ来生成客户端辅助类
2 ~码优先
服务被发布之后,会自动生成WSDL供客L使用。然而,使用annotations可以控制WSDL或WSDL-generated artifacts的生成?/p>

yuxh 2011-10-08 21:47 发表评论
]]>
XML介绍http://www.aygfsteel.com/yuxh/archive/2011/03/24/346908.htmlyuxhyuxhThu, 24 Mar 2011 01:05:00 GMThttp://www.aygfsteel.com/yuxh/archive/2011/03/24/346908.htmlhttp://www.aygfsteel.com/yuxh/comments/346908.htmlhttp://www.aygfsteel.com/yuxh/archive/2011/03/24/346908.html#Feedback0http://www.aygfsteel.com/yuxh/comments/commentRss/346908.htmlhttp://www.aygfsteel.com/yuxh/services/trackbacks/346908.htmlDTDs

Introduced as part of the XML 1.0 specification, DTDs are the oldest constraint model around in the XML world. They're simply to use, but this simplicity comes at a price: DTDs are inflexible, and offer you little for data type validation as well.

XML Schema (XSD)

XML Schema is the W3C's anointed successor to DTDs. XML Schemas are literally orders of magnitude more flexible than DTDs, and offer an almost dizzying array of support for various data types. However, just as DTDs were simple and limited, XML Schemas are flexible, complex, and (some would argue) bloated. It takes a lot of work to write a good schema, even for 50- or 100-line XML documents. For this reason, there's been a lot of dissatisfaction with XML Schema, even though they are widely being used.

[prefix]:[element name]
元素Q?br>root元素必须包含所有文档中的元素,只能有一个root元素。元素名只能以下划线或字母开_不能有空|区分大小写。开元素必须有对应闭元素Q也有类似html的简写,?lt;img src="http://www.aygfsteel.com/images/xml.gif" />Q。文档由DTD或schema来限制它是否合格?/pre>
属性:
什么时候用属性?基本原则Q多个值的数据用元素,单值的数据用元素。如果数据有很多值或者比较长Q数据最可能属于元素。他主要被当作文本,?lt;rss:author>Doug Hally</rss:author> <journal:author>Neil Gaiman</journal:author>易搜索,好用。比如一本书的章节描q。然而如果数据主要作为单值处理的话,最好作为属性。如果搞不清楚,可以安全的用元素?/pre>
命名I间NamespacesQ?br>xml的命名空间是一U用一个特定的URI来关联XML文档里的一个或多个元素的方法。意味着元素是由名字和命名空间一h识别的。许多复杂的XML文g里,同一个名字会有多个用途。比如,一个RSS feed有一个作者,q个作者同时是每个日记的。虽然这些数据都用author元素来表C,但他们不应该被当作同一?em>cd的数据。命名空间很好的解决了这个问题,命名I间说明书要求一个前~和唯一的URI联合h区分不同命名I间里的元素。如http://www.neilgaiman.com/entries作ؓURIQ联合前~journal用来表示日志相关的元素?br><rdf:RDF xmlns:rss="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:journal="http://www.neilgaiman.com/entries">Q然后就可用了Q?br><rss:author>Doug Hally</rss:author> <journal:author>Neil Gaiman</journal:author>实际上在使用命名I间前缀的时候再定义也可以的Q?br><rss:author xmlns:rss="http://www.w3.org/1999/02/22-rdf-syntax-ns#">Doug Hally</rss:author>
如果名字没有命名I间Q不代表在默认命名空间中Q而是xml处理器以在Q何命名空间以外方式解释他。要声明默认命名I间的话׃用后面冒号部分,?lt;Insured xmlns="使用的一些术?/strong>:
  • The name of a namespace (such as http://www.ibm.com/software) is the namespace URI.

  • The element or attribute name can include a prefix and a colon (as in prod:Quantity). A name in that form is called a qualified name, or QName, and the identifier that follows the colon is called a local name. If a prefix is not in use, neither is the colon, and the QName and local name are identical.

  • An XML identifier (such as a local name) that has no colon is sometimes called an NCName. (The NC comes from the phrase no colon.)

Entity references:
用来处理转义字符Q语法是& [entity name] ;XML解析器碰到这Uentity referenceQ就会用对应的值替换掉他。如&lt;Q?lt;Q?&gt;(>),&amp;(&),&quot;("),&apos;(')。注意entity reference是用户可定义的。比如多处用到版权提C,自己定义后以后更改就方便了:<ora:copyright>&OReillyCopyright;</ora:copyright>。除了用来表C数据中的复杂或Ҏ字符外,entity referenceq会有更多用途?/p>

不解析的数据Q?br>当传输大量数据给应用且不用xml解析的时候,CDATA有用了。当大量的字W需要用entity reference转义的时候,或空格必M留的时候,使用CDATA?lt;![CDATA[?]]>



yuxh 2011-03-24 09:05 发表评论
]]> վ֩ģ壺 | | ̨| ʷ| ȷɽ| | | | °| ǿ| ׯ| ³ƶ| | | | | ɽ| | | ʯɽ| ʡ| | | | | Ȫ| ˳| | | | ®| | غ| | ˮ| | ɳ| | ׺| | |