Reload resource bundle in struts2 in Websphere - struts2

I have struts.devMode=true in my struts.properties. Which will cause resource bundle to reload each time. But every time when it try to reload it throws exception below. My application is running on websphere 7. Any help will be appriciated.
com.opensymphony.xwork2.util.logging.commons.CommonsLogger error Could not reload resource bundles
java.lang.NoSuchFieldException: cacheList

You can't work with Struts 2 in devMode and Websphere. There isn't many information on the Internet (in French) but what I can understand with my limited French knowledge is that you have to put the server with production settings.
I mean that your struts.xml must be like this to make Struts2 work on Websphere:
<struts>
<constant name="struts.devMode" value="false" />
<constant name="struts.i18n.reload" value="false" />
<constant name="struts.configuration.xml.reload" value="false" />
...
</struts>
The reason that why is this happening is not very clear. The blog explains that maybe is for a different JVM implementation by IBM and maybe it differs in the implementation of the ResourceBundle class that has no private field cacheList and then raises an error when it reloads the i18n labels.

the follow solution worked for me in Tomcat 7 and WebSphere Application Server 7.
LocalizedTextUtil.reset();
ResourceBundle.clearCache(LocalizedTextUtil.class.getClassLoader());
This will clear the ResourceBundle cache.
*devMode and i18n.reload must be false.
Regards,
Felipe

Related

Log4Net can't locate logfile anywhere

I have followed many different guides on how to configure the log4net, it is up and running but i can't find a log file anywhere ...
This is how my configuration look like:
Web.Config
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
<log4net debug="true">
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="C:\\temp\\Log.txt" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-5p %d %5rms %-22.22c{1} %-18.18M - %m%n" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="RollingLogFileAppender" />
</root>
</log4net>
Global.asax:
XmlConfigurator.Configure(new FileInfo(Server.MapPath("~/Web.config")));
//XmlConfigurator.Configure();
StartUp.cs
//[assembly: XmlConfigurator(ConfigFile = "Web.config", Watch = true)]
[assembly: XmlConfigurator(Watch = true)]
Declaration
readonly log4net.ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
Logging
BasicConfigurator.Configure();
logger.Info("Info logging ...");
logger.Error("Homepage loading test logging ...");
Where my file value is: <file value="C:\\temp\\Log.txt" />
I have tried several paths, and commented out what above but no success.
What am i doing wrong?
UPDATE:
As suggested by John H i have tried configuring and calling the logger in the Application_Start method and tried several alternative configs with it but with no luck. Here are 2 screenshots of some debugging info:
Main properties:
Below are the Logger properties:
What am i doing wrong?
OK so i got it to work following this tutorial: log4net-guide-dotnet-logging
I have created a log4net.config file with content as showed in tutorial.
used [assembly: XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]
Called it like this:
ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
logger.Info("Application started.");
file is created and content logged as well.
I am gonna compare the config files content and see if the difference is in there and go gradually comparing everything till i have found what caused it not to work.
Thank you for helping me!
Kind regards
From your screenshots, we can see that your logger is not being initialised with your configuration, because IsDebug is false. One thing I notice from your screenshot, is you're trying to pass the path to Web.config directly to the Configure() method. I realise that may be an attempt to solve the problem, so you may have already tried my next suggestion, but calling Configure() in the manner you currently have won't work because Web.config is not published to your bin\debug folder. It will called Web.projectname.config. Calling
XmlConfigurator.Configure()
with no parameters, will automatically resolve the correct configuration file in your output directory. I'm guessing you've tried that, but if that still doesn't work, try this as well:
using log4net;
protected void Application_Start(object sender, EventArgs e)
{
// Initialising configuration before requesting a logger.
XmlConfigurator.Configure();
// Requesting a logger only after the configuration has been initialised.
var logger = LogManager.GetLogger(typeof(Global));
logger.Info("Application started.");
}
I'm not sure it will make any difference, but your configuration looks fine to me.
But by inspecting the IsDebug property on the logger, you'll at least be able to tell if the configuration has even been read.
Edit: One other thing, make sure the application will have the permissions to write to the file. From the documentation:
The RollingFileAppender extends the FileAppender and has the same behavior when opening the log file. The appender will first try to open the file for writing when ActivateOptions() is called. This will typically be during configuration. If the file cannot be opened for writing the appender will attempt to open the file again each time a message is logged to the appender. If the file cannot be opened for writing when a message is logged then the message will be discarded by this appender.

Underscores and wildcard action mapping in Struts 2

I'm working with a Struts 2 webapp with the following action mapping:
<action name="something_*" class="foo.whatever.MyAction" method="{1}">
<result>blah/myJsp.jsp</result>
...
</action>
So if I load the URL /something_load.action, it calls to MyAction.load(), and so on. Piece of cake. What puzzles me is that loading /something.action does work too (I guess it's invoking the execute() method). How is it possible? My action mapping is supposed to match "something_", but there is no underescore in my URL. It should give me an error! Shouldn't it?
I've double checked that there isn't another mapping for "something.action" in the struts config files. I also checked the web.xml file, just in case...
The only explanation that I can imagine is that the underscore is ignored in Struts if I use wildcard mappings. But then it would make no difference to load /something_load.action, /some_thing_lo_ad.action... and that's not true.
I'm aware that this must be a very noobish question, but I've been unable to solve the mistery, neither looking through Stackoverflow questions nor the Struts documentation.
This is the main struts.xml file:
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />
<constant name="struts.freemarker.templatesCache" value="true" />
<package name="default" extends="struts-default">
<!-- interceptors ... -->
<!-- global results for error pages -->
</package>
<!-- lots of includes -->
</struts>
It appears that wildcards are matched loosely in order to support some legacy syntax. So the issue isn't with underscore but with loose matching pattern.
From the javadocs:
Patterns can optionally be matched "loosely". When the end of the pattern matches \*[^*]\*$ (wildcard, no wildcard, wildcard), if the pattern fails, it is also matched as if the last two characters didn't exist. The goal is to support the legacy "*!*" syntax, where the "!*" is optional.

no effect of "resultpath" constant in struts.xml

I have all the jsp pages (ex: index.jsp) in the WebContent folder and my application is working smoothly.
Now, I created a folder "pages" inside WebContent, where I transferred all my jsp pages.
And I added the following line inside the <struts> tags:
<constant name="struts.convention.result.path" value="/pages" />
But still, its not searching for jsp inside the "pages" folder.
I am getting:
HTTP Status 404 - /MyApplicationName/index.jsp
Where am I doing a mistake?
EDIT: The current structure of my application is as follows:
The welcome page is an action instead of a jsp page. The result page of this action is index.jsp. This action populates the dropdown menu and some other fields in index.jsp. Now, I want to keep index.jsp along with other jsp pages in the folder "WebContent/pages". I have over 30 jsp pages in my application, and I don't want to mention the full path of every jsp in the result-tag. Thats why I want to make use of the struts2 constant "struts.convention.result.path"
My question is, why the code I have mentioned above is not working?
Accessing index.jsp directly bypasses all S2 request handling.
There's no S2 or S2 Convention plugin involved, you're just accessing a JSP page.
If index.jsp is first page of your application then you need to change its path to /pages/index.jsp in <welcome-file> tag of web.xml. And for rest I agree with #Dave Newton :)
Probably your mistake was in struts.xml.
When you create a new-Folder under web-content make with the same name (folder-name) of
xml file under src and include it in struts.xml file it will work fine.
For eg: suppose you created example folder under web-content, now create example.xml file
under src folder and in struts.xml file include example.xml
example.xml:
<struts>
<package name="example" namespace="/example" extends="default">
<action name="your action name" class="your class" method="your method">
</action>
</package>
</struts>
struts.xml:
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />
<action name="" class="" method="">
</action>
</package>
<include file="example.xml"/>

Struts2 file upload max size

I need to upload files upto 10 MB.I used the following .In my struts.xml i configured like as follows.
<action name="doUpload" class="com.example.UploadAction">
<interceptor-ref name="fileUpload">
<param name="maximumSize">20971520</param>
</interceptor-ref>
</action>
I did not configured any where other than this.I am getting the following error.
the request was rejected because its size (2102840) exceeds the configured maximum (2097152)
Can any one suggest me what might be the reason.Thanks in advance.
Put this in your struts.xml file
<constant name="struts.multipart.maxSize" value="30000000" />
See http://struts.apache.org/2.x/docs/file-upload.html#FileUpload-AdvancedConfiguration.
Updated link -
https://struts.apache.org/core-developers/file-upload.html#file-size-limits
Also check your container configuration. Tomcat itself, for example, has a maxPostSize parameter which, if not set defaults to 2097152 (2Mb)
put this code on your strtus.xml:
<constant name="struts.multipart.maxSize" value="50000000" />
where value denotes your file size limit . if you want to extend the limit you can change the value as well . hope it helps

How to fix redirect OGNL error, Unable to set param?

I am not sure if this is me or if this is a bug.
I got the following error
11:52:01,623 ERROR ObjectFactory:27 - Unable to set parameter [dest] in result of type [org.apache.struts2.dispatcher.ServletRedirectResult]
Caught OgnlException while setting property 'dest' on type 'org.apache.struts2.dispatcher.ServletRedirectResult'. - Class: ognl.ObjectPropertyAccessor
File: ObjectPropertyAccessor.java
Method: setProperty
Line: 132 - ognl/ObjectPropertyAccessor.java:132:-1
at com.opensymphony.xwork2.ognl.OgnlUtil.internalSetProperty(OgnlUtil.java:392)
And my config is pretty minimal
<package name="esupport" namespace="/esupport" extends="struts-default">
<action name="old-esupport" class="com.my.MyRedirectAction">
<result type="redirect">
<param name="location">http://some.server.com/init.asp</param>
<param name="dest">${dest}</param>
</result>
</action>
</package>
And my class has a pair of get/set method. And that's it. Nothing Fancy
I have found this thread in the forum. But it doesn't solve my problem
I am using
Struts 2.1.16
Spring 2
Spring Security + CAS
(The funny behavior is it sends me to the CAS server after the error, but I guess it will be corrected after the redirect issue got fixed)
it seems like a bug with Struts2. they recommend...hiding the error by:
<category name="com.opensymphony.xwork2.ObjectFactory">
<priority value="fatal"/>
</category>
from....TroubleShooting guide section on redirects
I faced this issue after deploying the application in WAS 7 server. It was an existing application and there was no code change.
Found the following exceptions in the server start-up logs
Failed to write out object: ext___405722372
com.ibm.wkplc.extensionregistry.util.XmlUtilException: Unable to write to the given file
Just cleared the server cache and restarted it and the issue got resolved.

Resources