Page 1 of 1
Problem setting cookie
Posted: 17 Sep 2009, 16:20
by melojoy
Hi all!
I need to call an url on my extension actionscript.
This url:
- set a cookie on the response and
- set a redirectUrl on the response.
redirectUrl use cookie information to performe some operations.
My actionscript follow this redirectUrl correctly but the cookie seems to be not set.
I use this script to call the url (I found it on this forum)
Code: Select all
function loadXml(httpUrl)
{
var theUrl = new java.net.URL(httpUrl);
var conn = theUrl.openConnection();
// set the connection for input
conn.setDoInput(true);
// Please, no cache
conn.setUseCaches(false);
var is = conn.getInputStream();
var isr = new java.io.InputStreamReader(is);
var br = new java.io.BufferedReader(isr);
var lineOfData = null;
sb = new java.lang.StringBuffer();
while((lineOfData = br.readLine()) != null)
{
sb.append(lineOfData);
}
return sb.toString()
}
In alternative I tried to use httpclient to performe this call but after put httpclient jars on the server and modify the wrapper this code doesn't work.
Code: Select all
function checkSessionByJava(url){
var client = new org.apache.common.httpclient.HttpClient();
var getMethod = new org.apache.commons.httpclient.methods.GetMethod(url);
client.setFollowRedirects(true);
client.executeMethod(getMethod);
var responseBody = getMethod.getResponseBody();
var resp = new java.lang.String(responseBody);
trace("checkSessionByJava: "+resp)
return resp;
}
the error is:
ReferenceError: "org" is not defined ... Internal: 190 -- Line number:
So: how can I call an url and keep the session?
Thanks,
best regards.
Posted: 19 Sep 2009, 12:36
by Lapo
In order to use the org.apache.common.httpclient.HttpClient class in your AS code, you will need to
1- add it to the SFS classpath
2- user the following name to reference it: Packages.org.apache.common.httpclient.HttpClient
See here:
http://www.smartfoxserver.com/docs/docP ... script.htm
("The Packages object")
Posted: 21 Sep 2009, 15:54
by melojoy
Hi Lapo,
after different test, this is the candidate version... but it doesn't works
Code: Select all
function checkSessionByJava(url){
trace("checkSessionByJava: "+url)
var clientPackage = Packages.org.apache.commons.httpclient;
var methodPackage = Packages.org.apache.commons.httpclient.methods;
var client = new clientPackage.HttpClient();
var getMethod = new methodPackage.GetMethod();
getMethod.setURI(url);
client.setFollowRedirects(true);
client.executeMethod(getMethod);
var responseBody = getMethod.getResponseBody();
var resp = new java.lang.String(responseBody);
trace("checkSessionByJava resp: "+resp)
return resp;
}
this's the error:
TypeError: [JavaPackage org.apache.commons.httpclient.HttpClient] is not a function, it is org.mozilla.javascript.NativeJavaPackage.
the line 161 is: var client = new clientPackage.HttpClient();
I'm using HttpClient 4.0 jar (
http://hc.apache.org/downloads.cgi)
Posted: 22 Sep 2009, 13:41
by Lapo
Maybe I am wrong but after a quick glance at the website it looks to me as if they are using a different package.
All the examples use this package:
Code: Select all
import org.apache.http.client.HttpClient;
which is not what you are using.
Check this for example:
http://svn.apache.org/repos/asf/httpcom ... lease.java
Posted: 23 Sep 2009, 13:40
by melojoy
Hi,
thanks for reply, but we'are errors...
this is the code:
Code: Select all
function checkSessionByJava2(url){
trace("checkSessionByJava2: "+url)
var clientPackage = Packages.org.apache.http.client;
trace("clientPackage: "+clientPackage)
var methodPackage = Packages.org.apache.http.client.methods;
trace("methodPackage: "+methodPackage)
var client = new clientPackage.HttpClient();
trace("client: "+client)
var getMethod = new methodPackage.GetMethod();
getMethod.setURI(url);
client.setFollowRedirects(true);
client.executeMethod(getMethod);
var responseBody = getMethod.getResponseBody();
trace("responseBody: "+responseBody)
var resp = new java.lang.String(responseBody);
trace("checkSessionByJava resp: "+resp)
return resp;
}
this right trace output:
checkSessionByJava2:
http://URL....
clientPackage: [JavaPackage org.apache.http.client]
methodPackage: [JavaPackage org.apache.http.client.methods]
And then error:
Code: Select all
INFO | jvm 1 | 2009/09/23 14:56:37 | Exception in thread "SystemHandler-1" java.lang.NoClassDefFoundError: org/apache/http/HttpRequest
INFO | jvm 1 | 2009/09/23 14:56:37 | at java.lang.ClassLoader.defineClass1(Native Method)
INFO | jvm 1 | 2009/09/23 14:56:37 | at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
INFO | jvm 1 | 2009/09/23 14:56:37 | at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
INFO | jvm 1 | 2009/09/23 14:56:37 | at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
INFO | jvm 1 | 2009/09/23 14:56:37 | at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
INFO | jvm 1 | 2009/09/23 14:56:37 | at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
INFO | jvm 1 | 2009/09/23 14:56:37 | at java.security.AccessController.doPrivileged(Native Method)
INFO | jvm 1 | 2009/09/23 14:56:37 | at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
INFO | jvm 1 | 2009/09/23 14:56:37 | at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
INFO | jvm 1 | 2009/09/23 14:56:37 | at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
INFO | jvm 1 | 2009/09/23 14:56:37 | at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
INFO | jvm 1 | 2009/09/23 14:56:37 | at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
INFO | jvm 1 | 2009/09/23 14:56:37 | at java.lang.Class.getDeclaredMethods0(Native Method)
INFO | jvm 1 | 2009/09/23 14:56:37 | at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
INFO | jvm 1 | 2009/09/23 14:56:37 | at java.lang.Class.privateGetPublicMethods(Class.java:2547)
INFO | jvm 1 | 2009/09/23 14:56:37 | at java.lang.Class.getMethods(Class.java:1410)
INFO | jvm 1 | 2009/09/23 14:56:37 | at org.mozilla.javascript.JavaMembers.discoverAccessibleMethods(JavaMembers.java:361)
INFO | jvm 1 | 2009/09/23 14:56:37 | at org.mozilla.javascript.JavaMembers.discoverAccessibleMethods(JavaMembers.java:335)
INFO | jvm 1 | 2009/09/23 14:56:37 | at org.mozilla.javascript.JavaMembers.reflect(JavaMembers.java:428)
INFO | jvm 1 | 2009/09/23 14:56:37 | at org.mozilla.javascript.JavaMembers.<init>(JavaMembers.java:77)
INFO | jvm 1 | 2009/09/23 14:56:37 | at org.mozilla.javascript.JavaMembers.lookupClass(JavaMembers.java:759)
INFO | jvm 1 | 2009/09/23 14:56:37 | at org.mozilla.javascript.NativeJavaClass.initMembers(NativeJavaClass.java:83)
INFO | jvm 1 | 2009/09/23 14:56:37 | at org.mozilla.javascript.NativeJavaClass.<init>(NativeJavaClass.java:78)
INFO | jvm 1 | 2009/09/23 14:56:37 | at org.mozilla.javascript.NativeJavaPackage.getPkgProperty(NativeJavaPackage.java:159)
INFO | jvm 1 | 2009/09/23 14:56:37 | at org.mozilla.javascript.NativeJavaPackage.get(NativeJavaPackage.java:105)
INFO | jvm 1 | 2009/09/23 14:56:37 | at org.mozilla.javascript.ScriptableObject.getProperty(ScriptableObject.java:1544)
INFO | jvm 1 | 2009/09/23 14:56:37 | at org.mozilla.javascript.ScriptRuntime.getObjectProp(ScriptRuntime.java:1375)
INFO | jvm 1 | 2009/09/23 14:56:37 | at org.mozilla.javascript.ScriptRuntime.getObjectProp(ScriptRuntime.java:1364)
INFO | jvm 1 | 2009/09/23 14:56:37 | at org.mozilla.javascript.gen.c3._c92(loginManager.as:1759)
INFO | jvm 1 | 2009/09/23 14:56:37 | at org.mozilla.javascript.gen.c3._c88(loginManager.as:1658)
INFO | jvm 1 | 2009/09/23 14:56:37 | at org.mozilla.javascript.gen.c3._c90(loginManager.as:1728)
INFO | jvm 1 | 2009/09/23 14:56:37 | at org.mozilla.javascript.gen.c3._c62(loginManager.as:1112)
INFO | jvm 1 | 2009/09/23 14:56:37 | at org.mozilla.javascript.gen.c3.call(loginManager.as)
INFO | jvm 1 | 2009/09/23 14:56:37 | at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:393)
INFO | jvm 1 | 2009/09/23 14:56:37 | at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2834)
INFO | jvm 1 | 2009/09/23 14:56:37 | at org.mozilla.javascript.gen.c3.call(loginManager.as)
INFO | jvm 1 | 2009/09/23 14:56:37 | at it.gotoandplay.smartfoxserver.extensions.JavascriptExtension.callJavaScriptFunction(JavascriptExtension.java:542)
INFO | jvm 1 | 2009/09/23 14:56:37 | at it.gotoandplay.smartfoxserver.extensions.JavascriptExtension.handleInternalEvent(JavascriptExtension.java:205)
INFO | jvm 1 | 2009/09/23 14:56:37 | at it.gotoandplay.smartfoxserver.controllers.MessageHandler.dispatchEvent(MessageHandler.java:147)
INFO | jvm 1 | 2009/09/23 14:56:37 | at it.gotoandplay.smartfoxserver.controllers.SystemHandler.handleLoginRequest(SystemHandler.java:482)
INFO | jvm 1 | 2009/09/23 14:56:37 | at it.gotoandplay.smartfoxserver.controllers.SystemHandler.processEvent(SystemHandler.java:221)
INFO | jvm 1 | 2009/09/23 14:56:37 | at it.gotoandplay.smartfoxserver.controllers.SystemHandler.run(SystemHandler.java:146)
INFO | jvm 1 | 2009/09/23 14:56:37 | at java.lang.Thread.run(Thread.java:619)
INFO | jvm 1 | 2009/09/23 14:56:37 | Caused by: java.lang.ClassNotFoundException: org.apache.http.HttpRequest
INFO | jvm 1 | 2009/09/23 14:56:37 | at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
INFO | jvm 1 | 2009/09/23 14:56:37 | at java.security.AccessController.doPrivileged(Native Method)
INFO | jvm 1 | 2009/09/23 14:56:37 | at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
INFO | jvm 1 | 2009/09/23 14:56:37 | at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
INFO | jvm 1 | 2009/09/23 14:56:37 | at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
INFO | jvm 1 | 2009/09/23 14:56:37 | at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
INFO | jvm 1 | 2009/09/23 14:56:37 | at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
INFO | jvm 1 | 2009/09/23 14:56:37 | ... 43 more
Thanks
Maurizio
Posted: 24 Sep 2009, 08:03
by Lapo
Are you sure those library were properly added to the server's classpath?
Can you double check, maybe from java code. The error seems to indicate that the class loader is not able to locate those classes.
Posted: 24 Sep 2009, 13:34
by melojoy
Hi Lapo,
thank you for support.
We have used a previous version with this code...
Code: Select all
var clientPackage = Packages.org.apache.commons.httpclient;
var methodPackage = Packages.org.apache.commons.httpclient.methods;
var client = new clientPackage.HttpClient();
var getMethod = new methodPackage.GetMethod(url);
client.executeMethod(getMethod);
var responseBody = getMethod.getResponseBody();
var resp = new java.lang.String(responseBody);
return resp;
...and now it works!
Bye
Maurizio