Java Extensions Problems

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

Post Reply
NebulaWare
Posts: 13
Joined: 02 Apr 2011, 12:33

Java Extensions Problems

Post by NebulaWare »

Hi, first of all my compliments for this kind of server which i found very useful for developing a project and saved me a lot of time.

My problem is that I read the tutorial and i still couldn't understand how to use java extensions.

I mean:

I wrote a simple java extension following this template:

Code: Select all

import it.gotoandplay.smartfoxserver.data.*;
import it.gotoandplay.smartfoxserver.extensions.*;
import it.gotoandplay.smartfoxserver.lib.ActionscriptObject;
import it.gotoandplay.smartfoxserver.events.InternalEventObject;

import org.json.JSONObject; 

public class ExtensionTemplate extends AbstractExtension
{

	public void init()
	{
		//Initialization
	}

	public void destroy()
	{
		//Called when the extension is destroyed
	}

	public void handleRequest(String cmd, ActionscriptObject ao, User u, int fromRoom)
	{	
			// Your code here, handles XML-based requests
	}
	
	public void handleRequest(String cmd, JSONObject jso, User u, int fromRoom)
	{
		// Your code here, handles JSON-based requests
	}
	
	public void handleRequest(String cmd, String params[], User u, int fromRoom)
	{
		// Your code here, handles String-based requests
	}

	public void handleInternalEvent(InternalEventObject ieo)
	{
		// Your code here, handles server events
	}
	
	public Object handleInternalRequest(Object param)
	{
		// (Optional) Your code here, handles an internal request
		return param;
	}
	
}
I compiled it and as said in the tutorial i put the .class file in the javaExtensions folder (i also tried putting the class and its package folders).
Then i opened the config.xml file and i added in a room this piece of XML:

Code: Select all

<Extensions>
				<extension name="ExtensionTemplate" className="ExtensionTemplate.class" type="script" />
			</Extensions>
Then i started the server but it said that my extension cannot be found in the sfsExtensions folder.
If i try to put my class in that folder the server finds it but it gives me an error about a wrong character at line xxx.

So, of course i'm missing something and i ask you if you can give me some simple instructions to make this extension work.
Thank you! :wink:
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Post by rjgtav »

as you are using a java extension, in the config.xml, the type of the extension must be java
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
NebulaWare
Posts: 13
Joined: 02 Apr 2011, 12:33

Post by NebulaWare »

Thank you very much, i had some doubts that "script" was not the right word to use, but i couldn't find an example for a java extension anywhere
Post Reply