Re: Application configuration file

2014-01-07 Thread Chris
Hello ,
I have the same request.
Perhaps the response can help you
You can use Interceptor#init()

http://struts.1045723.n5.nabble.com/Struts2-and-JDBC-How-to-read-jdbc-properties-only-once-for-100-or-1000-users-td5714995.html






Le Mardi 7 janvier 2014 10h17, Giuliano Catrambone giulia...@catrasoftware.it 
a écrit :
 
Hi all,
     can someone suggest me how to manage an application configuration file
     in a struts application?

     I'm thinking a configuration file like
         myapp.properties

     Is there a place in a struts app where I can read the properties 
cfg file just once
     and share it in every java file (actions, )?

     Thanks
         giu


-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Re: Application configuration file

2014-01-07 Thread Lukasz Lenart
I think it is a great place for plugin ;-)

You can use interceptor with connected interface as e.g.
ServletConfigInterceptor and RequestAware - interceptor will read the
config files and then it will apply them to actions implementing given
interface. You can have many interfaces to distinguish different
config types.

You can also use annotation instead of interfaces and scan for them
using AnnotationUtils or some other tool.


2014/1/7 Chris christal...@yahoo.fr:
 Hello ,
 I have the same request.
 Perhaps the response can help you
 You can use Interceptor#init()

 http://struts.1045723.n5.nabble.com/Struts2-and-JDBC-How-to-read-jdbc-properties-only-once-for-100-or-1000-users-td5714995.html






 Le Mardi 7 janvier 2014 10h17, Giuliano Catrambone 
 giulia...@catrasoftware.it a écrit :

 Hi all,
  can someone suggest me how to manage an application configuration file
  in a struts application?

  I'm thinking a configuration file like
  myapp.properties

  Is there a place in a struts app where I can read the properties
 cfg file just once
  and share it in every java file (actions, )?

  Thanks
  giu


 -
 To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
 For additional commands, e-mail: user-h...@struts.apache.org

-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



RE: application configuration

2004-07-19 Thread Pilgrim, Peter
 -Original Message-
 From: Andrew Hill [mailto:[EMAIL PROTECTED]
 Sent: 08 July 2004 12:26
 To: Struts Users Mailing List
 Subject: RE: application configuration
 
 
 I tend to put such things in XML files rather than properties files
 nowadays.
 
 When the app starts up I have a plugin read the files and create
 configuration objects (using Digester), and put these objects into the
 servlet context (application scope) where my code can get at 
 them easily.
 
 

Agreed +1

Basically this is the same I am persuaded to. I written some Digester
stuff in the past for simple and complex XML configuration

I have a simple property file for a service layer.

org.foobar.somelayer.MyPOJI = org.foobar.somelayer.impl.MyPOJOImpl

MyPOJI is a service Java interface.

MyPOJOImpl is a concreate java class that implements the service MyPOJI

I can easily turn this into a XML file or allow a light weight framework
to load. Such a simple service layer could load up the service implementations
and stick in the application scope where Struts action (or Expresso
Controllers)
can get them. I have come around to the thinking that Business Delegate
and Service Locator can be overfluous ( I have been reading Rod Johnson's
new book also).

The problem is that I want my services to be lazy loaded. If there
a complex service that pulls in XYZ number of Java class, very resource
intensive, or is generally particular heavy, then I dont want all of 
my service to spring into life.

Is there any IoC frameworks out there that do lazy loading?
Or has anyone on the knowledgeable Struts user done something like this?

Tia

====

--
Peter Pilgrim
Operations/IT - Credit Suisse First Boston, 
10 South Colonnade, London E14 4QJ, United Kingdom
Tel: +44 (0)207 883 4447

==
This message is for the sole use of the intended recipient. If you received
this message in error please delete it and notify us. If this message was
misdirected, CSFB does not waive any confidentiality or privilege. CSFB
retains and monitors electronic communications sent through its network.
Instructions transmitted over this system are not binding on CSFB until they
are confirmed by us. Message transmission is not guaranteed to be secure.
==


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: application configuration

2004-07-08 Thread Andrew Hill
I tend to put such things in XML files rather than properties files
nowadays.

When the app starts up I have a plugin read the files and create
configuration objects (using Digester), and put these objects into the
servlet context (application scope) where my code can get at them easily.


-Original Message-
From: news [mailto:[EMAIL PROTECTED] Behalf Of j h
Sent: Thursday, 8 July 2004 19:23
To: [EMAIL PROTECTED]
Subject: application configuration


If there are specific properties that need to be configured on deployment,
where should these be put? you could put these in the application.properties
file and read these in from an Action class every time they are needed:
MessageResources mr = getResources(request);
String config = mr.getMessage(configuration.detail);

This seems inefficient. Is there a way to read these into some global
variables?




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: application configuration

2004-07-08 Thread j h
Please can you give some example code for this


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: application configuration

2004-07-08 Thread Viral_Thakkar
I have a java file which read few properties file and put the key and
values read from these properties into HashMap object of singleton
class..

I am doing this to read all Fixed Values which I need to display in my
jsp pages.

Now I want this class to run as soon as server starts... how to achieve
this ..??

One approach ...to create a servlet and configure it in web.xml with 
load-on-startup1/load-on-startup

Is this ok...or is there any better approach to do the same thing..?

Regards,
Viral



-Original Message-
From: Andrew Hill [mailto:[EMAIL PROTECTED] 
Sent: Thursday, July 08, 2004 4:56 PM
To: Struts Users Mailing List
Subject: RE: application configuration

I tend to put such things in XML files rather than properties files
nowadays.

When the app starts up I have a plugin read the files and create
configuration objects (using Digester), and put these objects into the
servlet context (application scope) where my code can get at them
easily.


-Original Message-
From: news [mailto:[EMAIL PROTECTED] Behalf Of j h
Sent: Thursday, 8 July 2004 19:23
To: [EMAIL PROTECTED]
Subject: application configuration


If there are specific properties that need to be configured on
deployment,
where should these be put? you could put these in the
application.properties
file and read these in from an Action class every time they are needed:
MessageResources mr = getResources(request);
String config = mr.getMessage(configuration.detail);

This seems inefficient. Is there a way to read these into some global
variables?




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: application configuration

2004-07-08 Thread Andrew Hill
Thats one approach. The other is to use a struts plugin.
I guess its a matter of taste. My personal preference is for plugins but
either way also can.

Just implement the org.apache.struts.PlugIn interface and declare the plugin
in your struts-config.xml file. The ActionServlet will call the plugin when
your application starts.

To deal with your config,  properties files are nice and simple so if they
suit your needs go ahead and use them.

If you want to do anything complex (like the nested objects one finds in
struts config) then XML becomes easier to use than properties, and Digester
makes it easy to read XML into objects based on rules you define.
[http://jakarta.apache.org/commons/digester/]
I dont have time to give an example of using Digester right now, but its
documentation gives some and its pretty straightforward. (Check out the
package summary in the javadocs)


-Original Message-
From: Viral_Thakkar [mailto:[EMAIL PROTECTED]
Sent: Thursday, 8 July 2004 19:56
To: Struts Users Mailing List; [EMAIL PROTECTED]
Cc: Nilesh Suresh Rajurkar
Subject: RE: application configuration


I have a java file which read few properties file and put the key and
values read from these properties into HashMap object of singleton
class..

I am doing this to read all Fixed Values which I need to display in my
jsp pages.

Now I want this class to run as soon as server starts... how to achieve
this ..??

One approach ...to create a servlet and configure it in web.xml with
load-on-startup1/load-on-startup

Is this ok...or is there any better approach to do the same thing..?

Regards,
Viral



-Original Message-
From: Andrew Hill [mailto:[EMAIL PROTECTED]
Sent: Thursday, July 08, 2004 4:56 PM
To: Struts Users Mailing List
Subject: RE: application configuration

I tend to put such things in XML files rather than properties files
nowadays.

When the app starts up I have a plugin read the files and create
configuration objects (using Digester), and put these objects into the
servlet context (application scope) where my code can get at them
easily.


-Original Message-
From: news [mailto:[EMAIL PROTECTED] Behalf Of j h
Sent: Thursday, 8 July 2004 19:23
To: [EMAIL PROTECTED]
Subject: application configuration


If there are specific properties that need to be configured on
deployment,
where should these be put? you could put these in the
application.properties
file and read these in from an Action class every time they are needed:
MessageResources mr = getResources(request);
String config = mr.getMessage(configuration.detail);

This seems inefficient. Is there a way to read these into some global
variables?




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: application configuration

2004-07-08 Thread Geeta Ramani
Viral: Look at Struts Tips by Ted Husted on the struts home page. I am pretty 
certain he discusses this very issue in detail. (I can't seem to get to that link 
right now hence cannot verify..)

hth,
Geeta

 -Original Message-
 From: Andrew Hill [mailto:[EMAIL PROTECTED]
 Sent: Thursday, July 08, 2004 8:01 AM
 To: Struts
 Subject: RE: application configuration
 
 
 Thats one approach. The other is to use a struts plugin.
 I guess its a matter of taste. My personal preference is for 
 plugins but
 either way also can. 
 
 -Original Message-
 From: Viral_Thakkar [mailto:[EMAIL PROTECTED]
 Sent: Thursday, 8 July 2004 19:56
 To: Struts Users Mailing List; [EMAIL PROTECTED]
 Cc: Nilesh Suresh Rajurkar
 Subject: RE: application configuration
 
 

 
 Now I want this class to run as soon as server starts... how 
 to achieve
 this ..??
 
 One approach ...to create a servlet and configure it in web.xml with
 load-on-startup1/load-on-startup
 
 Is this ok...or is there any better approach to do the same thing..?
 
 Regards,

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: application configuration

2004-07-08 Thread James Mitchell
As an added bonus.  Just after 1.1 was released Joe offered a cool plugin
called DigestingPlugin that takes most (if not all) of the hard work out of
getting your xml - bean done.  The only thing I've used that comes close is
JAXB.

Check it out:

http://cvs.apache.org/viewcvs.cgi/jakarta-struts/src/share/org/apache/struts
/plugins/DigestingPlugIn.java


--
James Mitchell
Software Engineer / Open Source Evangelist
EdgeTech, Inc.
678.910.8017
AIM: jmitchtx

- Original Message -
From: Andrew Hill [EMAIL PROTECTED]
To: Struts [EMAIL PROTECTED]
Sent: Thursday, July 08, 2004 8:01 AM
Subject: RE: application configuration


 Thats one approach. The other is to use a struts plugin.
 I guess its a matter of taste. My personal preference is for plugins but
 either way also can.

 Just implement the org.apache.struts.PlugIn interface and declare the
plugin
 in your struts-config.xml file. The ActionServlet will call the plugin
when
 your application starts.

 To deal with your config,  properties files are nice and simple so if they
 suit your needs go ahead and use them.

 If you want to do anything complex (like the nested objects one finds in
 struts config) then XML becomes easier to use than properties, and
Digester
 makes it easy to read XML into objects based on rules you define.
 [http://jakarta.apache.org/commons/digester/]
 I dont have time to give an example of using Digester right now, but its
 documentation gives some and its pretty straightforward. (Check out the
 package summary in the javadocs)


 -Original Message-
 From: Viral_Thakkar [mailto:[EMAIL PROTECTED]
 Sent: Thursday, 8 July 2004 19:56
 To: Struts Users Mailing List; [EMAIL PROTECTED]
 Cc: Nilesh Suresh Rajurkar
 Subject: RE: application configuration


 I have a java file which read few properties file and put the key and
 values read from these properties into HashMap object of singleton
 class..

 I am doing this to read all Fixed Values which I need to display in my
 jsp pages.

 Now I want this class to run as soon as server starts... how to achieve
 this ..??

 One approach ...to create a servlet and configure it in web.xml with
 load-on-startup1/load-on-startup

 Is this ok...or is there any better approach to do the same thing..?

 Regards,
 Viral



 -Original Message-
 From: Andrew Hill [mailto:[EMAIL PROTECTED]
 Sent: Thursday, July 08, 2004 4:56 PM
 To: Struts Users Mailing List
 Subject: RE: application configuration

 I tend to put such things in XML files rather than properties files
 nowadays.

 When the app starts up I have a plugin read the files and create
 configuration objects (using Digester), and put these objects into the
 servlet context (application scope) where my code can get at them
 easily.


 -Original Message-
 From: news [mailto:[EMAIL PROTECTED] Behalf Of j h
 Sent: Thursday, 8 July 2004 19:23
 To: [EMAIL PROTECTED]
 Subject: application configuration


 If there are specific properties that need to be configured on
 deployment,
 where should these be put? you could put these in the
 application.properties
 file and read these in from an Action class every time they are needed:
 MessageResources mr = getResources(request);
 String config = mr.getMessage(configuration.detail);

 This seems inefficient. Is there a way to read these into some global
 variables?




 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]


 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]




 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]





-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: application configuration

2004-07-08 Thread McCormack, Chris
I have coded something similar to this but rather than pop the properties object in to 
the context I attached it to ThreadLocal.

Chris McCormack

-Original Message-
From: Andrew Hill [mailto:[EMAIL PROTECTED]
Sent: 08 July 2004 12:26
To: Struts Users Mailing List
Subject: RE: application configuration


I tend to put such things in XML files rather than properties files
nowadays.

When the app starts up I have a plugin read the files and create
configuration objects (using Digester), and put these objects into the
servlet context (application scope) where my code can get at them easily.


-Original Message-
From: news [mailto:[EMAIL PROTECTED] Behalf Of j h
Sent: Thursday, 8 July 2004 19:23
To: [EMAIL PROTECTED]
Subject: application configuration


If there are specific properties that need to be configured on deployment,
where should these be put? you could put these in the application.properties
file and read these in from an Action class every time they are needed:
MessageResources mr = getResources(request);
String config = mr.getMessage(configuration.detail);

This seems inefficient. Is there a way to read these into some global
variables?




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


***
This e-mail and its attachments are confidential
and are intended for the above named recipient
only. If this has come to you in error, please 
notify the sender immediately and delete this 
e-mail from your system.
You must take no action based on this, nor must 
you copy or disclose it or any part of its contents 
to any person or organisation.
Statements and opinions contained in this email may 
not necessarily represent those of Littlewoods.
Please note that e-mail communications may be monitored.
The registered office of Littlewoods Limited and its
subsidiaries is 100 Old Hall Street, Liverpool, L70 1AB.
Registered number of Littlewoods Limited is 262152.



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: application configuration

2004-07-08 Thread Kailash Vasani
Hi Viral  Andrew,

I dont have more information, but assumption is that Viral has some class
whose methods should be
invoked in servlet container startup.

Plugin approach has some disadvantages, namely, it gets invoked for all the
HTTP GET / POST requests,
that includes GET issued for things like images, CSS files etc.

in my opinion, Servlet approach should be fine.

I would go for static block in a servlet class  use that to invoke static
methods on the class.

JVM calls static block after loading class  before invoking
any method, including constructor. This static block gets called exactly
once (assuming that you dont have
class loader related maze :-)

Kailash

-Original Message-
From: Geeta Ramani [mailto:[EMAIL PROTECTED]
Sent: Thursday, July 08, 2004 5:54 PM
To: Struts Users Mailing List; [EMAIL PROTECTED]
Subject: RE: application configuration


Viral: Look at Struts Tips by Ted Husted on the struts home page. I am
pretty certain he discusses this very issue in detail. (I can't seem to get
to that link right now hence cannot verify..)

hth,
Geeta

 -Original Message-
 From: Andrew Hill [mailto:[EMAIL PROTECTED]
 Sent: Thursday, July 08, 2004 8:01 AM
 To: Struts
 Subject: RE: application configuration
 
 
 Thats one approach. The other is to use a struts plugin.
 I guess its a matter of taste. My personal preference is for 
 plugins but
 either way also can. 
 
 -Original Message-
 From: Viral_Thakkar [mailto:[EMAIL PROTECTED]
 Sent: Thursday, 8 July 2004 19:56
 To: Struts Users Mailing List; [EMAIL PROTECTED]
 Cc: Nilesh Suresh Rajurkar
 Subject: RE: application configuration
 
 

 
 Now I want this class to run as soon as server starts... how 
 to achieve
 this ..??
 
 One approach ...to create a servlet and configure it in web.xml with
 load-on-startup1/load-on-startup
 
 Is this ok...or is there any better approach to do the same thing..?
 
 Regards,

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: application configuration

2004-07-08 Thread Geeta Ramani
Kailash:

I don't think this is the case... I believe if you implement the Plugin interface and 
override the init() method, you will be ok..

Geeta

 -Original Message-
 From: Kailash Vasani [mailto:[EMAIL PROTECTED]
 Sent: Thursday, July 08, 2004 8:45 AM
 To: 'Struts Users Mailing List'
 Subject: RE: application configuration
 
 
 
 Plugin approach has some disadvantages, namely, it gets 
 invoked for all the
 HTTP GET / POST requests,
 that includes GET issued for things like images, CSS files etc.
 
 in my opinion, Servlet approach should be fine. 
 

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: application configuration

2004-07-08 Thread Andrew Hill
snip
Plugin approach has some disadvantages, namely, it gets invoked for all the
HTTP GET / POST requests,
that includes GET issued for things like images, CSS files etc.
/snip

You are confusing PlugIn with something else! (filters?)

PlugIns are expressely created for the purpose of doing this sort of
application config loading, and are called by the ActionServlet from the
ActionServlets own init() method on application startup. They are not called
in response to requests.

Id be wary about using static blocks for anything involving file access. I
cant give you a good reason for that, but it just seems like a bad idea to
me.

-Original Message-
From: Kailash Vasani [mailto:[EMAIL PROTECTED]
Sent: Thursday, 8 July 2004 20:45
To: 'Struts Users Mailing List'
Subject: RE: application configuration


Hi Viral  Andrew,

I dont have more information, but assumption is that Viral has some class
whose methods should be
invoked in servlet container startup.

Plugin approach has some disadvantages, namely, it gets invoked for all the
HTTP GET / POST requests,
that includes GET issued for things like images, CSS files etc.

in my opinion, Servlet approach should be fine.

I would go for static block in a servlet class  use that to invoke static
methods on the class.

JVM calls static block after loading class  before invoking
any method, including constructor. This static block gets called exactly
once (assuming that you dont have
class loader related maze :-)

Kailash

-Original Message-
From: Geeta Ramani [mailto:[EMAIL PROTECTED]
Sent: Thursday, July 08, 2004 5:54 PM
To: Struts Users Mailing List; [EMAIL PROTECTED]
Subject: RE: application configuration


Viral: Look at Struts Tips by Ted Husted on the struts home page. I am
pretty certain he discusses this very issue in detail. (I can't seem to get
to that link right now hence cannot verify..)

hth,
Geeta

 -Original Message-
 From: Andrew Hill [mailto:[EMAIL PROTECTED]
 Sent: Thursday, July 08, 2004 8:01 AM
 To: Struts
 Subject: RE: application configuration


 Thats one approach. The other is to use a struts plugin.
 I guess its a matter of taste. My personal preference is for
 plugins but
 either way also can.

 -Original Message-
 From: Viral_Thakkar [mailto:[EMAIL PROTECTED]
 Sent: Thursday, 8 July 2004 19:56
 To: Struts Users Mailing List; [EMAIL PROTECTED]
 Cc: Nilesh Suresh Rajurkar
 Subject: RE: application configuration




 Now I want this class to run as soon as server starts... how
 to achieve
 this ..??

 One approach ...to create a servlet and configure it in web.xml with
 load-on-startup1/load-on-startup

 Is this ok...or is there any better approach to do the same thing..?

 Regards,

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: application configuration

2004-07-08 Thread Hibbs, David
I'll give you a good reason... file access inevitably risks
IOExceptions, and exceptions don't propogate well from a static block.

That is to say, when the ClassLoader invokes the static block, it is
not invoked from within your code.  The exception gets thrown and propogates
through the *ClassLoader* stack rather than your application code, resulting
in an application that simply won't start for mysterious reasons, forcing a
long and drawn out investigation.

The only reason I use static blocks any more is to initialize
constants that require more than 1 line to initialize correctly (such as
NumberFormats, where you may have additional methods to invoke once they are
corrected) or are order-dependent, so that if a field gets renamed and/or
the members are resorted the code doesn't blow up.
Even these examples are pretty scarce and serve very special purposes.

Best Practice: Don't do anything in a static block that can throw an
exception without good reason.  

If you have something you'd like to initialize in a static way,
create a static synchronized accessor and allow the accessor to throw
exceptions as needed.  i.e.
a singleton-like implementation:

private static Config configInstance = null;
public static final synchronized getConfig()
{
if(configInstance==null)
{
// create instance and read config;
// this can throw any RuntimeExceptions
// and still be compatible with the signature
}
return configInstance;
}

David Hibbs, ACS
Staff Programmer / Analyst
American National Insurance Company

 Id be wary about using static blocks for anything involving 
 file access. I
 cant give you a good reason for that, but it just seems like 
 a bad idea to
 me.

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]