Java Enterprise Best Practices 1 O’Reilly – Java Enterprise Best Practices 2

Total Page:16

File Type:pdf, Size:1020Kb

Java Enterprise Best Practices 1 O’Reilly – Java Enterprise Best Practices 2 O’Reilly – Java Enterprise Best Practices 1 O’Reilly – Java Enterprise Best Practices 2 Table of Contents Preface ............................................................................................................................................................. 5 Audience .................................................................................................................................................. 5 Organization ............................................................................................................................................ 5 Conventions Used in This Book............................................................................................................ 7 How to Contact Us.................................................................................................................................. 8 Acknowledgments................................................................................................................................... 9 Chapter 1. Introduction to Java Enterprise Best Practices................................................................... 11 1.1 How Does a Best Practice Come About?................................................................................. 11 1.2 Can Best Practices Be Arguable? ............................................................................................. 13 1.3 What's in This Book? ................................................................................................................... 14 1.4 About the Practices Themselves................................................................................................ 15 1.5 Enterprise Java Programming Resources Online................................................................... 16 Chapter 2. EJB Best Practices ................................................................................................................. 18 2.1 Design............................................................................................................................................ 18 2.2 Implementation............................................................................................................................. 25 2.3 Deployment and Packaging ....................................................................................................... 44 Chapter 3. Servlet Best Practices ............................................................................................................ 46 3.1 Working Effectively with Servlets ............................................................................................... 46 3.2 Caching with Servlets .................................................................................................................. 67 3.3 Other Servlet Tips......................................................................................................................... 72 Chapter 4. JDBC Best Practices .............................................................................................................. 75 4.1 Configuration ................................................................................................................................ 75 4.2 Design............................................................................................................................................ 80 4.3 Code............................................................................................................................................... 92 4.4 General Database.................................................................................................................... 102 Chapter 5. XML Best Practices............................................................................................................. 105 5.1 XML Authoring .......................................................................................................................... 105 .2 SAX .............................................................................................................................................. 111 5.3 DOM........................................................................................................................................... 118 5.4 JAXP .......................................................................................................................................... 128 Chapter 6. RMI Best Practices ............................................................................................................. 132 6.1 Marshalling and Unmarshalling Objects ............................................................................... 132 6.2 Making Applications More Robust ......................................................................................... 147 6.3 Improving Application Performance....................................................................................... 162 6.4 Further Reading........................................................................................................................ 171 Chapter 7. Java Management Extensions.......................................................................................... 173 7.1 Naming ...................................................................................................................................... 173 7.2 Instrumentation......................................................................................................................... 176 Chapter 8. Enterprise Internationalization........................................................................................... 203 8.1 Internationalization and Localization..................................................................................... 204 8.2 Presentation Layer................................................................................................................... 205 8.3 Business Object Layer............................................................................................................. 221 8.4 Data Access Layer ................................................................................................................... 227 O’Reilly – Java Enterprise Best Practices 3 Chapter 9. JSP Best Practices ............................................................................................................. 233 9.1 Appropriate Usage of JSP in an Enterprise Application..................................................... 233 9.2 Page Design ............................................................................................................................. 237 9.3 Caching ..................................................................................................................................... 246 9.4 Error Handling........................................................................................................................... 252 9.5 Custom Component Development ........................................................................................ 255 9.6 Deployment............................................................................................................................... 264 Chapter 10. JavaMail Best Practices................................................................................................... 266 10.1 Understanding Enterprise Email.......................................................................................... 267 10.2 Sending Email ........................................................................................................................ 268 10.3 Email for System Integration................................................................................................ 276 10.4 Performance Optimization.................................................................................................... 287 Chapter 11. Enterprise Performance Tuning Best Practices............................................................ 292 11.1 Performance Planning ........................................................................................................... 292 11.2 The Performance Environment ............................................................................................ 294 11.3 Proactive Performance Management in Production ......................................................... 298 11.4 Efficient Distributed Computing Architecture ..................................................................... 301 11.5 Tuning Procedure................................................................................................................... 303 11.6 User Perceptions.................................................................................................................... 304 11.7 Tuning Techniques ................................................................................................................. 305 11.8 Miscellaneous Best Practices............................................................................................... 307 Chapter 12. List of Contributors............................................................................................................ 310 O’Reilly – Java Enterprise Best Practices 4 Copyright © 2003 O'Reilly & Associates, Inc. Printed in the United States of America. Published by O'Reilly & Associates, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O'Reilly & Associates books may be purchased for educational, business, or sales promotional use.
Recommended publications
  • Red Hat AMQ 6.1 Jboss A-MQ for Xpaas Release Notes
    Red Hat JBoss A-MQ 6.1 JBoss A-MQ for xPaaS Release Notes What's new in Red Hat JBoss A-MQ for xPaaS Last Updated: 2017-10-13 Red Hat JBoss A-MQ 6.1 JBoss A-MQ for xPaaS Release Notes What's new in Red Hat JBoss A-MQ for xPaaS JBoss A-MQ Docs Team Content Services [email protected] Legal Notice Copyright © 2014 Red Hat. The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/ . In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must provide the URL for the original version. Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law. Red Hat, Red Hat Enterprise Linux, the Shadowman logo, JBoss, OpenShift, Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries. Linux ® is the registered trademark of Linus Torvalds in the United States and other countries. Java ® is a registered trademark of Oracle and/or its affiliates. XFS ® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries. MySQL ® is a registered trademark of MySQL AB in the United States, the European Union and other countries.
    [Show full text]
  • Framework-Specific Modeling Languages
    Framework-Specific Modeling Languages by MichalAntkiewicz A thesis presented to the University of Waterloo in fulfillment of the thesis requirement for the degree of Doctor of Philosophy in Electrical and Computer Engineering Waterloo, Ontario, Canada, 2008 c Micha lAntkiewicz 2008 ISBN: 978-0-494-43232-7 I hereby declare that I am the sole author of this thesis. This is a true copy of the thesis, including any required final revisions, as accepted by my examiners. I understand that my thesis may be made electronically available to the public. Micha lAntkiewicz ii Abstract Framework-specific modeling languages (FSMLs) help developers build applications based on object-oriented frameworks. FSMLs formalize abstractions and rules of the framework's application programming interfaces (APIs) and can express models of how applications use an API. Such models, referred to as framework-specific models, aid developers in understanding, creating, and evolving application code. We present the concept of FSMLs, propose a way of specifying their abstract syntax and semantics, and show how such language specifications can be interpreted to provide reverse, forward, and round-trip engineering of framework-specific mod- els and framework-based application code. We present a method for engineering FSMLs that was extracted post-mortem from the experience of building four such languages. The method is driven by the use cases that the FSMLs under development are to support. We present the use cases, the overall process, and its instantiation for each language. The presenta- tion focuses on providing concrete examples for engineering steps, outcomes, and challenges. It also provides strategies for making engineering decisions.
    [Show full text]
  • 2Nd USENIX Conference on Web Application Development (Webapps ’11)
    conference proceedings Proceedings of the 2nd USENIX Conference Application on Web Development 2nd USENIX Conference on Web Application Development (WebApps ’11) Portland, OR, USA Portland, OR, USA June 15–16, 2011 Sponsored by June 15–16, 2011 © 2011 by The USENIX Association All Rights Reserved This volume is published as a collective work. Rights to individual papers remain with the author or the author’s employer. Permission is granted for the noncommercial reproduction of the complete work for educational or research purposes. Permission is granted to print, primarily for one person’s exclusive use, a single copy of these Proceedings. USENIX acknowledges all trademarks herein. ISBN 978-931971-86-7 USENIX Association Proceedings of the 2nd USENIX Conference on Web Application Development June 15–16, 2011 Portland, OR, USA Conference Organizers Program Chair Armando Fox, University of California, Berkeley Program Committee Adam Barth, Google Inc. Abdur Chowdhury, Twitter Jon Howell, Microsoft Research Collin Jackson, Carnegie Mellon University Bobby Johnson, Facebook Emre Kıcıman, Microsoft Research Michael E. Maximilien, IBM Research Owen O’Malley, Yahoo! Research John Ousterhout, Stanford University Swami Sivasubramanian, Amazon Web Services Geoffrey M. Voelker, University of California, San Diego Nickolai Zeldovich, Massachusetts Institute of Technology The USENIX Association Staff WebApps ’11: 2nd USENIX Conference on Web Application Development June 15–16, 2011 Portland, OR, USA Message from the Program Chair . v Wednesday, June 15 10:30–Noon GuardRails: A Data-Centric Web Application Security Framework . 1 Jonathan Burket, Patrick Mutchler, Michael Weaver, Muzzammil Zaveri, and David Evans, University of Virginia PHP Aspis: Using Partial Taint Tracking to Protect Against Injection Attacks .
    [Show full text]
  • Java- EE Web Application Development with Apache Struts 1
    +91-9791 044 044 Java- EE Web Application Development with Apache Struts 1 Duration:60 HOURS | Price: INR 7000 SAVE NOW! INR 6000 until December 1, 2011 Students Will Learn • Java EE Web Application Architecture • Servlets and JSPs • NDI, RMI, & JDBC • JMS (Java Messaging Service) • Developing Struts Applications • Developing a Struts Controller • Developing a Struts View Course Description: This hands-on course provides participants with the knowledge and experience necessary to develop and deploy large, robust and complex Java web applications utilizing the Apache Struts 1 framework. The Apache Software Foundation has provided numerous open-source tools, which set the standard for web application development. These include the Apache web server and the Tomcat Servlet Container. Apache Struts 1 provides a flexible controller layer for JSP-based applications, with significant facilites for validation, internationalization and page layout. Struts is an implementation of the Model-View-Controller (MVC) pattern, a recommended architectural design pattern for interactive applications. The Struts controller is based on standardized technologies including Servlets, JSP Pages, Tag libraries, JavaBeans and XML. Students will learn how to use the Struts framework to write, assemble, configure and deploy complex web applications. This course covers architectural design issues as well as specific coding models for Java EE components, and is up to date with the latest Java EE 5, JSP 2.1 and Servlet 2.5 specifications. Security, transaction management, inter-component communication and deployment issues are discussed in detail, with hands-on labs to solidify understanding. Since coding and deployment files are standardized by the Jave EE specifications, students may readily apply the skills learned in this class to write code for any compliant server, including Apache Tomcat, JBoss, WebSphere, Oracle, WebLogic and many others.
    [Show full text]
  • Open Source Licenses Applicable to Hitachi's Products Earlier Versions
    Open Source Licenses Applicable to Hitachi’s Products EARLIER VERSIONS Several products are listed below together with certain open source licenses applicable to the particular product. The open source software licenses are included at the end of this document. If the open source package has been modified, an asterisk (*) appears next to the name of the package. Note that the source code for packages licensed under the GNU General Public License or similar type of license that requires the licensor to make the source code publicly available (“GPL Software”) may be available for download as indicated below. If the source code for GPL Software is not included in the software or available for download, please send requests for source code for GPL Software to the contact person listed for the applicable product. The materials below are provided “AS IS,” without warranty of any kind, including, but not limited to, the implied warranties of merchantability, fitness for a particular purpose, and non-infringement. Access to this material grants you no right or license, express or implied, statutorily or otherwise, under any patent, trade secret, copyright, or any other intellectual property right of Hitachi Vantara Corporation (“Hitachi”). Hitachi reserves the right to change any material in this document, and any information and products on which this material is based, at any time, without notice. Hitachi shall have no responsibility or liability to any person or entity with respect to any damages, losses, or costs arising from the materials
    [Show full text]
  • Proceedings of the IEEE Visweek Workshop on Visual Analytics in Healthcare: Understanding the Physicians Perspective
    Proceedings of the IEEE VisWeek Workshop on Visual Analytics in Healthcare: Understanding the Physicians Perspective October 23rd, 2011 Providence, RI www.visualanalyticshealthcare.org Sponsors: ! Preface Visualization and visual analytics show great potential as methods to analyze, filter, and illustrate many of the diverse data used in clinical practice. Today, (a) physicians and clinical practitioners are faced with the challenging task of analyzing large amount of unstructured, multi-modal, and longitudinal data to effectively diagnose and monitor the progression of a particular disease; (b) patients are confronted with the difficult task of understanding the correlations between many clinical values relevant to their health; and (c) healthcare organizations are faced with the problem of improving the overall operational efficiency and performance of the institution while maintaining the quality of patient care and safety. Visualization and visual analytics can potentially provide great benefits to each of these three core areas of healthcare. However, to be successful, the resulting visualization must be able to meet the physician’s requirements and be useful for both patients and physicians. Despite the continuous use of scientific visualization and visual analytics in medical applications, the lack of communication between engineers and physicians has meant that only basic visualization and analytics techniques are currently employed in clinical practice. The goal of this workshop is to gather together leading physicians and clinical practitioners to share with the visualization community their need for specific visualization tools and discuss the areas in healthcare where additional visualization techniques are needed. Jesus J Caban, NICoE / Naval Medical Center CC / National Institutes of Health David Gotz IBM Research 3 ! 4 Invited Speakers Dr.
    [Show full text]
  • Automatic Method for Testing Struts-Based Application
    AUTOMATIC METHOD FOR TESTING STRUTS-BASED APPLICATION A Paper Submitted to the Graduate Faculty of the North Dakota State University of Agriculture and Applied Science By Shweta Tiwari In Partial Fulfillment for the Degree of MASTER OF SCIENCE Major Department: Computer Science March 2013 Fargo, North Dakota North Dakota State University Graduate School Title Automatic Method For Testing Strut Based Application By Shweta Tiwari The Supervisory Committee certifies that this disquisition complies with North Dakota State University’s regulations and meets the accepted standards for the degree of MASTER OF SCIENCE SUPERVISORY COMMITTEE: Kendall Nygard Chair Kenneth Magel Fred Riggins Approved: 4/4/2013 Brian Slator Date Department Chair ABSTRACT Model based testing is a very popular and widely used in industry and academia. There are many tools developed to support model based development and testing, however, the benefits of model based testing requires tools that can automate the testing process. The paper propose an automatic method for model-based testing to test the web application created using Strut based frameworks and an effort to further reduce the level of human intervention require to create a state based model and test the application taking into account that all the test coverage criteria are met. A methodology is implemented to test applications developed with strut based framework by creating a real-time online shopping web application and using the test coverage criteria along with automated testing tool. This implementation will demonstrate feasibility of the proposed method. iii ACKNOWLEDGEMENTS I would like to sincerely thank Dr. Kendall Nygard, Dr. Tariq M. King for the support and direction.
    [Show full text]
  • Dynamické Generovaní Obsahu S Java Server Pages
    MASARYKOVA UNIVERZITA F}w¡¢£¤¥¦§¨ AKULTA INFORMATIKY !"#$%&'()+,-./012345<yA| Dynamické generovaní obsahu s Java Server Pages BAKALÁRSKÁˇ PRÁCE Petr Lorenc Brno, podzim 2007 Prohlášení Prohlašuji, že tato bakaláˇrskápráce je mým p ˚uvodnímautorským dílem, které jsem vypra- coval samostatnˇe.Všechny zdroje, prameny a literaturu, které jsem pˇrivypracování použí- val nebo z nich ˇcerpal,v práci ˇrádnˇecituji s uvedením úplného odkazu na pˇríslušnýzdroj. Vedoucí práce: RNDr. Vlastislav Dohnal, Ph.D. ii Shrnutí Tato bakaláˇrskápráce provádí ˇctenáˇrevznikem webové aplikace. Ta je vystavˇenana plat- formˇeJava, konkrétnˇena technologiích JavaServlets a Java Server Pages. Umožˇnujedyna- mické generování obsahu uloženého v databázi MySQL. Architektura aplikace ctí návrhový vzor Model-Pohled-Rídícíˇ ˇcást.Model aplikace reprezentují JavaBean komponenty, pohled tvoˇríJSP stránky a ˇrídícíˇcástzastupují servlety. V prvních ˇctyˇrechkapitolách je probrána teorie užitá ve webové aplikaci spolu s vysvˇet- lením pojm ˚usouvisejících s danou problematikou. Pátá kapitola, spolu se zdrojovým kó- dem webové aplikace, tvoˇrínávod, demonstrující použití výše popsaných teoretických po- znatk ˚u,kvytvoˇreníwebové aplikace. Tato ukázková webová aplikace má ˇctyˇriverze. První je obdoba aplikace „Ahoj Svˇete!“, následující didakticky pˇridávajídalší funkˇcníprvky s tím, že poslední verze je již principiálnˇeplnohodnotnou webovou aplikací nabízející dynamické generování obsahu díky propojení s databází MySQL. Využívá se zde nástroj ˚utechnologie JSP nabízejících zefektivnˇenípráce pˇrivývoji webových stránek, jako napˇr.JSTL, Expression Language, JSP direktivy a akce. Vyústˇenímtohoto návodu je pak webová aplikace LogoArena.cz. Tato je, co do množ- ství zdrojového kódu, rozsáhlejší, nicménˇes pˇredešlouukázkovou aplikací naprosto rovno- cenná, bere-li se jako mˇeˇrítkonávrh architektury a použité technologie. Aplikace LogoArena.cz má již ambice reálného nasazení na web. Jedná se o internetový obchod s mobilním obsahem, jakým jsou napˇríkladobrázky ˇcianimace.
    [Show full text]
  • Google App Engine Paas Cloud Computing
    GOOGLE APP ENGINE PAAS CLOUD COMPUTING Google App Engine lets developers build scalable web and mobile backends in Services Ecosystem: Tap a growing ecosystem of GCP services from your app . Google cloud computing platform fees Google has set up Google App Engine to encourage its wide adoption. App Engine also features a dedicated Python runtime environment, which includes a fast Python interpreter and the Python standard library. A Web-based administration console: The console helps developers manage their applications. Core to this is the servlet 2. Ruby and C [6] are only available in the flexible environment. Each of these applications can use up to MB of storage, up to 5 million page views each month without an additional fee. No method for bulk downloading data from GAE using Java currently exists. App Engine packages those building blocks and provides access to scalable infrastructure that we hope will make it easier for developers to scale their applications automatically as they grow. Docker containerized applications can run on many types of infrastructure, such as Amazon Web Services , Microsoft Azure , and others. Restrictions[ edit ] Developers have read-only access to the filesystem on App Engine. Programming interfaces to support authenticating users and sending email by using Google Accounts Scheduled tasks for triggering events at specified times and regular intervals This is essentially the same platform that Google uses to build its own software. Apache Struts 1 is supported, and Struts 2 runs with workarounds. As with most cloud-hosting services, with App Engine, you only pay for what you use. Web2py web framework offers migration between SQL Databases and Google App Engine, however it doesn't support several App Engine-specific features such as transactions and namespaces.
    [Show full text]
  • An Analysis of CSRF Defenses in Web Frameworks
    Where We Stand (or Fall): An Analysis of CSRF Defenses in Web Frameworks Xhelal Likaj Soheil Khodayari Giancarlo Pellegrino Saarland University CISPA Helmholtz Center for CISPA Helmholtz Center for Saarbruecken, Germany Information Security Information Security [email protected] Saarbruecken, Germany Saarbruecken, Germany [email protected] [email protected] Abstract Keywords Cross-Site Request Forgery (CSRF) is among the oldest web vul- CSRF, Defenses, Web Frameworks nerabilities that, despite its popularity and severity, it is still an ACM Reference Format: understudied security problem. In this paper, we undertake one Xhelal Likaj, Soheil Khodayari, and Giancarlo Pellegrino. 2021. Where We of the first security evaluations of CSRF defense as implemented Stand (or Fall): An Analysis of CSRF Defenses in Web Frameworks. In by popular web frameworks, with the overarching goal to identify Proceedings of ACM Conference (Conference’17). ACM, New York, NY, USA, additional explanations to the occurrences of such an old vulner- 16 pages. https://doi.org/10.1145/nnnnnnn.nnnnnnn ability. Starting from a review of existing literature, we identify 16 CSRF defenses and 18 potential threats agains them. Then, we 1 Introduction evaluate the source code of the 44 most popular web frameworks Cross-Site Request Forgery (CSRF) is among the oldest web vul- across five languages (i.e., JavaScript, Python, Java, PHP, andC#) nerabilities, consistently ranked as one of the top ten threats to covering about 5.5 million LoCs, intending to determine the imple- web applications [88]. Successful CSRF exploitations could cause re- mented defenses and their exposure to the identified threats. We mote code execution [111], user accounts take-over [85, 87, 90, 122], also quantify the quality of web frameworks’ documentation, look- or compromise of database integrity—to name only a few in- ing for incomplete, misleading, or insufficient information required stances.
    [Show full text]
  • JSOC INSIGHT Vol.8 English Edition(PDF 1.0MB)
    vol.8 October 14, 2015 JSOC Analysis Team JSOC INSIGHT Vol.8 Introduction ................................................................................................................................................. 2 Section 1 Summary of Trends from January to March 2015 ................................................................... 3 1 Summary of trends from January to March 2015 ........................................................................ 3 2 Trends of Severe Incident in JSOC ............................................................................................... 4 2.1 Trends in severe incidents ............................................................................................................................ 4 2.2 Analysis of severe incidents ......................................................................................................................... 5 2.3 Attacking traffic from the Internet that has been detected many times ........................................................... 6 3 Topics of This Volume .................................................................................................................... 8 3.1 Code execution vulnerability in the JBoss Application Server........................................................................ 8 3.1.1 Detected attacks against the JBoss Application Server .......................................................................... 8 3.1.2 Testing the attacking code that exploits the JBoss Application Server vulnerability
    [Show full text]
  • Open Source Software Packages
    Hitachi Content Platform Core Software 5.1 Open Source Software Packages Contact information: Project Manager Hitachi Content Platform Hitachi Vantara Corporation 2535 Augustine Drive Santa Clara, California 95054 Name of Web site License Package Airspeed http://dev.sanityinc.com/airspeed BSD, Two Clause Apache Commons http://commons.apache.org/beanutils Apache License Version 2.0 beanutils Apache http://commons.apache.org/collections Apache License Version 2.0 Commons collections Apache commons http://commons.apache.org/jxpath Apache License Version 2.0 jxpath Apache http://commons.apache.org/cli Apache License Version 2.0 Commons CLI Apache http://commons.apache.org/codec/ Apache License Version 2.0 Commons Codec Apache http://commons.apache.org/compress/ Apache License Version 2.0 Commons Compress Apache http://commons.apache.org/lang/ Apache License Version 2.0 Commons Lang Apache http://hc.apache.org/httpclient-3.x/ Apache License Version 2.0 Commons HttpClient Apache Directory http://directory.apache.org/ Apache License Version 2.0 Server Apache Struts 1 http://struts.apache.org/2.x/index.html Apache License Version 2.0 Apache Struts 2 http://struts.apache.org/2.x/index.html Apache License Version 2.0 Apache Velocity http://velocity.apache.org/ Apache License Version 2.0 BeautifulSoup http://www.crummy.corn/software/BeautifulSoup/ PSF Bouncy Castle http://www.bouncycastle.org Bouncycastle License Crypto APIs Cheetah http://www.cheetahtemplate.org/ MIT Cjkcodecs http://cjkpython.i18n.org/ BSD, Two Clause Code Generation http://cglib.sourceforge.net
    [Show full text]