wste struts presenation 10-18-07

Upload: kishor-peddi

Post on 07-Aug-2018

223 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/21/2019 WSTE Struts Presenation 10-18-07

    1/37

    IBM Software Group

    WebSphereSupport Technical Exchange

    Introduction to the Struts Framework withWebSphereCommerce

    Meng Fu, Mike Callaghan, Polina Gohshtein

  • 8/21/2019 WSTE Struts Presenation 10-18-07

    2/37

    IBM Software Group

    WebSphereSupport Technical Exchange 2

    Agenda

    Introduction to Struts

    Struts Framework

    Mapping URLs and Views

    Customization Points

    Common Pitfalls

    Questions and Answers

  • 8/21/2019 WSTE Struts Presenation 10-18-07

    3/37

    IBM Software Group

    WebSphereSupport Technical Exchange 3

    What Is Struts?

    Struts framework was designed to help develop web

    applications that utilize an MVC architecture

    Separate display logic from business logic using MVC

    Model = business logic (data model)

    View = presentationController = navigational code between model and view

    Three key components to the Struts framework:

    A "request" handler

    A "response" handler

    A tag library

  • 8/21/2019 WSTE Struts Presenation 10-18-07

    4/37

    IBM Software Group

    WebSphereSupport Technical Exchange 4

    How Commerce Uses Struts?

    Supports the use of Struts 1.1

    Uses Struts for routing requests

    Extends the following struts components:

    org.apache.struts.action.ActionServlet

    org.apache.struts.action.Action

    org.apache.struts.action.ActionMapping

    Uses the following struts component:org.apache.struts.action.RequestProcessor

  • 8/21/2019 WSTE Struts Presenation 10-18-07

    5/37

    IBM Software Group

    WebSphereSupport Technical Exchange 5

    Struts Framework: Action Servlet

    Receives an HTTP request

    Uses Struts configurationfiles to determine theappropriate applicationmodule

    Routes the request to themodule's request processor

    ECActionServlet is theCommerce extension of theStruts ActionServlet class

  • 8/21/2019 WSTE Struts Presenation 10-18-07

    6/37

    IBM Software Group

    WebSphereSupport Technical Exchange 6

    Struts Framework: Request Processor

    Determines the action

    mapping and action formassociated with a request

    Populates and validates theaction form

    Passes the request, actionform, and action mapping tothe BaseAction

    Forwards the user to theappropriate view when theaction is complete

  • 8/21/2019 WSTE Struts Presenation 10-18-07

    7/37

    IBM Software Group

    WebSphereSupport Technical Exchange 7

    Struts Framework: Base Action

    Bridges an incoming

    request to thecorresponding businesslogic

    Uses the configuration in

    the action mapping todetermine the command toinvoke

    BaseAction is the

    Commerce extension of theStruts Action class

  • 8/21/2019 WSTE Struts Presenation 10-18-07

    8/37

    IBM Software Group

    WebSphereSupport Technical Exchange 8

    Struts Framework: Business Logic Faade

    Maps interface name to

    implementation

    Queries the CMDREG todetermine the appropriateimplementation

    Invokes the appropriatecontroller command

  • 8/21/2019 WSTE Struts Presenation 10-18-07

    9/37

    IBM Software Group

    WebSphereSupport Technical Exchange 9

    Struts Framework: Action Mapping

    Maps a request to a

    command interface or aview

    Includes Commerce specificproperties such as https,

    authenticate, andcredentialsAccepted

    ECActionMapping is theCommerce extension of the

    Struts ActionMapping class

  • 8/21/2019 WSTE Struts Presenation 10-18-07

    10/37

    IBM Software Group

    WebSphereSupport Technical Exchange 10

    Struts Framework: Global Forward

    Maps a request to a JSP

    Includes Commerce specificproperty resourceClassNameindicating a redirect orforward

    ECActionForward is theCommerce extension of theStruts ActionForward class

  • 8/21/2019 WSTE Struts Presenation 10-18-07

    11/37

    IBM Software Group

    WebSphereSupport Technical Exchange 11

    Mapping URLs to Controller Commands

    Action mappings

  • 8/21/2019 WSTE Struts Presenation 10-18-07

    12/37

    IBM Software Group

    WebSphereSupport Technical Exchange 12

    Mapping Views to JSPs

    Action mappings and global forwards

  • 8/21/2019 WSTE Struts Presenation 10-18-07

    13/37

    IBM Software Group

    WebSphereSupport Technical Exchange 13

    Mapping Messaging Views

    Global forwards

  • 8/21/2019 WSTE Struts Presenation 10-18-07

    14/37

    IBM Software Group

    WebSphereSupport Technical Exchange 14

    Customization Points

    ServletFilter

    ECActionServlet

    RequestProcessor

    BaseAction

    1 23

    1 Servlet Filters (such as Runtime Filter and Cache Filter)add processing for all requests

    2 Adds processing for non-cached requests

    3 Adds processing for selective commands

    Web Container

  • 8/21/2019 WSTE Struts Presenation 10-18-07

    15/37

    IBM Software Group

    WebSphereSupport Technical Exchange 15

    Customization: Servlet Filters

    Servlet filters allow you to intercept the request when it first

    enters and before it leaves the Web Container

    Use a servlet filter to perform pre- and post-processingactions on the incoming request or outgoing response objects

    The following servlet filters are provided with WebSphereCommerce:

    RuntimeServletFilter

    CacheFilter

  • 8/21/2019 WSTE Struts Presenation 10-18-07

    16/37

    IBM Software Group

    WebSphereSupport Technical Exchange 16

    Customization: Servlet Filters

    Typical applications of servlet filters:

    Logging and auditing track users and their behaviorusing a web application

    Authentication block requests based on user identity

    Localization target the request and response to aparticular locale

    XML conversion render an XML document to HTMLprior to returning to the caller

  • 8/21/2019 WSTE Struts Presenation 10-18-07

    17/37

    IBM Software Group

    WebSphereSupport Technical Exchange 17

    Customization: Request Processor

    The request processor allows you to execute some business

    logic before an action is executed

    Request processor has access to the Struts config data

    Request processor only processes non-cached requests

    TilesRequestProcessor:

    Extends the Struts RequestProcessor to handle tilesrequests

    Delegates non-tiles requests to the baseRequestProcessor class

  • 8/21/2019 WSTE Struts Presenation 10-18-07

    18/37

    IBM Software Group

    WebSphereSupport Technical Exchange 18

    Customization: Request Processor

    To customize the request processor:

    Extend the RequestProcessor or theTilesRequestProcessor

    Set the value of the processor class property in struts-

    config-ext.xml to your custom class:

    An example customization of the request processor is to forcea secured request into a non-secured request

  • 8/21/2019 WSTE Struts Presenation 10-18-07

    19/37

    IBM Software Group

    WebSphereSupport Technical Exchange 19

    Customization: Base Action

    Last point in the request processing before the request is

    handed over to the controller command

    WebSphere Commerce provides two extensions of the StrutsAction class

    BaseActionAjaxAction - used for AJAX style requests

    Customize the BaseAction or the AjaxAction classes, if you

    need to execute some business logic for a specific group ofcommands

  • 8/21/2019 WSTE Struts Presenation 10-18-07

    20/37

    IBM Software Group

    WebSphereSupport Technical Exchange 20

    Customization: Base Action

    To customize the base Action:

    Create a custom class extending BaseAction/AjaxActionand add functionality to the preProcess and thepostProcess methods

    Update the action mapping with the new class

    The Extending a Struts action tutorial provides an exampleof how to customize the BaseAction class in order to trackthe referral URL

  • 8/21/2019 WSTE Struts Presenation 10-18-07

    21/37

    IBM Software Group

    WebSphereSupport Technical Exchange 21

    Customization: Struts Validator

    Removes extensive parameter checking from the commands

    Makes use of ActionForms

    To use the Struts Validator:

    Add the Validator plug-in to the struts-config-ext.xml:

    Configure your action to use validation:

  • 8/21/2019 WSTE Struts Presenation 10-18-07

    22/37

    IBM Software Group

    WebSphereSupport Technical Exchange 22

    Customization: Struts Validator

    Define rules in validation.xml:

    Define message resources in struts-config-ext.xml:

    Define messages in storeErrorMessages properties:

  • 8/21/2019 WSTE Struts Presenation 10-18-07

    23/37

    IBM Software Group

    WebSphereSupport Technical Exchange 23

    Customization: Tiles

    Separate content from layout, reduce redundancy

    Alternative to the JSP include mechanism

    Tiles is a template-based, Struts custom tag library

    To enable the use of Tiles:Add the Tiles plug-in to the struts-config-ext.xml:

    Define the tiles tag library at the top of a JSP:

  • 8/21/2019 WSTE Struts Presenation 10-18-07

    24/37

    IBM Software Group

    WebSphereSupport Technical Exchange 24

    Customization: Tiles

    tiles-defs.xml

    struts-config-ext.xml

  • 8/21/2019 WSTE Struts Presenation 10-18-07

    25/37

    IBM Software Group

    WebSphereSupport Technical Exchange 25

    Common Pitfalls: Tiles definition

    Problem:

    Added tiles support to struts-config.xml, and definitionsin tiles-defs.xml, and although tiles plugin is loaded,the tiles themselves are not processed

    Cause:

    ECActionServlet changes the base implementation oftiles in struts

    Solution:

    The store identifier must be prepended to the storeidentifier name.

  • 8/21/2019 WSTE Struts Presenation 10-18-07

    26/37

    IBM Software Group

    WebSphereSupport Technical Exchange 26

    Common Pitfalls: struts-config XMLs

    Problem:

    You have custom struts definitions but are not surewhere to put them

    Solution:

    Order of loading for struts config files is in the web.xml

    of the module:

    The last configuration loaded is the one used

    com.ibm.commerce.struts.ECActionServletconfig/WEB-INF/struts-config.xml,/WEB-INF/struts-config-migrate.xml,/WEB-INF/struts-config-ext.xml

  • 8/21/2019 WSTE Struts Presenation 10-18-07

    27/37

    IBM Software Group

    WebSphereSupport Technical Exchange 27

    Common Pitfalls: Scheduler/Messaging

    Problem:

    Custom action mapping is not found by a scheduler ormessaging command

    The original action mapping is used instead

    Cause:

    Request from Web channel is evaluated differently thanone invoked by messaging or the scheduler

    Configuration is read in order the web modules areloaded, which may not be consistent

    Solution:

    Remove duplicate mappings in all other modules

    Or apply APAR LI72530

  • 8/21/2019 WSTE Struts Presenation 10-18-07

    28/37

    IBM Software Group

    WebSphereSupport Technical Exchange 28

    Common Pitfalls: URL forced to https

    Problem:

    Every time a particular view is executed, it forces theURL to HTTPS, but you want it to be accessedthrough HTTP

    Cause:

    The view is only defined with https enabled for thatstoreId, or only a site definition with https enabled

    Solution:

    Explicitly set the https property to 0 for the storeId:

  • 8/21/2019 WSTE Struts Presenation 10-18-07

    29/37

    IBM Software Group

    WebSphereSupport Technical Exchange 29

    Common Pitfalls: Adding Authentication

    Problem:

    Views with the 'authenticate flag set to true do notrender correctly, result in Generic Error page

    Cause:

    Guest user hits a page that requires authentication,

    CatalogDataBean fails on LogonForm pageRuntime authentication redirects the user to LogonForm

    URL using only the storeId and URL parameter, missingdue to missing catalog_id parameter

    Solution:Modify the LogonForm JSP so that when authenticated

    feature is used, it retrieves catalogId from the next URLrather than request properties

  • 8/21/2019 WSTE Struts Presenation 10-18-07

    30/37

    IBM Software Group

    WebSphereSupport Technical Exchange 30

    Common Pitfalls: Partial Credentials

    Problem:

    With persistent sessions, a user who is partiallyauthenticated (or Remembered) cannot accessrestricted views

    Cause:

    The default credentials accepted for a view is set to R,partially authenticated

    Solution:

    Update the credentialsAccepted property in the action

    mappings for the view and set it to P to accept partiallyauthenticated users, not just registered ones

  • 8/21/2019 WSTE Struts Presenation 10-18-07

    31/37

    IBM Software Group

    WebSphereSupport Technical Exchange 31

    Common Pitfalls: Web-Services

    Problem:

    Defined a web service response JSP (action mappingand global forward in the struts-config-ext.xml), butresponse is never received

    Cause:

    Web service definitions are in struts-wc-webservices.xml

    Definitions in any other struts xml files will not beregistered when a web service is executed

    Solution:

    Define the action mappings and global forwards for webservices in the struts-wc-webservices.xml

  • 8/21/2019 WSTE Struts Presenation 10-18-07

    32/37

    IBM Software Group

    WebSphereSupport Technical Exchange 32

    Common Pitfalls: Store Publish

    Problem:

    Publishing custom store archive (SAR) fails with:

    The store archive is not compatible with STRUTS.Migrate this store archive to STRUTS before publishing."

    Cause :

    A pre-6.0 SAR contains used VIEWREG and URLREG,and have no information for the struts configuration files

    Solution:

    You need to include struts configuration information inthe SAR prior to publishing it

    Refer to the InfoCenter document for full details,Updating the Web application configuration

  • 8/21/2019 WSTE Struts Presenation 10-18-07

    33/37

    IBM Software Group

    WebSphereSupport Technical Exchange 33

    Must Gather: Struts

    Trace components:

    com.ibm.websphere.commerce.WC_SERVER=all

    org.apache.struts.*=all

    /WEB-INF/web.xml

    /WEB-INF/struts-config*.xml For action forms and validation:

    /WEB-INF/validator-rules.xml,/WEB-INF/validation.xml

    For tiles:

    /WEB-INF/tiles-defs.xml

    IBM S ft G

  • 8/21/2019 WSTE Struts Presenation 10-18-07

    34/37

    IBM Software Group

    WebSphereSupport Technical Exchange 34

    Summary

    Implement MVC architecture with Struts framework

    Web request processing flow:

    Servlet Filter any cached or non-cached request

    ActionServlet routes request to appropriate module

    RequestProcessor determines action based on configBaseAction - bridges incoming request to business logic

    Business Logic Faade invokes controller command

    Represent views and URL mappings with global-forwards andaction-mappings within the module-specific struts config XMLs

    IBM S ft G

  • 8/21/2019 WSTE Struts Presenation 10-18-07

    35/37

    IBM Software Group

    WebSphereSupport Technical Exchange 35

    References

    Apache Struts:http://struts.apache.org/

    MustGather: WebSphere Commerce Struts framework problemshttp://www-1.ibm.com/support/docview.wss?uid=swg21257367

    WebSphere Commerce Struts Framework http://publib.boulder.ibm.com/infocenter/wchelp/v6r0m0/index.jsp?to

    pic=/com.ibm.commerce.developer.doc/concepts/csdstrutskeycompons.htm

    Struts Tutorials: http://publib.boulder.ibm.com/infocenter/wchelp/v6r0m0/index.jsp?to

    pic=/com.ibm.commerce.developer.tutorial.doc/tutorial/ttdstrutsview-intro.htm

    http://publib.boulder.ibm.com/infocenter/wchelp/v6r0m0/index.jsp?topic=/com.ibm.commerce.developer.tutorial.doc/tutorial/ttdstrutsaction-intro.htm

    IBM Software Group

  • 8/21/2019 WSTE Struts Presenation 10-18-07

    36/37

    IBM Software Group

    WebSphereSupport Technical Exchange 36

    Additional WebSphere Product Resources Discover the latest trends in WebSphere Technology and implementation, participate in

    technically-focused briefings, webcasts and podcasts at:http://www.ibm.com/developerworks/websphere/community/

    Learn about other upcoming webcasts, conferences and events:http://www.ibm.com/software/websphere/events_1.html

    Join the Global WebSphere User Group Community: http://www.websphere.org

    Access key product show-me demos and tutorials by visiting IBM Education Assistant:http://www.ibm.com/software/info/education/assistant

    View a Flash replay with step-by-step instructions for using the Electronic ServiceRequest (ESR) tool for submitting problems electronically:http://www.ibm.com/software/websphere/support/d2w.html

    Sign up to receive weekly technical My support emails:http://www.ibm.com/software/support/einfo.html

    IBM Software Group

  • 8/21/2019 WSTE Struts Presenation 10-18-07

    37/37

    IBM Software Group

    WebSphereSupport Technical Exchange 37

    Questions and Answers