Flex and Java LCDs blazeds configuration.
1. architecture principle
The principle of Flash remoting is similar to the Hessian of resin. It uses HTTP-based lightweight binary protocol (AMF.
Flash remoting uses AMF to communicate with the server. For details about the basic process, refer to the Flash website documentation. Simply put, on the server side, a servlet is required to receive Flash HTTP requests, then, the HTTP request encapsulated in AMF format is parsed into a call to the server object (for example, a Java service object). On the client, the flash remoting API receives the HTTP response from the server, parses the response encapsulated in AMF format into a flash data object.
The software architecture using flash remoting is as follows:
Flash (client) <----- (http amf) ----> spring Bean (server) <-> hibernate Po
From the above we can see that the traditional web layer is completely cut down. Flash can directly access the server bean through AMF protocol and gateway conversion.
2. modify web. xml and add servlet configuration ..
<Servlet> <br/> <servlet-Name> messagebrokerservlet </servlet-Name> <br/> <servlet-class> flex. messaging. messagebrokerservlet </servlet-class> <br/> <init-param> <br/> <param-Name> services. configuration. file </param-Name> <br/> <param-value>/WEB-INF/flex/services-config.xml </param-value> <br/> </init-param> <br /> <load-on-startup> 1 </load-on-startup> <br/> </servlet> </P> <p> <servlet-mapping> <br /> <servlet-Name> messagebrokerservlet </servlet-Name> <br/> <URL-pattern>/messagebroker/* </url-pattern> <br/> </Servlet -Mapping>
3. Add the following jar package under WEB-INF/lib (the above jar package comes from the downloaded blazeds library package)
Commons-httpclient-3.0.1.jar
Flex-messaging-common.jar
Flex-messaging-core.jar
Flex-messaging-opt.jar
Flex-messaging-proxy.jar
Flex-messaging-remoting.jar
Flex-rds-server.jar
4. Add the configuration file under the WEB-INF/flex (the above configuration file comes from the downloaded blazeds library package)
Services-config.xml
Messaging-config.xml
Proxy-config.xml
Remoting-config.xml
So far, the Java AMF has been configured with OK .....
Test it first:
Remove commons-httpclient-3.0.1.jar. Enter the following URL
Http: // localhost: 8080/baosteel_sgm/messagebroker/AMF
HTTP status 500-Error
Javax. servlet. servletexception: Java. Lang. noclassdeffounderror: ORG/Apache/commons/httpclient/usernamepasswordcredentials
It indicates that the configuration has taken effect ..
Put the commons-httpclient-3.0.jar back for next use...
5. Create a Java test class
Package com;
Public class Hello {
// Define a method return string and wait for remote call.
Public String hellolcdsremoting (string name ){
Return "hello" + name + "LCDs ";
}
}
6. Modify WEB-INF/flex/remoting-config.xml to add the following content
<Destination ID = "helloremoting"> <br/> <Properties> <br/> <source> COM. hello </source> <br/> </Properties> <br/> </destination>
Then run the Web Server
7. Start flex Configuration:
View the attributes in the flex Builde project.> flex server: Select J2EE for the application server.
Select "use remote access service", and click "blaze ds.
In the "server location" tab, configure as follows:
Root folder: e:/baosteel_sgm
Root URL: http: // localhost: 8080/baosteel_sgm
Context root directory:/baosteel_sgm
Click "Verify Configuration". This requires the Web server to be started before it can pass...
Now the "OK" button can be used... click to save...
If the server is not running and cannot pass verification, you can directly change the. flexproperties file under the project. The content is as follows:
<? XML version = "1.0" encoding = "UTF-8" standalone = "no"?> <Br/> <flexproperties enableservicemanager = "false" flexserverfeatures = "4" flexservertype = "2" servercontextroot = "/baosteel_sgm" </P> <p> serverroot = "E: /baosteel_sgm "serverrooturl =" http: // localhost: 8080/baosteel_sgm "toolcompile =" true "useserverflexsdk =" false "</P> <p> Version =" 2 "/> <br/>
8. Create a flex test code
Protected function button11_clickhandler (Event: mouseevent): void
{
VaR hellojava: remoteobject = new remoteobject ("helloremoting ");
// Add a listener whose call is successful or failed
Hellojava. addeventlistener (faultevent. Fault, hellojavafault );
Hellojava. addeventlistener (resultevent. Result, hellojavaresult );
Hellojava. hellolcdsremoting ("tata ");
}
// Declare the listener function that fails to be called
Private function hellojavafault (Event: faultevent): void {
// Display the error message
Alert. Show (event. Message. tostring (), "Call failed ");
}
// Declare the successfully called listener Function
Private function hellojavaresult (Event: resultevent): void {
// Display the returned results
Alert. Show (string (event. Result), "Call successful ");
}
Powered by zoundry