WebServiceProxy

62 views
Skip to first unread message

Junel Mata

unread,
Nov 5, 2014, 3:06:16 AM11/5/14
to codenameone...@googlegroups.com
Whenever I run my web service in local together with my simulated mobile application it works perfectly but when I deploy my web service to my beta test server and run my simulated mobile application and click the login button, it trows a java.lang.NullPointerException and it points out to the line where I invoked the web service proxy method. What is the possible cause of this exception and how can I prevent this kind of exception?

Shai Almog

unread,
Nov 5, 2014, 10:26:42 AM11/5/14
to codenameone...@googlegroups.com
Whats in that line exactly?
Can you post the full stack just to make sure?

Steve Hannah

unread,
Nov 5, 2014, 10:32:08 AM11/5/14
to codenameone...@googlegroups.com
My guess is that you still have the "localhost" address hard-coded in your proxy client class.  If running on a device, you'll need to use the full address of the server as it will no longer be running on localhost.

Steve

On Wed, Nov 5, 2014 at 7:26 AM, Shai Almog <shai....@gmail.com> wrote:
Whats in that line exactly?
Can you post the full stack just to make sure?

--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discu...@googlegroups.com.
Visit this group at http://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/9dbb32eb-eb72-4d52-a618-b0b734331849%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Steve Hannah
Web Lite Solutions Corp.

Junel Mata

unread,
Nov 5, 2014, 7:03:32 PM11/5/14
to codenameone...@googlegroups.com
this is my code:

 loginbtn.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent evt) {
                try{

                    boolean success = WebServiceProxy.authenticateUser(username, passwrd); <-- this is the line where the exception points.
                    
                    if(success){
                        Dialog.show("Successful","Welcome to IBC mobile","OK",null);
                        showSummary("acctBal");
                    }
                    else{
                        Dialog.show("Incorrect","Please enter the correct username and password","OK",null);
                    }
                   
                }
                catch(Exception ex){
                    ex.printStackTrace();
                    Dialog.show("Connection Error","Please check your Intenet connection and try again","OK",null);
                }
            }
        });

and this is my distination URL: private static final String DESTINATION_URL = "http://192.168.28.52:35594/ibcServiceProxy/cn1proxy"; <--because my glassfish server runs in port 35594

On Wednesday, November 5, 2014 11:32:08 PM UTC+8, shannah wrote:
My guess is that you still have the "localhost" address hard-coded in your proxy client class.  If running on a device, you'll need to use the full address of the server as it will no longer be running on localhost.

Steve
On Wed, Nov 5, 2014 at 7:26 AM, Shai Almog <shai....@gmail.com> wrote:
Whats in that line exactly?
Can you post the full stack just to make sure?

--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discussions+unsub...@googlegroups.com.

Steve Hannah

unread,
Nov 5, 2014, 7:07:49 PM11/5/14
to codenameone...@googlegroups.com
What about inside the WebServiceProxy class?  There should be server address hardcoded there.

Steve

To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discu...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Steve Hannah

unread,
Nov 5, 2014, 7:09:43 PM11/5/14
to codenameone...@googlegroups.com
Sorry... didn't see you included it at the end there.

That URL looks like it can only be accessed from inside your local network.  If your phone is accessing through its network, it won't be able to reach it.  You need to make the server accessible outside the network in that case.

However, if your phone is accessing through the same wireless network, then it should be fine.  You can test by trying to access that address in the web browser or your phone.  If it works, it should give you some sort of message like "This service is only for web services" or something like that.

Steve

Junel Mata

unread,
Nov 5, 2014, 7:11:26 PM11/5/14
to codenameone...@googlegroups.com
that destination URL that I pasted is from my WebServiceProxy class.


On Wednesday, November 5, 2014 11:32:08 PM UTC+8, shannah wrote:
My guess is that you still have the "localhost" address hard-coded in your proxy client class.  If running on a device, you'll need to use the full address of the server as it will no longer be running on localhost.

Steve
On Wed, Nov 5, 2014 at 7:26 AM, Shai Almog <shai....@gmail.com> wrote:
Whats in that line exactly?
Can you post the full stack just to make sure?

--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discussions+unsub...@googlegroups.com.

Junel Mata

unread,
Nov 5, 2014, 7:15:24 PM11/5/14
to codenameone...@googlegroups.com
Isn't it accessible by the codename-one simulator? 
this is my code:

To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discussions+unsubscr...@googlegroups.com.



--
Steve Hannah
Web Lite Solutions Corp.

--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discussions+unsub...@googlegroups.com.
Visit this group at http://groups.google.com/group/codenameone-discussions.



--
Steve Hannah
Web Lite Solutions Corp.

Steve Hannah

unread,
Nov 5, 2014, 7:20:35 PM11/5/14
to codenameone...@googlegroups.com
I may have misread your original post, but I think its still the same problem.  If you moved your application to a test server, then you'll need to change this value in the client to point to that beta test server.  Is that the correct URL to your beta test server?  Can you access that URL from the web browser on the machine where you are running the simulator?   Is your beta test server running inside the same local network as the computer on which the simulator is running?

Steve

To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discu...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Junel Mata

unread,
Nov 5, 2014, 7:29:48 PM11/5/14
to codenameone...@googlegroups.com
Yes, our beta test server is running within our local area network and I can access it from my browser. The URL that I posted earlier is the the URL to access my web service using the browser and I added /cn1proxy to access the servlet as mentioned on the how-do-I video for webservice wizard.



--
Steve Hannah
Web Lite Solutions Corp.



--
Steve Hannah
Web Lite Solutions Corp.

--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discussions+unsub...@googlegroups.com.
Visit this group at http://groups.google.com/group/codenameone-discussions.

Steve Hannah

unread,
Nov 5, 2014, 7:35:25 PM11/5/14
to codenameone...@googlegroups.com

Can you access that URL from a web browser on the machine that is running the simulator?

To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discu...@googlegroups.com.

Junel Mata

unread,
Nov 5, 2014, 7:37:57 PM11/5/14
to codenameone...@googlegroups.com
this is the exception thrown when I press login:

java.lang.NullPointerException
at com.icomm.ibcmobile.CustomerAccount$9.actionPerformed(CustomerAccount.java:191) <-- this line is where I invoked the method from the WebServiceProxy class.
at com.codename1.ui.util.EventDispatcher.fireActionEvent(EventDispatcher.java:345)
at com.codename1.ui.Button.fireActionEvent(Button.java:393)
at com.codename1.ui.Button.released(Button.java:424)
at com.codename1.ui.Button.pointerReleased(Button.java:512)
at com.codename1.ui.Form.pointerReleased(Form.java:2365)
at com.codename1.ui.Form.pointerReleased(Form.java:2301)
at com.codename1.ui.Component.pointerReleased(Component.java:2596)
at com.codename1.ui.Display.handleEvent(Display.java:1903)
at com.codename1.ui.Display.edtLoopImpl(Display.java:999)
at com.codename1.ui.Display.mainEDTLoop(Display.java:930)
at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120)
at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)

Damir Sović

unread,
Nov 5, 2014, 7:40:41 PM11/5/14
to codenameone...@googlegroups.com
I'm maybe jumping in, but have You tried with ConnectionRequest? I have a PHP services on the server and working without problem. Here's what I use:
ConnectionRequest request = new ConnectionRequest() {
                String result;

                protected void readResponse(InputStream input) {
                    JSONParser parser = new JSONParser();
                    try {
                        Map<String, Object> hash = parser.parseJSON(new InputStreamReader(input));
                        result = (String) hash.get("status");
                        input.close();

                    } catch (IOException ex) {
                        ex.printStackTrace();
                    } finally {
                        dlg.dispose();
                        nm.shutdown();
                    }

                }

                protected void postResponse() {
                    if (result.equals("0")) {
                        //User is OK
                        showForm("Main", null);
                    } else {
                        if (Dialog.show("Error!", "Incorect user", "OK", "Exit")) {
                            findUsernameInit().requestFocus();
                        } else {
                            Display.getInstance().exitApplication();
                        }
                    }

                }
            };
            request.setUrl("http://razvoj.group-mobicash.com.hr/PHPWebService/Check.php"); //here is my service
            request.setPost(true);
            request.setHttpMethod("POST");
            request.setDisposeOnCompletion(dlg);
            StringBuffer sb = new StringBuffer();
            sb.append(username).append('#').append(password);
            request.addArgument("poruka", sb.toString());
            nm.addToQueueAndWait(request); 
OK, it is just a service that passes data to database, but may be a starter

Junel Mata

unread,
Nov 5, 2014, 7:41:21 PM11/5/14
to codenameone...@googlegroups.com
Yes I can, I just did it many time already since yesterday.



--
Steve Hannah
Web Lite Solutions Corp.

--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discussions+unsub...@googlegroups.com.
Visit this group at http://groups.google.com/group/codenameone-discussions.

Steve Hannah

unread,
Nov 5, 2014, 7:46:30 PM11/5/14
to codenameone...@googlegroups.com

What is the method signature (eg return type) of your authenticateUser method.  The only thing I can think of that would cause a null pointer there is if it is doing auto unboxing of a null variable.  Eg does the method return boolean or Boolean?

To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discu...@googlegroups.com.

Junel Mata

unread,
Nov 5, 2014, 7:47:18 PM11/5/14
to codenameone...@googlegroups.com
I think webService Wizard is more accurate that Connection Request because my web service is a servlet and Shai suggested that I must use the WebServiceProxy for easy service connection.

Junel Mata

unread,
Nov 5, 2014, 7:49:56 PM11/5/14
to codenameone...@googlegroups.com
The return type is Boolean because when I use the boolean it causes me an error on my WebServiceProxy.

--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discussions+unsub...@googlegroups.com.
Visit this group at http://groups.google.com/group/codenameone-discussions.

Steve Hannah

unread,
Nov 5, 2014, 7:54:17 PM11/5/14
to codenameone...@googlegroups.com

OK.  It appears that your server is returning null to this request or that the response couldn't be unserialized for some reason.  Check the network monitor in the simulator and see if that provides more info about the response.

--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discu...@googlegroups.com.

Junel Mata

unread,
Nov 5, 2014, 8:02:29 PM11/5/14
to codenameone...@googlegroups.com
this is the response header(partial list):
Transfer-Encoding=[chunked]
null=[HTTP/1.1 200 OK]
Server=[GlassFish v3]
Date=[Mon, 28 Oct 2013 14:51:51 GMT]
X-Powered-By=[Servlet/3.0]

and the response body is empty.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discussions+unsub...@googlegroups.com.

Steve Hannah

unread,
Nov 5, 2014, 8:05:59 PM11/5/14
to codenameone...@googlegroups.com

OK.  Your answer is on the server side then.  Add debugging code on the server to see what is happening there.

To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discu...@googlegroups.com.

Junel Mata

unread,
Nov 5, 2014, 8:08:41 PM11/5/14
to codenameone...@googlegroups.com
Why is it that when I run it in local it works really fine?is changing the destination URL a big deal?
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discussions+unsubscr...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discussions+unsub...@googlegroups.com.
Visit this group at http://groups.google.com/group/codenameone-discussions.

Steve Hannah

unread,
Nov 5, 2014, 8:24:51 PM11/5/14
to codenameone...@googlegroups.com
Yes of course the URL is a big deal.  Moving an application to a different server almost always has a few hiccups.  There may be server compatibility issues or network issues (e.g. firewalls, etc..).  Luckily, these are easy to debug.  Have you looked at your server logs to at least verify that the requests are getting through? The 200 response code indicates that the server is responding, but the empty response suggests that it is having a problem.  If you're lucky, there is a stack trace in your server log that will point you to the exact problem.

Steve

To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discu...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Reply all
Reply to author
Forward
0 new messages