The method of action call in WebWork _javascript skill

Source: Internet
Author: User
Tags locale prepare

This article mainly through three aspects to introduce webwork action call related knowledge, three aspects are:

1. This part of the Framework class relationship

2.Webwork getting and wrapping web parameters

3.DefaultActionProxyFactory, Defaultactionproxy, defaultactioninvocation

All the way, finally to start webwork core Business class summary, webwork through the web parameters to the client to repackage, carry out the business Action class, and feedback execution results, this source analysis corresponds to the following figure WebWork frame flow diagram in the red box place.

1. This part of the Framework class relationship

2.Webwork getting and wrapping web parameters

• Each web framework more or less of the Web request parameters of the packaging, used to take to facilitate their use, of course, WebWork is no exception.
WebWork The entry method for each response request:

public void Service (HttpServletRequest request, httpservletresponse response) throws Servletexception {
try {
if (encoding!= null) {
try {
request.setcharacterencoding (encoding);
} catch (Exception localexception) { c6/>}
}
if (locale!= null) {
response.setlocale (locale);
}
if (this.paramsworkaroundenabled) {
request.getparameter ("foo");
}
Request = Wraprequest (request); Encapsulates request requests
serviceaction (request, response, GetNamespace (requests), Getactionname (Request), Getrequestmap ( Request), Getparametermap (Request), Getsessionmap (Request), Getapplicationmap ());
catch (IOException e) {
String message = ' could not wrap servlet request with multipartrequestwrapper! ';
Log.error (message, e);
Senderror (Request, response,, new servletexception (message, E));
}

• Accept request, response parameters, and the request parameter encapsulation, the package is mainly for multimedia requests for special processing, such as project file upload request, export various types of files, etc. ...

• After packing the request, the service method invokes the Servletdispatche.serviceaction () method and invokes Getapplicationmap, Getsessionmap, Getrequestmap, Getparametermap, Getactionname, GetNamespace 6 methods begin the foreplay before the action business logic calls.

The GetNamespace method is used to obtain a namespace to which the action belongs, for example: "/my/myaction.action" returns "/my", which is implemented as follows:

Protected string GetNamespace (HttpServletRequest request) {
string servletpath = Request.getservletpath ();
Return Getnamespacefromservletpath (Servletpath);
}
public static string Getnamespacefromservletpath (String servletpath) {
Servletpath = servletpath.substring (, Servletpath.lastindexof ("/"));
return servletpath;
}

Getactionname Returns the name of the requested action, for example: "Myaction.action" returns "Myaction", which is implemented as follows:

Protected string Getactionname (HttpServletRequest request) {
String Servletpath = (String) request.getattribute (" Javax.servlet.include.servlet_path ");
if (Servletpath = = null) {
Servletpath = Request.getservletpath ();
}
Return Getactionname (Servletpath);
}
Protected string Getactionname (string name) {
int beginidx = Name.lastindexof ("/");
int endidx = Name.lastindexof (".");
Return name.substring (Beginidx = =-: Beginidx +, Endidx = =-Name.length (): ENDIDX);

The Getrequestmap method returns a map containing all the attributes in the request, and the concrete implementation class is Requestmap, as follows:

Protected Map Getrequestmap (HttpServletRequest request) {return
new Requestmap (request);
}

The Getparametermap method returns a map containing all the parameters in the request, with the following specific code:

Protected Map Getparametermap (HttpServletRequest request) throws ioexception{return
Request.getparametermap ();
}

The Getsessionmap method returns a Map that contains all the attributes in the session, the concrete implementation class is Sessionmap, as follows:

Protected Map Getsessionmap (HttpServletRequest request) {return
new Sessionmap (request);
}

The Getapplicationmap method returns a map that contains all the attributes in application, and the implementation class is applicationmap with the following code:

Protected Map Getapplicationmap () {return
new Applicationmap (Getservletcontext ());
}

webwork The attributes, parameters, properties of the session, attributes in the application, the attributes in the session are encapsulated into a Map, only for the convenience of their own use.

public void Serviceaction (HttpServletRequest request, httpservletresponse Response, String namespace, String ActionName , map Requestmap, map Parametermap, map Sessionmap, map Applicationmap) {HashMap Extracontext = Createcontextmap (requestm
AP, Parametermap, Sessionmap, Applicationmap, request, Response, getservletconfig ());
Extracontext.put ("Com.opensymphony.xwork.dispatcher.ServletDispatcher", this);
Ognlvaluestack stack = (ognlvaluestack) request.getattribute ("Webwork.valuestack"); if (stack!= null) {extracontext.put ("Com.opensymphony.xwork.util.OgnlValueStack.ValueStack"), New Ognlvaluestack (
stack));
try {actionproxy proxy = Actionproxyfactory.getfactory (). Createactionproxy (namespace, ActionName, Extracontext);
Request.setattribute ("Webwork.valuestack", Proxy.getinvocation (). Getstack ());
Proxy.execute (); if (stack!= null) {Request.setattribute ("Webwork.valuestack", stack);} catch (ConfigurationException e) {log.error ("could not find action", e); Senderror (Request, ResponSE, 404, E); catch (Exception e) {log.error ("Could not execute action", e); Senderror (request, response, E);}

• First serviceaction called the Createcontextmap Creation Action context (Extracontext). It wraps Javaservlet-related objects into the Extracontext map object.

• Then check to see if there is a stack of values available in the previous request, and if so, put it in the Extracontext map object for use on this request.

Actioncontext (Com.opensymphony.xwork.ActionContext) is the context in which the action is executed, and the context can be considered a container (in fact, our container here is just a map), It holds the object that the action needs to use when it executes.

Servletactioncontext (com.opensymphony.webwork. Servletactioncontext), this class inherits directly from Actioncontext, which provides functions that directly relate to Javaservlet as access.

The main function of Ognlvaluestack is to access the properties of an object through an expression language.

3.DefaultActionProxyFactory, Defaultactionproxy, defaultactioninvocation

Before the play finally finished, the action called the three brothers to debut for the most important operation, is the following three code, and WebWork Learning Road (v) before the request jump Xwork.xml read code has very similar writing and design:

Actionproxy proxy = Actionproxyfactory.getfactory (). Createactionproxy (namespace, ActionName, extracontext);
Request.setattribute ("Webwork.valuestack", Proxy.getinvocation (). Getstack ());

Proxy.execute (); • By creating the Invoke proxy Actonproxy instance from the previous namespace, ActionName, Extracontext, this is called Defaultactionproxy, and then the Actionproxy.execute method to execute our logical action.execute.

Actionproxy is an interface, Actionproxyfactory is an abstract class, and by default they are done through Defaultactionproxy and defaultactionproxyfactory.

• There is a static variable factory in Actionproxyfactory that points to a defaultactionproxyfactory instance with the following code:

Static Actionproxyfactory factory = new Defaultactionproxyfactory ();
public static void Setfactory (Actionproxyfactory factory) {
factory = factory;
}
public static Actionproxyfactory GetFactory () {return
factory;
}

The

defaultactionproxyfactory Createactionproxy method returns the Defaultactionproxy instance.

Public Actionproxy Createactionproxy (string namespace, String actionname, Map extracontext) throws Exception {Setupconfi
Gifactioniscommand (namespace, actionname);
return new Defaultactionproxy (namespace, ActionName, Extracontext, true); } defaultactionproxy Constructors protected Defaultactionproxy (string namespace, String actionname, Map Extracontext, Boolean Executeresult) throws exception{if (log.isdebugenabled ()) {Log.debug ("Creating an Defaultactionproxy for namespace" + N
Amespace + "and action name" + ActionName);}
This.actionname = ActionName;
This.namespace = namespace;
This.executeresult = Executeresult;
This.extracontext = Extracontext; This.config = Configurationmanager.getconfiguration (). Getruntimeconfiguration (). Getactionconfig (Namespace,
ActionName);
if (This.config = = null) {String message;
String message; if ((namespace!= null) && (Namespace.trim (). Length () > 0)) {message = Localizedtextutil.finddefaulttext ("Xwo Rk.exception.missing-package-action ", Locale.Getdefault (), new string[] {namespace, actionname}); else {message = Localizedtextutil.finddefaulttext ("Xwork.exception.missing-action", Locale.getdefault (), New String
[] {actionname});
} throw new ConfigurationException (message);
} prepare (); }

• Assign parameters such as incoming namespaces, action names, and so on to local variables, and then obtain the configuration information for the current requested action via ConfigurationManager [described here in 5]. Then call its own prepare method to create a Actioninvocation object to give itself variable invocation. In the following Execute method, the invocation of the action written by us is implemented by manipulating invocation.

protected void Prepare () throws Exception {
this.invocation = Actionproxyfactory.getfactory (). Createactioninvocation (this, this.extracontext);

The above is the relevant knowledge of action call in WebWork, hope to be helpful to everybody.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.