- 浏览: 1319035 次
- 性别:
- 来自: 广州
文章分类
- 全部博客 (351)
- Java General (37)
- .net General (2)
- Linux Toy (55)
- Oracle (81)
- Mysql (11)
- Programer Career (12)
- Oh, my living ! (2)
- Shell Script (8)
- Web Service (0)
- Linux Server (22)
- Php/Python/Perl (3P) (2)
- Javascript General (5)
- Saleforce Apex Dev (2)
- Web General (5)
- Xen & VM tech. (17)
- PSP (13)
- OpenSolaris (34)
- php (1)
- RAI/flex/action script (16)
- asterisk/CTI (7)
- 交互设计 (6)
- English (3)
- Lucene (1)
最新评论
-
GuolinLee:
markmark
JVM调优总结 -Xms -Xmx -Xmn -Xss -
di1984HIT:
写的太好啊。
JVM调优总结 -Xms -Xmx -Xmn -Xss -
javajdbc:
javajdbc 写道
JVM调优总结 -Xms -Xmx -Xmn -Xss -
javajdbc:
...
JVM调优总结 -Xms -Xmx -Xmn -Xss -
alvin198761:
非常感谢,国外的被封杀了,你这里还有一份
How to Convert An Image-Based Guest To An LVM-Based Guest
What You Need |
The latest version of Java 5 Tomcat (5.5 or later) Ant (1.6 or later) JAX-WS |
The Architecture of JAX-WS 2.0
Figure 1. JAX-WS High-Level Architecture |
What is the JAX-WS? Essentially, it consists of the following four things:
- An API for developing Web services using Java and XML
- A standard implementation (SI, as in JAXWS-SI.jar) of the Web services servlet
- Annotations, such as @WebService, that are processed by apt (annotation processing tool) to generate components for the service and client (A list of all JAX-WS annotations can be found here.)
- A set of tools (primarily wsimport) for generating the "portable artifacts" (beans, stubs, and XML) for the client code. (wsimport stands for Web service import, which reads in the descriptors of the published Web service and generates the client artifacts.)
Clearly, JAX-WS is more than just an API for building Web services. Figure 1 shows its high-level architecture.
JAX-WS Under the Hood
How does a JAX-WS application work? The developer need be exposed only to the client and service endpoint. The rest is generated and run automatically (see Figure 2).
Figure 2. JAX-WS: How It Works |
On the client side, the only Java file the developer supplies is the client class itself. The interface and JavaBeans are generated automatically by wsimport. On the server side, the only Java file the developer supplies is the service implementation. The JavaBeans are generated by apt, and the servlet is part of the JAX-WS library.
The generated JavaBeans (also known as a type of portable artifact) are responsible for marshaling/unmarshaling method invocations and responses, as well as service-specific exceptions. Marshaling and unmarshaling are the transformation from XML to Java objects and back using JAXB. Two JavaBeans are generated for each method in the Web service. One bean is for invoking the method and the other for handling the response. An additional JavaBean is generated for each service-specific exception. (JAX-WS 2.0 Beta User's Guide 3.1.1.1 Generate Portable Artifacts)
Running the Examples
In the following examples, the Web service method uses a custom exception, which must also be supplied to apt by the developer and which has a JavaBean generated for it (but is not shown in Figure 2). Once the Web service has been published and the client artifacts have been generated, the client class can call the Web service method via the Service Endpoint Interface (SEI). The service bean then translates the method call into XML using JAXB and transmits it to the Web service servlet using HTTP/SOAP. The process is then reversed so that the Service Endpoint Implementation (also called SEI) can process the request and return the response. The handling of SOAP and HTTP on the service side is seamlessly provided by the Web service servlet. The handling of SOAP and HTTP on the client side is taken care of behind the scenes by the javax.xml.ws package.
<!---->
|
To complete the examples, begin by downloading and unzipping the latest version of Java 5, Tomcat (5.5 or later), Ant (1.6 or later), JAX-WS, and the example code for this article. If you use Java 6, be sure to use a compatible version of Tomcat, Ant, and JAX-WS. These examples will not work using Java 6, Tomcat 5, and JAX-WS RC3 because of library incompatibilities.
Open the build.xml file in the examples directory and set the values of the properties jaxws.home, java.home, and tomcat.home to the root directories of those downloads. Now, open a command prompt and run the following ant targets:
- Run $ANT_HOME/bin/ant -buildfile $EXAMPLE_HOME/build.xml install, which copies the *.jar files from jaxws.home/jaxws-ri/lib/ into tomcat.home/commons/lib.
- Run $ANT_HOME/bin/ant -buildfile $EXAMPLE_HOME/build.xml server, which generates the Web service files for the example Java code, packages it in a WAR, and deploys it to Tomcat's /webapps. [NOTE: some warnings and errors may occur when using apt in early versions of JAX-WS. They do not effect the functionality of the examples.]
- Start Tomcat, which will automatically deploy the WAR file.
- Test that the service is running by opening a browser to the following pages:
- http://localhost:8080/manager/html: should show the deployed war under the application listing [NOTE: In order to access this page, you may need to edit TOMCAT_HOME/conf/tomcat-users.xml to add roles="manager,..." to your account.]
- http://localhost:8080/jaxws-simpleexample/simplemethod: shows the Web service listing
- http://localhost:8080/jaxws-simpleexample/simplemethod?wsdl: the WSDL file gives an XML description of the Web service provided.
- http://localhost:8080/jaxws-simpleexample/simplemethod?xsd=1: shows the XML schema describing the JAXB bindings for the arguments and the return value of the Web service
- Run $ANT_HOME/bin/ant -buildfile $EXAMPLE_HOME/build.xml client, which generates the client artifacts from the deployed WSDL and XSD.
- Run $ANT_HOME/bin/ant -buildfile $EXAMPLE_HOME/build.xml run, which executes the client and outputs the result to the command window.
The Development Process
To JAX-WS, the development process is a somewhat simplified version of WS development using RPC. Unlike with the JAX-RPC of old, you can use JAX-WS to transform almost any existing Java class into a Web service. The class doesn't need to implement an interface and its methods do not need to declare RMI exceptions. The method, however, does require JAXB 2.0-compatible parameters and return values. Simply add the @WebService annotation to the .java file, add some cookie cutter configuration files, and run an Ant script. Figure 3 diagrams the basic process for the Web service.
<!---->
|
Figure 3. The Development Process for the Web Service |
Notice in Figure 3 that SimpleMethod.java and SimpleMethodResopnse.java are the JavaBeans responsible for marshaling/unmarshaling the invocation and response. Notice also that the developer inputs only three files; the remaining components are generated by apt and the servlet container. The servlet container generates the WSDL and schema at the time of deployment, which is a change from JAX-RPC. These files are therefore not bundled in the WAR.
SimpleJAXWS.java (see Listing 1) is the same as a non-Web service class definition except for the @WebService annotation:
@WebService public class SimpleJAXWS { public int simpleMethod(int number1, int number2) throws SimpleException { if ( number2 == 0 ) { throw new SimpleException("Cannot divide by zero!", "Numbers: " + number1 + ", " + number2); } return number1 / number2; } }
The sun-jaxws.xml file (see Listing 2) designates the URL for the service endpoint implementation:
<endpoint name='simpleexample' implementation='simpleexample.server.SimpleJAXWS' url-pattern='/simplemethod'/> </endpoints>
The web.xml (see Listing 3) file assigns the WSServlet to the Web service's URL:
<web-app> <servlet> <servlet-name>simpleexample</servlet-name> <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>simpleexample</servlet-name> <url-pattern>/simplemethod</url-pattern> </servlet-mapping> </web-app>
The URL http://localhost:8080/jaxws-simpleexample/simplemethod?wsdl shows the definition for the simpleMethod message:
<definitions targetNamespace="http://server.simpleexample/" name="SimpleJAXWSService"> <message name="simpleMethod"> <part element="tns:simpleMethod" name="parameters"/> </message>
The URL http://localhost:8080/jaxws-simpleexample/simplemethod?xsd=1 shows the simple method and it's parameters:
<xs:element type="ns1:simpleMethod" name="simpleMethod"/> <xs:complexType name="simpleMethod"> <xs:sequence> <xs:element type="xs:int" name="arg0"/> <xs:element type="xs:int" name="arg1"/> </xs:sequence> </xs:complexType>
Figure 4 diagrams the basic development process on the client side.
Figure 4. The Development Process for the Client |
Notice in Figure 4 that the developer inputs only three files; the remaining components are generated by wsimport. The other files required by wsimport are the WSDL and schema generated by the servlet container at time of deployment. This is why it's important to wait for Tomcat to completely deploy the Web service before building the client.
The wsimport-generated files can be found in the build/classes/simpleexample/client directory of the example's home. SimpleMethod.java and SimpleMethodResopnse.java are the JavaBeans that marshal/unmarshal the invocation and response. Because package-level annotations are declared in their own .java file, @XMLSchema is found in package-info.java. The annotation maps the client package name to an XML namespace. ObjectFactory.java uses the class-level annotation @XMLRegistry to indicate it will be an XML registry with the factory methods for the client's JavaBeans and their XML equivalents. Other JavaBeans not shown in Figure 4 are generated for handling the exception used by the service.
SimpleMethodClient.java (Listing 4) has a main method that instantiates the SimpleJAXWS Web service object and calls its method. The SimpleJAXWS object is treated the same as a non-webservice object once it has been instantiated:
SimpleJAXWS port = new SimpleJAXWSService().getSimpleJAXWSPort(); double result = port.simpleMethod ( 20, 10 );
The build.properties file (Listing 5) designates the SEI and client class, the client's bindings for its WSDL and schema:
# service endpoint implementation class sei=simpleexample.server.SimpleMethod # customization files client.binding=custom-client.xml, custom-schema.xml server.binding= client.wsdl=http://localhost:8080/jaxws-simpleexample/simplemethod?wsdl client=simpleexample.client.SimpleMethodClient
The custom-client.xml file (Listing 6) binds the package to the WSDL:
<bindings wsdlLocation="http://localhost:8080/jaxws-simpleexample/simplemethod?wsdl"> <bindings node="wsdl:definitions"> <package name="simpleexample.client"/> </bindings> </bindings>
The custom-schema.xml file (Listing 7) binds the package to the schema:
<bindings schemaLocation="http://localhost:8080/jaxws-simpleexample/simplemethod?xsd=1 " node="/xsd:schema"> <schemaBindings> <package name="simpleexample.client"/> </schemaBindings> </bindings>
Of course, much of this code can be generated by a development tool very simply. As the next section demonstrates, coding all these cookie cutter files by hand can be tedious. As with most JSRs, JAX-WS was designed by Java tool vendors for Java tool vendors. What JAX-WS really does is provide the framework by which the developer's tool of choice can provide one-click generation of a Web service and client skeleton.
Transform Existing Java Classes into a Web Service/Client
A good demonstration of the development process is to customize the example from the previous section using your own Java class file. Add the "@WebService" annotation to the line after the imports and make the following changes to the additional files in order:- Copy the JAXWS_EXAMPLE directory and change the two directories named "simpleExample" in "simpleExample/src/simpleExample" to your project name.
- Replace SimpleJAXWS.java and SimpleException.java with your new @WebService java file and any accompanying exceptions.
- Rename SimpleMethodClient.java to your class name.
- Open all the .java, .properties, and .xml files (including
build.xml) in an editor, and use batch search/replace to make the
following changes (be sure the replacements are case sensitive):
- Replace all "simpleexample" references with your project name.
- Replace all "simpleMethod" references with your method name.
- Replace all "SimpleJAXWS" references with your class name.
- Replace all "simplemethod" references with your URL pattern.
- Replace all "SimpleException" references with your exception class name.
- Replace all remaining "SimpleMethod" references with your method name (these occur in pointers to the derivative classes).
- Now you must edit the client class in accordance with the parameters and return the type of the Web service.
- Lastly, run the ant targets server and client, and run the same as above.
<!---->
|
By following these steps you have transformed your own Java class into a Web service, enabling it to communicate over a network in a distributed computing environment.
Raw SOAP for Web Services Is Now Obsolete
With the advent of JAX-WS, the use of raw SOAP for Web services has become deprecated. This means that popular projects such as Apache Axis (Apache's implementation of SOAP) are no longer necessary for Web service developers. By abstracting the protocol binding, JAX-WS can provide simultaneous support for SOAP 1.1 and 1.2. By utilizing annotations, simplified build tools, and JAXB, JAX-WS removes many of the unnecessary complications of JAX-RPC.发表评论
-
使用Spring 的封装的MailSender
2010-11-29 22:24 6733使用Spring 的封装的Ma ... -
有时候,SVN 上代码太多,而我们只想下载自己负责的那个部分进行修改,这时可以这样
2010-09-04 09:06 1277svn checkout <url_of_big_dir ... -
tomcat session replication on linux server.
2010-07-26 10:49 1204Specially, to turn on multicast ... -
Session lost when app. is redeployed (Solved)
2010-07-07 16:02 1270There is a workaround to this p ... -
jvm 5.0 GC 回收机制
2009-10-16 11:55 1775http://java.sun.com/docs/hotspo ... -
How to Create a Custom Annotations?
2009-10-08 11:32 1238There are a lot of documentatio ... -
JAXB 深入学习<1>
2009-08-04 22:22 2357说白了就是一个api将 xml+schema->ja ... -
simple json lib for java
2009-08-04 21:57 3228有时候为了需要将一个对象或数组转成json string 给前 ... -
在servlet 上输出图片
2008-07-30 21:38 4290public void doGet(HttpServletRe ... -
用java 对 oracle 中的 image 存取
2008-07-30 21:35 1858package data; import java.io. ... -
有关 java 的 tnameserv的link
2008-07-15 22:39 2303http://java.sun.com/j2se/1.4.2/ ... -
SOAP and JDOM
2008-06-18 21:54 2152看完上一篇 blog: Web 服务搜 ... -
Java Reflection API 运用示例
2008-05-05 15:51 2393本文节选 ... -
将系统移植到Spring
2008-04-29 11:06 1490Spring已经是一个在Apache 2.0许可下发布的基础构 ... -
动态代理一例
2008-04-28 15:33 1218在之前的一篇关于Dec ... -
使用JAVA中的动态代理实现数据库连接池
2008-04-28 13:48 1479作者通过使用JAVA中的动 ... -
Have you known enough about DBCP?
2008-04-23 12:08 2261Have you known enough about DBC ... -
更改 Netbeans 界面的字体大小
2008-03-22 07:29 4704学习或者使用 Netbeans 的时候, 有时候觉得界面字体很 ... -
JSF+Spring+Hibernate的实例讲解
2008-03-20 16:41 2456我一直认为jsf必定会成为MS的 Net ... -
Struts+Spring+Hibernate练习(完整)
2008-03-20 16:17 2076工具: Eclipse3.2.1、MyEclipse5 ...
相关推荐
For the first time, I learned how to exploit the modern browser, and I dove into the many HTML5 features. The modern web evolves very quickly and reaches so many people that it’s an exciting place ...
With this practical guide, Facebook web developer Stoyan Stefanov teaches you how to build components--React's basic building blocks--and organize them into maintainable, large-scale apps. If you're ...
As society evolves and individuals grow, there is a process of revisiting and reassessing the past to find connections with current challenges and seek guidance. Reflecting calmly on pain is the best ...
In The Swift Developer’s Cookbook, renowned author Erica Sadun joins powerful strategies with ready-to-use Swift code for solving everyday development challenges. As in all of Sadun’s programming ...
a more robust, and potentially more efficient manner. The interfaces and OSPM concepts defined within this specification are suitable to all classes of computers including (but not limited to) ...
The intention is to add much supplementary material in future updates to this document, as it evolves into a comprehensive book that matches or surpasses any of the shell scripting manuals in print....
ACPI evolves the existing motherboard configuration interfaces to support these advanced architectures in a more robust, and potentially more efficient manner. This document describes the structures...
ACPI evolves the existing motherboard configuration interfaces to support these advanced architectures in a more robust, and potentially more efficient manner. This document describes the structures...
it evolves into a dynamic cultural center that enriches the lives of its users and contributes to the urban fabric of the city. In conclusion, the Guangzhou Library, designed by Nikken Sekkei, ...
As the process evolves and requirements converge, more detail is added, refining the use-case descriptions to ensure they accurately reflect the stakeholders' needs and expectations. This iterative ...
web developer Stoyan Stefanov teaches you how to build components - React's basic building blocks - and organize them into maintainable, large-scale apps. If you're familiar with basic JavaScript ...
Temperature-dependent photoluminescence (PL) ...gradually evolves from a strong “S-shaped” (“W-shaped”) temperature dependence into a weak “S-shaped” (an approximately “V-shaped”), until becoming
Learn how the language works, how to take advantage of the CPAN's immense trove of time-tested solutions, and how to write clear, concise, powerful code that runs everywhere. Specific coverage ...
- **Business People**: Gain insights into how to communicate their needs effectively to development teams. In conclusion, "Specification by Example" provides a valuable resource for teams looking to ...
Robotics, benefiting from IT, particularly the integration with advanced network communication technologies, evolves into network robotics, which is a testament to this inevitable trend. With the ...
As existing technology evolves and new technologies are introduced to provide new capabilities and features, new vulnerabilities are often introduced as well. Organizations implementing and using ...