RequestBuilder returning "empty argument" result?

53 views
Skip to first unread message

dk

unread,
Nov 9, 2009, 2:47:59 PM11/9/09
to Google Web Toolkit
Hi,

This is about GWT 1.7.1 on a RedHat EL 5.4 system.

I have been messing with GWT for a while now. I am not an expert and
am really still a java newbie. I have the following code snippet
in an application I am writing. There is an existing CGI app and
I am replacing the GUI with GWT and using the existing CGI scripts
for the data operations.

I am setting up a RequestBuilder call to retrieve data from a CGI
script. That script generates data and sends it as a JSON string back
to this routine. The issue is that I am receiving an:

empty argument

message that is generated by the JSONParser. The message comes
through the catch clause that holds the

LOG("getInfo:onResponseReceived:e2:"

line.

I *know* the CGI script is doing its thing. I can run it from the
command line and visit its URL and I get JSON'd data that looks OK
to my eye. The code section looks like:


public void getInfo() {
RequestBuilder req;
LOG("getInfo:a");

req = new RequestBuilder(RequestBuilder.GET,
URL.encode(baseURL + "archive.cgi"));

LOG("getInfo:b:"+req.getUrl());

try {
req.sendRequest(null, new RequestCallback() {
public void onError(Request request, Throwable e) {
Window.alert("getInfo failed: " + e.toString());
}

public void onResponseReceived(Request request,
Response response) {
JSONObject Info;
try {
LOG("getInfo:onResponseReceived:a:");
Info = JSONParser.parse(response.getText()
).isObject
();
}
catch (NullPointerException e) {
LOG("getInfo:onResponseReceived:e1:" +
e.getMessage());
throw new RuntimeException(
"Failed to send JSON
request");
}
catch(IllegalArgumentException e) {
LOG("getInfo:onResponseReceived:e2:" +
e.getMessage());
throw new RuntimeException(
"Failed to send JSON
request");
}
catch(Exception e) {
LOG("getInfo:onResponseReceived:e3:" +
e.getMessage());
throw new RuntimeException(
"Failed to send JSON
request");
}


Here is a sample JSON'd string.

{"searchTerm":"","pending":["<h2>Calendar for Fall 2009</h2>
\n","<h3>Tuesday, November 10, 2009<br/>MRI Stuff</h3>\n<h4>Speaker:
Andrew <a href=\"mailto:and...@north.com\"><img src=\"/images/email.jpg
\" alt=\"(email)\"/></a>, Radiology and Biomedical Engineering</h4>
\n<h4>Time: 12:00PM</h4>\n<h4>Location: Room 5602</h4>\n<h4>Abstract:</
h4>\n<p>Transcatheter and percutaneous liver-directed approaches are
widely used for the treatment of ... procedures.</p>\n","<h3>Tuesday,
November 17, 2009<br/>Title Forthcoming</h3>\n<h4>Speaker: Chas
Conway</h4>\n<h4>Time: 12:00PM</h4>\n<h4>Location: </h4>
\n<h4>Abstract:</h4>\n<p>Abstract Forthcoming</p>\n","<h3>Tuesday,
November 24, 2009\n<br/>No Forum - Thanksgiving Vacation</h3>
\n","<h3>Tuesday, December 1, 2009<br/>Title Forthcoming</h3>
\n<h4>Speaker: Yi Lu, Professor</h4>\n<h4>Time: 12:00PM</h4>
\n<h4>Location: </h4>\n<h4>Abstract:</h4>\n<p>Abstract Forthcoming</p>
\n","<h3>Tuesday, December 8, 2009<br/>Title Forthcoming</h3>
\n<h4>Speaker: </h4>\n<h4>Time: 12:00PM</h4>\n<h4>Location: </h4>
\n<h4>Abstract:</h4>\n\n","<h3>2009-12-09<br/>Fall Semester Ends</h3>
\n"]}


This was produced from a Perl cgi script using CGI.pm and JSON::XS


FireFox/FireBug shows the request call and the headers but the result
is missing.

This code is not really different than other working code and the
CGI is not really all that different either.

I have tried using a POST method and setting

req.setHeader("Content-Type", "application/x-www-form-
urlencoded");

though I am not "sending" any data to the script.

I have tried setting

req.sendRequest(null, new RequestCallback() {
req.sendRequest("", new RequestCallback() {
req.sendRequest("dummy=value", new RequestCallback() {

and it is still happening.

It must be something very trivial that I am not seeing. Can you help?

RPB

unread,
Nov 10, 2009, 4:07:37 AM11/10/09
to Google Web Toolkit
Could you be running into the SOP (same origin policy) problem? If
your GWT and CGI script are running on different hosts the GET/POST
requests won't work. See:
http://code.google.com/docreader/#p=google-web-toolkit-doc-1-5&s=google-web-toolkit-doc-1-5&t=FAQ_SOP
http://code.google.com/docreader/#p=google-web-toolkit-doc-1-5&s=google-web-toolkit-doc-1-5&t=GettingStartedJSON
(scroll down to the SOP section for potential workarounds).

Hope this helps.

dk

unread,
Nov 10, 2009, 5:36:45 PM11/10/09
to Google Web Toolkit
Hi RPB,

Thanks for the links. There is a lot of good info in there. I don't
think my issue is with SOP though. There is something wacky about
what I am doing this time and I am not seeing it.

So, here is a more complete description of my environment: my
development platform is a recent Ubuntu distro with eclipse 3.4.2
and GWT 1.7.1. The target platform is running RHEL 5.4 and Apache-2.

I have changed/rewritten the code several times today and nothing
is working. The section of the GWT code that should take in the JSON
data now looks like:

public void getInfo() {
RequestBuilder req;
LOG("getInfo:a");

req = new RequestBuilder(RequestBuilder.POST,
URL.encode(baseURL + "archive.cgi"));
LOG("getInfo:a1");
req.setHeader("Content-Type",
"application/x-www-form-urlencoded");
LOG("getInfo:a3");
try {
req.sendRequest(null, new RequestCallback() {
public void onError(Request request, Throwable e) {
Window.alert("getInfo failed: " + e.toString());
}

public void onResponseReceived(Request request,
Response response) {
JSONObject Info;
if (response.getStatusCode() == 200) {
try {
LOG("getInfo:onResponseReceived:a:" +
response.getText());
Info = JSONParser.parse(response.getText()
).isObject
();
}
catch (NullPointerException e) {
LOG("getInfo:onResponseReceived:e1:"+
e.getMessage());
throw new RuntimeException(
"Failed to send JSON
request");
}
catch(IllegalArgumentException e) {
LOG("getInfo:onResponseReceived:e2:"+
e.getMessage());
throw new RuntimeException(
"Failed to send JSON
request");
}
catch(Exception e) {
LOG("getInfo:onResponseReceived:e3:"+
e.getMessage());
throw new RuntimeException(
"Failed to send JSON
request");
}
LOG("getInfo:onResponseReceived:b");

if (Info == null) {
throw new RuntimeException(
"Get info returned
null");
}

LOG("getInfo:onResponseReceived:c");
refreshList(Info);
LOG("getInfo:onResponseReceived:d");
} else {
LOG("getInfo:onResponseReceived:f:"+
response.getStatusText());
}
}
});
} catch (RequestException e) {
// TODO Auto-generated catch block
LOG("getInfo:b"+e.getMessage());
}
LOG("getInfo:a4");
}


A valid URL to point this to is:
http://apache-dev.itg.beckman.illinois.edu/communications/forum2/archive.cgi

the "LOG()" call are going to a JSNI method that calls "console.log()"
for FireBug.

At this instant the sendRequest() method is not being fired at all.

I have used sendRequest with null, empty ("") and dummy data values
("dummy=dummy"). I have tried to use the send() method instead of
sendRequest() and have tried the setRequestData() method with send().
I have added and removed various header arguments to set the encoding
and the "Accept" pragmas in this code and in my CGI script. I have
had both expect content-types of:

text/plain
text/javascript
application/javascript
application/json

I have set the request type above to both GET and POST.
I have set a request header to:

req.setHeader("Content-Type", "application/x-www-form-
urlencoded");

I have deleted the resulting "source" dir in the war directory.

many hours ago FireBug would show a connection in the console with
a return status of 200 but an "error" icon as well. You could see
request and response headers but no JSON payload. You could open
the request in another browser and see the JSON string. You could
point your browser to the archive.cgi URL and see the JSON string
but RequestBuilder does not seem to be actually sucking the data in.

Ian Bambury

unread,
Nov 10, 2009, 6:09:37 PM11/10/09
to google-we...@googlegroups.com
What is the full url that the cgi is at, and what is the url in hosted mode?

I can't see anything else it can be but SOP.

Try putting a plain text file in the /public/ directory (or the doc root if using -noserver) and I think you'll find it will pick it up. You might have to restart hosted mode for it to pick up the new file.

dk

unread,
Nov 11, 2009, 12:33:23 PM11/11/09
to Google Web Toolkit
Hello Ian,

the full url is: http://apache-dev.itg.beckman.illinois.edu/communications/forum2/

I forgot a major thing in the environment I listed above. The site is
being run through Perl's Template::Toolkit to manage an overall "look
and feel". Basically, in this case, there is a local index.cgi script
that runs the TT stuff. There is a local index.html file that is the
"normal" GWT encrusted index.html. The index.cgi sucks in the local
index.html, parses it, wraps the content in the site decoration and
displays it.

All of the paths are local to the host machine. If this is a SOP
issue please educate me.

Also, I don't think I am configuring "hosted" mode correctly. It is
not bringing up a browser.

Ian Bambury

unread,
Nov 11, 2009, 12:52:58 PM11/11/09
to google-we...@googlegroups.com
Hi Dean,

So when I go to http://apache-dev.itg.beckman.illinois.edu/communications/forum2/ this is where you get the problem and I should be seeing Calendar for Fall 2009 and so on?

I assumed that you were having trouble testing it somewhere before you uploaded it to the web.

So is it working in test? Or are you unable to test like that and testing by uploading to the live site? Or have I got it completely A about F?

You may have tried this, but I suppose you *do* get the right url if you log URL.encode(baseURL + "archive.cgi") ?

There's no way to see where baseURL comes from in the code you supplied, but it's not a silly error like a missing '/' is it?

The reason I said I thought it was an SOP problem was because your code works for me with a dummy file and the cgi page sends me data back.

So somewhere the two aren't matching up.

Sorry I can't be more help.

Ian

Dean Karres

unread,
Nov 11, 2009, 2:19:11 PM11/11/09
to google-we...@googlegroups.com
> So when I go
> to http://apache-dev.itg.beckman.illinois.edu/communications/forum2/ this is
> where you get the problem and I should be seeing Calendar for Fall 2009 and
> so on?

Yes, you should see that... I am not currently.

> I assumed that you were having trouble testing it somewhere before you
> uploaded it to the web.
> So is it working in test? Or are you unable to test like that and testing by
> uploading to the live site? Or have I got it completely A about F?

Correct, you can think of the apache-dev site as the live-test area if
you like. The whole site at that URL is under development and will go
"live" in a few weeks.

> You may have tried this, but I suppose you *do* get the right url if you
> log URL.encode(baseURL + "archive.cgi") ?

Yes, I just added that back to the current version to make sure

> There's no way to see where baseURL comes from in the code you supplied, but
> it's not a silly error like a missing '/' is it?

I don't think so.

> The reason I said I thought it was an SOP problem was because your code
> works for me with a dummy file and the cgi page sends me data back.
> So somewhere the two aren't matching up.
> Sorry I can't be more help.

<time passes as i check this stuff again...>
... Oh crap... Thank you Ian. You made me look at all of this yet
again and your comment about the URL made me triple check that. It
turns out that our sysadmin (bless his heart) changed the DNS on this
machine which modified the default URL. So it WAS a SOP issue after
all. I never saw the URL change until just now and the embedded URL
in the code was, of course, the old one.

Thanks again, silly me

--
Dean Karres

Ian Bambury

unread,
Nov 12, 2009, 12:02:28 AM11/12/09
to google-we...@googlegroups.com
Glad it's sorted. Sounds like a very understandable left-hand/right-hand confusion.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---


Reply all
Reply to author
Forward
0 new messages