`
wobfei
  • 浏览: 146987 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

No write method for property问题的解决

XML 
阅读更多

  使用XFire进行ws调用中,发生了No write method for property问题,看了下代码发现问题如下:

 

服务器端的接口信息如下:

 

public interface QueryFacade {
 
    public QueryResult queryById(String id);

}

 

 其中的QueryResult代码如下:

public class QueryReslt implements Serializable{

    private static final long serialVersionUID = 3688506614705500726L;

    // 状态量
    private int page; // 当前页码。(1-based)
    private int items; // 总共项数
    private int itemsPerPage; // 每页项数。


    public int getPages() {
        return (int) Math.ceil((double) items / itemsPerPage);
    }

    public int getPage() {
        return page;
    }
    public void setPage(int page) {
        this.page =page;
    }

    public int getItems() {
        return items;
    }
    public void setItems(int items) {
        this.items = items;
    }


    public int getItemsPerPage() {
        return itemsPerPage;
    }
    public void setItemsPerPage(int itemsPerPage) {
        this.itemsPerPage = itemsPerPage;
    }

}

 

在QueryResult对象中,有一个 getPages() 方法,但其实pages并不是该对象的属性。问题就出在这里了。

 

使用xfirews调用时,会将对象与xml进行捆绑。整体的大概流程是:

1、 通过传递对象的getis方法获取需要传递的属性(属性私有)

2、 xml捆绑并网络传输

3、 解绑参数,并调用set方法将参数设置进去。

 

因此,虽然getPages()只是一个方法,还是会被误以为是属性并与xml进行捆绑,在客户端当做属性进行解绑,并调用setPages进行设置时,发现没有该方法,就跑出了一个异常。

 

这种实现确认很容易让人中招。。

 

在不改动源代码的情况下,我们在使用xfire中就得绕过这个坑:

1、如果你需要传递某些属性,一定要同时定义它的getset方法,否则会丢失这些信息

2、自定义的方法名不要使用get打头的方法名,否则会被识别为属性并调用set设值,这样就会抛错了

分享到:
评论

相关推荐

    FlexGraphics_V_1.79_D4-XE10.2_Downloadly.ir

    - ADD: Added the method TEnumProp.SetItem for convenience. The enumerable type can now be defined as a sequence: TEnum = ( eOne, eTwo ); . . . EnumProp.SetItem(integer(eOne), 'One'); EnumProp....

    VclZip pro v3.10.1

    The default value for this property is True for normal PKZip compatability. Added OnEncrypt and OnDecrypt events. These allow you to replace the standard pkzip encryption with your own. Data is ...

    FastReport.v4.15 for.Delphi.BCB.Full.Source企业版含ClientServer中文修正版支持D4-XE5

    + [enterprise] added property "MimeType" for each output format in server configuration + [enterprise] added property "BrowserPrint" in server configuration - allow printing by browser, added new ...

    NativeXml-master

    fixed property handlers for ExternalEncoding and ExternalCodepage + updated DtpEditor XE Version 4.00 (23jul2011) + implemented binary xml (BXM) + added ValueAsDate and ValueAsTime besides ...

    XtraGrid帮助文件

    With a massive collection of advanced features, developers only need to specify simple property settings or write one line method calls to build cutting edge interfaces. Whether you use the XtraGrid ...

    Sakemail

    .- Reduced the line sleep to 30 (tell me if this value doesn‘t work for you).27/4/981.7.0- Fixed a memory leak, thanks to Don Higgins.- Moved the string esErrorInFormatOfMsg to a property of SakPOP.-...

    delphi编译错误.txt

    Cannot read a write-only property 不能读取只写属性 Case label outside of range of case expression CASE标号超出了CASE表达式的范围 Circular unit reference to <Unitname> 对单元循环引用 Class already has ...

    Bochs - The cross platform IA-32 (x86) emulator

    - Added write protect option for floppy drives. - Bugfixes / improved internal debugger + instrumentation. Detailed change log : - CPU and internal debugger - Implemented Process Context ID (PCID) ...

    WPTools.v6.29.1.Pro

    This is only useful if ObjRef = nil and so no ObjRef.Filename can be set. + TParagraph.GetSubText now has optional parameter to disable the object reference char codes #1, #2 and #3 * ...

    acpi控制笔记本风扇转速

    semaphore per control method, the interpreter lock is simply no longer released before a blocking operation during control method execution. This effectively makes the AML Interpreter single- threaded...

    Java邮件开发Fundamentals of the JavaMail API

    read and write e-mail, whereas MUAs rely on MTAs to handle the actual delivery. The JavaMail API is designed to provide protocol-independent access for sending and receiving messages by dividing ...

    Senfore_DragDrop_v4.1

    Delphi 6, DragDropD5.dpk for Delphi 5, DragDropC5.bpk for C++ Builder 5, etc. 4) Add the Drag and Drop Component Suite components directory to your library path. 5) Load the demo project group: ...

    Universal-USB-Installer

    that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the ...

    Google C++ Style Guide(Google C++编程规范)高清PDF

    Classes Inheritance Multiple Inheritance Interfaces Operator Overloading Access Control Declaration Order Write Short Functions Google-Specific Magic Smart Pointers cpplint Other C++ Features ...

    File_实用案例_实现文件拷贝_FileCopy.java

    abort("no such source file: " + from_name); if (!from_file.isFile()) abort("can't copy directory: " + from_name); if (!from_file.canRead()) abort("source file is unreadable: " + from_name); //...

    WizFlow网页编辑

    there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the ...

    hibernate-shards.jar

    there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the ...

    fso浏览54646465465464564

    For Each oDrive In oFso.Drives Response.Write "(this.value);""" If Islight Then Response.Write " bgcolor='#EEEEEE'" Response.Write ">" Response.Write "<td>"&oDrive.DriveLetter&"</td>" ...

    python3.6.5参考手册 chm

    The plistlib module: A Property-List Parser ctypes Enhancements Improved SSL Support Deprecations and Removals Build and C API Changes Port-Specific Changes: Windows Port-Specific Changes: Mac OS...

    计算机网络第六版答案

    An important property of such botnets is that the originator of the botnet can remotely control and issue commands to all the nodes in the botnet. Hence, it becomes possible for the attacker to issue...

Global site tag (gtag.js) - Google Analytics