海盗和会话 Bean - 它们之间有关联





4.00/5 (7投票s)
一篇关于海盗和会话 Bean 的文章——它们之间有关联。
Web 服务领域要求
我的朋友 Matt Raible 将 AppFuse 服务委托或管理器类比作 Session Facade(会话外观)。这个周末我一直在思考这个问题。我当时正在使用无状态会话 Bean Web 服务,宝马北美公司通过这些服务来准备客户满意度调查数据的报告。这些数据对他们非常重要,因为它提供了一个全国范围的经销商绩效指标仪表板。 当我准备这些 Web 服务时,我有一个模板 J2EE 项目,我把它放在一起,它使用纯 JDBC 可调用语句访问 Oracle 存储过程,但使用 JBoss 容器和这些托管的会话 bean 来隔离客户端调用。
我一直觉得这些服务太简单了,因为每次创建新的 Web 服务时我都复制这个项目。我脑海中一直有一个想法,也许我会遇到性能问题,而我所听到的关于 EJB 的所有抱怨都将成为我的毁灭。 虽然我认为在 3.0 版本之前使用 EJB 进行持久化是多余的,但会话 EJB 有其存在的意义。 我在使用会话 bean 进行 Web 服务方面取得了成功。
设计非常简单。 会话 bean 将托管 Web 服务方法。 我创建了一个请求和响应对象,例如 DetailReportArgObj
和 DetailReportReplyObj.java。 这些简单的 Java bean 首先用于处理 Web 服务报告请求参数,最终处理到 Oracle 存储过程,然后响应对象将返回建模为报告行的数据。
这是一个请求和响应值对象的示例
package com.isky.detail;
/** A custom data object class that specifies a custom serializer
*
* @jboss-net.xml-schema urn="DetailReport:DetailReportArgObj"
*/
public class DetailReportArgObj implements java.io.Serializable
{
private String _endDate;
private String _programId;
private String _orgId;
private String _orgLevel;
public DetailReportArgObj()
{
}
public DetailReportArgObj(String _reportType,
String _endDate, String _orgId, String _programId,
String _orgLevel )
{
this._endDate = _endDate;
this._programId = _programId;
this._orgId = _orgId;
this._orgLevel = _orgLevel;
}
/**
* @return Returns the _programId.
*/
public String get_programId() {
return _programId;
}
/**
* @param date The _programId to set.
*/
public void set_programId(String id) {
_programId = id;
}
/**
* @return Returns the _endDate.
*/
public String get_endDate() {
return _endDate;
}
/**
* @param date The _endDate to set.
*/
public void set_endDate(String date) {
_endDate = date;
}
/**
* @return Returns the _orgId.
*/
public String get_orgId() {
return _orgId;
}
/**
* @param id The _orgId to set.
*/
public void set_orgId(String id) {
_orgId = id;
}
/**
* @return Returns the _orgLevel.
*/
public String get_orgLevel() {
return _orgLevel;
}
/**
* @param level The _orgLevel to set.
*/
public void set_orgLevel(String level) {
_orgLevel = level;
}
}
package com.isky.detail;
/** A custom data object class that needs to specify a custom serializer
*
* @jboss-net.xml-schema urn="DetailReport:DetailReportReplyObj"
*/
public class DetailReportReplyObj implements java.io.Serializable
{
private String _lineNo;
private String _lineText;
private String _labelText;
private String _janScore;
private String _febScore;
private String _marScore;
...
private String _ytdScore;
public DetailReportReplyObj()
{
}
/**
* @return Returns the _aprScore.
*/
public String get_aprScore() {
return _aprScore;
}
/**
* @param score The _aprScore to set.
*/
public void set_aprScore(String score) {
_aprScore = score;
}
...
/**
* @return Returns the _labelText.
*/
public String get_labelText() {
return _labelText;
}
/**
* @param text The _labelText to set.
*/
public void set_labelText(String text) {
_labelText = text;
}
...
// your basic Java Bean
}
这些 Web 服务项目的优点在于能够将需求规范反馈给 Oracle 开发人员,并保持各个 Web 服务之间的 Web 服务接口基本相同。 我还能够保持 Web 服务定义语言 (WSDL) (发音为 wizz-duhl)在服务之间相似,并且能够复制文件并基本上重构服务之间的名称。 我并没有真正从头开始编写这些项目。 我以完全合法的方式从开源社区盗用了它们。
这是一个定义我托管的 Web 服务的 WSDL 文件示例
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions
targetNamespace="https://:8080/jboss-net/services/DetailReport"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:apachesoap="http://xml.apache.org/xml-soap"
xmlns:impl="https://:8080/jboss-net/services/DetailReport"
xmlns:intf="https://:8080/jboss-net/services/DetailReport"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:tns1="https:///DetailReportBean"
xmlns:tns2="http://net.jboss.org/jmx"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<schema targetNamespace="https:///DetailReportBean"
xmlns="http://www.w3.org/2001/XMLSchema">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<complexType name="DetailReportArgObj">
<sequence>
<element name="_endDate" nillable="true" type="xsd:string"/>
<element name="_orgId" nillable="true" type="xsd:string"/>
<element name="_orgLevel" nillable="true" type="xsd:string"/>
<element name="_programId" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
<complexType name="DetailReportReplyObj">
<sequence>
<element name="_labelText" nillable="true" type="xsd:string"/>
<element name="_lineNo" nillable="true" type="xsd:string"/>
<element name="_lineText" nillable="true" type="xsd:string"/>
<element name="_qualifier" nillable="true" type="xsd:string"/>
<element name="_janScore" nillable="true" type="xsd:string"/>
<element name="_febScore" nillable="true" type="xsd:string"/>
<element name="_marScore" nillable="true" type="xsd:string"/>
<element name="_aprScore" nillable="true" type="xsd:string"/>
<element name="_mayScore" nillable="true" type="xsd:string"/>
<element name="_junScore" nillable="true" type="xsd:string"/>
<element name="_julScore" nillable="true" type="xsd:string"/>
<element name="_augScore" nillable="true" type="xsd:string"/>
<element name="_sepScore" nillable="true" type="xsd:string"/>
<element name="_octScore" nillable="true" type="xsd:string"/>
<element name="_novScore" nillable="true" type="xsd:string"/>
<element name="_decScore" nillable="true" type="xsd:string"/>
<element name="_ytdScore" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
</schema>
<schema targetNamespace="https://:8080/jboss-net/services/DetailReport"
xmlns="http://www.w3.org/2001/XMLSchema">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<complexType name="ArrayOf_xsd_anyType">
<complexContent>
<restriction base="soapenc:Array">
<attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:anyType[]"/>
</restriction>
</complexContent>
</complexType>
</schema>
</wsdl:types>
<wsdl:message name="DetailReportRequest">
<wsdl:part name="in0" type="xsd:anyType"/>
</wsdl:message>
<wsdl:message name="DetailReportResponse">
<wsdl:part name="DetailReportReturn" type="impl:ArrayOf_xsd_anyType"/>
</wsdl:message>
<wsdl:portType name="DetailReport">
<wsdl:operation name="getReport" parameterOrder="in0">
<wsdl:input message="impl:DetailReportRequest" name="DetailReportRequest"/>
<wsdl:output message="impl:DetailReportResponse" name="DetailReportResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="DetailReportSoapBinding" type="impl:DetailReport">
<wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getReport">
<wsdlsoap:operation soapAction="DetailReport"/>
<wsdl:input name="DetailReportRequest">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="https://:8080/jboss-net/services/DetailReport"
use="encoded"/>
</wsdl:input>
<wsdl:output name="DetailReportResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="https://:8080/jboss-net/services/DetailReport"
use="encoded"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="DetailReportService">
<wsdl:port binding="impl:DetailReportSoapBinding" name="DetailReport">
<wsdlsoap:address
location="https://:8080/jboss-net/services/DetailReport"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
结论
如果我可以与有前途的开发人员分享任何东西,那就是成为一个开源海盗! 窃取一切,并为你自己选择最有效的方法。 不要相信任何人的话。 尝试所有方法! 我只向你展示了我的 Web 服务背后的一小部分代码。 SOAP 请求使用 Apache Axis 处理。 我必须让一个项目工作,第一个项目并不容易。 此外,Apache ANT 用于构建和部署所有内容。
我还使用了一个 Visual Studio 包来为每个服务创建 .NET 客户端,提供给我的客户。 另外,如果你为你的服务创建一个客户端,你可以确定它们能正常工作。 但请注意我的话,伙计们,开源世界有很多战利品,你猜怎么着? 其中大部分都是专业人士编写的。 很多时候,这些专业人士因为一些无能的架构师或经理做出了错误的决定而陷入困境,而被迫编写乏味且效率低下的代码来换取报酬。 但是,这些有创造力的人在晚上编写代码并免费赠送他们引以为傲的创造。
所以,尽可能地偷窃和掠夺这些免费下载。 利用现有资源。 我是 irc.freenode.net 上的 piratepete,我的一些朋友认为“海盗”这个名字带有负面含义。 我不相信这一点。 开源是免费的,所以偷它、抢它、使用它。 只是不要说其中的任何部分是你自己的。 在应该给予荣誉的地方给予荣誉。
现在有一个由苹果的史蒂夫·乔布斯 (Steve Jobs) 撰写的好博客。 他猛烈抨击盖茨。 有趣的是,盖茨也窃取软件和软件概念。 这就是我热爱开源的原因,一切都是公开的,我不需要玩游戏。 如果我使用别人的代码来完成工作,我可以完成工作,给予对方荣誉,回家,支付抵押贷款,并且仍然可以安心地入睡,因为我不是专有软件废话的一部分。
天哪,我居然偏离了会话 Bean Web 服务。 对不起。 去找一些免费软件,成为一些商人或女人的 IT 英雄。 商人是拥有金钱的人。 去找他们。