Create an array of externalizable object using codename one webservice wizard

102 views
Skip to first unread message

Housseini Moussa

unread,
Dec 30, 2014, 1:37:27 PM12/30/14
to codenameone...@googlegroups.com
hi
please I would like to know if is the a possibility to create an array of externalizable object base on codename webservice wizard.


Shai Almog

unread,
Dec 31, 2014, 1:10:32 AM12/31/14
to codenameone...@googlegroups.com
Hi,
Array of Object[] is externalizable. You must make sure that all the objects within it are also.

Housseini Moussa

unread,
Jan 1, 2015, 12:59:57 PM1/1/15
to codenameone...@googlegroups.com
hi
I have a problem I am trying do call a method that return an externalizable object using the asynchone method of webservice call but the respond I receive is an error. In the following I present the code I use to do the work.
1- This is the code of the externalizable object I use

public class Message implements Externalizable {
    private String byLogin;
    private String text;
    private long when;
   
    static {
        Util.register("Message",Message.class);
    }
     public int getVersion() {
        return 1;
    }

    public String getByLogin() {
        return byLogin;
    }

    public void setByLogin(String byLogin) {
        this.byLogin = byLogin;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public long getWhen() {
        return when;
    }

    public void setWhen(long when) {
        this.when = when;
    }
   
    public void externalize(DataOutputStream out) throws IOException {
       
        Util.writeUTF(byLogin, out);
        Util.writeUTF(text, out);
        out.writeLong(when);
    }

    public void internalize(int version, DataInputStream in) throws IOException {
        byLogin = Util.readUTF(in);
        text = Util.readUTF(in);
        when = in.readLong();
    }

    public String getObjectId() {
        return "Message";
    }
}

2-This is the asychrone method call in my client side

Button bt5 = new Button("externalizable object display");
        bt5.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {     
                     WebServiceProxy.pollAsync("moussa", new Callback<Externalizable>() {
                        public void onSucess(Externalizable value) {
                            Util.register("Message",Message.class);
                            Dialog.show("serveur message","respond is ok","OK",null);
                        }
                        public void onError(Object sender, Throwable err, int errorCode, String errorMessage) {

                            Dialog.show("serveur error","error","OK",null);

                        }
                    }
               );
3-This is the code generated by the webservice wizard on my server side to call the methode poll

 if(methodName.equals("poll")) {
         
            Util.register("Message",Message.class); //This ligne is added by me
            Object[] args = ProxyServerHelper.readMethodArguments(di, def_poll);
            ProxyServerHelper.writeResponse(response, def_poll, WebServiceProxyServer.poll((String)args[0]));
            return;
        }

4- This is the code of how I am trying to display the externalizable object to the client on the server side base on the code generated by the webservicewizard

 public static com.codename1.io.Externalizable poll(String Login) {
           System.out.println(Login);
        // your code goes here...
           Externalizable message = new Message() ;
                Message m = new Message();
                m.setByLogin(Login);
                m.setText(Login);
                m.setWhen(System.currentTimeMillis());
                Message ms = (Message)m ;
           return ms;
    }

please help. Thank

Shai Almog

unread,
Jan 1, 2015, 1:36:35 PM1/1/15
to codenameone...@googlegroups.com
Don't use the static initializer to register, always do this in the init(Object) method of your main class or something like that.
If something fails stacks/error messages help.

Housseini Moussa

unread,
Jan 5, 2015, 5:22:44 AM1/5/15
to codenameone...@googlegroups.com
OK it work thank.
Reply all
Reply to author
Forward
0 new messages