Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Struts in a WebSphere Cluster

Reply
Thread Tools

Struts in a WebSphere Cluster

 
 
Michael
Guest
Posts: n/a
 
      12-01-2003
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
 
Reply With Quote
 
 
 
 
Sudsy
Guest
Posts: n/a
 
      12-01-2003
Michael wrote:
> 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.

 
Reply With Quote
 
 
 
 
Sudsy
Guest
Posts: n/a
 
      12-02-2003
Sudsy wrote:
> Michael wrote:
>
>> 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.
>


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

 
Reply With Quote
 
Michael
Guest
Posts: n/a
 
      12-02-2003
Sudsy <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> Sudsy wrote:
> > Michael wrote:
> >
> >> 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.
> >

>
> 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("ApplicationR esources");

Would doing:

MessageResources resources = getResources(request);

work in my action? Any ideas would be appreciated.

Thanks
 
Reply With Quote
 
Sudsy
Guest
Posts: n/a
 
      12-03-2003
Michael wrote:
> MessageResources resources =
> MessageResources.getMessageResources("ApplicationR esources");


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

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

 
Reply With Quote
 
Michael
Guest
Posts: n/a
 
      12-17-2003
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.


Sudsy <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> Michael wrote:
> > MessageResources resources =
> > MessageResources.getMessageResources("ApplicationR esources");

>
> Try doing MessageResources.getMessageResources(
> org.apache.struts.Globals.MESSAGES_KEY );
>
> It's too late for me to try it tonight...

 
Reply With Quote
 
Sudsy
Guest
Posts: n/a
 
      12-17-2003
Michael wrote:
> 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?

 
Reply With Quote
 
Michael
Guest
Posts: n/a
 
      12-18-2003
Sudsy <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> Michael wrote:
> > 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?



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.
 
Reply With Quote
 
Sudsy
Guest
Posts: n/a
 
      12-18-2003
Michael wrote:
> 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!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster. Mark B ASP .Net 2 09-11-2009 07:09 AM
Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster. Dhruba Bandopadhyay ASP .Net 1 05-25-2006 01:06 AM
Is it safe to point to Internet for locating struts DTD files in struts TLDs and XML files? Katie Wright Java 8 01-07-2005 03:37 PM
Integrate a Struts app with a non-struts app jc1771 Java 0 12-28-2003 06:36 PM
Struts Installation - missing struts.tld??? Jason Us Java 0 10-03-2003 11:36 PM



Advertisments