• Decrease font size
  • Reset font size to default
  • Increase font size
Banner
Merapi Forums
Welcome, Guest
Please Login or Register.    Lost Password?
How to use the PolicyServer (1 viewing) (1) Guest
Go to bottom Post Reply Favoured: 0
TOPIC: How to use the PolicyServer
#313
jahwork (User)
Posts: 2
graphgraph
User Offline Click here to see the profile of this user
How to use the PolicyServer 11 Months, 2 Weeks ago Karma: 0  
Hi all,

I'm writing a web application with Flex / Java(applet) communication through Merapi.

As soon as the flash is launched remotely, the flash player requests the policy file : <policy-file-request/>

You then need to feed the socket with a cross domain xml entry. Example
<?xml version="1.0"?>
<cross-domain-policy>
<allow-access-from domain="*" to-ports="12345" />
</cross-domain-policy>

Which is exactly what the merapi.PolicyServer class is written for.
(No no you won't find it in the trunk, it's in a branch: http://code.google.com/p/merapi/source/browse/branches/as3-js-cs-core-devel/java/merapi-core/src/merapi/PolicyServer.java)
Why isn't it in the trunk BTW, as this feature is essential to be able to run merapi with flex.

However:
1. I'm not sure the code is quite stable/finished
2. I'm not sure how to use it.

Obviously you need to start the policy server 1st on port 12345, since Flex will communicate on this port.
But that means you can start the Bridge until he's finished.

Here's my code

PolicyServer ps=new PolicyServer(12345, null);
ps.start();
while(ps.isAlive());
Bridge.open();
new HelloWorldHandler();

I can see the policy file request and the answer.
The problem is that I get other connections on the policy server, so finally I never exit it...
 
Logged Logged  
  The administrator has disabled public write access.
#314
jahwork (User)
Posts: 2
graphgraph
User Offline Click here to see the profile of this user
Re:How to use the PolicyServer 11 Months, 2 Weeks ago Karma: 0  
I reply to myself.
I found a solution (call it workaround if you want).

First problem is that PolicyServer can accept several connections.
line 104: while(_listening)

and _listening is never set to false.

Why listen all the time? we only need to reply to the policy file request.

The clean way would be to notify the main thread that a policy file request was answered, since it's a SocketConnection (new Thread) that does it.

I simplified this and set _listening to true as soon as you enter the while loop.

Second, even when the policy file request is answered we need to close the PolicyServer socket server.

So:
- remove line 119 to 124 (useless)
- add the end of run method, close socket server (be polite and wait for SocketConnction to finish)

while(_socketConnection.isAlive());
try {
_socketServer.close();
} catch (IOException e) {
e.printStackTrace();
}
if(DEBUG) System.out.println("PolicyServer closing" );

That will do the trick
 
Logged Logged  
  The administrator has disabled public write access.
Go to top Post Reply
Powered by FireBoardget the latest posts directly to your desktop