Struts in a WebSphere Cluster

Discussion in 'Java' started by Michael, Dec 1, 2003.

  1. Michael

    Michael Guest

    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
     
    Michael, Dec 1, 2003
    #1
    1. Advertising

  2. Michael

    Sudsy Guest

    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.
     
    Sudsy, Dec 1, 2003
    #2
    1. Advertising

  3. Michael

    Sudsy Guest

    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?
     
    Sudsy, Dec 2, 2003
    #3
  4. Michael

    Michael Guest

    Sudsy <> wrote in message news:<>...
    > 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("ApplicationResources");

    Would doing:

    MessageResources resources = getResources(request);

    work in my action? Any ideas would be appreciated.

    Thanks
     
    Michael, Dec 2, 2003
    #4
  5. Michael

    Sudsy Guest

    Michael wrote:
    > 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...
     
    Sudsy, Dec 3, 2003
    #5
  6. Michael

    Michael Guest

    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 <> wrote in message news:<>...
    > Michael wrote:
    > > 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...
     
    Michael, Dec 17, 2003
    #6
  7. Michael

    Sudsy Guest

    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?
     
    Sudsy, Dec 17, 2003
    #7
  8. Michael

    Michael Guest

    Sudsy <> wrote in message news:<>...
    > 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.
     
    Michael, Dec 18, 2003
    #8
  9. Michael

    Sudsy Guest

    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!
     
    Sudsy, Dec 18, 2003
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Max
    Replies:
    0
    Views:
    393
  2. Helge Kalnes

    Web server cluster related problem

    Helge Kalnes, Feb 24, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    727
    bkalidindi
    Jun 26, 2006
  3. Programmer
    Replies:
    1
    Views:
    305
    Michael Pearson
    May 19, 2004
  4. news.microsoft.com

    ASP.NET w/ SQL Server Sessions & Cluster Failover

    news.microsoft.com, May 27, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    3,168
    bruce barker
    May 27, 2004
  5. Alex Callea

    sql session state, cluster required?

    Alex Callea, Nov 8, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    329
    Alex Callea
    Nov 8, 2004
Loading...

Share This Page