网站首页

家园论坛

老版论坛

家园博客

业界新闻

技术文档

下载中心

速查中心

图片中心

硬件资讯
上一篇:Web Services在Powerbuilder中的应用(二) 下一篇:Web Services在Powerbuilder中的应用(四)
Web Services在Powerbuilder中的应用(三)

来源: 作者: 添加日期:2005-9-4 19:19:56 点击次数:
Adding a custom tag for Web services

添加一个Web Services用户自定义标签

Once you have generated your custom tag, it appears in the System Tree. When you drag it to a JSP, the tag library is automatically associated with the page. You must specify the input and output arguments for the custom tags for the Web services in the JSP. Output arguments are stored in the pageContext of the JSP container.

当你已经生成了你的自定义标签,它会出现在系统树中。当你拖动它到一个JSP页面时,标签库会自动关联那个页面。你必须在JSP页面中定义Web Services的自定义标签的输入和输出参数。输出参数保存在JSP容器的页的上下文中。

Deployment of the custom tag for Web services is the same as deployment of any custom tag in PowerBuilder. See "Editing a JSP deployment configuration" for details.

Web Services的自定义标签的开发扩展 和PowerBuilder中的其它自定义标签扩展是一样的。详细信息请参照“编辑JSP的扩展配置”。

Custom tags for Web services throw a JspTagException for nonrecoverable errors. The JspTagException contains information about the root cause of the exception and the point the error occurred in processing the custom tag. This exception can be caught in a Try-Catch block or mapped to a specific error page in the Deployment Configuration Properties dialog box for the JSP target. An error page can also be specified in a page directive. See "Error handling" and "Error Mapping" for details.

Web Services的自定义标签抛出一个无法回收的错误,Jsp标签异常(JspTagException)。JspTagException包含了异常的根本原因和处理自定义标签时发生的错误点的信息。这些异常可以用Try-Catch批捕获或者在JSP应用中的开发配置属性对话框映射一个详细错误页面来捕获。一个错误页面也可以在指定的页面中定义。详细信息请参照“错误处理”和“错误映射”。

Example using a currency exchange Web service

使用流通交易的Web Service的例子

This example, using the currency exchange service available on the XMethods Web site , demonstrates how custom tags for Web services on a JSP are defined to a JSP container. You proceed with these steps after generating a TLD and JAR file for the service using the JSP Web Service Proxy wizard. The remainder of this example assumes that you accept all the wizard defaults after selecting the CurrencyExchangeService.wsdl file.

这个例子,使用了Xmethods网站上的可用的流通交易服务。演示了在JSP容器中如何定义一个JSP页面来使用Web Services的自定义标签。你可以在使用了JSP Web Services代理向导生成了这些服务的一个TLD文件和JAR文件之后继续这些步骤。这个例子的剩下部分,假定你在选择了CurrencyExchangeService.wsdl文件之后,完全接受向导的默认设置。

First you declare the custom tag library to the JSP. This makes all of the tags in the library available to the JSP. The exchange prefix allows for easy reference to the tag library. You can drag the library from the Components tab of the System Tree to the JSP in the HTML editor to add this code.

<%@ taglib uri="WEB-INF/tlds/CurrencyExchangeService.tld"
 prefix="exchange" %>
首先你得定义JSP的用户自定义标签库。这将使库中的所有标签都能够被JSP使用。
exchange前缀可以从标签库中方便地引用。你可以从系统树的组件标签页中拖动库到JSP页面中并在HTML编辑器中添加它的代码。
<%@ taglib uri="WEB-INF/tlds/CurrencyExchangeService.tld"
 prefix="exchange" %>

Once the tag library is available to the page, you declare the input arguments for the custom tags in a server script.

<%
     String firstCountry = "usa";
     String secondCountry = "japan";
 %>
当标签库对于页面是可用时,你可以声明在服务器脚本中定义自定义用户标签的输入参数。
<%
     String firstCountry = "usa";
     String secondCountry = "japan";
 %>

Next, you invoke the Web service through the custom tag, passing the input parameters in a server-side expression.


     country2="<%= secondCountry %>" />
下一步,你可以通过向自定义标签的服务器端表达式传入参数来调用Web Service。
     country2="<%= secondCountry %>" />

Then you get the value of the returnValue variable from the custom tag and display it. This value is set when the tag is executed.

The exchange rate between "<%= firstCountry %>" and "<%= secondCountry %>" is:
 <%= CurrencyExchangeService_getRate_returnValue %>

你可以获取自定义标签的返回变量的值并显示它们。当标签执行完后,返回变量被赋值。

The exchange rate between "<%= firstCountry %>" and "<%= secondCountry %>" is:
 <%= CurrencyExchangeService_getRate_returnValue %>

Web services with user datatypes

If a Web service requires a complex datatype for an input or output parameter or return value, the corresponding WSDL Part element may contain a Type attribute, such as prefix:localpart, where prefix is a reference to the namespace that governs the type and localpart is the name of the XML element that describes the type. The prefix may refer to the current WSDL document or some other XML document. The namespace referenced by the prefix must contain a definition of the datatype named by the localpart.

Web Services中使用用户自定义类型

如果一个Web Services需要一个复杂数据类型的输入、输出参数或返回值时,相应的WSDL组件元素可以包含一个属性类型,如:prefix:localpart, prefix是提供了涉及那个类型的命名空间,localpart是描述那个类型的XML元素。前缀可能指向当前的WSDL文档或一些其它的XML文档。被前缀引用的命名空间必须包含被localpart命名的数据类型的定义。

For example, the AirportWeather.wsdl on the CapeClear Web site contains a Part element with the Type attribute xsd1:WeatherSummary. The Schema element nested in the Types element of the same WSDL file also contains a WeatherSummary element.

例如,在CapeClear的网站上的AirportWeather.wsdl包含了xsd1:WeatherSummary属性类型组件元素。这些Schema元素被嵌套在相同的WSDL文件的类型元素也包含了一个WeatherSummary元素。

The WeatherSummary element is composed of seven xsd:string types. (The xsd:string types are defined in the XML schema .) In this case, you need to create and compile a Java class for the JSP Web service client that defines the WeatherSummary datatype. Once the Java class is created, place it in the Shared\PowerBuilder\WEB-INF\classes directory in the Sybase path. In your JSP target, import or copy the compiled class to the Source\Web-INF\classes directory of your target.

WeatherSummary元素封装了七个xsd:string类型。(xsd:string类型在xml schema中定义),在这个案例中,你必须创建和编译一个JSP Web Service 客户端的Java类来定义WeatherSummary数据类型。

Registering user defined types

Before deploying a JSP Web service client, you must update the user.encoding.props file to include the user defined type. In this case, to register the WeatherSummary class, you would add the following entry using no blank spaces:

soap.user.encodings=WeatherSummary,com.sybase.esdweb.
 soap.encoding.BeanSerializer,com.sybase.esdweb.soap.
 encoding.BeanSerializer,http://www.capeclear.com/
 AirportWeather.xsd,http://schemas.xmlsoap.org/soap/
 encoding/
注册用户自定义类型
在配置一个JSP Web service客户端之前,你必须修改user.encoding.props文件来包含用户自定义类型。在这个案例中,为了注册WeatherSummary类,你可以使用非空的空间来添加下面的入口。
soap.user.encodings=WeatherSummary,com.sybase.esdweb.
 soap.encoding.BeanSerializer,com.sybase.esdweb.soap.
 encoding.BeanSerializer,http://www.capeclear.com/
 AirportWeather.xsd,http://schemas.xmlsoap.org/soap/
 encoding/
 

This entry corresponds to the follwing comma-separated items: the fully qualified class name, the fully qualified class name of the serializer, the fully qualified class name of the deserializer, the URI of the encoding style being used for the type, and the URI of the schema defining the serialization rules for the type.

这些输入符合下面的逗号分割项目:完全资格的类名、完全资格的序列化类名、完全反序列化的类名、使用类型的编码种类的URI、类型定义的序列化定义计划的URI。

If another entry for a user defined type is already within the file, separate the entries with a semicolon. By registering the user defined type, the client-side SOAP processing is able to extract data from the user defined type supplied by the JSP, use the data to create a SOAP request, retrieve data from the SOAP response, and fill the user defined type returned to the JSP.

如果文件中已经包含了另一个用户自定义类型的入口定义,请用分号来分割这些入口定义。通过注册用户自定义类型,SOAP客户端使由JSP支持的用户自定义类型的提取数据,并填充返回给JSP的用户自定义类型变成可能。

If you save the user.encoding.props file to the Sybase\Shared\PowerBuilder\WEB[Unmapped Entity: shy ] [Unmapped Entity: shy ] -INF\classes directory, it will be copied to the target source\Web-Inf\classes directory and contained in the target WAR file when you deploy your target. The user.encoding.props file must be in the runtime classpath. Alternatively, you can set the location of the user.encoding.props file in the syuproxy.props file.

如果你保存了user.encoding.props文件到“Sybase\Shared\PowerBuilder\WEB[Unmapped Entity: shy ] [Unmapped Entity: shy ] -INF\”类库目录下,它将被复制到应用程序source\Web-Inf\classes”目录下,并在你配置你的应用程序时,被包含在应用程序WAR 文件中user.encoding.props文件必须在运行类库目录下。或者你可以在syuproxy.props ”文件中设置user.encoding.props文件的位置。

Example Java code for a user datatype

For example, the Airport Weather service on the Cape Science Web site contains a complex datatype defined in the WSDL as xsd1:WeatherSummary. When the Web service returns an object of this datatype to a client, the client must be able to process the object. Therefore you must create a Java class definition for this datatype and have this available to the JSP application.

使用用户自定义数据类型的Java代码的例子

例如,在Cape Science网站上的飞机场天气预报服务包含了一个WSDL定义的复杂的数据类型xsd1:WeatherSummary。当Web Service返回给客户端一个这个数据类型的实例时,客户端必须能够处理这个实例。所以你必须创建一个这个数据类型的Java类定义,并使JSP应用对象可以使用。

The WeatherSummary datatype is a combination of many string values into a single data structure with get and set methods for each of the strings. It contains a zero-argument constructor. The following is Java code for creating the WeatherSummary class:

WeatherSummary数据类型是包含每个String变量的GET和SET方法的多个String值的集合组成的简单的数据结构。它包含一个无参数的构造函数。下面是构造WeatherSummary类的Java代码:

public class WeatherSummary 
 {
     private String location="";
     private String wind="";
     private String sky="";
     private String temp="";
     private String humidity="";
     private String pressure="";
     private String visibility="";
     public void setLocation( String location )
     {    this.location = location;    } 
    ... //set methods for other data members
    public String getLocation( )    
     {    return this.location;    }  
   ... //get methods for other data members
  } 
 
设为首页 | 加入收藏 | 业务办理 | 友情链接 | 论坛版面 | 浙ICP备07502118号 |