Struts in a WebSphere Cluster

M

Michael

I am currently developing a web application using Struts 1.1 on WSAD v
5.0.0.8. I everything is working fine when I run it using the test
environment for WebSphere 4.0. However, when I try to run the
application in our test environment (a cluster of WebSphere 4.0. The
same configuration as in production), I can't seem to get a handle on
my MessageResources. Any suggestions would be appreciated.

Thanks in advance,
Mike
 
S

Sudsy

Michael said:
I am currently developing a web application using Struts 1.1 on WSAD v
5.0.0.8. I everything is working fine when I run it using the test
environment for WebSphere 4.0. However, when I try to run the
application in our test environment (a cluster of WebSphere 4.0. The
same configuration as in production), I can't seem to get a handle on
my MessageResources. Any suggestions would be appreciated.

Thanks in advance,
Mike

You know that the location is relative to WEB-INF/classes, right?
If I have this line in my WEB-INF/struts-config.xml file:
<message-resources null="false" parameter="com.myorg.Messages">
then I'd better have the file
WEB-INF/classes/com/myorg/ValidationMessages.properties
I only ask since I was bitten a while back, thinking that they had
to be in the WEB-INF directory.
 
S

Sudsy

Sudsy said:
You know that the location is relative to WEB-INF/classes, right?
If I have this line in my WEB-INF/struts-config.xml file:
<message-resources null="false" parameter="com.myorg.Messages">
then I'd better have the file
WEB-INF/classes/com/myorg/ValidationMessages.properties
I only ask since I was bitten a while back, thinking that they had
to be in the WEB-INF directory.

Oopsy! That file name should read:
WEB-INF/classes/com/myorg/Messages.properties
We all make mistakes, eh?
 
M

Michael

Sudsy said:
Oopsy! That file name should read:
WEB-INF/classes/com/myorg/Messages.properties
We all make mistakes, eh?

That is the way I have it. In my struts-config.xml I have:

<message-resources parameter="ApplicationResources"/>

And the file ApplicationResources.properties is in the WEB-INF/classes
directory. I am trying to get a handle of the MessageResources by
doing:

MessageResources resources =
MessageResources.getMessageResources("ApplicationResources");

Would doing:

MessageResources resources = getResources(request);

work in my action? Any ideas would be appreciated.

Thanks
 
S

Sudsy

Michael said:
MessageResources resources =
MessageResources.getMessageResources("ApplicationResources");

Try doing MessageResources.getMessageResources(
org.apache.struts.Globals.MESSAGES_KEY );

It's too late for me to try it tonight...
 
M

Michael

Thanks for all your help so far. I ended up using a java Properties
object instead of going with Struts' MessageResources because I
couldn't get it to work. The properties object is working fine,
however, I still have the issue when using ActionErrors. I pass the
message key into the constructor, and am getting nothing displayed. I
am using Struts 1.1. I know that they changed the way the messages
are configured for the web app in 1.1 (moved it from the web.xml file
to the struts-config.xml). I am wondering if this is an issue. Any
help would be extremely helpful.

Just to re-itterate my issue, I am using Struts 1.1 in a WebSphere
cluster (2 nodes). Neither my code or Struts code can get the values
in my ApplicationResources.properties file. It workes fine in one
node, but when we deploy to two nodes, this problem appears.
 
S

Sudsy

Michael said:
Thanks for all your help so far. I ended up using a java Properties
object instead of going with Struts' MessageResources because I
couldn't get it to work. The properties object is working fine,
however, I still have the issue when using ActionErrors. I pass the
message key into the constructor, and am getting nothing displayed. I
am using Struts 1.1. I know that they changed the way the messages
are configured for the web app in 1.1 (moved it from the web.xml file
to the struts-config.xml). I am wondering if this is an issue. Any
help would be extremely helpful.

Just to re-itterate my issue, I am using Struts 1.1 in a WebSphere
cluster (2 nodes). Neither my code or Struts code can get the values
in my ApplicationResources.properties file. It workes fine in one
node, but when we deploy to two nodes, this problem appears.

Perhaps some code extracts would be of some assistance. Here's
the relevant section of my struts-config.xml:

<message-resources null="false" parameter="ApplicationResources"/>

This indicates that I MUST have the following file:

$APP_HOME/WEB-INF/classes/ApplicationResources.properties

Within a Struts Action I can access the messages resources
thusly:

MessageResources msgs = getResources( req );

(where req is the HttpServletRequest reference passed to the
execute method)

In order to invoke MessageResource#getMessage you'll need a
reference to the caller's locale. I posted this code a few
days ago:

Locale locale = getLocale( req );

Now you can pull the appropriate message and replace the
positional parameters by including the correct number of
arguments. Take a look at this message from the standard
Struts validator:

errors.minlength={0} can not be less than {1} characters.

I can generate the message string with the following code:

String msg = msgs.getMessage( locale, "errors.minlength",
"This field", "10" );

Of course, this is unnecessary when you're overriding the
validate method in a class which extends ActionForm. All
this "behind the scenes" work is done for you. Here's a
code snippet:

public ActionErrors validate( ActionMapping mapping,
HttpServletRequest req ) {
ActionErrors errors = new ActionErrors();
// add an error to the global errors
errors.add( ActionErrors.GLOBAL_ERROR,
new ActionError( "message_key" ) );
// add an error to a field name CCNUMBER
errors.add( "CCNUMBER",
new ActionError( "errors.minlength",
"Credit card number", "10" ) );
return( errors );
}

Does this help at all?
 
M

Michael

Sudsy said:
Perhaps some code extracts would be of some assistance. Here's
the relevant section of my struts-config.xml:

<message-resources null="false" parameter="ApplicationResources"/>

This indicates that I MUST have the following file:

$APP_HOME/WEB-INF/classes/ApplicationResources.properties

Within a Struts Action I can access the messages resources
thusly:

MessageResources msgs = getResources( req );

(where req is the HttpServletRequest reference passed to the
execute method)

In order to invoke MessageResource#getMessage you'll need a
reference to the caller's locale. I posted this code a few
days ago:

Locale locale = getLocale( req );

Now you can pull the appropriate message and replace the
positional parameters by including the correct number of
arguments. Take a look at this message from the standard
Struts validator:

errors.minlength={0} can not be less than {1} characters.

I can generate the message string with the following code:

String msg = msgs.getMessage( locale, "errors.minlength",
"This field", "10" );

Of course, this is unnecessary when you're overriding the
validate method in a class which extends ActionForm. All
this "behind the scenes" work is done for you. Here's a
code snippet:

public ActionErrors validate( ActionMapping mapping,
HttpServletRequest req ) {
ActionErrors errors = new ActionErrors();
// add an error to the global errors
errors.add( ActionErrors.GLOBAL_ERROR,
new ActionError( "message_key" ) );
// add an error to a field name CCNUMBER
errors.add( "CCNUMBER",
new ActionError( "errors.minlength",
"Credit card number", "10" ) );
return( errors );
}

Does this help at all?


That depends. Is the locale required? What you have specified is
what I am doing, however, I am not specifying the locale. Here is an
example of my code:

try {
delegate.setEmailPrefs(custID, userID, pref);
} catch (PasswordValidationException e) {
logger.error(ERROR, e);
errors.add("password", new
ActionError("password.validation"));
return;
} catch (PasswordPreviouslyUsedException e) {
logger.error(ERROR, e);
errors.add("password", new ActionError("password.reuse"));
return;
} catch (CoreException e) {
logger.error(ERROR, e);
errors.add("emailPrefs", new ActionError("exception",
e.toString()));
throw e;
}


The keys ("password.reuse", etc) all exist in my
ApplicationResouces.properties file. The file is located in the
$APP_HOME/WEB-INF/classes directory and is specified in the
struts-config.xml by the following line:

<message-resources parameter="ApplicationResources"/>

I am trying to display the errors in the JSP with the <html:errors />
tag. This all works fine with one node. It's when we go to multiple
nodes that things break down.
 
S

Sudsy

Michael said:
I am trying to display the errors in the JSP with the <html:errors />
tag. This all works fine with one node. It's when we go to multiple
nodes that things break down.

So it's definitely a deployment issue. Is the properties file included
in your war? Try doing 'tar tf filename.war' and checking the output.
Could it be a permissions problem? Does the userid running the server
have read privileges on the file? If the file is mode 400 or the like
(rw-------) and the owner is different then the server won't be able
to read the file. Are you using NFS mounts?
These are the kinds of questions you have to ask yourself. Good luck!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top