Let your OpenAMF support Session

xiaoxiao2021-03-06  34

A friend who often writes Flash and server (J2EE server) program must be familiar with OpenAMF's open source Flash Remoting service, which uses AMF protocol, uses it to use the REMOTING of MM, and is not subject to server restrictions, can be installed Any J2EE server.

OpenAMF provides a lot of convenience for the Flash application for us to develop client / server-side interactions, is something that we can only use HTML, now you can use Flash to implement, so we can achieve it before. It's hard to achieve something.

However, when using the OpenAMF to call the Java class, there is a shortcoming that there is no session object that acquires this client, so that our implementation has some difficulties, how can it be in Remoting can also be like a JSP / servlet? Like the session, then we need to make a little modification for OpenAMF

In fact, Flash calls the Java class with JSP or servlet, which is also a request, which is a request from the client. We can get this request object, ORG.OpenAmf.invoker in OpenAMF's source file. JavaServiceInvoker Class found that there is an object of HTTPSERVLETREQUEST, then we can save this object.

Create a class first in the package org.openamf.invoker:

Package org.openamf.invoker;

Import javax.servlet.http.httpservletRequest;

/ **

* Author: goldgoat

*
TYPE_NAME: JavaServiceInvokerHttpServlegetRequest

*
Purpose: If the Class called by the Remote is called by this class extends

*
You can use Request to HTTPSERVLETREQUEST directly

*
can be obtained from SESSION variables

*
CREATE_DATE: 2004-2-14

13:10:09

* /

Public Class JavaServiceInvokerseTrequest {

Protected httpservletRequest request;

Public void setRequest (httpservletRequest request) {

THIS.REQUEST = REQUEST;

}

Protected httpservletRequest gethtpservletRequest () {

Return this.Request;

}

}

Then modify the InvokeService method in JavaServiceInvoker, add the following code:

ServiceClass =

Thread.currentthread (). GetContextClassLoader (). Loadingclass (

Request.getServiceName ());

Service = personistantserviceObject;

IF (service == null) {

Service = serviceClass.newinstance ();

}

Service InstanceOf JavaServiceInvokerSetRequest {

(JavaServiceInvokersetRequest) service) .SetRequest

httpservletRequest);

System.out.println (

"Information: The class /" ""

serviceClass.getName ()

"/" Is Extended by JavaServiceInvokerseTRequest! ");

Else {system.out.println

"Information: The class /" ""

serviceClass.getName ()

"/" Isn't Extended by JavaServiceInvokerseTRequest! ");

}

In the case, it is a JavaServiceInvokerSetRequest type if it is this type, indicating that this class can use the request, and then pass the request to request so that our class can be inherited from JavaServiceInvokerseTrequest, you can use Request directly.

However, it is that only a method of this class is called after calling, the request is really set, in order to be truly used, can not be used in the constructor of the class. Otherwise, a null pointer error will be prompted.

转载请注明原文地址:https://www.9cbs.com/read-64469.html

New Post(0)