The root element of the configuration file is vrd-config. It may have 0 or many request elements. E.g.
The request elements take two attributes, pattern (mandatory) and exclude. Both accepts java regular expressions, e.g.
<vrd-config>
<request ...>
...
</request>
</vrd-config>
The above definition is to intercept all URIs except those followed by /script/ .
<request pattern=".*" exclude="/scripts/.*">
...
</request>
Each request element can have either response or invocation as child element. The response element takes two attributes, url (mandatory) and redirect (optional with default value false), e.g.
Normal if the response is a forward, the redirect attribute is not specified. To do a response redirect on the same web application, you need to specify #{contextPath} as prefix in the path attribute, e.g.
<request pattern=".*">
<response url="http://www.google.com" redirect="true"/>
</request>
The invocation element of the response object is used to invoke java method. There are two attributes, method-name (mandatory) and bean-class. There are two ways to specify the method to invoke:
<request pattern="/|/index.jsp">
<response path="#{contextPath}/welcome.jsp" redirect="true"/>
</request>
1. Using method-name and bean-class attributes:
<request pattern=".*">2. Using only the method-name attribute:
<invocation bean-class="Foo" method-name="bar"/>
</request>
<request pattern=".*">
<invocation method-name="Foo.bar"/>
</request>
The above mentioned methods are only applicable to public static methods of a public class. If the method is public but not static, there are two additional (optional) attributes, var and scope. The var attribute is used to specify a variable name to refer instance of bean-class. The scope is the scope of the instance. The possible values of scope are application, session, and request. If not specified, the scope is local. E.g.
<request pattern=".*">
<invocation bean-class="Foo" method-name="bar" var="foo" scope="request"/>
</request>
Note: The method that can be invoked must satisfy one of the following method signatures:
The Object can be an instance of any java class, but if it is a String, it can be used to define navigation. For navigation, you must use result element of invocation element. The result element takes two attributes, pattern and exclude and allows either response or invocation element just like request element.
public (static) void|Object methodName();
public (static) void|Object methodName(javax.servlet.http.HttpServletRequest);
public (static) void|Object methodName(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse);
Or
<invocation method-name="java.util.Date.toString" var="dt" scope="application">
<result pattern="(Sat|Sun).*">
<response url="#{contextPath}/access-denied.html" redirect="true"/>
</result>
</invocation>
<invocation method-name="A.m1">This is all about writing vrd-config.xml file.
<result pattern="value1">
<invocation method-name="B.m2">
<result pattern="value2">
<response url="http://www.someurl.com" redirect="true"/>
</result>
</invocation>
</result>
</invocation>
No comments:
Post a Comment