"fork that one single class for your standalone app and re-implement the 
methods you use so that they don't call StripesFilter"

Heh.  This is actually what I did...


"Last, if you have a refactoring proposal for the class (to make the crypto 
feature independant of Stripes) that's worth it, we'll surely consider the 
option."

Would be nice.  The problem is the way the secret key is pulled from the 
web.xml.  Certainly there's a number of other ways of doing this, it would not 
be too hard to call a setter on startup instead (quick example below, this 
probably isn't much better).  StripesFilter.getConfiguration() is a bit 
overused across the board - it effectively ties each class to the servlet 
container, but I don't have any better suggestions at this time.


    protected static byte[] getKeyMaterialFromConfig() {
-        try {
-            Configuration config = StripesFilter.getConfiguration(); //
-            if (config != null) {
-                String key = 
config.getBootstrapPropertyResolver().getProperty(CONFIG_ENCRYPTION_KEY);
-                if (key != null) {
-                    return key.getBytes();
-                }
-            }
-        }
-        catch (Exception e) {
-            log.warn("Could not load key material from configuration.", e);
-        }
-
-        return null;
+     return CryptoUtil.keyMaterial; // passed to init method
    }

DefaultConfiguration:
public void init()  {
+                String key = 
getBootstrapPropertyResolver().getProperty(CONFIG_ENCRYPTION_KEY);
+                if (key != null) {
+                       CryptoUtil.init(key.getBytes());
+               }
}

From: VANKEISBELCK Remi [mailto:r...@rvkb.com]
Sent: Monday, November 08, 2010 4:24 AM
To: Stripes Users List
Subject: Re: [Stripes-users] CryptoUtils standalone

Hi Keith,

Sorry for the late reply.

What exactly are you trying to reuse ?

I'm just trying to understand. Stripes is supposed to handle the Web MVC part : 
if your application's logic is written in its "tier", then it should not depend 
on Stripes. Your action beans usually just invoke your biz logic, that should 
be written in an independent module.

If you depend directly on CryptoUtils, then your best option is probably to ". 
Using MockRoundtrip in a standalone app seems odd.

Last, if you have a refactoring proposal for the class (to make the crypto 
feature independant of Stripes) that's worth it, we'll surely consider the 
option.

Cheers

Remi
2010/11/4 Keith <khyl...@bge.ie<mailto:khyl...@bge.ie>>
Hi,

We have a stripes web application.

We now wish to re-use some of the functionality of the web application in a
standalone java program without re-writing the code.

The problem we are facing is that the web-application uses the CryptoUtils
class to encrypt/ decript some values.

When this is run from a standalone program we get the error below.

Is it possible to use the CryptoUtil in standalone mode, perhaps by Mocking
certain objects, or injecting a Configuration instance.

Cheers,
Keith

ERROR: net.sourceforge.stripes.controller.StripesFilter -
net.sourceforge.stripes.exception.StripesRuntimeException: Something is trying
to access the current Stripes configuration but the current request was never
routed through the StripesFilter! As a result the appropriate Configuration
object cannot be located. Please take a look at the exact URL in your
browser's address bar and ensure that any requests to that URL will be filtered
through the StripesFilter according to the filter mappings in your web.xml.

       at
net.sourceforge.stripes.controller.StripesFilter.getConfiguration
(StripesFilter.java:161)
       at net.sourceforge.stripes.util.CryptoUtil.decrypt(CryptoUtil.java:181)
...




------------------------------------------------------------------------------
The Next 800 Companies to Lead America's Growth: New Video Whitepaper
David G. Thomson, author of the best-selling book "Blueprint to a
Billion" shares his insights and actions to help propel your
business during the next growth cycle. Listen Now!
http://p.sf.net/sfu/SAP-dev2dev
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net<mailto:Stripes-users@lists.sourceforge.net>
https://lists.sourceforge.net/lists/listinfo/stripes-users

------------------------------------------------------------------------------
The Next 800 Companies to Lead America's Growth: New Video Whitepaper
David G. Thomson, author of the best-selling book "Blueprint to a 
Billion" shares his insights and actions to help propel your 
business during the next growth cycle. Listen Now!
http://p.sf.net/sfu/SAP-dev2dev
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to