I'm asking for help to my problem. I am new to JSF and I have a simple JSF online store demo page. I don't even use navigation rules since I only include the page with search results beneath the searching tags fields. The problem is a have sth like 15 fields (input texts and menus) to perform a detailed search. After selecting the fields and clicking on the search button I have to generate a long GET request for the database (which is located on a different server than my page and uses REST). The search patter is sth like this:
Where x1-xn are the values for the search engine and have to be read from the page's fields, so it has to be generated dynamically. The get request can be very long since there are 15 fields and one can have some additional options
I found some solutions on the internet and this forum how to perform a GET request using params but don't really how can it fit to my problem with long dynamically created search value in the get form.
I am using JSF 1.2, with Eclipse IDE and JBoss on Ubuntu. The search request has to be GET since the data base uses that REST interface.
I am asking for your help in this matter if someone is able to find a solution to this problem or provide me with some link. I would strongly appreciate an example code with the solution.
Actually a GET request can't get very long. There's a limit to the buffer size on the receiving server. Granted, it's typically 4K or so, but if you try REAL hard, you can blow it out. That's one of the reasons that there's POST.
There's really nothing JSF-specific about all this. Although you're apparently using positional arguments, here's a prototype of something that would take all the elements of a Map and build a URL out of them:
For best results, URLEncode the parameter value. Otherwise you could end up with "broken" URLs or even security exploits.
Customer surveys are for companies who didn't pay proper attention to begin with.
Joined: Sep 01, 2009
Thank for your response but I don't really see how did you help me. Creating a string with the url address in java is not hard problem for me. The thing is that I don't know how can I perform a get request using it and how to manage the response from the data base.
Oh. That comes next. I was misled because you said "long GET request". Any Java app that's authorized to make network connections can make a REST request to a server. It's easy to do using the HttpURLConnection class. Which can do both GET and POST requests.
If by "long GET request", you mean it takes a long time to respond, rather that that the request URL is simply a long string, it's a bit more of a problem, since any long-running process can cause serious issues in a web application server. If it takes a really long period of time, in fact, it's better done via an independent engine thread. Although if you're primarily doing database I/O and there's no long-running stored procedure involved, the REST request processing shouldn't be taking that long.
Joined: Sep 01, 2009
Thank you. Ahh HttpURLConnection... so simple.. and I've spent 2 days trying to comprehance some magic JSF tricks ore seam and RESTEasy frameworks... Any way I tried this code:
And unfortunately I met some other problems. When I am accessing a single element like this:
However, if I try to send a search request like this:
I get an Server returned HTTP response code 500 Exception.
An typing the same url in the browser works just fine.
The x1-x4 keys are now typed manually so no problem with reading parameter values and they do not consist any 'strange' chars.
The problem is that at this moment I cannot access the server log to check what's going on. Any ideas?
While I don't recommend using System.out in a live web app, this is just a quick-and-dirty test, so:
Copy and paste EVERYTHING that comes back between the '[' and ']' into your web browser's navigation control and see what happens. A 500 error means that the receiving server had a failure in processing the URL (normally it's a server application logic bug).
Joined: Sep 01, 2009
The url was correct. Moreover i've noticed that the url works in firefox but deas not work in opera. I spoke to the guy who created this search engine, he checked my code and can't see anything wrong so it's propably a server bug.
Any way thanks for you help. Your advice about using HttpURLClass probably solved the case