Problem getting parameters in web script

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2014 12:10 PM
Hi,
I don't know why I can't obtain a parameter in my java backed web script.
I do this to call my java backed webscript by REST:
HttpClient client = new HttpClient();
PostMethod method = new PostMethod("http://IP/alfresco/service/mywebscript");
// 2 ways to set de parameter. No one works!
client.getParams().setParameter("name", "George");
method.setParameter("name", "George");
int statusCode = client.executeMethod(method);
And on the java webscript side, I would to obtain the parameter doing this:
public void execute(WebScriptRequest req, WebScriptResponse res) throws WebScriptException
{
(…)
String param = req.getParameter("name")
(…)
}
But the param is null! What I'm doing wrong??
If I call the url throw the Firefox, doing "http://IP/alfresco/service/mywebscript?name=George" the param isn't null and arrives George. And if I do
PostMethod method = new PostMethod("http://IP/alfresco/service/mywebscript?name=George");
it works fine too. Why don't works using the setParameter?? I don't understand.
Thanks a lot!
I don't know why I can't obtain a parameter in my java backed web script.
I do this to call my java backed webscript by REST:
HttpClient client = new HttpClient();
PostMethod method = new PostMethod("http://IP/alfresco/service/mywebscript");
// 2 ways to set de parameter. No one works!
client.getParams().setParameter("name", "George");
method.setParameter("name", "George");
int statusCode = client.executeMethod(method);
And on the java webscript side, I would to obtain the parameter doing this:
public void execute(WebScriptRequest req, WebScriptResponse res) throws WebScriptException
{
(…)
String param = req.getParameter("name")
(…)
}
But the param is null! What I'm doing wrong??
If I call the url throw the Firefox, doing "http://IP/alfresco/service/mywebscript?name=George" the param isn't null and arrives George. And if I do
PostMethod method = new PostMethod("http://IP/alfresco/service/mywebscript?name=George");
it works fine too. Why don't works using the setParameter?? I don't understand.
Thanks a lot!
Labels:
- Labels:
-
Archive
4 REPLIES 4
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2014 11:24 PM
You can try with
HttpClient client = new HttpClient(); PostMethod method = new PostMethod("http://IP/alfresco/service/mywebscript");method.setQueryString(new NameValuePair[] { new NameValuePair("name", "George") });

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2014 04:28 AM
Yes! This solution resolves the problem. With setQueryString the parameter arrives to the Webscript. Thank you very much!
But why client.getParams().setParameter or method.setParameter don't works? You know the reason?
I try this:
JSONObject data = new JSONObject();
data.put("test", "this is a test");
method.setRequestEntity(new StringRequestEntity(data.toString(), "application/json", "UTF-8"));
but don't works. Only the setQueryString works.
But why client.getParams().setParameter or method.setParameter don't works? You know the reason?
I try this:
JSONObject data = new JSONObject();
data.put("test", "this is a test");
method.setRequestEntity(new StringRequestEntity(data.toString(), "application/json", "UTF-8"));
but don't works. Only the setQueryString works.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2014 05:07 AM
Following code will add ("test", "this is a test") to http request body.
setParameter is used to set http request header,for example
JSONObject data = new JSONObject();data.put("test", "this is a test");method.setRequestEntity(new StringRequestEntity(data.toString(), "application/json", "UTF-8"));
setParameter is used to set http request header,for example
setParameter("Connection", "Keep-Alive");

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2014 12:52 PM
Oks, I understand. Thanks for your help! Best regards!

