Request dispatching, is there other way than using xml?

3 views
Skip to first unread message

petr kobalicek

unread,
Feb 22, 2010, 8:46:12 PM2/22/10
to Induction Framework
Hi list,

I'm wondering if there is also other way how to configure request
dispatching. I'm trying to play with Induction, but for my project I
need to configure request dispatching at startup (and I can very easy
connect controller with action string).

This question is related to all xml-based configuration.

Thanks
- Petr

DavidNia

unread,
Feb 23, 2010, 2:00:26 AM2/23/10
to Induction Framework
Hey Petr,

I've had some experience with Induction and would like to help you if
I can. But I don't quite understand what you are asking.

In what way do you need to configure requests dispatching?
What specifically are you trying to do?

david

Adinath

unread,
Feb 23, 2010, 3:58:14 AM2/23/10
to induction...@googlegroups.com
Petr,

There are 2 different ways I can interpret your question, so I will try to cover both.

Controlling the URL dispatch mechanism
==============================
URL dispatching is also controlled via plug-ins known as resolvers in Induction (http://www.inductionframework.org/using-resolvers-1-tutorial.html). There are 2 resolver interfaces used to control URL dispatching:

com.acciente.induction.resolver.ControllerResolver and
com.acciente.induction.resolver.ViewResolver

An HTTP request is first sent to the ControllerResolver and if that returns a null resolution, the  HTTP request is sent to the ViewResolver.

The default resolver implementation provided for these resolvers are known as the ShortURL resolvers. You can easily write your own resolvers by implementing the above interfaces and specifying the custom resolver implementation classnames in your Induction XML using the directives shown below:

<config>

    ...other config stuff....

    <controller-resolver>
        <class>the_name_of_a_class_that_implements_a_controller_resolver</class>
    </controller-resolver>

    <view-resolver>
        <class>the_name_of_a_class_that_implements_a_view_resolver</class>
    </view-resolver>
    ...other config stuff....

</config>

Note that the resolvers classes you write can have injected into their constructor via injection, just by declaring a constructor parameter of the respective type, the types documented here: http://www.inductionframework.org/param-injection-2-reference.html#ControllerresolverCONSTRUCTOR

If you were asking how to customize Induction initial config loading in general, I cover that next.

Customizing config loading in general
===========================
As for configuration in general the Induction XML is only one way to configure Induction at startup. Loading the initial configuration is actually done via a plug-in and the XML loader is simply the default built-in plug-in.

To provide your own configuration, you would implement the com.acciente.induction.init.config.ConfigLoader interface that looks like as follows:

public interface ConfigLoader
{
   Config getConfig() throws ConfigLoaderException;
}

You basically populate a Config (a simple container class) object and return it from your implementation.

To activate your custom configuration loader you specify your fully class name as value of an init parameter named "config-loader-class" for the Induction dispatcher servlet in your web.xml (note this cannot go in the Induction XML since there is is no Induction XML with a custom config loader!)

So your web.xml would look something like:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
          http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
           version="2.5">
   <description>DemoApp</description>

   <servlet>
       <servlet-name>demoapp</servlet-name>
       <servlet-class>com.acciente.induction.dispatcher.HttpDispatcher</servlet-class>
       <load-on-startup>1</load-on-startup>
       <init-param>
           <param-name>config-loader-class</param-name>
           <param-value>com.yourpackage.YourClassThatImplementsConfigLoader</param-value>
       </init-param>
   </servlet>

   <servlet-mapping>
       <servlet-name>demoapp</servlet-name>
       <url-pattern>/*</url-pattern>
   </servlet-mapping>

</web-app>

Hope this helps.

Regards,
Adi

--
Acciente, LLC
Systems Architecture and Software Design

www.acciente.com
www.inductionframework.org

petr kobalicek

unread,
Feb 23, 2010, 4:43:50 PM2/23/10
to Induction Framework
Hi guys,

thanks for reply.

Firstly I'd like to specify what I'm doing. I'd like to
programmaticaly setup url resolving on application startup. The URL
resolving is based on servlet configuration, but it's not Induction
configuration (it's our framework configuration). In fact I have some
code written and I'm trying to make it working with Induction
(hopefully there are only few web pages, because I wrote mainly web
services in past).

My URL resolver is very simple, I have modules that are scanned when
application starts and each module is traversed at the startup time so
it can add URL/Controller pair to the application. It's no problem for
me to write such Container because it's de-facto Map<String, String>.

I will start to use way #1, which seems to me less complicated at the
beginning. I'm new to Induction so it will take some time to
understand core concepts. I'm also at framework evaluating phase so
I'm trying Induction possibilities:)

Thanks
- Petr

On Feb 23, 9:58 am, Adinath <adin...@acciente.com> wrote:
> Petr,
>
> There are 2 different ways I can interpret your question, so I will try to
> cover both.
>
> Controlling the URL dispatch mechanism
> ==============================

> URL dispatching is also controlled via plug-ins known as *resolvers* in


> Induction (http://www.inductionframework.org/using-resolvers-1-tutorial.html).
> There are 2 resolver interfaces used to control URL dispatching:
>
> com.acciente.induction.resolver.ControllerResolver and
> com.acciente.induction.resolver.ViewResolver
>
> An HTTP request is first sent to the ControllerResolver and if that returns
> a null resolution, the  HTTP request is sent to the ViewResolver.
>
> The default resolver implementation provided for these resolvers are known
> as the ShortURL resolvers. You can easily write your own resolvers by
> implementing the above interfaces and specifying the custom resolver
> implementation classnames in your Induction XML using the directives shown
> below:
>
> <config>
>
>     ...other config stuff....
>
>     <controller-resolver>
>
> <class>the_name_of_a_class_that_implements_a_controller_resolver</class>
>     </controller-resolver>
>
>     <view-resolver>
>         <class>the_name_of_a_class_that_implements_a_view_resolver</class>
>     </view-resolver>
>     ...other config stuff....
>
> </config>
>
> Note that the resolvers classes you write can have injected into their
> constructor via injection, just by declaring a constructor parameter of the

> respective type, the types documented here:http://www.inductionframework.org/param-injection-2-reference.html#Co...

> *       <init-param>


>            <param-name>config-loader-class</param-name>
>
> <param-value>com.yourpackage.YourClassThatImplementsConfigLoader</param-value>
>        </init-param>

> *   </servlet>

Reply all
Reply to author
Forward
0 new messages