ofbiz的服务(service)export成web service的方法(2)

ofbiz的一个bug?

在被外部系统调用的时候,SOAP应该是一个常用的方式,但是很遗憾的是,ofbiz对SOAP的支持并不是很好,我们可以试一个简单的例子,就是party组件中的createPerson,我们把export修改成true:
  1. <service name="createPerson" engine="java" default-entity-name="Person"
  2.             location="org.ofbiz.party.party.PartyServices" invoke="createPerson" auth="false" export="true">
  3.         <description>Create a Person</description>
  4.         <auto-attributes mode="INOUT" include="pk" optional="true"/>
  5.         <auto-attributes mode="IN" include="nonpk" optional="true"/>
  6.         <attribute name="statusId" type="String" mode="IN" optional="true"/>
  7.         <attribute name="preferredCurrencyUomId" type="String" mode="IN" optional="true"/>
  8.         <attribute name="description" type="String" mode="IN" optional="true"/>
  9.         <override name="firstName" optional="false"/>
  10.         <override name="lastName" optional="false"/>
  11.     </service>


重启ofbiz后,我们访问:
http://127.0.0.1:8080/webtools/control/SOAPService/createPerson?WSDL,浏览器提示出错,

查看日志,console.log,在访问失败的时候提示:
2008-11-10 13:35:49,093 (http-0.0.0.0-8080-Processor3) [     RequestHandler.java:305:ERROR] Request SOAPService caused an error with the following message: Error calling event: org.ofbiz.webapp.event.EventHandlerException: Unable to obtain WSDL (WSDLException: faultCode=OTHER_ERROR: Service cannot be described with WSDL (birthDate / java.sql.Date))
 
 
根据"org.ofbiz.webapp.event.EventHandlerException"的提示,我们到framework/webapp/src/org/ofbiz/event目录下去看,有一个class,SOAPEventHandler.java
打开看,正是这个类来把处理wsdl的请求的。
 
根据浏览器提示的错误信息"Unable to obtain WSDL",在这个类里面看,果然在96行有:
sendError(response, "Unable to obtain WSDL");
 
这是
wsdl = dctx.getWSDL(serviceName, locationUri);
抛出异常后的错误。所以问题9成是这里造成的。
 
再回顾
2008-11-10 13:35:49,093 (http-0.0.0.0-8080-Processor3) [     RequestHandler.java:305:ERROR] Request SOAPService caused an error with the following message: Error calling event: org.ofbiz.webapp.event.EventHandlerException: Unable to obtain WSDL (WSDLException: faultCode=OTHER_ERROR: Service cannot be described with WSDL (birthDate / java.sql.Date))
看到最后的"birthDate / java.sql.Date"了吗?birthDate是Person里面的一个字段,难道和数据类型有关系,存疑。
 
 
顺着wsdl = dctx.getWSDL(serviceName, locationUri);用eclipse很容易就找到了ofbiz/framework/service/src/org/ofbiz/service/ModelParam.java里面的:
protected String java2wsdlType() throws WSDLException
这个方法是来吧serivce中参数类型转换成web service的参数类型的,
 
这里补充一个基础知识,ofbiz中实体中的字段类型,对应的java中的数据类型的定义是通过一个xml文件定义的,在framework/entity/fieldtype下,这下面有很多个文件,是不同的数据库对应的配置文件,
我们看无论是mysql或者是derby,实体中的date对应的java类型是java.sql.Date。
 
回到正题,protected String java2wsdlType() throws WSDLException 方法中,大家找一下,只有java.util.Date这个的转换,而没有java.sql.Date的转换,问题就出在这里了,
好了,我们新加一段在这个函数里面:
  1.         } else if (ObjectType.instanceOf(java.sql.Date.classthis.type)) {
  2.             return "dateTime";
  3.         } else if (ObjectType.instanceOf(java.sql.Time.classthis.type)) {
  4.             return "string";
  5.         }

对java.sql.Date和java.sql.Time进行一下处理,重新build一下源代码,再试着访问一下,果然就可以了。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值