"localhost" always points to the local system - which in the case of the emulator is ... the emulator. Which, I am prepared to guess, is not running a web server :-)
The emulator can access the host OS through the "magic" IP address 10.0.2.2. If you connect an actual device via USB, it can reach the host OS via 10.0.1.2.
thank you very much for the answer but it did not work. I knew about that "localhost" adress but while tinkering around with the code it seems like I overwrote my own changes. Here is the new code:
The behavior is still the same. I only see "Hello, World false" after executing the HTTP Put request via the Android emulator. I am pretty sure I am doing something really stupid here which keeps it from running properly but right now I just do not get it
If you guys need anymore information, I will post it. Just let me know.
Greetings
André
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35437
9
posted
0
The PUT call does not seem to execute anything - make sure it actually gets to the server. Calling httpCon.connect() may be sufficient for that, or writing something to the output stream.
I did not monitor so far. How would I do that with Glassfish? Do I have to add a plugin or is this an already installed feature? Can I find it in Netbeans or in the admin console?
Sorry, Glassfish is new for me.
Greetings
André
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35437
9
posted
0
I'd start by finding out if putHtml is called; a well-placed System.out.println statement will tell you that (it should go to some GlassFish log file).
You can do HTTP monitoring by using a proxy like TcpMon, or a tool like WireShark.
as you suggested I added some Sysouts to the code so I can see which methods are called. That gives me:
HelloAndroid.java
and HelloWorld.java:
Result: I can now see in the protocols on the Admin Console that HTTP GET was executing but HTTP PUT is still missing. I attached two screenshots showing that the method on the Android was executed but that only a GET request send from the browser shows up in the logs.
I installed wireshark. It looks really interesting but I am new to it and it gives me way too much information so I am having a hard time filtering and looking for the right stuff. I did not find the HTTP PUT but I am not sure if I am doing it right. Could you point me to the proper way of filtering so it only shows the java HTTP PUT if it is there? Maybe you know how to filter that and can give me an advice? That would be highly appreciated as I tinkered around with it for an hour but could not get the results I wanted.
Altogether I think the call from the Android is not reaching the server at all but I don't get why Would be nice if you could give me some more hints?
Watching the wireshark introduction from their site right now. Hope to understand the filtering soon.
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35437
9
posted
0
Thinking some more about, I'm not actually sure if Wireshark would be able to see HTTP requests between two processes on the same machine. Were you able to see the GET request? If not, I apologize for sending you on a wild goose chase.
What should definitely work is TCPMon. If you run that, say, listening on port 7070 and forwarding to port 8080, it will log all HTTP conversations going on. You'd just have to use port 7070 in your Android code.
Discussing with some firends of mine I got the same idea about the http request and Wireshark today. I will try tcpmon also. But before that: I am on Windows 7 and did not check the firewall so far - I did not install one but forgot that there is one from Microsoft already installed which may block the connection.
I will post the results later.
Thanks for clearing things up as I already started to run in the wrong direction
André
I tried TCP Mon and it works better for me than wireshark - even if I still will inspect wirshark as it looks pretty interesting.
TCPMon does not show what I expected: I used port 7070 and when I so the HTTP GET with http://localhost:7070/HelloWorldApplication/resources/helloworld it shows up niccely - see screenshot.
Executing the Android code gives unexpected results:
This results in an empty request followed by an empty response if I interpret TCPMon right - see screenshot #2.
I finally tried the HTTP POST method:
HelloAndroid.java
HelloWorld.java
So, this gives a "204" message but finally shows up in the logs - see attachment. BUT: The GET method through the browser still gives me the "Hello, World false" content - you can see that in the logs attachment also - and I don't get why!?
Can you help? The Post method was called and the variables changed. Any ideas about that? Do I have to write a bean for that or something? Or do I have to save that in a special way - through a ressource on the website - as this is a Rest Webservice? Really like to understand even if Imay get the code up and running now.
Do you think the POST method did not work because the ressource was already there? I read it is only for not existing stuff.
Greetings - and thanks so far as I think I learned a lot through that already... but still have a long way to go...
André
found the mistake about the PUT method - I always called the GET through the browser to test that the application is running... In my little world i understand: It created the ressource so PUT makes no sense anymore and wassn't called on the server.
Did I interpret that right?
Still I don't get why GET is not returning the changed state when ccalling PUT or POST - hope to figure that out soon. Maybe a little hint?