diff --git a/jonas/.checkstyle b/jonas_4_10/jonas/.checkstyle similarity index 100% rename from jonas/.checkstyle rename to jonas_4_10/jonas/.checkstyle diff --git a/jonas/.checkstyle_eclipse_config b/jonas_4_10/jonas/.checkstyle_eclipse_config similarity index 100% rename from jonas/.checkstyle_eclipse_config rename to jonas_4_10/jonas/.checkstyle_eclipse_config diff --git a/jonas/.classpath b/jonas_4_10/jonas/.classpath similarity index 100% rename from jonas/.classpath rename to jonas_4_10/jonas/.classpath diff --git a/jonas_4_10/jonas/.cvsignore b/jonas_4_10/jonas/.cvsignore new file mode 100644 index 0000000000000000000000000000000000000000..7786cc6e79bf7690cc12643dcc978157b5495b8d --- /dev/null +++ b/jonas_4_10/jonas/.cvsignore @@ -0,0 +1,5 @@ +classes +output +output_eclipse +.project +temp diff --git a/jonas_4_10/jonas/.jdis b/jonas_4_10/jonas/.jdis new file mode 100644 index 0000000000000000000000000000000000000000..b353a72391c99da661d2e117dd293a1990a163c2 --- /dev/null +++ b/jonas_4_10/jonas/.jdis @@ -0,0 +1,6 @@ +Note regarding JOnAS J2EE certification: +This is an intermediate build made available for testing purposes. +The code is untested and presumed incompatible with the Java[tm] 2 Platform, +Enterprise Edition (J2EE [tm])" specification. You should not deploy or write +to this code, but instead use the tested and certified J2EE compatible version of +the code that is available at http://jonas.objectweb.org/download. diff --git a/jonas/.project b/jonas_4_10/jonas/.project similarity index 100% rename from jonas/.project rename to jonas_4_10/jonas/.project diff --git a/jonas_4_10/jonas/LicenceAgreement.txt b/jonas_4_10/jonas/LicenceAgreement.txt new file mode 100644 index 0000000000000000000000000000000000000000..678c6921d59838dd7d9240be016e05f877d261f1 --- /dev/null +++ b/jonas_4_10/jonas/LicenceAgreement.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! + + diff --git a/jonas_4_10/jonas/README b/jonas_4_10/jonas/README new file mode 100644 index 0000000000000000000000000000000000000000..fcc6b4f87b0578232b020366d9cd352a6fdabacf --- /dev/null +++ b/jonas_4_10/jonas/README @@ -0,0 +1,39 @@ + + ==================== + How to compile JOnAS + ==================== + + +This is the content of the "How to compile JOnAS" Guide which is also available +in the JOnAS documentation at http://jonas.objectweb.org/doc. + + +1) Recompiling JOnAS from sources Using Ant +----------------------------------------------- + + 1. Download latest Ant from http://ant.apache.org. + You will find the build.xml file used for building JOnAS in + jonas directory. + + 2. You must have configure the JDK and ANT successfully. + (JAVA_HOME, ANT_HOME, PATH environment variables) + JOnAS 4.X requires a JDK 1.4.X + + 3. Set the following environment variables with the correct value: + JONAS_ROOT (mandatory) + JETTY_HOME (jetty 5.x) or CATALINA_HOME (tomcat 5.x) + + 4. build.properties file may be customized to set debug to on/off + and set the mapper to use for MEJB. + + 5. Run in this directory : + $ ant install # to build JOnAS + or + $ ant install_tomcat # to build JOnAS-Tomcat + or + $ ant install_jetty # to build JOnAS-Jetty + + +The result of the build will be equivalent to a binary distribution and will +be installed under JONAS_ROOT. + diff --git a/jonas_4_10/jonas/README.J2EE b/jonas_4_10/jonas/README.J2EE new file mode 100644 index 0000000000000000000000000000000000000000..e46800d8d985fcddd2ad1aaf0ec2d98ef469522e --- /dev/null +++ b/jonas_4_10/jonas/README.J2EE @@ -0,0 +1,12 @@ +This version of JOnAS source code is made available in support of the open source +development process. Some numbered or tagged revisions of this source have been +tested and found to pass the Java[TM] 2 Platform, Enterprise Edition (J2EE[TM]) +Compatibility Test Suite, and you can find information on which revisions or tags +at http://jonas.objectweb.org/download. Please note that since only binaries can be +tested, source code cannot be described as a compatible implementation of the J2EE +Specification. The different build environment on your machine and any changes you +may make to this code could render your resulting build incompatible. Because of this, +writing or deploying applications to builds based on this code can lead to lack of +portability. You should instead consider deploying production applications on the +pre-built binaries of JOnAS that are available at http://jonas.objectweb.org/download +that have been tested and certified to meet the J2EE compatibility requirements. diff --git a/jonas/ReleaseNotes.txt b/jonas_4_10/jonas/ReleaseNotes.txt similarity index 100% rename from jonas/ReleaseNotes.txt rename to jonas_4_10/jonas/ReleaseNotes.txt diff --git a/jonas_4_10/jonas/apps/README b/jonas_4_10/jonas/apps/README new file mode 100644 index 0000000000000000000000000000000000000000..63fc8bf9404f1867700bc128c02b3fd867c14534 --- /dev/null +++ b/jonas_4_10/jonas/apps/README @@ -0,0 +1 @@ +This directory contains .ear files diff --git a/jonas_4_10/jonas/apps/autoload/README b/jonas_4_10/jonas/apps/autoload/README new file mode 100644 index 0000000000000000000000000000000000000000..fafa3b953529f669dd82dac34ef7f4aef9136990 --- /dev/null +++ b/jonas_4_10/jonas/apps/autoload/README @@ -0,0 +1 @@ +This directory contains application that will be autodeployed at jonas starting diff --git a/jonas/build-jb.properties b/jonas_4_10/jonas/build-jb.properties similarity index 100% rename from jonas/build-jb.properties rename to jonas_4_10/jonas/build-jb.properties diff --git a/jonas/build-jb.xml b/jonas_4_10/jonas/build-jb.xml similarity index 100% rename from jonas/build-jb.xml rename to jonas_4_10/jonas/build-jb.xml diff --git a/jonas_4_10/jonas/build.dtd b/jonas_4_10/jonas/build.dtd new file mode 100644 index 0000000000000000000000000000000000000000..b5dfb27d35acad8f46ccddb373696f4ac9c0be3f --- /dev/null +++ b/jonas_4_10/jonas/build.dtd @@ -0,0 +1,3934 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jonas/build.properties b/jonas_4_10/jonas/build.properties similarity index 100% rename from jonas/build.properties rename to jonas_4_10/jonas/build.properties diff --git a/jonas/build.xml b/jonas_4_10/jonas/build.xml similarity index 100% rename from jonas/build.xml rename to jonas_4_10/jonas/build.xml diff --git a/jonas_4_10/jonas/clientbuild.xml b/jonas_4_10/jonas/clientbuild.xml new file mode 100644 index 0000000000000000000000000000000000000000..3081ff58ec37949b82236599d60253cda626f0b8 --- /dev/null +++ b/jonas_4_10/jonas/clientbuild.xml @@ -0,0 +1,609 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + JONAS_BASE structure is not initialized properly. + Run ANT create_jonasbase before attempting to create a Win32 Service. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jonas_4_10/jonas/clients/README b/jonas_4_10/jonas/clients/README new file mode 100644 index 0000000000000000000000000000000000000000..6e9e02dd2a0502d9de346df96ccd5b834f345049 --- /dev/null +++ b/jonas_4_10/jonas/clients/README @@ -0,0 +1 @@ +This directory contains .jar client files diff --git a/jonas_4_10/jonas/doc/README b/jonas_4_10/jonas/doc/README new file mode 100644 index 0000000000000000000000000000000000000000..cc76c9081eb26f2bdf8f4a216ba700b0b51f6ecc --- /dev/null +++ b/jonas_4_10/jonas/doc/README @@ -0,0 +1,4 @@ +$Id: $ +The war file come from http://forge.objectweb.org/projects/jonas-doc +This file will be unpacked into JONAS_ROOT/webapps/autoload directory +Version of this file can be found in versions.properties. \ No newline at end of file diff --git a/jonas/doc/jonas-doc-en.war b/jonas_4_10/jonas/doc/jonas-doc-en.war similarity index 100% rename from jonas/doc/jonas-doc-en.war rename to jonas_4_10/jonas/doc/jonas-doc-en.war diff --git a/jonas_4_10/jonas/doc/jonas-emb-javadoc.war b/jonas_4_10/jonas/doc/jonas-emb-javadoc.war new file mode 100644 index 0000000000000000000000000000000000000000..58302dad340f52a8112d349eb515bfc6db1d943f Binary files /dev/null and b/jonas_4_10/jonas/doc/jonas-emb-javadoc.war differ diff --git a/jonas_4_10/jonas/eclipse-settings/checkstyle-convention.xml b/jonas_4_10/jonas/eclipse-settings/checkstyle-convention.xml new file mode 100644 index 0000000000000000000000000000000000000000..24314732bfe69e373f0f2becd7d201a68423fbf9 --- /dev/null +++ b/jonas_4_10/jonas/eclipse-settings/checkstyle-convention.xml @@ -0,0 +1,188 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jonas_4_10/jonas/eclipse-settings/eclipse-java-code-formatter.xml b/jonas_4_10/jonas/eclipse-settings/eclipse-java-code-formatter.xml new file mode 100644 index 0000000000000000000000000000000000000000..8d7be071a084b1c4d92b288b5833f938eed98a3f --- /dev/null +++ b/jonas_4_10/jonas/eclipse-settings/eclipse-java-code-formatter.xml @@ -0,0 +1,181 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jonas_4_10/jonas/eclipse-settings/eclipse-java-codestyle-organize-import b/jonas_4_10/jonas/eclipse-settings/eclipse-java-codestyle-organize-import new file mode 100644 index 0000000000000000000000000000000000000000..1b52f7ec0913065f63e8ddb1795ed3cfd65894c2 --- /dev/null +++ b/jonas_4_10/jonas/eclipse-settings/eclipse-java-codestyle-organize-import @@ -0,0 +1,24 @@ +#Organize Import Order +#Mon Apr 19 08:43:05 CEST 2004 +19=org.objectweb.security +18=org.objectweb.medor +17=org.objectweb.jorm +16=org.objectweb.joram +15=org.objectweb.jonas +14=org.objectweb.jonas_ws +13=org.objectweb.jonas_web +12=org.objectweb.jonas_rar +11=org.objectweb.jonas_jms +10=org.objectweb.jonas_lib +9=org.objectweb.jonas_ejb +8=org.objectweb.jonas_ear +7=org.objectweb.jonas_client +6=org.objectweb.common +5=org.objectweb.carol +4=org.objectweb +3=org.apache +2=org +1=javax +21=com +0=java +20=org.objectweb.util diff --git a/jonas_4_10/jonas/eclipse-settings/jonas-style-convention.xml b/jonas_4_10/jonas/eclipse-settings/jonas-style-convention.xml new file mode 100644 index 0000000000000000000000000000000000000000..8d7be071a084b1c4d92b288b5833f938eed98a3f --- /dev/null +++ b/jonas_4_10/jonas/eclipse-settings/jonas-style-convention.xml @@ -0,0 +1,181 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jonas_4_10/jonas/eclipse-settings/plugin-checkstyle-config.xml b/jonas_4_10/jonas/eclipse-settings/plugin-checkstyle-config.xml new file mode 100644 index 0000000000000000000000000000000000000000..c8e751d12ca16dc1f0d0df691051c68d111f8933 --- /dev/null +++ b/jonas_4_10/jonas/eclipse-settings/plugin-checkstyle-config.xml @@ -0,0 +1,253 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jonas_4_10/jonas/ejbjars/README b/jonas_4_10/jonas/ejbjars/README new file mode 100644 index 0000000000000000000000000000000000000000..0ad601162f2c7c1c597f46abe7d23265054b2b4a --- /dev/null +++ b/jonas_4_10/jonas/ejbjars/README @@ -0,0 +1 @@ +This directory contains .jar files. diff --git a/jonas_4_10/jonas/ejbjars/autoload/README b/jonas_4_10/jonas/ejbjars/autoload/README new file mode 100644 index 0000000000000000000000000000000000000000..f01cda1ffd42df11c4b1fa89e98682fd12663ce0 --- /dev/null +++ b/jonas_4_10/jonas/ejbjars/autoload/README @@ -0,0 +1 @@ +Put here ejb jar files that will be autodeployed at jonas starting. diff --git a/jonas_4_10/jonas/examples/README b/jonas_4_10/jonas/examples/README new file mode 100644 index 0000000000000000000000000000000000000000..c0a33394c1db9ad5daeb8a98244a71d503768f94 --- /dev/null +++ b/jonas_4_10/jonas/examples/README @@ -0,0 +1,48 @@ +Copyright (C) BULL S.A. 1998-2002. + + +There are 4 kind of examples: + + - examples with enterprise java beans accessed from a simple client which + is a java program, (these examples are all on examples/src); + + - examples with enterprise java beans accessed from a servlet + or JSP and packaged in .ear file: + examples/earsample, examples/cmp2, examples/alarm. + + - examples of AXIS use in JOnAS : examples/webservices + + - 1 example of JOnAS application generation via xdoclet. + +There is also the well-known Java Pet Store application. (petstore1.3) + +Before compiling and running these examples, the installation and configuration +of JOnAS have to be done: + + - initialization of the JONAS_ROOT environment variable, + - optionally, initialization of the JONAS_BASE environment variable, + - update of your PATH, + - update of the JOnAS config_env script, + - configuration of JNDI environment via the carol.properties file + - configuration of the database access: + - update of the JOnAS config_env script, + - configuration of JOnAS environment via the jonas.properties file, + - update of the .properties file. + - configuration of Tomcat for JOnAS. + +Refer to install documentation for more information. + + + +Compiling these examples: +------------------------ + Use the Ant 1.5 build tool in one of the directories where there is a build.xml file. + + You may have to modify $JONAS_ROOT/examples/build.properties + + The default "install" target allows to build the examples and copy the built ejb-jar + file in your JOnAS_BASE/ejbjars directory. + + Example: + export JONAS_ROOT= + cd $JONAS_ROOT/examples; ant install diff --git a/jonas_4_10/jonas/examples/alarm/README b/jonas_4_10/jonas/examples/alarm/README new file mode 100644 index 0000000000000000000000000000000000000000..833a46da431d95186c70284eb6731a5e4fb3e4fa --- /dev/null +++ b/jonas_4_10/jonas/examples/alarm/README @@ -0,0 +1,79 @@ +Application Overview: +-------------------- +This application watch alarm messages generated asynchronously via +JMS. It involves the different technics used in JOnAS: +- Entity Bean for AlarmRecord, persistent in a DataBase +- Session Bean to allow clients to visualize alarm received +- Message Driven Bean to catch Alarms +- JMS to use a topic where Alarms are sent and received +- a service included in EJBServer (AlarmManager) +- tomcat or jetty (for JSP pages and servlets) +- security +Alarm messages are formed of (severity 1-3, from, reason). + +Directory structure: +-------------------- +etc/web.xml application description +etc/web-jetty.xml xml file for configuring the Realm for Jetty. +web/ JSPs, images, html files. +beans/ beans and service, to be loaded in JOnAS. +client/ client java program generating alarms and using JMS. + this alarm generator is obsolete. + +Compiling this test: +------------------- + +Use the Ant 1.5 build tool: + ant install + + +Running this test: +----------------- +Prerequisite: + - You must have installed Tomcat4.1.x or Jetty 4.2.x + - You must have configured a Database. + The jndi name used in the bean is jdbc_1. + See $JONAS_ROOT/doc/GettingStarted.html for more information. + + +1) run JOnAS server + The jonas.properties file must specify the following services : + - web service, jms service, ear service + You also have to add the alarm.ear component in the list of jonas.service.ear.descriptors. + + Note that the AlarmTopic that will be used by this test will be automatically created + when the message driven bean will be loaded in the container. + jonas start + +2) Load the alarm.ear if you have not added it in the ear service descriptors list + jonas admin -a alarm.ear + +3) Generate alarms + The easiest way is to use the link on the first html page that will run + a servlet that will generate customized alarms. + +4) Look at http://$HOSTNAME:/alarm/index.html + to start using the web application. + +5) Stop the jonas server + jonas stop + +Known bugs or Limitations: +-------------------------- +1. +Sending many alarm messages concurrently with InstantDB as database will +not work (deadlock leading to transaction timeout, and delay on servlet +display) This can occur with every database that cannot handle multithreading +properly. + +2. +The display pages are not automatically refreshed when a new alarm is +arrived. To be done in a future version. + +3. +Filter names cannot contain "space" characters. + +4. +The first time you run this application, the table will be created in the +database. An error message will be printed by JOnAS because it tries +to drop the table, but it does not exist. Ignore it. diff --git a/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/AlarmData.java b/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/AlarmData.java new file mode 100644 index 0000000000000000000000000000000000000000..aa6570b2890ac2c77b879c00003e46589d62a4b2 --- /dev/null +++ b/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/AlarmData.java @@ -0,0 +1,157 @@ +/** + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2005 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer: JOnAS Team + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ + +package org.objectweb.alarm.beans; + +import java.io.Serializable; + +/** + * + * @author Florent Benoit + */ +/** + * Data associated with an AlarmRecord. This is what will be passed to servlets + * to be displayed. + */ +public class AlarmData implements Serializable { + + /** + * AlarmRecord number (=pk) + */ + private int num; + + /** + * Severity Level + */ + private int sev; + + /** + * Device that generated Alarm + */ + private String device; + + /** + * Alarm Message + */ + private String message; + + /** + * Count of received messages + */ + private int count; + + /** + * State (1=received, 2=processed, 3=deleted) + */ + private int state; + + /** + * Date of first message + */ + private java.sql.Date date; + + /** + * @param n AlarmRecord number + * @param s Severity Level + * @param dev Device that generated Alarm + * @param m Alarm Message + * @param d Date of first message + */ + public AlarmData(int n, int s, String dev, String m, java.sql.Date d) { + num = n; + sev = s; + device = dev; + message = m; + count = 1; + state = 1; + date = d; + } + + /** + * @return the alarm record number + */ + public int getNum() { + return num; + } + + /** + * @return Severity Level + */ + public int getSev() { + return sev; + } + + /** + * @return the device + */ + public String getDevice() { + return device; + } + + /** + * @return the alarm message + */ + public String getMessage() { + return message; + } + + /** + * @return nb of messages received + */ + public int getCount() { + return count; + } + + /** + * Set the nb of messages received + * @param c Count of received messages + */ + public void setCount(int c) { + count = c; + } + + /** + * @return the state + */ + public int getState() { + return state; + } + + /** + * Set the current state + * @param s State (1=received, 2=processed, 3=deleted) + */ + public void setState(int s) { + state = s; + } + + /** + * @return Date of first message + */ + public java.util.Date getDate() { + return date; + } +} diff --git a/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/AlarmListenerBean.java b/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/AlarmListenerBean.java new file mode 100644 index 0000000000000000000000000000000000000000..0d7739ba76089d6a8a0bbc2bd4e914d13a58a4ea --- /dev/null +++ b/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/AlarmListenerBean.java @@ -0,0 +1,111 @@ +/** + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2005 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer: JOnAS Team + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ + +package org.objectweb.alarm.beans; + +import javax.ejb.EJBException; +import javax.ejb.MessageDrivenBean; +import javax.ejb.MessageDrivenContext; +import javax.jms.JMSException; +import javax.jms.MapMessage; +import javax.jms.Message; +import javax.jms.MessageListener; + +/** + * + */ +public class AlarmListenerBean implements MessageDrivenBean, MessageListener { + + /** + * Reference to the alarm manager + */ + private static transient AlarmManager alarmManager = null; + + /** + * Default constructor + */ + public AlarmListenerBean() { + } + + /** + * Set the associated context. The container call this method after the + * instance creation. The enterprise Bean instance should store the + * reference to the context object in an instance variable. This method is + * called with no transaction context. + * @param ctx A MessageDrivenContext interface for the + * instance. + */ + + public void setMessageDrivenContext(MessageDrivenContext ctx) { + } + + /** + * A container invokes this method before it ends the life of the + * message-driven object. This happens when a container decides to terminate + * the message-driven object. This method is called with no transaction + * context. + * @throws EJBException Thrown by the method to indicate a failure caused by + * a system-level error. + */ + public void ejbRemove() throws EJBException { + } + + /** + * The Message driven bean must define an ejbCreate methods with no args. We + * can do here all operations that will be common to all messages, i.e. + * asking JNDI for bean homes, ... + */ + public void ejbCreate() { + // Get a reference on the AlarmManager. + alarmManager = AlarmManager.getInstance(); + + } + + /** + * Called when there is a messgae + * @param message the message + * @see javax.jms.MessageListener#onMessage(javax.jms.Message) + */ + public void onMessage(Message message) { + + int sev = 0; + String from = null; + String reason = null; + + // Decode the message (MapMessage) + MapMessage msg = (MapMessage) message; + try { + sev = msg.getInt("Severity"); + from = msg.getString("From"); + reason = msg.getString("Reason"); + } catch (JMSException e) { + Debug.logError("AlarmListenerBean exception:" + e); + } + // Give all messages to the AlarmServiceHelper. + alarmManager.alarm(sev, from, reason); + + } +} diff --git a/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/AlarmManager.java b/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/AlarmManager.java new file mode 100644 index 0000000000000000000000000000000000000000..7a896345f402530928658a950f4629ca1240f0cb --- /dev/null +++ b/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/AlarmManager.java @@ -0,0 +1,281 @@ +/** + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2004 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer: JOnAS Team + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ + +package org.objectweb.alarm.beans; + +import java.rmi.RemoteException; +import java.util.Iterator; +import java.util.LinkedList; + +import javax.ejb.CreateException; +import javax.ejb.FinderException; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.rmi.PortableRemoteObject; + +/** + * AlarmManager implementation. + */ +public class AlarmManager { + + /** + * Unique instance of this class + */ + private static AlarmManager unique = null; + + /** + * Initial context + */ + private Context ictx = null; + + /** + * Home the bean AlarmRecord + */ + private AlarmRecordHome arh = null; + + /** + * Bean alarm Record + */ + private AlarmRecord arcount = null; + + /** + * List of profiles + */ + private LinkedList profilList = new LinkedList(); + + /** + * Default constructor + */ + private AlarmManager() { + Debug.log("AlarmManager - creating"); + + // Get a ref on AlarmRecordHome + try { + ictx = new InitialContext(); + arh = (AlarmRecordHome) PortableRemoteObject.narrow(ictx.lookup("alarmrecord"), AlarmRecordHome.class); + } catch (NamingException e) { + Debug.logError("AlarmManager : Cannot get AlarmRecordHome:" + e); + } + + // Get number of alarms still in database + // Create AlarmTable if does not exist + int trycount = 0; + while (arcount == null) { + try { + arcount = arh.findByPrimaryKey("0"); + int alarmid = arcount.getAlarmCount(); + Debug.log("AlarmManager: " + alarmid + " alarm records"); + } catch (Exception e) { + if (trycount > 0) { + Debug.logError("AlarmManager - bad start"); + return; + } + Debug.log("AlarmTable does not exist: create it"); + try { + arh.create(); + } catch (Exception f) { + Debug.logError("AlarmManager: Cannot init database:" + e); + } + trycount++; + } + } + + // Create a set of default profils + newProfil("all", "A"); + + Debug.log("AlarmManager - created"); + } + + /** + * @return unique instance of this class + */ + public static AlarmManager getInstance() { + if (unique == null) { + unique = new AlarmManager(); + } + return unique; + } + + /** + * * a new Alarm is arrived must be synchronized to make sure we do not + * create several AlarmRecord for the same Alarm (in case of many identical + * Alarm arriving at the same time) + * @param severity the level of severity + * @param from the device name + * @param reason the reason of the alarm + */ + public synchronized void alarm(int severity, String from, String reason) { + Debug.log("AlarmManager new Alarm from " + from + ": " + reason); + + // Search if alarm already known + // Key information is made of "from"+"reason" + AlarmRecord arec = null; + try { + arec = arh.findAlarm(from, reason); + } catch (FinderException e) { + Debug.logError("AlarmManager: " + e); + } catch (RemoteException e) { + Debug.logError("AlarmManager: " + e); + } + + if (arec == null) { + // If New Alarm: Create the AlarmRecord + Debug.log("new AlarmRecord"); + AlarmData ad = null; + try { + // Allocate a unique ident + int alarmid = arcount.getNewIdent(); + java.util.Date now = new java.util.Date(); + ad = new AlarmData(alarmid, severity, from, reason, new java.sql.Date(now.getTime())); + arec = arh.create(ad); + } catch (CreateException e) { + Debug.logError("AlarmManager: " + e); + } catch (RemoteException e) { + Debug.logError("AlarmManager: " + e); + } + // Notice profiles interested + Iterator i = profilList.iterator(); + while (i.hasNext()) { + Profil prof = (Profil) i.next(); + if (prof.interestedBy(ad)) { + prof.noticeAlarm(arec); + } + } + } else { + // Old Alarm -> just increment count. + Debug.log("AlarmRecord already known"); + try { + arec.update(severity); + } catch (RemoteException e) { + Debug.logError("AlarmManager: " + e); + } + } + + } + + /** + * Mark an AlarmRecord as processed. We don't remove it now to keep it in + * history. + * @param pk the primary key + * @throws RemoteException as it is remote it can fails + */ + public void forgetAlarm(String pk) throws RemoteException { + Debug.log("entering for " + pk); + + // Find this Alarm by its PK + AlarmRecord arec = null; + try { + arec = arh.findByPrimaryKey(pk); + } catch (FinderException e) { + Debug.logError("AlarmManager Alarm not found"); + throw new RemoteException("Alarm not found"); + } catch (RemoteException e) { + Debug.logError("AlarmManager: " + e); + throw e; + } + + // Change Alarm state + try { + arec.setProcessed(); + } catch (RemoteException e) { + Debug.logError("AlarmManager: " + e); + throw e; + } + } + + /** + * Makes a new Profil + * @param from the device name + * @param maxsev the maximum level of severity + * @return the new profile created + */ + public Profil newProfil(String from, String maxsev) { + Debug.log("entering for " + from + "/" + maxsev); + + // Check if already exist + Iterator i = profilList.iterator(); + while (i.hasNext()) { + Profil prof = (Profil) i.next(); + if (prof.getDevice().equals(from) && prof.getSeverity().equals(maxsev)) { + return null; + } + } + + Profil p = new Profil(from, maxsev, arh); + profilList.add(p); + return p; + } + + /** + * @return the list of available profils + */ + public String[] getProfilNames() { + Debug.log("entering"); + LinkedList nlist = new LinkedList(); + Iterator i = profilList.iterator(); + while (i.hasNext()) { + Profil prof = (Profil) i.next(); + nlist.add(prof.getName()); + } + return (String[]) nlist.toArray(new String[0]); + } + + /** + * @param name of the profile to remove + * @return a reference on Profil object, given its name. + */ + public Profil getProfil(String name) { + Debug.log("entering for " + name); + Profil ret = null; + Iterator i = profilList.iterator(); + while (i.hasNext()) { + Profil prof = (Profil) i.next(); + if (prof.getName().equals(name)) { + ret = prof; + } + } + return ret; + } + + /** + * remove a Profil + * @param name the name of the profile to remove + * @return true if the profile was removed + */ + public boolean delProfil(String name) { + Debug.log("entering for " + name); + Iterator i = profilList.iterator(); + while (i.hasNext()) { + Profil prof = (Profil) i.next(); + if (prof.getName().equals(name)) { + i.remove(); + return true; + } + } + return false; + } +} \ No newline at end of file diff --git a/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/AlarmRecord.java b/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/AlarmRecord.java new file mode 100644 index 0000000000000000000000000000000000000000..de07d67808e91f0bf6de48fac4424da5adceb6d3 --- /dev/null +++ b/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/AlarmRecord.java @@ -0,0 +1,90 @@ +/** + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2005 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer: JOnAS Team + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ + +package org.objectweb.alarm.beans; + +import java.rmi.RemoteException; + +import javax.ejb.EJBObject; + +/** + * AlarmRecord remote interface + */ +public interface AlarmRecord extends EJBObject { + + /** + * Update the record + * @param s severity level + * @throws RemoteException if remote call failed + */ + void update(int s) throws RemoteException; + + /** + * @throws RemoteException if remote call failed + */ + void forget() throws RemoteException; + + /** + * @throws RemoteException if remote call failed + */ + void setProcessed() throws RemoteException; + + /** + * @return the sender + * @throws RemoteException if remote call failed + */ + String getFrom() throws RemoteException; + + /** + * @return the severity level + * @throws RemoteException if remote call failed + */ + int getSeverity() throws RemoteException; + + /** + * @return the number of messages + * @throws RemoteException if remote call failed + */ + int getCount() throws RemoteException; + + /** + * @return number of alarms + * @throws RemoteException if remote call failed + */ + int getAlarmCount() throws RemoteException; + + /** + * @return the new ident + * @throws RemoteException if remote call failed + */ + int getNewIdent() throws RemoteException; + + /** + * @return the data + * @throws RemoteException if remote call failed + */ + AlarmData getAlarmData() throws RemoteException; +} diff --git a/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/AlarmRecordBean.java b/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/AlarmRecordBean.java new file mode 100644 index 0000000000000000000000000000000000000000..50b5913690f8a62a0089e632e6c63a69896945d7 --- /dev/null +++ b/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/AlarmRecordBean.java @@ -0,0 +1,316 @@ +/** + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2005 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer: JOnAS Team + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ + +package org.objectweb.alarm.beans; + +import java.rmi.RemoteException; +import java.sql.Connection; +import java.sql.Date; +import java.sql.SQLException; +import java.sql.Statement; + +import javax.ejb.CreateException; +import javax.ejb.DuplicateKeyException; +import javax.ejb.EJBException; +import javax.ejb.EntityBean; +import javax.ejb.EntityContext; +import javax.ejb.RemoveException; +import javax.naming.InitialContext; +import javax.sql.DataSource; + +/** + * + */ +public class AlarmRecordBean implements EntityBean { + + EntityContext ejbContext; + + // ------------------------------------------------------------------ + // State of the bean. + // They must be public for Container Managed Persistance. + // ------------------------------------------------------------------ + public String pk; + + public int sev; + + public String from; + + public String reason; + + public int count; + + public int state; + + public Date date; + + // ------------------------------------------------------------------ + // init DataBase + // ------------------------------------------------------------------ + private void initDB() { + + // Get my DataSource from JNDI + DataSource ds = null; + InitialContext ictx = null; + try { + ictx = new InitialContext(); + } catch (Exception e) { + throw new EJBException("Cannot get JNDI InitialContext"); + } + try { + ds = (DataSource) ictx.lookup("java:comp/env/jdbc/myDS"); + } catch (Exception e) { + throw new EJBException("cannot lookup datasource"); + } + + // Drop table + Connection conn = null; + Statement stmt = null; + String myTable = "AlarmTable"; + try { + conn = ds.getConnection(); + stmt = conn.createStatement(); + stmt.execute("drop table " + myTable); + stmt.close(); + } catch (SQLException e) { + // The first time, table will not exist. + } + + // Create table. + try { + stmt = conn.createStatement(); + stmt + .execute("create table " + + myTable + + "(dbpk varchar(12) not null primary key, dbsev integer, dbfrom varchar(12), dbreason varchar(30), dbcount integer, dbstate integer, dbdate date)"); + stmt.close(); + conn.close(); + } catch (SQLException e) { + throw new EJBException("Exception in createTable"); + } + } + + // ------------------------------------------------------------------ + // EntityBean implementation + // ------------------------------------------------------------------ + + /** + * Set the associated entity context. The container invokes this method on + * an instance after the instance has been created. This method is called in + * an unspecified transaction context. + * @param ctx - An EntityContext interface for the instance. The instance + * should store the reference to the context in an instance variable. + * @throws EJBException Thrown by the method to indicate a failure caused by + * a system-level error. + */ + public void setEntityContext(EntityContext ctx) { + ejbContext = ctx; + } + + /** + * Unset the associated entity context. The container calls this method + * before removing the instance. This is the last method that the container + * invokes on the instance. The Java garbage collector will eventually + * invoke the finalize() method on the instance. This method is called in an + * unspecified transaction context. + * @throws EJBException Thrown by the method to indicate a failure caused by + * a system-level error. + */ + public void unsetEntityContext() { + ejbContext = null; + } + + /** + * A container invokes this method before it removes the EJB object that is + * currently associated with the instance. This method is invoked when a + * client invokes a remove operation on the enterprise Bean's home interface + * or the EJB object's remote interface. This method transitions the + * instance from the ready state to the pool of available instances. This + * method is called in the transaction context of the remove operation. + * @throws RemoveException The enterprise Bean does not allow destruction of + * the object. + * @throws EJBException - Thrown by the method to indicate a failure caused + * by a system-level error. + */ + public void ejbRemove() throws RemoveException { + } + + /** + * A container invokes this method to instruct the instance to synchronize + * its state by loading it state from the underlying database. This method + * always executes in the proper transaction context. + * @throws EJBException Thrown by the method to indicate a failure caused by + * a system-level error. + */ + public void ejbLoad() { + } + + /** + * A container invokes this method to instruct the instance to synchronize + * its state by storing it to the underlying database. This method always + * executes in the proper transaction context. + * @throws EJBException Thrown by the method to indicate a failure caused by + * a system-level error. + */ + public void ejbStore() { + } + + /** + * There must be an ejbPostCreate par ejbCreate method + * @throws CreateException Failure to create an entity EJB object. + */ + public void ejbPostCreate(AlarmData ad) throws CreateException { + } + + public void ejbPostCreate() throws CreateException { + } + + /** + * The Entity bean can define 0 or more ejbCreate methods. + * @throws CreateException Failure to create an entity EJB object. + * @throws DuplicateKeyException An object with the same key already exists. + */ + public String ejbCreate(AlarmData ad) throws CreateException, DuplicateKeyException { + + // Init here the bean fields + Integer i = new Integer(ad.getNum()); + pk = i.toString(); + sev = ad.getSev(); + from = ad.getDevice(); + reason = ad.getMessage(); + count = 1; + state = 1; + date = (java.sql.Date) ad.getDate(); + + // In CMP, should return null. + return null; + } + + public String ejbCreate() throws CreateException, DuplicateKeyException { + + // init database + initDB(); + + // init bean fields + pk = "0"; + sev = 99; // avoids taking this as a true AlarmRecord. + from = "init"; + reason = "init"; + count = 0; + state = 0; + date = null; + + // In CMP, should return null. + return null; + } + + /** + * A container invokes this method on an instance before the instance + * becomes disassociated with a specific EJB object. + */ + public void ejbPassivate() { + } + + /** + * A container invokes this method when the instance is taken out of the + * pool of available instances to become associated with a specific EJB + * object. + */ + public void ejbActivate() { + } + + // ------------------------------------------------------------------ + // AlarmRecord implementation + // ------------------------------------------------------------------ + + /** + * + */ + public void update(int s) { + count++; + if (s < sev) { + sev = s; + } + java.util.Date now = new java.util.Date(); + date = new java.sql.Date(now.getTime()); + } + + /** + * forget + */ + public void forget() { + state = 3; + } + + /** + * setProcessed + */ + public void setProcessed() { + state = 2; + } + + public String getFrom() { + return from; + } + + public int getSeverity() { + return sev; + } + + public int getCount() { + return count; + } + + /** + * Get the number of alarms in database only valid for special "0" element. + */ + public int getAlarmCount() throws RemoteException { + if (!pk.equals("0")) { + throw new RemoteException("pk should be 0"); + } + return count; + } + + /** + * Get a new Ident only valid for special "0" element. + */ + public int getNewIdent() throws RemoteException { + if (!pk.equals("0")) { + throw new RemoteException("pk should be 0"); + } + return ++count; + } + + /** + * Returns the AlarmData for that instance + */ + public AlarmData getAlarmData() throws RemoteException { + Integer id = new Integer(pk); + AlarmData ret = new AlarmData(id.intValue(), sev, from, reason, date); + ret.setCount(count); + ret.setState(state); + return ret; + } +} diff --git a/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/AlarmRecordHome.java b/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/AlarmRecordHome.java new file mode 100644 index 0000000000000000000000000000000000000000..67c3373464ed7d12b0a7fdf01655d6f6fa7a68eb --- /dev/null +++ b/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/AlarmRecordHome.java @@ -0,0 +1,96 @@ +/** + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2004 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer: JOnAS Team + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ + +package org.objectweb.alarm.beans; + +import java.rmi.RemoteException; +import java.util.Collection; + +import javax.ejb.CreateException; +import javax.ejb.EJBHome; +import javax.ejb.FinderException; + +/** + * Home interface for the bean AlarmRecord + */ +public interface AlarmRecordHome extends EJBHome { + + /** + * @return + * @throws CreateException + * @throws RemoteException + */ + AlarmRecord create() throws CreateException, RemoteException; + + /** + * @param ad + * @return + * @throws CreateException + * @throws RemoteException + */ + AlarmRecord create(AlarmData ad) throws CreateException, RemoteException; + + /** + * @param pk + * @return + * @throws FinderException + * @throws RemoteException + */ + AlarmRecord findByPrimaryKey(String pk) throws FinderException, RemoteException; + + /** + * @param from + * @param mess + * @return + * @throws FinderException + * @throws RemoteException + */ + AlarmRecord findAlarm(String from, String mess) throws FinderException, RemoteException; + + /** + * @return + * @throws FinderException + * @throws RemoteException + */ + Collection findAll() throws FinderException, RemoteException; + + /** + * @param from + * @param sev + * @return + * @throws FinderException + * @throws RemoteException + */ + Collection findByInterest(String from, int sev) throws FinderException, RemoteException; + + /** + * @param sev + * @return + * @throws FinderException + * @throws RemoteException + */ + Collection findBySeverity(int sev) throws FinderException, RemoteException; +} \ No newline at end of file diff --git a/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/Debug.java b/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/Debug.java new file mode 100644 index 0000000000000000000000000000000000000000..fe00843cfbb7ce10492bc5f43df23066c15d2a0a --- /dev/null +++ b/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/Debug.java @@ -0,0 +1,64 @@ +/** + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2004 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer: JOnAS Team + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ + +package org.objectweb.alarm.beans; + +/** + * Provide a ligth Debug. + */ +public class Debug { + + /** + * No public constructor (Utility class) + */ + private Debug() { + + } + + /** + * True if only if use the debug. + */ + private static boolean debug = false; + + /** + * Log some debugging info, if debug is true. + * @param msg the message to log. + */ + public static void log(String msg) { + if (debug) { + System.out.println(msg); + } + } + + /** + * Log some errors. + * @param msg the error message to log. + */ + public static void logError(String msg) { + System.err.println(msg); + } + +} \ No newline at end of file diff --git a/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/Profil.java b/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/Profil.java new file mode 100644 index 0000000000000000000000000000000000000000..fcad1e137df3f377d4e2c147886d5cc38eeee837 --- /dev/null +++ b/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/Profil.java @@ -0,0 +1,206 @@ +/** + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2005 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer: JOnAS Team + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ + +package org.objectweb.alarm.beans; + +import java.rmi.RemoteException; +import java.util.Collection; +import java.util.Iterator; +import java.util.LinkedList; + +import javax.ejb.FinderException; +import javax.rmi.PortableRemoteObject; + + +/** + * Helper class Profil Profils are managed by AlarmManager and used by View + * session beans We do not use an Entity because we need neither persistence nor + * remote accesses. We cannot use a Session bean because it's accessed from + * several clients, and from the AlarmManager. + */ +public class Profil { + + /** + * Device name or "all" + */ + private String device; + + /** + * max severity level + */ + private int maxsev; // + + /** + * Name + */ + private String name; + + /** + * Is the device is all ? + */ + private boolean fromAll; + + /** + * Home of the bean AlarmRecord + */ + private AlarmRecordHome arh; + + /** + * A list of AlarmRecord objects + */ + private LinkedList alarmList = new LinkedList(); + + /** + * constructor + * @param device the device name + * @param sev the severity level + * @param arh the home of the eban + */ + + public Profil(String device, String sev, AlarmRecordHome arh) { + + // init object + this.device = device; + this.arh = arh; + fromAll = device.equals("all"); + if (sev.startsWith("S")) { + maxsev = 1; + sev = "S"; + } else if (sev.startsWith("W")) { + maxsev = 2; + sev = "W"; + } else { + maxsev = 3; + sev = "I"; + } + name = device + "-" + sev; + + // find alarms already arrived and matching this Profil + Collection knal = null; + try { + if (fromAll) { + knal = arh.findBySeverity(maxsev); + } else { + knal = arh.findByInterest(device, maxsev); + } + alarmList.addAll(knal); + } catch (FinderException e) { + System.out.println("Profil constructor: No Alarm found"); + } catch (RemoteException e) { + System.out.println("Error getting AlarmRecords:" + e); + } + } + + /** + * @return the device + */ + public String getDevice() { + return device; + } + + /** + * @return the severity watched + */ + public String getSeverity() { + switch (maxsev) { + case 1: + return "S"; + case 2: + return "W"; + case 3: + return "I"; + default: + return "A"; + } + } + + /** + * @return the profil name + */ + public String getName() { + return name; + } + + /** + * get Alarms for this Profil. + * @param all true if get all alarms, false if get only new alarms + * @return Alarms for this Profil. + */ + public synchronized Collection getAlarms(boolean all) { + LinkedList ret = new LinkedList(); + Iterator it = alarmList.iterator(); + while (it.hasNext()) { + AlarmRecord arec = (AlarmRecord) PortableRemoteObject.narrow(it.next(), AlarmRecord.class); + AlarmData ad = null; + try { + ad = arec.getAlarmData(); + if (all || (ad.getState() == 1)) { + ret.add(ad); + } + } catch (RemoteException e) { + System.out.println("Error getting AlarmRecord:" + e); + } + } + return ret; + } + + /** + * Gets current Alarm level + * @return current Alarm level + */ + public synchronized int getCurrentLevel() { + int ret = 1000; + Iterator it = alarmList.iterator(); + while (it.hasNext()) { + AlarmRecord arec = (AlarmRecord) PortableRemoteObject.narrow(it.next(), AlarmRecord.class); + try { + AlarmData ad = arec.getAlarmData(); + if (ad.getState() == 1 && ad.getSev() <= ret) { + ret = ad.getSev(); + } + } catch (RemoteException e) { + System.out.println("Error getting AlarmRecord:" + e); + } + } + return ret; + } + + /** + * @param ad alarm data object + * @return true if this Profil is interested by this AlarmRecord. + */ + public boolean interestedBy(AlarmData ad) { + return ((fromAll || ad.getDevice().equals(device)) && ad.getSev() <= maxsev); + } + + /** + * add an Alarm Record to this Profil. + * @param arec the record + */ + public synchronized void noticeAlarm(AlarmRecord arec) { + alarmList.add(arec); + } +} \ No newline at end of file diff --git a/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/View.java b/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/View.java new file mode 100644 index 0000000000000000000000000000000000000000..bb718dadbd2d774d12b00f1b9c87cfdba28ea6e3 --- /dev/null +++ b/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/View.java @@ -0,0 +1,88 @@ +/** + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2004 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer: JOnAS Team + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ + +package org.objectweb.alarm.beans; + +import java.rmi.RemoteException; + +import javax.ejb.EJBObject; + +/** + * View remote interface + */ +public interface View extends EJBObject { + + /** + * @return + * @throws RemoteException + */ + AlarmData[] getAllAlarms() throws RemoteException; + + /** + * @return + * @throws RemoteException + */ + AlarmData[] getNewAlarms() throws RemoteException; + + /** + * @return + * @throws RemoteException + */ + String[] getProfils() throws RemoteException; + + /** + * @param name + * @throws RemoteException + */ + void setProfil(String name) throws RemoteException; + + /** + * @param name + * @return + * @throws RemoteException + */ + int alarmLevel(String name) throws RemoteException; + + /** + * @param pk + * @throws RemoteException + */ + void forgetAlarm(String pk) throws RemoteException; + + /** + * @param device + * @param level + * @return + * @throws RemoteException + */ + String newProfil(String device, String level) throws RemoteException; + + /** + * @param name + * @throws RemoteException + */ + void removeProfil(String name) throws RemoteException; +} \ No newline at end of file diff --git a/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/ViewBean.java b/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/ViewBean.java new file mode 100644 index 0000000000000000000000000000000000000000..b0af3635b524c1d7d478bad051b947c0bf871dcd --- /dev/null +++ b/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/ViewBean.java @@ -0,0 +1,198 @@ +/** + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2005 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer: JOnAS Team + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ + +package org.objectweb.alarm.beans; + +import java.rmi.RemoteException; +import java.util.Collection; + +import javax.ejb.SessionBean; +import javax.ejb.SessionContext; + +/** + * Session bean View. Does not implement SessionSynchronization. We assume that + * this bean and AlarmManager run in the same JVM. Each Session bean is + * dedicated to 1 client: Here, the ViewProxy class. Each Session may be + * connected to 1 Profil or not. + */ +public class ViewBean implements SessionBean { + + /** + * Reference to the alarm manager + */ + private static transient AlarmManager alarmManager = null; + + /** + * Profil reference + */ + private Profil prof = null; + + /** + * Set the context for this bean + * @param ctx the context + * @see javax.ejb.SessionBean#setSessionContext(javax.ejb.SessionContext) + */ + public void setSessionContext(SessionContext ctx) { + + } + + /** + * Remove + * @see javax.ejb.SessionBean#ejbRemove() + */ + public void ejbRemove() { + } + + /** + * The Session bean must define 1 or more ejbCreate methods. + */ + public void ejbCreate() { + // Get a reference on the AlarmManager. + alarmManager = AlarmManager.getInstance(); + } + + /** + * Passivate + * @see javax.ejb.SessionBean#ejbPassivate() + */ + public void ejbPassivate() { + } + + /** + * Activate + * @see javax.ejb.SessionBean#ejbActivate() + */ + public void ejbActivate() { + } + + /** + * @return all messages for the current profil + * @throws RemoteException if remote call failed + */ + public AlarmData[] getAllAlarms() throws RemoteException { + if (prof == null) { + throw new RemoteException("No Profil defined for this session"); + } + Collection alist = prof.getAlarms(true); + return (AlarmData[]) alist.toArray(new AlarmData[0]); + } + + /** + * @return new messages for the current profil + * @throws RemoteException if remote call failed + */ + public AlarmData[] getNewAlarms() throws RemoteException { + if (prof == null) { + throw new RemoteException("No Profil defined for this session"); + } + Collection alist = prof.getAlarms(false); + return (AlarmData[]) alist.toArray(new AlarmData[0]); + } + + /** + * @return an enumeration of all available profils + */ + public String[] getProfils() { + return alarmManager.getProfilNames(); + } + + /** + * Chooses to work on a particular profil. + * @param name of the profil + * @throws RemoteException if remote call failed + */ + public void setProfil(String name) throws RemoteException { + if (name == null) { + prof = null; + return; + } + prof = alarmManager.getProfil(name); + if (prof == null) { + throw new RemoteException("This Profil does not exist yet: " + name); + } + } + + /** + * @return the Alarm Level for Profil specified + * @param name of the profil + * @throws RemoteException if remote call failed + */ + public int alarmLevel(String name) throws RemoteException { + Profil prof = alarmManager.getProfil(name); + if (prof == null) { + throw new RemoteException("This Profil does not exist yet: " + name); + } + return prof.getCurrentLevel(); + } + + /** + * Forget this message because problem has been taken into account. + * @param pk primary key + * @throws RemoteException if remote call failed + */ + public void forgetAlarm(String pk) throws RemoteException { + alarmManager.forgetAlarm(pk); + } + + /** + * creates a new Profil + * @param device the name of the device + * @param level the severity level + * @return the newly created profil + * @throws RemoteException if remote call failed + */ + public String newProfil(String device, String level) throws RemoteException { + + // Check arg validity + if (device.length() == 0) { + throw new RemoteException("null device string"); + } + if (!level.startsWith("S") && !level.startsWith("W") && !level.startsWith("I")) { + throw new RemoteException("severity must be one of S|W|I"); + } + + prof = alarmManager.newProfil(device, level); + if (prof == null) { + return null; + } + return prof.getName(); + } + + /** + * remove a Profil + * @param name the name of the profil + * @throws RemoteException if remote call failed + */ + public void removeProfil(String name) throws RemoteException { + if (name == null) { + return; + } + boolean ok = alarmManager.delProfil(name); + if (!ok) { + throw new RemoteException("This Profil does not exist yet: " + name); + } + } +} diff --git a/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/ViewHome.java b/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/ViewHome.java new file mode 100644 index 0000000000000000000000000000000000000000..cc9084256f9e4a8dd7fcf4cd27b0ac72b738c8a7 --- /dev/null +++ b/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/ViewHome.java @@ -0,0 +1,46 @@ +/** + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2004 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer: JOnAS Team + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ + + +package org.objectweb.alarm.beans; + +import java.rmi.RemoteException; + +import javax.ejb.CreateException; +import javax.ejb.EJBHome; + +/** + * Home interface for the bean View + */ +public interface ViewHome extends EJBHome { + + /** + * @return the bean created + * @throws CreateException if the bean can't be created + * @throws RemoteException if remote call failed + */ + View create() throws CreateException, RemoteException; +} diff --git a/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/ViewProxy.java b/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/ViewProxy.java new file mode 100644 index 0000000000000000000000000000000000000000..1970921af4dc6cbb6011619a7e7a07eadeca5452 --- /dev/null +++ b/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/ViewProxy.java @@ -0,0 +1,240 @@ +/** + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2004 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer: JOnAS Team + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ + +package org.objectweb.alarm.beans; + +import java.rmi.RemoteException; + +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.rmi.PortableRemoteObject; + +/** + * proxy used to access the "View" session bean. must be instantiated by JSP's + * with a tag like this: + */ +public class ViewProxy { + +/** + * Initial context + */ + private Context ictx = null; + + /** + * Home of the bean View + */ + private ViewHome vh = null; + + /** + * Bean View + */ + private View ejbview = null; + + /** + * Name of my profil + */ + private String myprofil = null; + + /** + * Error message + */ + private String errorMessage = null; + + private View getEjbView() { + if (ejbview == null) { + // Create the Session Bean + try { + ejbview = vh.create(); + } catch (Exception e) { + errorMessage = "ViewProxy : Cannot create EJB:" + e.toString(); + } + } + return ejbview; + } + + /** + * Init procedure + * Gets the bean and create one + */ + private void init() { + // Get the ViewHome + try { + ictx = new InitialContext(); + vh = (ViewHome) PortableRemoteObject.narrow(ictx.lookup("viewhome"), ViewHome.class); + } catch (NamingException e) { + errorMessage = "ViewProxy : Cannot get ViewHome:" + e.toString(); + return; + } + getEjbView(); + } + + /** + * constructor: Create here the EJB session. + */ + public ViewProxy() { + init(); + } + + /** + * @return RO attribute: Get all Profils already created by Alarm Manager. + */ + public String[] getProfils() { + String[] ret = new String[0]; + try { + ret = getEjbView().getProfils(); + errorMessage = null; + } catch (RemoteException e) { + errorMessage = "ViewProxy : Cannot get Profil list:" + e.toString(); + ejbview = null; + } + return ret; + } + + /** + * @return RW attribute: Profil used. + */ + public String getProfil() { + errorMessage = null; + return myprofil; + } + + /** + * Set the current profil + * @param p the name of the profil + */ + public void setProfil(String p) { + try { + getEjbView().setProfil(p); + errorMessage = null; + // keep it on local for efficiency + myprofil = p; + } catch (RemoteException e) { + errorMessage = "ViewProxy : Cannot set Profil:" + e.toString(); + ejbview = null; + } + } + + /** + * @return RO attribute: list of new alarms on the current Profil + */ + public AlarmData[] getNewAlarms() { + AlarmData[] ret = null; + try { + ret = getEjbView().getNewAlarms(); + errorMessage = null; + } catch (RemoteException e) { + errorMessage = "ViewProxy : Cannot get new alarms:" + e.toString(); + ejbview = null; + } + return ret; + } + + /** + * @return RO attribute: list of all alarms on the current Profil + */ + public AlarmData[] getAllAlarms() { + AlarmData[] ret = null; + try { + ret = getEjbView().getAllAlarms(); + errorMessage = null; + } catch (RemoteException e) { + errorMessage = "ViewProxy : Cannot get all alarms:" + e.toString(); + ejbview = null; + } + return ret; + } + + /** + * @param profilName the name of the profil + * @return the maximum level of alarm for this Profil. + */ + public int alarmLevel(String profilName) { + int level = 0; + try { + level = getEjbView().alarmLevel(profilName); + errorMessage = null; + } catch (RemoteException e) { + errorMessage = "ViewProxy : Cannot get AlarmLevel:" + e.toString(); + ejbview = null; + } + return level; + } + + /** + * @return error message if any + */ + public String getErrorMessage() { + return errorMessage; + } + + /** + * Forget this Alarm because it has been treated. + * @param pk primary key + */ + public void forgetAlarm(String pk) { + try { + getEjbView().forgetAlarm(pk); + errorMessage = null; + } catch (RemoteException e) { + errorMessage = "ViewProxy : Cannot forget Alarm:" + e.toString(); + ejbview = null; + } + } + + /** + * Creates a new Profil + * @param device the name of the device + * @param level the severity level + * @return the newly created profil + */ + public String newProfil(String device, String level) { + String ret = null; + try { + ret = getEjbView().newProfil(device, level); + errorMessage = null; + } catch (RemoteException e) { + errorMessage = "ViewProxy : Cannot create Profil:" + e.toString(); + ejbview = null; + } + return ret; + } + + /** + * remove a Profil + * @param profil name of the profil to remove + */ + public void removeProfil(String profil) { + try { + getEjbView().removeProfil(profil); + errorMessage = null; + } catch (RemoteException e) { + errorMessage = "ViewProxy : Cannot remove Profil:" + e.toString(); + ejbview = null; + } + } +} \ No newline at end of file diff --git a/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/alarm.xml b/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/alarm.xml new file mode 100644 index 0000000000000000000000000000000000000000..a39659b9ce2947525e5115d10c5dbabe3f46ffd4 --- /dev/null +++ b/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/alarm.xml @@ -0,0 +1,100 @@ + + + + Demo Appli: Alarm Manager + Alarm + + + + + session bean View + View + View + org.objectweb.alarm.beans.ViewHome + org.objectweb.alarm.beans.View + org.objectweb.alarm.beans.ViewBean + Stateful + Container + + + + AlarmRecord + AlarmRecord + AlarmRecord + org.objectweb.alarm.beans.AlarmRecordHome + org.objectweb.alarm.beans.AlarmRecord + org.objectweb.alarm.beans.AlarmRecordBean + Container + java.lang.String + True + 1.x + + pk + + + sev + + + from + + + reason + + + count + + + state + + + date + + pk + + jdbc/myDS + javax.sql.DataSource + Application + + + + + Message Driven Bean AlarmListener + AlarmListener + AlarmListener + org.objectweb.alarm.beans.AlarmListenerBean + Container + Auto-acknowledge + + javax.jms.Topic + Durable + + + + + + + + + AlarmRecord + create + + Supports + + + + View + * + + + AlarmRecord + * + + + AlarmListener + * + + Required + + + + diff --git a/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/jonas-alarm.xml b/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/jonas-alarm.xml new file mode 100644 index 0000000000000000000000000000000000000000..8e0507bbb47b660456a4f1f8ac0b349c0972e179 --- /dev/null +++ b/jonas_4_10/jonas/examples/alarm/beans/org/objectweb/alarm/beans/jonas-alarm.xml @@ -0,0 +1,86 @@ + + + + + + + View + viewhome + + + + AlarmRecord + alarmrecord + + jdbc/myDS + + jdbc_1 + + false + 20 + + jdbc_1 + AlarmTable + + pk + dbpk + + + sev + dbsev + + + from + dbfrom + + + reason + dbreason + + + count + dbcount + + + state + dbstate + + + date + dbdate + + + + findAlarm + + where dbfrom = ? and dbreason = ? and dbstate = 1 + + + + findAll + + + + + + findByInterest + + where dbfrom = ? and dbsev <= ? + + + + findBySeverity + + where dbsev <= ? + + + + + + AlarmListener + + AlarmTopic + + + + diff --git a/jonas_4_10/jonas/examples/alarm/build.xml b/jonas_4_10/jonas/examples/alarm/build.xml new file mode 100644 index 0000000000000000000000000000000000000000..e1a3d5f5025ddc222e8634b02a12412a337747d8 --- /dev/null +++ b/jonas_4_10/jonas/examples/alarm/build.xml @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jonas_4_10/jonas/examples/alarm/client/org/objectweb/alarm/AlarmGenerator.java b/jonas_4_10/jonas/examples/alarm/client/org/objectweb/alarm/AlarmGenerator.java new file mode 100644 index 0000000000000000000000000000000000000000..4eddfa9dcca2084a958407fc2830b4679cc54ed7 --- /dev/null +++ b/jonas_4_10/jonas/examples/alarm/client/org/objectweb/alarm/AlarmGenerator.java @@ -0,0 +1,214 @@ +// AlarmGenerator.java + +package org.objectweb.alarm; + +import java.rmi.RemoteException; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.jms.*; + +class ClientThread extends Thread { + String name; + + public ClientThread(int num) { + name = AlarmGenerator.m_device; + if (name == null) { + name = "device"+num; + } + setName(name); + } + + /** + * random returns an integer between 0 and max - 1 + */ + private int random(int max) { + + double d = Math.random(); + int ret = (int) (max * d); + return ret; + } + + private String getReason(int sev) { + String reason; + int num = AlarmGenerator.m_mess; + if (num == 0) { + num = random(10) + 1; + } + switch (sev) { + case 1: + reason = "Severe Error "+num; + break; + case 2: + reason = "Warning "+num; + break; + case 3: + reason = "Running OK"; + break; + default: + reason = "Unknown Alarm"; + break; + } + return reason; + } + + public void run() { + + // Create Session + Publisher + TopicSession session = null; + TopicPublisher tp = null; + try { + session = AlarmGenerator.mytc.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); + tp = session.createPublisher(AlarmGenerator.mytopic); + } catch (Exception e) { + System.err.println("Cannot create JMS Publisher:"+ e); + } + + // main loop + int severity = AlarmGenerator.m_severity; + try { + for (int i = 0; i < AlarmGenerator.m_loops; i++) { + // publish messages to the topic + try { + MapMessage message = session.createMapMessage(); + // randomize the severity level if not specified + if (severity == 0) + severity = random(2)+1; + message.setInt("Severity", severity); + message.setString("From", name); + message.setString("Reason", getReason(severity)); + tp.publish(message); + } catch (JMSException e) { + System.err.println("Exception occurred: "+ e); + } + } + } catch (Exception e) { + System.err.println("Exception in main loop"+ e); + } + } +} + + +public class AlarmGenerator { + + static Context ictx = null; + static Topic mytopic = null; + static TopicConnection mytc = null; + + + static boolean m_reinit = false; + static int m_threads = 1; + static int m_loops = 1; + static int m_severity = 0; + static int m_mess = 0; + static String m_device = null; + + private static void usage() { + System.out.println("AlarmGenerator [-d device] [-l loops] [-t threads] [-s severity] [-m num]"); + } + + public static void main(String[] args) { + + TopicConnectionFactory tcf = null; + + // Get Args + // Get command args + for (int argn = 0; argn < args.length; argn++) { + String s_arg = args[argn]; + Integer i_arg; + if (s_arg.equals("-l")) { + s_arg = args[++argn]; + i_arg = java.lang.Integer.valueOf(s_arg); + m_loops = i_arg.intValue(); + } else if (s_arg.equals("-d")) { + m_device = args[++argn]; + } else if (s_arg.equals("-t")) { + s_arg = args[++argn]; + i_arg = java.lang.Integer.valueOf(s_arg); + m_threads = i_arg.intValue(); + } else if (s_arg.equals("-s")) { + s_arg = args[++argn]; + i_arg = java.lang.Integer.valueOf(s_arg); + m_severity = i_arg.intValue();; + } else if (s_arg.equals("-m")) { + s_arg = args[++argn]; + i_arg = java.lang.Integer.valueOf(s_arg); + m_mess = i_arg.intValue(); + } else { + usage(); + System.exit(2); + } + } + + // Get InitialContext + try { + ictx = new InitialContext(); + } catch (NamingException e) { + System.err.println("Cannot get InitialContext:"+ e); + } + + // Lookup JMS resources + try { + // lookup the TopicConnectionFactory through its JNDI name + tcf = (TopicConnectionFactory) ictx.lookup("JTCF"); + // lookup the Topic through its JNDI name + mytopic = (Topic) ictx.lookup("AlarmTopic"); + } catch (NamingException e) { + System.err.println("Cannot lookup JMS Resources:"+ e); + } + + // Create Connection + try { + mytc = tcf.createTopicConnection(); + } catch (Exception e) { + System.err.println("Cannot create JMS Connection:"+ e); + } + + // If reinit: send a special message to reinit AlarmTable first. + // This doesn't work (DuplicateKey exception) + // Code to remove! + if (m_reinit) { + TopicSession session = null; + TopicPublisher tp = null; + MapMessage message; + try { + session = AlarmGenerator.mytc.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); + tp = session.createPublisher(AlarmGenerator.mytopic); + message = session.createMapMessage(); + message.setInt("Severity", 1); + message.setString("From", "reinit"); + message.setString("Reason", "reinit"); + tp.publish(message); + } catch (JMSException e) { + System.err.println("Exception occurred: "+ e); + } finally { + try { + session.close(); + } catch (Exception i) {} + } + } + + // Create and start threads + ClientThread[] t_thr = new ClientThread[m_threads]; + for (int i = 0; i < m_threads; i++) { + t_thr[i] = new ClientThread(i+1); + t_thr[i].start(); + } + + // Wait end of all threads + for (int p = 0; p < m_threads; p++) { + try { + t_thr[p].join(); + } catch (InterruptedException e) { + System.err.println("ERROR: Problem in ClientThread.join"+ e); + } + } + + // close connection + try { + mytc.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/jonas_4_10/jonas/examples/alarm/db1.prp b/jonas_4_10/jonas/examples/alarm/db1.prp new file mode 100644 index 0000000000000000000000000000000000000000..5dae3df2a4888aa0a91da824b86e03b6d4e2303c --- /dev/null +++ b/jonas_4_10/jonas/examples/alarm/db1.prp @@ -0,0 +1,325 @@ +!--------------------------------------------------------------------- +! +! PROPERTIES for the InstantDB database used in the JOnAS alarm example +! (builded from InstantDB/3.25/Examples/sample.prp) +! +!--------------------------------------------------------------------- + +!--------------------------------------------------------------------- +! +! BASIC PROPERTIES +! +!--------------------------------------------------------------------- + +! +! Path where index tables are held. Can be absolute or relative +! to the properties file. Defaults to tablePath. +! +indexPath=./tmp/indexes +! +! Path where system tables are held. Can be absolute or relative to +! the properties file. Defaults to tablePath. +! +systemPath=./tmp/system +! +! Path where database tables are held. Can be absolute or relative +! to the properties file. Defaults to "current" directory. +! +tablePath=./tmp/tables +! +! Path where results set tables are held. Can be absolute or relative +! to the properties file. Defaults to tablePath. +! +tmpPath=./tmp/tmp +! +! Non-zero means paths are relative to the properties file. +! Default is absolute paths for files. +! +relativeToProperties=1 +! +! Alternative partitions can be defined so that tables can be placed +! in multiple locations. Each partition is numbered: 1, 2, 3,... Tables +! can be created on partitions using the syntax +! +! CREATE TABLE ON PARTITION ... +! +! The partition count has to be supplied. +! +!partitionCount=2 +! +! The locations of each partition must be supplied. These are always +! absolute path names. +! +!partition1=d:/petes +!partition2=c:/temp + + +!--------------------------------------------------------------------- +! +! TUNING PROPERTIES +! +!--------------------------------------------------------------------- + +! +! The amount of each column to cache, expressed either as an absolute +! number of rows or as a percentage figure. Defaults to 256 or 10 respectively. +! +! This value applies only when tables are first created. It has no effect +! when a table is being re-opened. +! +cacheAmount=512 +! +! CACHE_ROWS Must be one of CACHE_ROWS or CACHE_PERCENT. Determines whether +! to cache columns in tables based on an absolute number of rows, or the +! percentage number of rows in the table. +! +! This value applies only when tables are first created. It has no effect +! when a table is being re-opened. +! +cacheCondition=CACHE_ROWS +! +! The amount of the system tables to be cached. Defaults to 100. +! +! This value applies only when tables are first created. It has no effect +! when a table is being re-opened. +! +!systemCacheSize=10 +! +! Similar to cacheCondition, but applies only to the system tables. +! +! This value applies only when tables are first created. It has no effect +! when a table is being re-opened. +! +!systemCacheCondition=CACHE_ROWS +! +! The percentage cache hit improvement required in order to move the +! cache to a new location in a column. +! +! (Currently not implemented). +! +cacheResetPercent=10 +! +! Non-zero means that database changes do not get written to the +! database immediately. See tuning.html. +! +fastUpdate=0 +! +! Percentage of free space in an index that must be present before +! the index reorganises itself. High values means frequent index +! reorganisation. Low values means slow index inserts. +! +indexLoad=5 +! +! The number of cache misses to include in calculations of the next +! base for the cache. +! +! (Currently not implemented). +! +missesInCacheStats=100 +! +! Non-zero means that results sets get instantiated on disk. By default +! InstantDB holds results sets emtirely in memory (apart from Binary +! columns). For large results sets this can be a problem. This property +! forces all results sets to be held on disk. +! +resultsOnDisk=0 +! +! Similar to cacheCondition but applies only to disk based +! results sets. Default is CACHE_ROWS. +! +resultsSetCache=CACHE_ROWS +! +! Similar to cacheAmount but applies only to disk based +! results sets. Default is 100. +! +resultsSetCacheAmount=100 +! +! Number of rows to read into the disk read ahead buffer. +! Recommended to be set somewhere around 128 to 256. +! Default is 20. +! +rowCacheSize=128 +! +! The read ahead buffer is effective at speeding up full +! table scans. However for indexed lookups or multiple +! simultaneous scans it is better to read a single row at +! a time. Each table holds a small number of single row +! buffers to improve such operations. Default is 8. +! +!singleRowCount=4 +! +! Sometimes the look ahead buffer can be held by a single +! thread even though it is not retrieveing many values from it. +! If too many lookups retrieve data from the single row +! buffers then it is better to flush the look ahead buffer and +! make it available for re-use. Default is 128. +! +!flushAfterCacheMisses=64 +! +! Number of rows to read ahead for system tables. By default +! system tables cache everything, so it is wasteful to have large +! read ahead buffers since they will very rarely be used. This +! allows the size of the system read ahead buffers to be reduced +! if necessary. Defaults to rowCacheSize. +! +!systemRows=20 +! +! The control column in all tables normally has a large cache +! since this speeds up all operation on that table. This can be +! varied to either improve performance or to reduce space. +! default is 8192. +! +! This value applies only when tables are first created. It has no effect +! when a table is being re-opened. +! +!controlColCacheSize=512 +! +! By default, InstantDB only does a cursory search for deleted rows during +! UPDATE statements. Setting searchDeletes=1 causes more detailed searches +! for deleted rows. This slows down UPDATE executions, but reults in more +! compact tables. Default is 0. +! +searchDeletes=0 +! +! The interval, in milliseconds, between checks for statement execution +! timeouts. Default is 5000. +! +!timerCheck=5000 + +!--------------------------------------------------------------------- +! +! LOGGING AND DEBUGGING PROPERTIES +! +!--------------------------------------------------------------------- + +! +! Non-zero means include SQL statements in the export file. +! +exportSQL=0 +! +! Non-zero means trace output also directed to console. +! Defaults to 0. +! +!traceConsole=1 +traceConsole=0 +! +! Relative or absolute path where exporting and tracing goes. +! +traceFile=./tmp/trace.log +! +! Bitmap of various items that can be traced. See debug.html. +! Defaults to 0. +! +traceLevel=2 + + +!--------------------------------------------------------------------- +! +! TRANSACTION AND RECOVERY PROPERTIES +! +!--------------------------------------------------------------------- + +! +! 0 means do not perform recovery on startup. +! 1 means perform automatic recovery +! 2 (default) means prompt the user using standard in +! +recoveryPolicy=2 +! +! Sets the level of transaction journalling. See trans.html. +! Defaults to 1. +! +! 0 - No journalling takes place. +! 1 - Normal journalling (default). +! 2 - Full journalling. +! +transLevel=1 +! +! When doing an import, defines the number of rows imported +! before the transaction is committed. Recommended value 8192. +! defaults to 100. +! +transImports=100 + +!--------------------------------------------------------------------- +! +! DATE, TIME AND CURRENCY PROPERTIES +! +!--------------------------------------------------------------------- + +! +! Number of digits after decimal point in currency outputs. Defaults to 2. +! +currencyDecimal=2 +! +! Currency symbol used in currency outputs. Defaults to $. +! +currencySymbol=$ +! +! Default format for date columns. Defaults to "yyyy-mm-dd". +! +dateFormat=yyyy-mm-dd +! +! Default format for timestamp columns. Defaults to "yyyy-mm-dd hh:mm:ss.lll". +! +dateTimeFormat=yyyy-mm-dd hh:mm:ss.lll +! +! If set, then all two digit dates less than its value are interpreted +! as 21st century dates. +! +!milleniumBoundary=50 +! +! Set to 1 causes the date string "now" to store a full timestamp. +! Default is to store only the date for fields with now hour in the +! format string. +! +nowMeansTime=0 + +!--------------------------------------------------------------------- +! +! STRING HANDLING PROPERTIES +! +!--------------------------------------------------------------------- + +! +! If set to 1 then String hashes use the JDK Object.hashCode() function. +! By default, uses InstantDB's String hashing. +! +altStringHashing=0 +! +! Set to 1 to cause LIKE clauses to always perform case insensitive +! comparisons. +! +likeIgnoreCase=0 +! +! Same as SET LITERAL STRICT_ON. Prevents string literals being interpreted +! as column names or numbers. Default is 0. +! +strictLiterals=0 +! +! Set this value to 1 (one) if you would like PreparedStatement.setString() +! to ignore "\" (backslash) characters when proceesing string constants. +! When set, InstantDB will not attempt to interpret \ as the start of an +! escape sequence. Default is 0. +! +!prepareIgnoresEscapes=1 + +!--------------------------------------------------------------------- +! +! MISCELLANEOUS PROPERTIES +! +!--------------------------------------------------------------------- + +! +! Allows selected InstantDB keywords to be un-reserved. +! e.g. ignoreKeywords=url,quote would allow the keywords +! url and quote to be used as table or column names. +! +! This faciliy is provided for compatatbility reasons only. +! It's use is not recommended AND IS NOT SUPPORTED. +! +!ignoreKeywords +! +! Non-zero means database is opened in read only mode. +! +readOnly=0 diff --git a/jonas_4_10/jonas/examples/alarm/etc/application.xml b/jonas_4_10/jonas/examples/alarm/etc/application.xml new file mode 100644 index 0000000000000000000000000000000000000000..f48944b614f4dacf37f97fa55e8c2600714287d3 --- /dev/null +++ b/jonas_4_10/jonas/examples/alarm/etc/application.xml @@ -0,0 +1,18 @@ + + + + + alarm + alarm demo + + + alarm.jar + + + + + alarm.war + alarm + + + diff --git a/jonas_4_10/jonas/examples/alarm/etc/jonas-web.xml b/jonas_4_10/jonas/examples/alarm/etc/jonas-web.xml new file mode 100644 index 0000000000000000000000000000000000000000..f05f484aff5cd9454bf143266003e645b7949b90 --- /dev/null +++ b/jonas_4_10/jonas/examples/alarm/etc/jonas-web.xml @@ -0,0 +1,16 @@ + + + + + + + jms/AlarmTopic + AlarmTopic + + + + jms/TopicFactory + JTCF + + + diff --git a/jonas_4_10/jonas/examples/alarm/etc/web-jetty.xml b/jonas_4_10/jonas/examples/alarm/etc/web-jetty.xml new file mode 100644 index 0000000000000000000000000000000000000000..20da7c6c4358001627433dbfb0ef3e0db07ddb40 --- /dev/null +++ b/jonas_4_10/jonas/examples/alarm/etc/web-jetty.xml @@ -0,0 +1,25 @@ + + + + + + + + + Example Basic Authentication Area + + + + + Example Basic Authentication Area + memrlm_1 + + + + + diff --git a/jonas_4_10/jonas/examples/alarm/etc/web.xml b/jonas_4_10/jonas/examples/alarm/etc/web.xml new file mode 100644 index 0000000000000000000000000000000000000000..5be7afd8533642145b1181b2d42800f27699bc7f --- /dev/null +++ b/jonas_4_10/jonas/examples/alarm/etc/web.xml @@ -0,0 +1,58 @@ + + + + + + + + alarmsender + org.objectweb.alarm.Sender + + + + alarmsender + /secured/alarmsender + + + + jms/AlarmTopic + javax.jms.Topic + + + + jms/TopicFactory + javax.jms.TopicConnectionFactory + Container + + + + + Protected Area + + /secured/* + + + + tomcat + jetty + + + + + + BASIC + ALARM Authentication Area + + + + + tomcat + + + + jetty + + + diff --git a/jonas_4_10/jonas/examples/alarm/src/org/objectweb/alarm/Sender.java b/jonas_4_10/jonas/examples/alarm/src/org/objectweb/alarm/Sender.java new file mode 100644 index 0000000000000000000000000000000000000000..141b9f36e4ac9f2f45a77ba5adc6fe72248729ad --- /dev/null +++ b/jonas_4_10/jonas/examples/alarm/src/org/objectweb/alarm/Sender.java @@ -0,0 +1,115 @@ +// "plain/text" +package org.objectweb.alarm; + +import java.io.*; +import javax.jms.*; +import javax.servlet.*; +import javax.servlet.http.*; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.rmi.PortableRemoteObject; + +/** + * This servlet is used to send Alarms on a JMS topic + */ +public class Sender extends HttpServlet { + + public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { + + res.setContentType("text/html"); + PrintWriter out = res.getWriter(); + String device = req.getParameter("device"); + String level = req.getParameter("level"); + String message = req.getParameter("message"); + String sloop = req.getParameter("number"); + String stimeout = req.getParameter("timeout"); + int severity; + String error = ""; + + out.write("Alarm Sender Servlet"); + if (level.startsWith("S")) { + severity = 1; + } else if (level.startsWith("W")) { + severity = 2; + } else { + severity = 3; + } + int loop = (new Integer(sloop)).intValue(); + int timeout = (new Integer(stimeout)).intValue(); + + Context ictx = null; + try { + ictx = new InitialContext(); + } catch (Exception e) { + error += "Cannot get initial context:"+e; + } + + // Lookup JMS resources + TopicConnectionFactory tcf = null; + Topic mytopic = null; + TopicConnection mytc = null; + try { + // lookup the TopicConnectionFactory through its JNDI name + tcf = (TopicConnectionFactory) ictx.lookup("java:comp/env/jms/TopicFactory"); + // lookup the Topic through its JNDI name + mytopic = (Topic) ictx.lookup("java:comp/env/jms/AlarmTopic"); + } catch (NamingException e) { + error += "Cannot lookup JMS Resources:"+ e; + } + + // Create Connection + try { + mytc = tcf.createTopicConnection(); + } catch (Exception e) { + error += "Cannot create JMS Connection:"+ e; + } + + // Create Session + Publisher + TopicSession session = null; + TopicPublisher tp = null; + try { + session = mytc.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); + tp = session.createPublisher(mytopic); + } catch (Exception e) { + error += "Cannot create JMS Publisher:"+ e; + } + + // publish messages to the topic + try { + for (int i = 0 ; i < loop; i++) { + if (timeout > 0) { + Thread.currentThread().sleep(1000*timeout); + } + MapMessage mess = session.createMapMessage(); + mess.setInt("Severity", severity); + mess.setString("From", device); + mess.setString("Reason", message); + tp.publish(mess); + } + } catch (JMSException e) { + String l = e.getLinkedException().toString(); + error += " Exception while creating or sending message: "+ e; + error += " Linked Exception: "+l; + } catch (java.lang.InterruptedException e) { + out.println("Alarm Generator Interrupted"); + } + + if (error.equals("")) { + out.println("Message sent"); + } else { + out.println(error); + } + out.println("

return to Alarm Generator"); + out.println("

go to Alarm List"); + + // close connection + try { + mytc.close(); + } catch (Exception e) { + } + + out.println(""); + out.println(""); + } +} diff --git a/jonas_4_10/jonas/examples/alarm/web/generator.html b/jonas_4_10/jonas/examples/alarm/web/generator.html new file mode 100644 index 0000000000000000000000000000000000000000..10a01e1ee4fca1d7bd358e1f02cdcf90221d4778 --- /dev/null +++ b/jonas_4_10/jonas/examples/alarm/web/generator.html @@ -0,0 +1,37 @@ + +generator + + + + + + + + +
JOnAS LogoThe Alarm GeneratorTomcat LogoJetty Logo
+ +You can select which alarms will be sent, and how many of them. +It is also possible to periodically resend the same alarms by +setting a timer. + +

+

+text of the message itself: +

+device where the alarm comes from: +

+severity level of the Alarm Message: +

+ Severe Alarm
+ Warning
+ Informative Message
+
+

+number of messages that will be sent: +

+timeout in seconds: +

+ +

+ + diff --git a/jonas_4_10/jonas/examples/alarm/web/images/alarmArchi.gif b/jonas_4_10/jonas/examples/alarm/web/images/alarmArchi.gif new file mode 100644 index 0000000000000000000000000000000000000000..18e45cc9bd6e73fc5dab1c7735856c5017cf19b1 Binary files /dev/null and b/jonas_4_10/jonas/examples/alarm/web/images/alarmArchi.gif differ diff --git a/jonas_4_10/jonas/examples/alarm/web/images/jetty.png b/jonas_4_10/jonas/examples/alarm/web/images/jetty.png new file mode 100644 index 0000000000000000000000000000000000000000..21b5e63874b322808625b6ead0ef20cf56fa1c6f Binary files /dev/null and b/jonas_4_10/jonas/examples/alarm/web/images/jetty.png differ diff --git a/jonas_4_10/jonas/examples/alarm/web/images/logo_jonas.jpg b/jonas_4_10/jonas/examples/alarm/web/images/logo_jonas.jpg new file mode 100644 index 0000000000000000000000000000000000000000..3fe9b43072176d2275d8725eb977b781a9730306 Binary files /dev/null and b/jonas_4_10/jonas/examples/alarm/web/images/logo_jonas.jpg differ diff --git a/jonas_4_10/jonas/examples/alarm/web/images/return.gif b/jonas_4_10/jonas/examples/alarm/web/images/return.gif new file mode 100644 index 0000000000000000000000000000000000000000..af4f68f4a3a13e0ef1dc0045b04c2c93354cdf40 Binary files /dev/null and b/jonas_4_10/jonas/examples/alarm/web/images/return.gif differ diff --git a/jonas_4_10/jonas/examples/alarm/web/images/tomcat.gif b/jonas_4_10/jonas/examples/alarm/web/images/tomcat.gif new file mode 100644 index 0000000000000000000000000000000000000000..32f7d809fbf745e814598cae44329394515c4879 Binary files /dev/null and b/jonas_4_10/jonas/examples/alarm/web/images/tomcat.gif differ diff --git a/jonas_4_10/jonas/examples/alarm/web/index.html b/jonas_4_10/jonas/examples/alarm/web/index.html new file mode 100644 index 0000000000000000000000000000000000000000..1e833ab6d97a6d0ed146a89e3e689666601cff1e --- /dev/null +++ b/jonas_4_10/jonas/examples/alarm/web/index.html @@ -0,0 +1,68 @@ + + + The JOnAS Alarm Demo + + + + + + + + + + +
JOnAS LogoThe JOnAS Alarm DemoTomcat LogoJetty Logo
+ +

Goal of this demo

+ This little demo intends to show how you can use JOnAS, Tomcat or Jetty, and Joram + together to get a complete application using EJBs, servlets, html, JSPs, and + message driven beans. + +

Running this demo

+When you click to access this demo, your web browser should open a dialog box +asking you a user ID and a password. +Enter as login/password jonas/jonas. +

+Click Here to Start the Demo +

+Notice that the first time, Tomcat or Jetty has to compile each JSP and this may take several seconds. + +

Description of the different parts

+ + + + + + + + + + + + + + + + + + +
AlarmGeneratorAlarmGenerator is a servlet that generates alarms by +publishing messages on a topic. Once the JOnAS Server is running, this +servlet may be used to feed the Message Driven Bean listening +on the topic. +Click Here to Generate new Alarms +
Session bean ViewA Session bean is used to provide a remote access to the Alarm Service. Each user +will create its own session that will be reached from JSP pages or servlets.
Entity Bean AlarmRecordWhen a new alarm type is received, an entity bean is created. If the Alarm is already +known, its count is incremented only.
Message Driven BeanJMS is used to access asynchronously to the service. A Message Driven Bean is used +to collect Alarm sent by AlarmGenerator. It will then inform the AlarmManager +that will process it.
+

Architecture

+Alarm Demo Architecture + + diff --git a/jonas_4_10/jonas/examples/alarm/web/secured/createfilter.jsp b/jonas_4_10/jonas/examples/alarm/web/secured/createfilter.jsp new file mode 100644 index 0000000000000000000000000000000000000000..52750066d9af6f684c1dcd42705395451b2874ce --- /dev/null +++ b/jonas_4_10/jonas/examples/alarm/web/secured/createfilter.jsp @@ -0,0 +1,12 @@ + +create filter + + +<% + String device = request.getParameter("device"); + String level = request.getParameter("level"); + String profil = myview.newProfil(device, level); +%> + + + diff --git a/jonas_4_10/jonas/examples/alarm/web/secured/current.jsp b/jonas_4_10/jonas/examples/alarm/web/secured/current.jsp new file mode 100644 index 0000000000000000000000000000000000000000..70a68e686c0b1c26ef4ff0904eeca97985eeef33 --- /dev/null +++ b/jonas_4_10/jonas/examples/alarm/web/secured/current.jsp @@ -0,0 +1,115 @@ + +current page +<%@ include file="top.html" %> +<%@ page import="org.objectweb.alarm.beans.AlarmData" %> + +<% + String error = myview.getErrorMessage(); + if (error != null) { +%> +

+An error occured in the JOnAS Server: +<%=error%> +<% + } +%> +<% + AlarmData[] adlist = null; + boolean history = request.getParameter("listType").equals("History"); +%> + +<% + if (history) { + adlist = myview.getAllAlarms(); +%> + Log of all +<% + } else { + adlist = myview.getNewAlarms(); +%> + Current list of +<% + } +%> + alarms received on <%=myview.getProfil()%> + + + + + + + + + + + +<% + for (int i = 0; i < adlist.length; i++) { + AlarmData ad = adlist[i]; + int sev = ad.getSev(); + int state = ad.getState(); +%> + +<% switch (sev) { + case 1: +%> + + + + + + + +<% + } +%> +
identdatefrommessagecountstate
+<% + break; + case 2: +%> + +<% + break; + case 3: +%> + +<% + break; + default: +%> + +<% + break; + } +%> +<%=ad.getNum()%><%=ad.getDate()%><%=ad.getDevice()%><%=ad.getMessage()%><%=ad.getCount()%> +<% switch (state) { + case 1: +%> +received +<% + break; + case 2: +%> +processed +<% + break; + default: +%> +removed +<% + break; + } +%>
+
+

+<% if (history) { %> +View only the current list of Alarms for this filter. +<% } else { %> +View the full log of Alarms received for this filter. +<% } %> +

+Return to the list of filters + + diff --git a/jonas_4_10/jonas/examples/alarm/web/secured/list.jsp b/jonas_4_10/jonas/examples/alarm/web/secured/list.jsp new file mode 100644 index 0000000000000000000000000000000000000000..37879e8ec5fac22f4b9aca18514ee2e85252db80 --- /dev/null +++ b/jonas_4_10/jonas/examples/alarm/web/secured/list.jsp @@ -0,0 +1,107 @@ + +list page +<%@ include file="top.html" %> + +<% + String error = myview.getErrorMessage(); + if (error != null) { +%> +

+An error occured in the JOnAS Server: +

+<%=error%> +

+<% + } +%> +<% + String[] plist = myview.getProfils(); +%> +You have been authenticated by web container and you can access now the list of +alarms received for each filter. +The color used shows the current level of alarm: + + + + + + + + + + + + + + +
SEVERE ERROR
WARNING
INFO
NO ALARM
+
+

+ + + + + +
+You can see the list of alarm received for a special filter by +choosing in the list here after. +

+ + <% + for (int i = 0; i < plist.length; i++) { + String profil = plist[i]; + %> +<% + switch (myview.alarmLevel(profil)) { + case 1: +%> + +<% + break; + case 2: +%> + +<% + break; + case 3: +%> + +<% + break; + default: +%> + +<% + } +%> + + + + + <% + } + %> +
+<%=profil%> + +>See details + +>Remove filter +
+

+You can create a new filter by using +the following form. +
+

+device name: +

+ Only Severe Alarms
+ Warnings and Severe Alarms
+ All Alarm Messages
+

+ +

+
+Return to index page + + diff --git a/jonas_4_10/jonas/examples/alarm/web/secured/remove.jsp b/jonas_4_10/jonas/examples/alarm/web/secured/remove.jsp new file mode 100644 index 0000000000000000000000000000000000000000..ef063c475159b88d59bcf7230a1959b827ea0615 --- /dev/null +++ b/jonas_4_10/jonas/examples/alarm/web/secured/remove.jsp @@ -0,0 +1,13 @@ + +remove page + + +<% + String alarmPK = request.getParameter("alarm"); + myview.forgetAlarm(alarmPK); +%> + + + + + diff --git a/jonas_4_10/jonas/examples/alarm/web/secured/removefilter.jsp b/jonas_4_10/jonas/examples/alarm/web/secured/removefilter.jsp new file mode 100644 index 0000000000000000000000000000000000000000..a66d56d0e3c435914d7318535f2113edb16a1e24 --- /dev/null +++ b/jonas_4_10/jonas/examples/alarm/web/secured/removefilter.jsp @@ -0,0 +1,11 @@ + +remove filter + + +<% + String profil = request.getParameter("profil"); + myview.removeProfil(profil); +%> + + + diff --git a/jonas_4_10/jonas/examples/alarm/web/secured/setfilter.jsp b/jonas_4_10/jonas/examples/alarm/web/secured/setfilter.jsp new file mode 100644 index 0000000000000000000000000000000000000000..e22ebc4d45181ed57efe2a6d2d49a623a0579fda --- /dev/null +++ b/jonas_4_10/jonas/examples/alarm/web/secured/setfilter.jsp @@ -0,0 +1,13 @@ + +set filter + + +<% + String profil = request.getParameter("profil"); + myview.setProfil(profil); +%> + + + + + diff --git a/jonas_4_10/jonas/examples/alarm/web/secured/top.html b/jonas_4_10/jonas/examples/alarm/web/secured/top.html new file mode 100644 index 0000000000000000000000000000000000000000..ece8a76459e1fa1491cd47fbfe35fd614352422a --- /dev/null +++ b/jonas_4_10/jonas/examples/alarm/web/secured/top.html @@ -0,0 +1,15 @@ + + + + + + + + + + +
JOnAS LogoThe JOnAS Alarm DemoTomcat LogoJetty Logo
diff --git a/jonas_4_10/jonas/examples/alarm/web/secured/unsetfilter.jsp b/jonas_4_10/jonas/examples/alarm/web/secured/unsetfilter.jsp new file mode 100644 index 0000000000000000000000000000000000000000..4b53e8f3556c44d72b2189c5689a4349e1720cfd --- /dev/null +++ b/jonas_4_10/jonas/examples/alarm/web/secured/unsetfilter.jsp @@ -0,0 +1,10 @@ + +unset filter + + +<% + myview.setProfil(null); +%> + + + diff --git a/jonas_4_10/jonas/examples/build.properties b/jonas_4_10/jonas/examples/build.properties new file mode 100644 index 0000000000000000000000000000000000000000..71733ff650594bf2c69d5e97eb1ececa63a95d90 --- /dev/null +++ b/jonas_4_10/jonas/examples/build.properties @@ -0,0 +1,42 @@ +# --------------------------------------------------------------------------- +# JOnAS: Java(TM) Open Application Server +# Copyright (C) 1999 Bull S.A. +# Contact: jonas-team@objectweb.org +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +# USA +# +# Initial developer(s): ____________________________________. +# Contributor(s): ______________________________________. +# +# --------------------------------------------------------------------------- +# $Id$ +# --------------------------------------------------------------------------- + +# Properties defined in this file could be customized + +# options for java compiler +opt.javac.debug on +opt.javac.optimize off + +# To use the jike compiler +#build.compiler jikes + +# genic args +#verbose=true + +# protocols for Carol (jrmp,jeremie,iiop,cmi) +protocols.names=jrmp,jeremie,iiop +genicargs=-rmicopts -keep diff --git a/jonas_4_10/jonas/examples/build.xml b/jonas_4_10/jonas/examples/build.xml new file mode 100644 index 0000000000000000000000000000000000000000..49e40f910de13bc2cc30d8977a626ae26a80e7ae --- /dev/null +++ b/jonas_4_10/jonas/examples/build.xml @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jonas_4_10/jonas/examples/clusterDemo/README b/jonas_4_10/jonas/examples/clusterDemo/README new file mode 100644 index 0000000000000000000000000000000000000000..dafe130fb3adc855f0a9d59400d2fa05d6f98f68 --- /dev/null +++ b/jonas_4_10/jonas/examples/clusterDemo/README @@ -0,0 +1,49 @@ +Application Overview: +-------------------- +This application creates a number of thread that will do debit and credit operations +on an account. If the client runs against a cluster of JOnAS, the load will be balanced +between them. +It involves the different technics used in JOnAS: +- Entity Bean for BankAccount and BankOperation, persistent in a DataBase +- Session Bean to allow clients to create account and operations + +Directory structure: +-------------------- +src/ beans to be loaded in JOnAS. +client/ client java program. + +Compiling this test: +------------------- + +Use the Ant 1.5 build tool: + ant install + +Running this test: +----------------- +Prerequisite: + - You must have configured a Database. + The jndi name used in the bean is jdbc_1. + See $JONAS_ROOT/doc/GettingStarted.html for more information. + + +1) run JOnAS server on each server + The jonas.properties file must specify the following services : + - registry,jmx,jtm,dbm,ejb + The carol.properties file must specify that the used JNDI is cmi + - carol.protocols=cmi + See $JONAS_ROOT/doc/howto/Clustering.htlm for more information. + + jonas start + +2) Load the clusterDemo.jar on each server + jonas admin -a clusterDemo.jar + +3) Launch the client + jclient -cp $JONAS_BASE/ejbjars/clusterDemo.jar org.objectweb.clusterDemo.BankClient -l 10 -c 10 + + - The -l option specifies the number of loop each client thread does (in one loop, one debit and + one credit operations are realized + - The -c option specifies the number of client thread + +4) Stop the jonas server on every servers + jonas stop diff --git a/jonas_4_10/jonas/examples/clusterDemo/build.xml b/jonas_4_10/jonas/examples/clusterDemo/build.xml new file mode 100644 index 0000000000000000000000000000000000000000..c10d3ec20275e4831150df06c5e3ea249a610206 --- /dev/null +++ b/jonas_4_10/jonas/examples/clusterDemo/build.xml @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jonas_4_10/jonas/examples/clusterDemo/client/org/objectweb/clusterDemo/BankClient.java b/jonas_4_10/jonas/examples/clusterDemo/client/org/objectweb/clusterDemo/BankClient.java new file mode 100644 index 0000000000000000000000000000000000000000..3d6f2eea2c64654727f577ea34a068a509f40810 --- /dev/null +++ b/jonas_4_10/jonas/examples/clusterDemo/client/org/objectweb/clusterDemo/BankClient.java @@ -0,0 +1,161 @@ +// BankClient.java + +package org.objectweb.clusterDemo; + +import java.util.Date; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.rmi.PortableRemoteObject; +import javax.transaction.UserTransaction; +import java.lang.Thread; + +import org.objectweb.clusterDemo.*; + +public class BankClient { + + private static final int m_MAXTHREADS = 100; + + private static int m_loops = 1; + + private static int m_clients = 1; + + private static void usage() { + System.out.println("Usage: java org.objectweb.clusterDemo.BankClient "); + System.out.println(" -l number of loops per thread"); + System.out.println(" -c number of client threads"); + System.out.println("default args:"); + System.out.println(" -l " + m_loops + " -c " + m_clients); + } + + public static void main(String args[]) { + + // Get command args + for (int argn = 0; argn < args.length; argn++) { + String s_arg = args[argn]; + Integer i_arg; + if ((s_arg.equals("-l") == true)) { + s_arg = args[++argn]; + i_arg = java.lang.Integer.valueOf(s_arg); + m_loops = i_arg.intValue(); + } else if ((s_arg.equals("-c") == true)) { + s_arg = args[++argn]; + i_arg = java.lang.Integer.valueOf(s_arg); + m_clients = i_arg.intValue(); + } else if (s_arg.equals("-?") == true) { + usage(); + System.exit(0); + } else { + usage(); + System.exit(2); + } + } + + // Check command args + if (m_loops < 1) { + usage(); + System.exit(2); + } + if (m_clients < 0) { + usage(); + System.exit(2); + } + + System.out.println("BankClient" + " -b " + m_loops + " -c " + m_clients); + + // Start pool of client threads + BankClientThread t_thr[] = new BankClientThread[m_MAXTHREADS]; + long ttime[] = new long[m_MAXTHREADS]; + for (int p = 0; p < m_clients; p++) { + t_thr[p] = new BankClientThread(m_loops); + t_thr[p].start(); + } + for (int p = 0; p < m_clients; p++) { + try { + t_thr[p].join(); + ttime[p] = t_thr[p].getTime(); + + } catch (InterruptedException e) { + System.out.println("ERROR: Problem in BankClientThread.join():\n" + e); + System.exit(2); + } + } + + System.out.println("BankClient " + " -l " + m_loops + " -c " + m_clients); + for (int p = 0; p < m_clients; p++) { + System.out.println(" " + ttime[p]); + } + System.out.println(""); + } + +} + +class BankClientThread extends Thread { + + private int m_loops; + + private long m_time; + + private Integer m_accountId; + + public BankClientThread(int b) { + m_loops = b; + } + + public void run() { + + System.out.println("Running a BankClientThread..."); + BankSessionHome bsh; + BankSession bs = null; + + Context initialContext = null; + try { + initialContext = new InitialContext(); + bsh = (BankSessionHome) initialContext.lookup("BankEJBBankSessionHome"); + bs = bsh.create(); + } catch (Exception e) { + System.out.println("ERROR: Problem initializing :\n" + e); + System.exit(2); + } + + // Create a client account + String clientName = "Client" + System.currentTimeMillis(); + try { + m_accountId = bs.createAccount(clientName, 1000); + } catch (Exception e) { + System.out.println("ERROR: Problem creating Account :\n" + e); + System.exit(2); + } + + // Loop + long d_begin = System.currentTimeMillis(); + + System.out.println("Start loop"); + System.out.println("Each loop does 1 debit and 1 credit operations"); + + for (int l = 0; l < m_loops; l++) { + + // Do one debit and one credit + try { + bs.debit(m_accountId, clientName, 100, "Retrait ATM"); + //sleep(1000); + bs.credit(m_accountId, clientName, 100, "Depot ATM"); + //sleep(1000); + + } catch (Exception e) { + System.out.println("ERROR: Problem during debit / credit phase :\n" + e); + System.exit(2); + } + + System.out.println("End of loop " + (l + 1) + " OK"); + } + + long d_end = System.currentTimeMillis(); + m_time = (d_end - d_begin) / (m_loops); + //m_time = m_time - 2000; + System.out.println("Time per transaction in millisec: " + m_time); + } + + public long getTime() { + return m_time; + } +} diff --git a/jonas/examples/clusterDemo/src/org/objectweb/clusterDemo/BankAccountECL.java b/jonas_4_10/jonas/examples/clusterDemo/src/org/objectweb/clusterDemo/BankAccountECL.java similarity index 100% rename from jonas/examples/clusterDemo/src/org/objectweb/clusterDemo/BankAccountECL.java rename to jonas_4_10/jonas/examples/clusterDemo/src/org/objectweb/clusterDemo/BankAccountECL.java diff --git a/jonas_4_10/jonas/examples/clusterDemo/src/org/objectweb/clusterDemo/BankAccountLocal.java b/jonas_4_10/jonas/examples/clusterDemo/src/org/objectweb/clusterDemo/BankAccountLocal.java new file mode 100644 index 0000000000000000000000000000000000000000..ee8d61650f406a637e97ec2cf6efbcc83759003c --- /dev/null +++ b/jonas_4_10/jonas/examples/clusterDemo/src/org/objectweb/clusterDemo/BankAccountLocal.java @@ -0,0 +1,24 @@ +// BankAccount.java + +package org.objectweb.clusterDemo; + +import javax.ejb.EJBLocalObject; + +/** + * BankAccount local interface + */ +public interface BankAccountLocal extends EJBLocalObject { + + /** + * credit method + */ + public void putMoney(int value); + + /** + * debit method + */ + public void getMoney(int value); + + public double getBalance(); + +} diff --git a/jonas_4_10/jonas/examples/clusterDemo/src/org/objectweb/clusterDemo/BankAccountLocalHome.java b/jonas_4_10/jonas/examples/clusterDemo/src/org/objectweb/clusterDemo/BankAccountLocalHome.java new file mode 100644 index 0000000000000000000000000000000000000000..20a4751821dd7ceaef2fc0932a0432bee391b4a2 --- /dev/null +++ b/jonas_4_10/jonas/examples/clusterDemo/src/org/objectweb/clusterDemo/BankAccountLocalHome.java @@ -0,0 +1,16 @@ +// BankAccountHome.java + +package org.objectweb.clusterDemo; + +import java.util.Collection; +import javax.ejb.CreateException; +import javax.ejb.EJBLocalHome; +import javax.ejb.FinderException; + +/** + * Local Home interface for the bean BankAccount + */ +public interface BankAccountLocalHome extends EJBLocalHome { + BankAccountLocal create(int balance, String name) throws CreateException; + BankAccountLocal findByPrimaryKey(java.lang.Integer pk) throws FinderException; +} diff --git a/jonas/examples/clusterDemo/src/org/objectweb/clusterDemo/BankOperationECL.java b/jonas_4_10/jonas/examples/clusterDemo/src/org/objectweb/clusterDemo/BankOperationECL.java similarity index 100% rename from jonas/examples/clusterDemo/src/org/objectweb/clusterDemo/BankOperationECL.java rename to jonas_4_10/jonas/examples/clusterDemo/src/org/objectweb/clusterDemo/BankOperationECL.java diff --git a/jonas_4_10/jonas/examples/clusterDemo/src/org/objectweb/clusterDemo/BankOperationLocal.java b/jonas_4_10/jonas/examples/clusterDemo/src/org/objectweb/clusterDemo/BankOperationLocal.java new file mode 100644 index 0000000000000000000000000000000000000000..2c55a7bf779eb43f9ceb36cc521d2a49b7342076 --- /dev/null +++ b/jonas_4_10/jonas/examples/clusterDemo/src/org/objectweb/clusterDemo/BankOperationLocal.java @@ -0,0 +1,26 @@ +// BankOperation.java + +package org.objectweb.clusterDemo; + +import javax.ejb.EJBLocalObject; + +/** + * BankOperation local interface + */ +public interface BankOperationLocal extends EJBLocalObject { + /** + * get value + */ + int getValue(); + + /** + * get date + */ + String getDate(); + + /** + * get reason + */ + String getReason(); + +} diff --git a/jonas_4_10/jonas/examples/clusterDemo/src/org/objectweb/clusterDemo/BankOperationLocalHome.java b/jonas_4_10/jonas/examples/clusterDemo/src/org/objectweb/clusterDemo/BankOperationLocalHome.java new file mode 100644 index 0000000000000000000000000000000000000000..1c3dbf8ece4a56c8e726f2d000973b1a4648a734 --- /dev/null +++ b/jonas_4_10/jonas/examples/clusterDemo/src/org/objectweb/clusterDemo/BankOperationLocalHome.java @@ -0,0 +1,16 @@ +// BankOperationHome.java + +package org.objectweb.clusterDemo; + +import java.util.Collection; +import javax.ejb.CreateException; +import javax.ejb.EJBLocalHome; +import javax.ejb.FinderException; + +/** + * Local Home interface for the bean BankOperation + */ +public interface BankOperationLocalHome extends EJBLocalHome { + BankOperationLocal create(int v, String r, String d) throws CreateException; + BankOperationLocal findByPrimaryKey(java.lang.Integer pk) throws FinderException; +} diff --git a/jonas_4_10/jonas/examples/clusterDemo/src/org/objectweb/clusterDemo/BankSession.java b/jonas_4_10/jonas/examples/clusterDemo/src/org/objectweb/clusterDemo/BankSession.java new file mode 100644 index 0000000000000000000000000000000000000000..fbc1f19c6ac1ee7b46b1214d64dc6917ee5ca16b --- /dev/null +++ b/jonas_4_10/jonas/examples/clusterDemo/src/org/objectweb/clusterDemo/BankSession.java @@ -0,0 +1,29 @@ +// BankSession.java + +package org.objectweb.clusterDemo; + +import java.rmi.RemoteException; +import javax.ejb.EJBObject; + +import java.util.*; + +/** + * BankSession remote interface + */ +public interface BankSession extends EJBObject { + /** + * credit method + */ + public void credit(Integer accountId, String clientName, int value, String reason) throws RemoteException; + + /** + * debit method + */ + public void debit(Integer accountId, String clientName, int value, String reason) throws RemoteException; + + /** + * createAccount method + */ + public Integer createAccount(String clientName, int value) throws RemoteException; + +} diff --git a/jonas_4_10/jonas/examples/clusterDemo/src/org/objectweb/clusterDemo/BankSessionHome.java b/jonas_4_10/jonas/examples/clusterDemo/src/org/objectweb/clusterDemo/BankSessionHome.java new file mode 100644 index 0000000000000000000000000000000000000000..75ec7d239145b5a673837ee3ef82d7240ade9008 --- /dev/null +++ b/jonas_4_10/jonas/examples/clusterDemo/src/org/objectweb/clusterDemo/BankSessionHome.java @@ -0,0 +1,18 @@ +// BankSessionHome.java + +package org.objectweb.clusterDemo; + +import java.rmi.RemoteException; +import java.util.Collection; +import javax.ejb.CreateException; +import javax.ejb.EJBHome; +import javax.ejb.FinderException; + +import java.util.Enumeration; + +/** + * Home interface for the bean BankSession + */ +public interface BankSessionHome extends EJBHome { + BankSession create() throws CreateException, RemoteException; +} diff --git a/jonas_4_10/jonas/examples/clusterDemo/src/org/objectweb/clusterDemo/BankSessionSLR.java b/jonas_4_10/jonas/examples/clusterDemo/src/org/objectweb/clusterDemo/BankSessionSLR.java new file mode 100644 index 0000000000000000000000000000000000000000..9c2e9bf32550fced49d2f4257b09b971d8ea3295 --- /dev/null +++ b/jonas_4_10/jonas/examples/clusterDemo/src/org/objectweb/clusterDemo/BankSessionSLR.java @@ -0,0 +1,211 @@ +// BankSessionSLR.java +// Stateless Session bean + +package org.objectweb.clusterDemo; + +import java.rmi.RemoteException; +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.Statement; +import javax.ejb.CreateException; +import javax.ejb.EJBException; +import javax.ejb.RemoveException; +import javax.ejb.EJBObject; +import javax.ejb.SessionBean; +import javax.ejb.SessionContext; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.sql.DataSource; + +import java.util.Vector; +import java.util.Calendar; +import java.util.GregorianCalendar; +import java.util.Iterator; + +import org.objectweb.jonas.common.Log; +import org.objectweb.util.monolog.api.Logger; +import org.objectweb.util.monolog.api.BasicLevel; + + +/** + * + */ +public class BankSessionSLR implements SessionBean { + + static private Logger logger = null; + SessionContext ejbContext; + + InitialContext ic = null; + private DataSource dataSource = null; + Connection conn = null; + Statement stmt; + + // ------------------------------------------------------------------ + // SessionBean implementation + // ------------------------------------------------------------------ + + /** + * Set the associated session context. The container calls this method + * after the instance creation. + * The enterprise Bean instance should store the reference to the context + * object in an instance variable. + * This method is called with no transaction context. + * + * @param sessionContext A SessionContext interface for the instance. + * @throws EJBException Thrown by the method to indicate a failure caused by + * a system-level error. + */ + public void setSessionContext(SessionContext ctx) { + if (logger == null) { + logger = Log.getLogger("org.objectweb.jonas_tests"); + } + logger.log(BasicLevel.DEBUG, ""); + ejbContext = ctx; + } + + /** + * A container invokes this method before it ends the life of the session object. + * This happens as a result of a client's invoking a remove operation, or when a + * container decides to terminate the session object after a timeout. + * This method is called with no transaction context. + * + * @throws EJBException Thrown by the method to indicate a failure caused by + * a system-level error. + */ + public void ejbRemove() { + logger.log(BasicLevel.DEBUG, ""); + } + + /** + * The Session bean must define 1 or more ejbCreate methods. + * + * @throws CreateException Failure to create a session EJB object. + */ + public void ejbCreate() throws CreateException { + logger.log(BasicLevel.DEBUG, ""); + try { + ic = new InitialContext(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + + /** + * A container invokes this method on an instance before the instance + * becomes disassociated with a specific EJB object. + */ + public void ejbPassivate() { + logger.log(BasicLevel.DEBUG, ""); + } + + /** + * A container invokes this method when the instance is taken out of + * the pool of available instances to become associated with a specific + * EJB object. + */ + public void ejbActivate() { + logger.log(BasicLevel.DEBUG, ""); + } + + // ------------------------------------------------------------------ + // BankSession implementation + // ------------------------------------------------------------------ + + /** + * credit method + */ + public void credit(Integer accountId, String clientName, int value, String reason) { + try { + logger.log(BasicLevel.DEBUG, ""); + BankAccountLocalHome accountHome = (BankAccountLocalHome)ic.lookup("java:comp/env/ejb/account"); + BankAccountLocal account = (BankAccountLocal)accountHome.findByPrimaryKey(accountId); + account.putMoney(value); + BankOperationLocalHome operationHome = (BankOperationLocalHome)ic.lookup("java:comp/env/ejb/operation"); + operationHome.create(value, reason+ " in bank " + getBank(), getDate()); + System.out.println(">>>>>> account " + clientName + " credited"); + } catch (Exception e) { + e.printStackTrace(); + } + + } + + /** + * debit method + */ + public void debit(Integer accountId, String clientName, int value, String reason) { + try { + logger.log(BasicLevel.DEBUG, ""); + BankAccountLocalHome accountHome = (BankAccountLocalHome)ic.lookup("java:comp/env/ejb/account"); + BankAccountLocal account = (BankAccountLocal)accountHome.findByPrimaryKey(accountId); + account.getMoney(value); + BankOperationLocalHome operationHome = (BankOperationLocalHome)ic.lookup("java:comp/env/ejb/operation"); + operationHome.create(value, reason + " in bank " + getBank(), getDate()); + System.out.println(">>>>>> account " + clientName + " debited"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * create new account + */ + public Integer createAccount(String clientName, int value) { + Integer accountId = null; + try { + logger.log(BasicLevel.DEBUG, ""); + BankAccountLocalHome accountHome = (BankAccountLocalHome)ic.lookup("java:comp/env/ejb/account"); + BankAccountLocal account = accountHome.create(value,clientName); + System.out.println(">>>>>> account " + clientName + " created"); + } catch (Exception e) { + e.printStackTrace(); + } + return accountId; + } + + + /** + * get Date method for primary key generation + */ + public String getDate() { + Calendar c = new GregorianCalendar(); + String result = c.get(Calendar.YEAR) + "/" + + c.get(Calendar.MONTH) + "/" + + c.get(Calendar.DAY_OF_MONTH) + " "; + int hour = c.get(Calendar.HOUR_OF_DAY); + if (hour < 10) { + result += "0"+hour+"h"; + } else { + result += ""+hour+"h"; + } + int minute = c.get(Calendar.MINUTE); + if (minute < 10) { + + result += "0"+minute+"m"; + } else { + result += ""+minute+"m"; + } + + int second = c.get(Calendar.SECOND); + if (second < 10) { + result += "0"+second+"s"; + } else { + result += ""+second+"s"; + } + return result + " " + getBank(); + } + + /** + * get Bank value from env value + */ + public String getBank() { + try { + return (String)ic.lookup("java:comp/env/bankname"); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + +} diff --git a/jonas_4_10/jonas/examples/clusterDemo/src/org/objectweb/clusterDemo/OperationJavaBean.java b/jonas_4_10/jonas/examples/clusterDemo/src/org/objectweb/clusterDemo/OperationJavaBean.java new file mode 100644 index 0000000000000000000000000000000000000000..c32a0ca94ee3d4d32cb154172f968f7a3feb1c1c --- /dev/null +++ b/jonas_4_10/jonas/examples/clusterDemo/src/org/objectweb/clusterDemo/OperationJavaBean.java @@ -0,0 +1,44 @@ +package org.objectweb.clusterDemo; + +import java.io.Serializable; + + +public class OperationJavaBean implements Serializable { + + + public String date; + public String value; + public String reason; + public String deleted; + + public OperationJavaBean(String d, String v, String r) { + date = d; + value = v; + reason = r; + } + + public void setDate(String d) { + date = d; + } + + public String getDate() { + return date; + } + + public void setValue(String s) { + value = s; + } + + public String getValue() { + return value; + } + + public void setReason(String r) { + reason = r; + } + + public String getReason() { + return reason; + } + +} diff --git a/jonas_4_10/jonas/examples/clusterDemo/src/org/objectweb/clusterDemo/clusterDemo.xml b/jonas_4_10/jonas/examples/clusterDemo/src/org/objectweb/clusterDemo/clusterDemo.xml new file mode 100644 index 0000000000000000000000000000000000000000..d3bf2f6f30f1ec6f110feb2794c3efa2ebdb5e03 --- /dev/null +++ b/jonas_4_10/jonas/examples/clusterDemo/src/org/objectweb/clusterDemo/clusterDemo.xml @@ -0,0 +1,117 @@ + + + + + Deployment Descriptor of clusterDemo + clusterDemo + + + + entity bean BankAccount + BankAccountECL + BankAccountECL + org.objectweb.clusterDemo.BankAccountLocalHome + org.objectweb.clusterDemo.BankAccountLocal + org.objectweb.clusterDemo.BankAccountECL + Container + java.lang.Object + false + 2.x + accounttable + + name + + + balance + + + + + entity bean BankOperation + BankOperationECL + BankOperationECL + org.objectweb.clusterDemo.BankOperationLocalHome + org.objectweb.clusterDemo.BankOperationLocal + org.objectweb.clusterDemo.BankOperationECL + Container + java.lang.Object + false + 2.x + operationtable + + value + + + reason + + + date + + + + + Describe here the session bean BankSession + BankSessionSLR + BankSessionSLR + org.objectweb.clusterDemo.BankSessionHome + org.objectweb.clusterDemo.BankSession + org.objectweb.clusterDemo.BankSessionSLR + Stateless + Container + + bankname + java.lang.String + JonasBank + + + ejb/account + Entity + org.objectweb.clusterDemo.BankAccountLocalHome + org.objectweb.clusterDemo.BankAccountLocal + BankAccountECL + + + ejb/operation + Entity + org.objectweb.clusterDemo.BankOperationLocalHome + org.objectweb.clusterDemo.BankOperationLocal + BankOperationECL + + + jdbc/clusterDemo + javax.sql.DataSource + Application + + + + + + + + + + BankAccountECL + * + + Required + + + + + BankOperationECL + * + + Required + + + + + BankSessionSLR + * + + Required + + + + + diff --git a/jonas_4_10/jonas/examples/clusterDemo/src/org/objectweb/clusterDemo/jonas-clusterDemo.xml b/jonas_4_10/jonas/examples/clusterDemo/src/org/objectweb/clusterDemo/jonas-clusterDemo.xml new file mode 100644 index 0000000000000000000000000000000000000000..1bc13f387a9425816868e1e698261c122ca73287 --- /dev/null +++ b/jonas_4_10/jonas/examples/clusterDemo/src/org/objectweb/clusterDemo/jonas-clusterDemo.xml @@ -0,0 +1,37 @@ + + + + + + BankAccountECL + BankEJBBankAccountECLHome + true + removeall + + jdbc_1 + + + + + BankOperationECL + BankEJBBankOperationECLHome + true + removeall + + jdbc_1 + + + + + BankSessionSLR + BankEJBBankSessionHome + + jdbc/clusterDemo + jdbc_1 + + + + diff --git a/jonas_4_10/jonas/examples/cmp2/README b/jonas_4_10/jonas/examples/cmp2/README new file mode 100644 index 0000000000000000000000000000000000000000..aaf9dfe63baef97d8ce6ca02667b152b764a6a7d --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/README @@ -0,0 +1,109 @@ + + +Example Overview +================ + +This example shows how to use new features of container managed persistence +in EJB 2.0, like Entity Relationships and EJB-QL. + +The code of the EJBs used in this example comes from the book: + "Enterprise JavaBeans(TM)" Third Edition + by Richard Monson-Haefel + [O'REILLY edition ISBN 0-596-00226-2] + +We have packaged this example as an ear since the client is implemented +as three servlets. + + +Directories structure +===================== + +The "src" directory contains: + +- eight Entity beans: + CustomerEJB, + AddressEJB, + PhoneEJB, + CreditCardEJB, + CruiseEJB, + ShipEJB, + ReservationEJB, + CabinEJB, + Sequence. + The seven first beans shows the seven relationship types, + the last is used for an automatic generation of primary keys. + +- three Session beans: + TravelAgentEJB, + RTravelAgentEJB, + SequenceSession. + +- three servlets: + ServletTest + shows one to one relationship unidirectional or bidirectional, + ServletTest2 + shows one to many, many to one, many to many + uni and bidirectional relationships + ServletTest3 + shows example of finder methods using many EJB-QL examples + +The "etc" directory contains: + +- the "xml" directory which contains all the deployment descriptors + used for this example : + application.xml (ear file), + ejb-jar.xml and jonas-ejb-jar.xml (jar file), + web.xml and jonas-web.xml (war file). + +- the "resources" directory which contains all the resources for this + application + "web" directory contains all resources used by the servlets + + +Compiling this example creates an .ear file that represents the application +including : +- all the beans used by the web application, +- a web application that will be used by Tomcat or Jetty to run the servlets. + + +Prerequisites +============= +First, you must have installed a web container (ie : Catalina or Jetty) +as the web container service + +You have to set the environment variables + CATALINA_HOME and CATALINA_BASE as indicated in the Tomcat 4.1.x documentation. +or JETTY_HOME for Jetty 4.2.x + +(See the howto on ObjectWeb : http://www.objectweb.org/jonas/doc/index.html) + +As for the other JOnAS examples, you have to configure a datasource. +It's JNDI name must be 'jdbc_1'. +The 'datasource.mappername' property value must be up-to-date. + + +Building this example +===================== +Under $JONAS_ROOT/examples/cmp2, do + $ ant install + + +Running this example +==================== +Commands are given for an Unix system, similar commands can be done on +Windows. + +1) Run a JOnAS server: + $ jonas start + +2) Load cmp2.ear (if you have not added it in the ear service descriptors list) using jonasAdmin +management application (http://:/jonasAdmin) or the 'jonas admin' command. + +3) Lookup at http://:/cmp2 to start this example + - is the name of your machine (localhost by default), and + - the port number (9000 by default). + +4) Stop the jonas server + $jonas stop + + diff --git a/jonas_4_10/jonas/examples/cmp2/build.xml b/jonas_4_10/jonas/examples/cmp2/build.xml new file mode 100644 index 0000000000000000000000000000000000000000..f908e750b1e79c14f3e4182b55dfd820b04b031a --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/build.xml @@ -0,0 +1,137 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jonas_4_10/jonas/examples/cmp2/etc/resources/web/index.html b/jonas_4_10/jonas/examples/cmp2/etc/resources/web/index.html new file mode 100644 index 0000000000000000000000000000000000000000..28695422eb009cd8e48506c96fc58256182fc110 --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/etc/resources/web/index.html @@ -0,0 +1,111 @@ + + + + + JOnAS example cmp2 + + + + +

cmp2 : EJB 2.0 Container Managed Persistence

+ +

This example shows how to use new features of container managed persistence + in EJB 2.0, like Entity Relationships and EJB-QL.

+ +

The code of the EJBs used in this example comes from the book + "Enterprise JavaBeans(TM)" Third Edition by Richard Monson-Haefel +
[O'REILLY edition ISBN 0-596-00226-2] +

+ +

Examples Showing One to One Relationships:

+
    +
  • One to One Unidirectional Relationship: +
    Customer --> Address

  • +
  • One to One Bidirectional Relationship: +
    Customer <--> CreditCard

  • +
  • One to Many Unidirectional Relationship: +
    Customer --> Phone

  • +
+ + + + + + +
+ Run the tests? + +
+ +
+
+ + +

Examples Showing Many to One, One to Many, and Many to Many Relationships:

+
    +
  • Many to One Unidirectional Relationship: +
    Cruise --> Ship

  • +
  • One to Many Bidirectional Relationship: +
    Cruise <--> Reservation

  • +
  • Many to Many Bidirectional Relationship: +
    Customer <--> Reservation

  • +
  • Many to Many Unidirectional Relationship: +
    Reservation --> Cabin

  • +
+ + + + + + +
+ Run the tests? + +
+ +
+
+ +

Examples Showing EJB-QL:

+
    +
  • SELECT OBJECT(s) FROM JE2_Ship AS s WHERE s.tonnage = ?1
  • +
  • SELECT OBJECT(s) FROM JE2_Ship AS s WHERE s.tonnage BETWEEN ?1 AND ?2
  • +
  • SELECT OBJECT(c) FROM JE2_Customer AS c
  • +
  • SELECT OBJECT(c) FROM JE2_Cruise AS c WHERE c.name = ?1
  • +
  • SELECT OBJECT(c) FROM JE2_Customer AS c +
    WHERE c.lastName = ?1 AND c.firstName = ?2
  • +
  • SELECT OBJECT(c) FROM JE2_Customer AS c WHERE c.lastName = 'Smith90'
  • +
  • SELECT OBJECT(c) FROM JE2_Customer AS c +
    WHERE c.lastName LIKE ?1 AND c.firstName LIKE ?2
  • +
  • SELECT OBJECT(c) FROM JE2_Customer AS c WHERE c.hasGoodCredit = TRUE
  • +
  • SELECT OBJECT(c) FROM JE2_Customer AS c +
    WHERE c.homeAddress.city = ?1 AND c.homeAddress.state = ?2
  • +
  • SELECT OBJECT(c) FROM JE2_Customer AS c +
    WHERE c.lastName LIKE ?1 AND c.firstName LIKE ?2 AND c.homeAddress.state = ?3
  • +
  • SELECT OBJECT(c) FROM JE2_Cabin AS c WHERE c.deckLevel = ?1
  • +
  • SELECT OBJECT(c) FROM JE2_Customer AS c +
    WHERE c.homeAddress.state IN ('FL','TX','AZ','CA')
  • +
  • SELECT OBJECT(c) FROM JE2_Customer AS c WHERE c.reservations IS EMPTY
  • +
  • SELECT OBJECT(c) FROM JE2_Customer AS cust, Cruise AS cr, IN (cr.reservations) AS res +
    WHERE cr = ?1 AND cust MEMBER OF res.customers
  • +
  • SELECT a.zip FROM JE2_Address AS a WHERE a.state = ?1
  • +
  • SELECT OBJECT(c) FROM JE2_Customer AS c WHERE c.homeAddress = ?1
  • +
  • .....
  • +
+ + + + + + +
+ Run the tests? + +
+ +
+
+ + + + diff --git a/jonas_4_10/jonas/examples/cmp2/etc/resources/web/style.css b/jonas_4_10/jonas/examples/cmp2/etc/resources/web/style.css new file mode 100644 index 0000000000000000000000000000000000000000..4f852c2a87c8be61ad1e242e706f92197a35396c --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/etc/resources/web/style.css @@ -0,0 +1,13 @@ +body { + background : white; + color : black; +} +h1, h2, h3 {font-family : sans-serif; } +h1 {font-size : 175%; color : DarkCyan; text-align : center;} +h2 {font-size : 150%; color : DarkCyan; + border-bottom : solid; + border-bottom-width : 1; +} +h3 {font-size : 125%; } +strong { font-weight : bold; } +hr { size : 1; width : 100%; } diff --git a/jonas_4_10/jonas/examples/cmp2/etc/xml/application.xml b/jonas_4_10/jonas/examples/cmp2/etc/xml/application.xml new file mode 100644 index 0000000000000000000000000000000000000000..945d7cc97dd4fb377c4e5b8897ba848c73748683 --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/etc/xml/application.xml @@ -0,0 +1,23 @@ + + + + + cmp2 example EJB2.0 container managed persistence + cmp2 servlet + + + + cmp2.jar + + + + + cmp2.war + cmp2 + + + diff --git a/jonas_4_10/jonas/examples/cmp2/etc/xml/cmp2.xml b/jonas_4_10/jonas/examples/cmp2/etc/xml/cmp2.xml new file mode 100644 index 0000000000000000000000000000000000000000..c24df0a211c5fe1801034be17ea8ecb160d1827c --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/etc/xml/cmp2.xml @@ -0,0 +1,715 @@ + + + + + Deployment descriptor for the cmp2 JOnAS example + cmp2 example + + + + CustomerEJB + com.titan.customer.CustomerHomeRemote + com.titan.customer.CustomerRemote + com.titan.customer.CustomerHomeLocal + com.titan.customer.CustomerLocal + com.titan.customer.CustomerBean + Container + java.lang.Integer + false + 2.x + JE2_Customer + id + lastName + firstName + hasGoodCredit + id + + ejb/AddressHomeLocal + Entity + com.titan.address.AddressHomeLocal + com.titan.address.AddressLocal + AddressEJB + + + ejb/CreditCardHome + Entity + com.titan.customer.CreditCardHomeLocal + com.titan.customer.CreditCardLocal + CreditCardEJB + + + ejb/PhoneHomeLocal + Entity + com.titan.phone.PhoneHomeLocal + com.titan.phone.PhoneLocal + PhoneEJB + + + + + findAllCustomers + + + SELECT OBJECT(c) FROM JE2_Customer AS c + + + + findByName + + java.lang.String + java.lang.String + + + + SELECT OBJECT(c) FROM JE2_Customer c + WHERE c.lastName LIKE ?1 AND c.firstName LIKE ?2 + + + + + findSmith90 + + + + SELECT OBJECT(c) FROM JE2_Customer c + WHERE c.lastName = 'Smith90' + + + + + findByExactName + + java.lang.String + java.lang.String + + + + SELECT OBJECT(c) FROM JE2_Customer c + WHERE c.lastName = ?1 AND c.firstName = ?2 + + + + + findByNameAndState + + java.lang.String + java.lang.String + java.lang.String + + + + SELECT OBJECT(c) FROM JE2_Customer c + WHERE c.lastName LIKE ?1 AND c.firstName LIKE ?2 AND c.homeAddress.state = ?3 + + + + + findByGoodCredit + + + + SELECT OBJECT(c) FROM JE2_Customer c + WHERE c.hasGoodCredit = TRUE + + + + + findByCity + + java.lang.String + java.lang.String + + + + SELECT OBJECT(c) FROM JE2_Customer c + WHERE c.homeAddress.city = ?1 AND c.homeAddress.state = ?2 + + + + + findInHotStates + + + + SELECT OBJECT(c) FROM JE2_Customer c + WHERE c.homeAddress.state IN ('FL','TX','AZ','CA') + + + + + findWithNoReservations + + + + SELECT OBJECT(c) FROM JE2_Customer c + WHERE c.reservations IS EMPTY + + + + + findOnCruise + + com.titan.cruise.CruiseLocal + + + + SELECT OBJECT(cust) FROM JE2_Customer cust, JE2_Cruise cr, IN (cr.reservations) AS res + WHERE cr = ?1 AND cust MEMBER OF res.customers + + + + + findByState + + java.lang.String + + + + SELECT OBJECT(c) FROM JE2_Customer c + WHERE c.homeAddress.state = ?1 + ORDER BY c.lastName,c.firstName + + + + + + AddressEJB + com.titan.address.AddressHomeLocal + com.titan.address.AddressLocal + com.titan.address.AddressBean + Container + java.lang.Object + false + 2.x + JE2_Address + street + city + state + zip + + + + findAllAddress + + + SELECT OBJECT(c) FROM JE2_Address c + + + + ejbSelectZipCodes + + java.lang.String + + + SELECT a.zip FROM JE2_Address AS a WHERE a.state = ?1 + + + + ejbSelectAll + + + SELECT OBJECT(a) FROM JE2_Address AS a + + + + ejbSelectCustomer + + com.titan.address.AddressLocal + + + SELECT OBJECT(c) FROM JE2_Customer AS c WHERE c.homeAddress = ?1 + + + + + PhoneEJB + com.titan.phone.PhoneHomeLocal + com.titan.phone.PhoneLocal + com.titan.phone.PhoneBean + Container + java.lang.Object + false + 2.x + JE2_Phone + number + type + + + + findAllPhones + + + SELECT OBJECT(c) FROM JE2_Phone c + + + + + CreditCardEJB + com.titan.customer.CreditCardHomeLocal + com.titan.customer.CreditCardLocal + com.titan.customer.CreditCardBean + Container + java.lang.Object + false + 2.x + JE2_CreditCard + expirationDate + number + nameOnCard + creditOrganization + + + + findAllCreditCards + + + SELECT OBJECT(cc) FROM JE2_CreditCard cc + + + + + CruiseEJB + com.titan.cruise.CruiseHomeLocal + com.titan.cruise.CruiseLocal + com.titan.cruise.CruiseBean + Container + java.lang.Object + false + 2.x + JE2_Cruise + name + + + + findAllCruises + + + SELECT OBJECT(cc) FROM JE2_Cruise cc + + + + findByName + + java.lang.String + + + SELECT OBJECT(c) FROM JE2_Cruise c WHERE c.name = ?1 + + + + + ShipEJB + com.titan.ship.ShipHomeLocal + com.titan.ship.ShipLocal + com.titan.ship.ShipBean + Container + java.lang.Integer + false + 2.x + JE2_Ship + id + name + tonnage + id + + + + findAllShips + + + SELECT OBJECT(cc) FROM JE2_Ship cc + + + + findByTonnage + + java.lang.Double + + + + SELECT OBJECT(s) FROM JE2_Ship s + WHERE s.tonnage = ?1 + + + + + findByTonnage + + java.lang.Double + java.lang.Double + + + + SELECT OBJECT(s) FROM JE2_Ship s + WHERE s.tonnage BETWEEN ?1 AND ?2 + + + + + + ReservationEJB + com.titan.reservation.ReservationHomeLocal + com.titan.reservation.ReservationLocal + com.titan.reservation.ReservationBean + Container + java.lang.Object + false + 2.x + JE2_Reservation + amountPaid + date + + + + findAllReservations + + + SELECT OBJECT(cc) FROM JE2_Reservation cc + + + + + CabinEJB + com.titan.cabin.CabinHomeRemote + com.titan.cabin.CabinRemote + com.titan.cabin.CabinHomeLocal + com.titan.cabin.CabinLocal + com.titan.cabin.CabinBean + Container + java.lang.Integer + false + 2.x + JE2_Cabin + id + name + deckLevel + bedCount + id + + + + findAllOnDeckLevel + + java.lang.Integer + + + + SELECT OBJECT(c) FROM JE2_Cabin as c WHERE c.deckLevel = ?1 + + + + + findAllCabins + + + SELECT OBJECT(cc) FROM JE2_Cabin cc + + + + ejbSelectAllForCustomer + + com.titan.customer.CustomerLocal + + + SELECT OBJECT(cab) FROM JE2_Customer AS cust, + IN (cust.reservations) AS res, IN (res.cabins) AS cab + WHERE cust = ?1 + + + + + + TravelAgentEJB + com.titan.travelagent.TravelAgentHomeRemote + com.titan.travelagent.TravelAgentRemote + com.titan.travelagent.TravelAgentBean + Stateless + Container + + ejb/CabinHomeLocal + Entity + com.titan.cabin.CabinHomeLocal + com.titan.cabin.CabinLocal + CabinEJB + + + + + + RTravelAgentEJB + com.titan.travelagent.RTravelAgentHomeRemote + com.titan.travelagent.RTravelAgentRemote + com.titan.travelagent.RTravelAgentBean + Stateless + Container + + ejb/CabinHomeRemote + Entity + com.titan.cabin.CabinHomeRemote + com.titan.cabin.CabinRemote + + + + + + + + + Customer-Address + + Customer-has-a-Address + One + + CustomerEJB + + + homeAddress + + + + Address-belongs-to-Customer + One + + + AddressEJB + + + + + + Customer-CreditCard + + Customer-has-a-CreditCard + One + + CustomerEJB + + creditCard + + + CreditCard-belongs-to-Customer + One + + + CreditCardEJB + + customer + + + + + Customer-Phones + + Customer-has-many-Phone-numbers + One + + CustomerEJB + + + phoneNumbers + java.util.Collection + + + + Phone-belongs-to-Customer + Many + + + PhoneEJB + + + + + + Customer-Reservation + + Customer-has-many-Reservations + Many + + CustomerEJB + + + reservations + java.util.Collection + + + + Reservation-has-many-Customers + Many + ReservationEJB + + + customers + java.util.Set + + + + + + Cruise-Ship + + Cruise-has-a-Ship + Many + + CruiseEJB + + ship + + + Ship-has-many-Cruises + One + + ShipEJB + + + + + + Cruise-Reservation + + Cruise-has-many-Reservations + One + + CruiseEJB + + + reservations + java.util.Collection + + + + Reservation-has-a-Cruise + Many + + ReservationEJB + + cruise + + + + + Cabin-Ship + + Cabin-has-a-Ship + Many + + CabinEJB + + ship + + + Ship-has-many-Cabins + One + + ShipEJB + + + + + + Cabin-Reservation + + Cabin-has-many-Reservations + Many + + CabinEJB + + + + Reservation-has-many-Cabins + Many + + ReservationEJB + + + cabins + java.util.Set + + + + + + + + + + + + CabinEJB + * + + + RTravelAgentEJB + * + + + TravelAgentEJB + * + + + CustomerEJB + * + + + AddressEJB + * + + + CreditCardEJB + * + + + PhoneEJB + * + + + CruiseEJB + * + + + ShipEJB + * + + + ReservationEJB + * + + Required + + + + + SequenceSession + * + + + Sequence + * + + Required + + + + + + diff --git a/jonas_4_10/jonas/examples/cmp2/etc/xml/jonas-cmp2.xml b/jonas_4_10/jonas/examples/cmp2/etc/xml/jonas-cmp2.xml new file mode 100644 index 0000000000000000000000000000000000000000..147cfb33b75db6b558f526905abcd87c3c0b3a6e --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/etc/xml/jonas-cmp2.xml @@ -0,0 +1,74 @@ + + + + + + CustomerEJB + CustomerHomeRemote + jdbc_1 + + + + AddressEJB + + jdbc_1 + + + + + CabinEJB + jdbc_1 + + + + PhoneEJB + + jdbc_1 + + + + + CreditCardEJB + + jdbc_1 + + + + + CruiseEJB + + jdbc_1 + + + + + ShipEJB + jdbc_1 + + + + ReservationEJB + + jdbc_1 + + + + + + RTravelAgentEJB + RTravelAgentHomeRemote + + ejb/CabinHomeRemote + CabinHomeRemote + + + + diff --git a/jonas_4_10/jonas/examples/cmp2/etc/xml/web.xml b/jonas_4_10/jonas/examples/cmp2/etc/xml/web.xml new file mode 100644 index 0000000000000000000000000000000000000000..7d1526774735b7640f814704193520b80ae841eb --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/etc/xml/web.xml @@ -0,0 +1,103 @@ + + + + + + + ServletTest + servlets.ServletTest + + + + ServletTest2 + servlets.ServletTest2 + + + + ServletTest3 + servlets.ServletTest3 + + + + ServletTest + /test1 + + + + ServletTest2 + /test2 + + + + ServletTest3 + /test3 + + + + ejb/CreditCardHomeLocal + Entity + com.titan.customer.CreditCardHomeLocal + com.titan.customer.CreditCardLocal + cmp2.jar#CreditCardEJB + + + + ejb/CustomerHomeLocal + Entity + com.titan.customer.CustomerHomeLocal + com.titan.customer.CustomerLocal + cmp2.jar#CustomerEJB + + + + ejb/AddressHomeLocal + Entity + com.titan.address.AddressHomeLocal + com.titan.address.AddressLocal + cmp2.jar#AddressEJB + + + + ejb/ShipHomeLocal + Entity + com.titan.address.ShipHomeLocal + com.titan.address.ShipLocal + cmp2.jar#ShipEJB + + + + ejb/CruiseHomeLocal + Entity + com.titan.address.CruiseHomeLocal + com.titan.address.CruiseLocal + cmp2.jar#CruiseEJB + + + + ejb/ReservationHomeLocal + Entity + com.titan.address.ReservationHomeLocal + com.titan.address.ReservationLocal + cmp2.jar#ReservationEJB + + + + ejb/CabinHomeLocal + Entity + com.titan.address.CabinHomeLocal + com.titan.address.CabinLocal + cmp2.jar#CabinEJB + + + + ejb/PhoneHomeLocal + Entity + com.titan.adress.PhoneHomeLocal + com.titan.address.PhoneLocal + cmp2.jar#PhoneEJB + + + diff --git a/jonas_4_10/jonas/examples/cmp2/src/com/titan/address/AddressBean.java b/jonas_4_10/jonas/examples/cmp2/src/com/titan/address/AddressBean.java new file mode 100644 index 0000000000000000000000000000000000000000..1c59356ade661cb03523dac05a3a494d81ba1437 --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/src/com/titan/address/AddressBean.java @@ -0,0 +1,83 @@ +package com.titan.address; + +import java.util.Collection; +import java.util.Set; + +import javax.ejb.EntityContext; +import javax.ejb.FinderException; + +import com.titan.customer.CustomerLocal; + +public abstract class AddressBean implements javax.ejb.EntityBean { + + public Integer ejbCreateAddress(String street, String city, String state, String zip) + throws javax.ejb.CreateException { + setStreet(street); + setCity(city); + setState(state); + setZip(zip); + return null; + } + + public void ejbPostCreateAddress(String street, String city, String state, String zip) { + + } + + // select methods + public abstract Set ejbSelectZipCodes(String state) throws FinderException; + + public abstract Collection ejbSelectAll() throws FinderException; + + public abstract CustomerLocal ejbSelectCustomer(AddressLocal addr) throws FinderException; + + // Public Home method required to test the private ejbSelectZipCodes method + public Collection ejbHomeSelectZipCodes(String state) throws FinderException { + return this.ejbSelectZipCodes(state); + } + + // Public Home method required to test the private ejbSelectCustomer method + public CustomerLocal ejbHomeSelectCustomer(AddressLocal addr) throws FinderException { + return (CustomerLocal) (this.ejbSelectCustomer(addr)); + } + + // persistent fields + public abstract String getStreet(); + + public abstract void setStreet(String street); + + public abstract String getCity(); + + public abstract void setCity(String city); + + public abstract String getState(); + + public abstract void setState(String state); + + public abstract String getZip(); + + public abstract void setZip(String zip); + + // standard call back methods + + public void setEntityContext(EntityContext ec) { + } + + public void unsetEntityContext() { + } + + public void ejbLoad() { + } + + public void ejbStore() { + } + + public void ejbActivate() { + } + + public void ejbPassivate() { + } + + public void ejbRemove() throws javax.ejb.RemoveException { + } + +} diff --git a/jonas_4_10/jonas/examples/cmp2/src/com/titan/address/AddressHomeLocal.java b/jonas_4_10/jonas/examples/cmp2/src/com/titan/address/AddressHomeLocal.java new file mode 100644 index 0000000000000000000000000000000000000000..7bac2363c4cf50f65f53f3f34657b5c1ca462ed7 --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/src/com/titan/address/AddressHomeLocal.java @@ -0,0 +1,26 @@ +package com.titan.address; + +import java.util.Collection; + +import com.titan.customer.CustomerLocal; + +// Address EJB's local home interface +public interface AddressHomeLocal extends javax.ejb.EJBLocalHome { + + public AddressLocal createAddress(String street, String city, String state, String zip ) + throws javax.ejb.CreateException; + + public AddressLocal findByPrimaryKey(Integer primaryKey) + throws javax.ejb.FinderException; + + public Collection findAllAddress() + throws javax.ejb.FinderException; + + // Home method, requires ejbHomeSelectZipCodes method in bean class + public Collection selectZipCodes(String state) + throws javax.ejb.FinderException; + + // Home method, requires ejbHomeSelectCustomer method in bean class + public CustomerLocal selectCustomer(AddressLocal addr) + throws javax.ejb.FinderException; +} diff --git a/jonas_4_10/jonas/examples/cmp2/src/com/titan/address/AddressLocal.java b/jonas_4_10/jonas/examples/cmp2/src/com/titan/address/AddressLocal.java new file mode 100644 index 0000000000000000000000000000000000000000..360a00bbe96a93f690804ad3abcb3d45f4ea16e0 --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/src/com/titan/address/AddressLocal.java @@ -0,0 +1,21 @@ +package com.titan.address; + +// Address EJB's local interface +public interface AddressLocal extends javax.ejb.EJBLocalObject { + + public String getStreet(); + + public void setStreet(String street); + + public String getCity(); + + public void setCity(String city); + + public String getState(); + + public void setState(String state); + + public String getZip(); + + public void setZip(String zip); +} \ No newline at end of file diff --git a/jonas_4_10/jonas/examples/cmp2/src/com/titan/cabin/CabinBean.java b/jonas_4_10/jonas/examples/cmp2/src/com/titan/cabin/CabinBean.java new file mode 100644 index 0000000000000000000000000000000000000000..5919fe467eb13c6397826a4b8f195709f586ce62 --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/src/com/titan/cabin/CabinBean.java @@ -0,0 +1,87 @@ +package com.titan.cabin; + +import java.util.Set; + +import javax.ejb.EntityContext; +import javax.ejb.FinderException; + +import com.titan.customer.CustomerLocal; +import com.titan.ship.ShipLocal; + +public abstract class CabinBean implements javax.ejb.EntityBean { + + public Integer ejbCreate(Integer id) throws javax.ejb.CreateException { + this.setId(id); + return null; + } + + public void ejbPostCreate(Integer id) { + + } + + public abstract Set ejbSelectAllForCustomer(CustomerLocal cust) throws FinderException; + + // Public Home method required to test the private ejbSelectAllForCustomer + // method + public Set ejbHomeSelectAllForCustomer(CustomerLocal cust) throws FinderException { + return this.ejbSelectAllForCustomer(cust); + } + + public abstract void setId(Integer id); + + public abstract Integer getId(); + + public abstract void setShip(ShipLocal ship); + + public abstract ShipLocal getShip(); + + public abstract void setName(String name); + + public abstract String getName(); + + public abstract void setBedCount(int count); + + public abstract int getBedCount(); + + public abstract void setDeckLevel(int level); + + public abstract int getDeckLevel(); + + public int getShipId() { + return getShip().getId().intValue(); + } + + public void setShipId(int sp) { + ShipLocal sl = getShip(); + sl.setId(new Integer(sp)); + setShip(sl); + } + + public void setEntityContext(EntityContext ctx) { + // Not implemented. + } + + public void unsetEntityContext() { + // Not implemented. + } + + public void ejbActivate() { + // Not implemented. + } + + public void ejbPassivate() { + // Not implemented. + } + + public void ejbLoad() { + // Not implemented. + } + + public void ejbStore() { + // Not implemented. + } + + public void ejbRemove() throws javax.ejb.RemoveException { + // Not implemented. + } +} \ No newline at end of file diff --git a/jonas_4_10/jonas/examples/cmp2/src/com/titan/cabin/CabinHomeLocal.java b/jonas_4_10/jonas/examples/cmp2/src/com/titan/cabin/CabinHomeLocal.java new file mode 100644 index 0000000000000000000000000000000000000000..32a6bc30fbf1347361e66ab2c78d5edc16247872 --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/src/com/titan/cabin/CabinHomeLocal.java @@ -0,0 +1,28 @@ +package com.titan.cabin; + +import com.titan.customer.CustomerLocal; + +import java.util.Collection; +import java.util.Set; +import javax.ejb.EJBException; +import javax.ejb.CreateException; +import javax.ejb.FinderException; + +public interface CabinHomeLocal extends javax.ejb.EJBLocalHome { + + public CabinLocal create(Integer id) + throws CreateException, EJBException; + + public CabinLocal findByPrimaryKey(Integer pk) + throws FinderException, EJBException; + + public Collection findAllOnDeckLevel(Integer level) + throws FinderException; + + public Collection findAllCabins() + throws FinderException; + + // Home method, requires ejbHomeSelectAllForCustomer method in bean class + public Set selectAllForCustomer(CustomerLocal cust) + throws FinderException; +} diff --git a/jonas_4_10/jonas/examples/cmp2/src/com/titan/cabin/CabinHomeRemote.java b/jonas_4_10/jonas/examples/cmp2/src/com/titan/cabin/CabinHomeRemote.java new file mode 100644 index 0000000000000000000000000000000000000000..d5c2dea860b271d2fbc49e800a21918d18763402 --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/src/com/titan/cabin/CabinHomeRemote.java @@ -0,0 +1,14 @@ +package com.titan.cabin; + +import java.rmi.RemoteException; +import javax.ejb.CreateException; +import javax.ejb.FinderException; + +public interface CabinHomeRemote extends javax.ejb.EJBHome { + + public CabinRemote create(Integer id) + throws CreateException, RemoteException; + + public CabinRemote findByPrimaryKey(Integer pk) + throws FinderException, RemoteException; +} diff --git a/jonas_4_10/jonas/examples/cmp2/src/com/titan/cabin/CabinLocal.java b/jonas_4_10/jonas/examples/cmp2/src/com/titan/cabin/CabinLocal.java new file mode 100644 index 0000000000000000000000000000000000000000..40a187219223173e9076fdf258178d959b078097 --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/src/com/titan/cabin/CabinLocal.java @@ -0,0 +1,17 @@ +package com.titan.cabin; + +import javax.ejb.EJBException; +import com.titan.ship.ShipLocal; + +public interface CabinLocal extends javax.ejb.EJBLocalObject { + + public String getName() throws EJBException; + public void setName(String str) throws EJBException; + public int getDeckLevel() throws EJBException; + public void setDeckLevel(int level) throws EJBException; + public ShipLocal getShip(); + public void setShip(ShipLocal ship); + public int getBedCount() throws EJBException; + public void setBedCount(int bc) throws EJBException; + +} diff --git a/jonas_4_10/jonas/examples/cmp2/src/com/titan/cabin/CabinRemote.java b/jonas_4_10/jonas/examples/cmp2/src/com/titan/cabin/CabinRemote.java new file mode 100644 index 0000000000000000000000000000000000000000..29faff6fdcb3391bc2123e513506c1b416775a92 --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/src/com/titan/cabin/CabinRemote.java @@ -0,0 +1,14 @@ +package com.titan.cabin; + +import java.rmi.RemoteException; + +public interface CabinRemote extends javax.ejb.EJBObject { + public String getName() throws RemoteException; + public void setName(String str) throws RemoteException; + public int getDeckLevel() throws RemoteException; + public void setDeckLevel(int level) throws RemoteException; + public int getShipId() throws RemoteException; + public void setShipId(int sp) throws RemoteException; + public int getBedCount() throws RemoteException; + public void setBedCount(int bc) throws RemoteException; +} diff --git a/jonas_4_10/jonas/examples/cmp2/src/com/titan/cruise/CruiseBean.java b/jonas_4_10/jonas/examples/cmp2/src/com/titan/cruise/CruiseBean.java new file mode 100644 index 0000000000000000000000000000000000000000..3373f90cec2db317dac946d4db813f9b5eb63a6b --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/src/com/titan/cruise/CruiseBean.java @@ -0,0 +1,45 @@ +package com.titan.cruise; + +import javax.ejb.CreateException; +import javax.ejb.RemoveException; +import javax.ejb.EntityContext; +import com.titan.ship.*; +import java.util.Collection; +import javax.naming.InitialContext; +import javax.naming.NamingException; + +public abstract class CruiseBean implements javax.ejb.EntityBean { + + public Integer ejbCreate(String name, ShipLocal ship) throws CreateException { + setName(name); + return null; + } + + public void ejbPostCreate(String name, ShipLocal ship) { + setShip(ship); + } + + // persistent fields + public abstract void setName(String name); + public abstract String getName( ); + + public abstract void setShip(ShipLocal ship); + public abstract ShipLocal getShip( ); + + // relationship fields + + public abstract void setReservations(Collection res); + public abstract Collection getReservations( ); + + // standard call back methods + + public void setEntityContext(EntityContext ec){} + + public void unsetEntityContext(){} + public void ejbLoad(){} + public void ejbStore(){} + public void ejbActivate(){} + public void ejbPassivate(){} + public void ejbRemove() throws RemoveException {} + +} diff --git a/jonas_4_10/jonas/examples/cmp2/src/com/titan/cruise/CruiseHomeLocal.java b/jonas_4_10/jonas/examples/cmp2/src/com/titan/cruise/CruiseHomeLocal.java new file mode 100644 index 0000000000000000000000000000000000000000..6b6e30d8a5663d5b3763ed499987bbb069f51900 --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/src/com/titan/cruise/CruiseHomeLocal.java @@ -0,0 +1,23 @@ +package com.titan.cruise; + +import com.titan.ship.*; +import javax.ejb.CreateException; +import javax.ejb.FinderException; +import java.util.Collection; + + +// Cruise EJB's local home interface +public interface CruiseHomeLocal extends javax.ejb.EJBLocalHome { + + public CruiseLocal create(String name, ShipLocal ship) + throws javax.ejb.CreateException; + + public CruiseLocal findByPrimaryKey(Object primaryKey) + throws javax.ejb.FinderException; + + public Collection findAllCruises() + throws FinderException; + + public CruiseLocal findByName(String name) + throws FinderException; +} diff --git a/jonas_4_10/jonas/examples/cmp2/src/com/titan/cruise/CruiseLocal.java b/jonas_4_10/jonas/examples/cmp2/src/com/titan/cruise/CruiseLocal.java new file mode 100644 index 0000000000000000000000000000000000000000..e632bedf373356f28f5ce3a8612e51b5e72d179c --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/src/com/titan/cruise/CruiseLocal.java @@ -0,0 +1,18 @@ +package com.titan.cruise; + +import com.titan.ship.*; +import java.util.Collection; + +// Cruise EJB's local interface +public interface CruiseLocal extends javax.ejb.EJBLocalObject { + + public String getName(); + public void setName(String name); + + public ShipLocal getShip(); + public void setShip(ShipLocal ship); + + public void setReservations(Collection res); + public Collection getReservations( ); + +} diff --git a/jonas_4_10/jonas/examples/cmp2/src/com/titan/customer/AddressDO.java b/jonas_4_10/jonas/examples/cmp2/src/com/titan/customer/AddressDO.java new file mode 100644 index 0000000000000000000000000000000000000000..cae7e22182b85eac5d1d746b972114459dd61f99 --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/src/com/titan/customer/AddressDO.java @@ -0,0 +1,28 @@ +package com.titan.customer; + +public class AddressDO implements java.io.Serializable { + + private String street; + private String city; + private String state; + private String zip; + + public AddressDO(String street, String city, String state, String zip ) { + this.street = street; + this.city = city; + this.state = state; + this.zip = zip; + } + public String getStreet(){ + return street; + } + public String getCity(){ + return city; + } + public String getState(){ + return state; + } + public String getZip(){ + return zip; + } +} diff --git a/jonas_4_10/jonas/examples/cmp2/src/com/titan/customer/CreditCardBean.java b/jonas_4_10/jonas/examples/cmp2/src/com/titan/customer/CreditCardBean.java new file mode 100644 index 0000000000000000000000000000000000000000..5855282576d19f83eeec5a15d19f3f68c01cf1a0 --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/src/com/titan/customer/CreditCardBean.java @@ -0,0 +1,48 @@ +package com.titan.customer; + +import javax.ejb.EntityContext; +import java.util.Date; +import javax.naming.InitialContext; +import javax.naming.NamingException; + +public abstract class CreditCardBean implements javax.ejb.EntityBean { + + public Object ejbCreate(Date exp, String numb, String name, String org) + throws javax.ejb.CreateException { + + setExpirationDate(exp); + setNumber(numb); + setNameOnCard(name); + setCreditOrganization(org); + return null; + } + + public void ejbPostCreate(Date exp, String numb, String name, String org) { + } + + // relationship fields + + public abstract CustomerLocal getCustomer( ); + public abstract void setCustomer(CustomerLocal cust); + + // persistent fields + public abstract Date getExpirationDate(); + public abstract void setExpirationDate(Date date); + public abstract String getNumber(); + public abstract void setNumber(String number); + public abstract String getNameOnCard(); + public abstract void setNameOnCard(String name); + public abstract String getCreditOrganization(); + public abstract void setCreditOrganization(String org); + + // standard call back methods + + public void setEntityContext(EntityContext ec){} + public void unsetEntityContext(){} + public void ejbLoad(){} + public void ejbStore(){} + public void ejbActivate(){} + public void ejbPassivate(){} + public void ejbRemove() throws javax.ejb.RemoveException{} + +} diff --git a/jonas_4_10/jonas/examples/cmp2/src/com/titan/customer/CreditCardHomeLocal.java b/jonas_4_10/jonas/examples/cmp2/src/com/titan/customer/CreditCardHomeLocal.java new file mode 100644 index 0000000000000000000000000000000000000000..1e20caf8185a5e45ca878f033e172d0357258c61 --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/src/com/titan/customer/CreditCardHomeLocal.java @@ -0,0 +1,18 @@ +package com.titan.customer; + +import javax.ejb.CreateException; +import javax.ejb.FinderException; +import java.util.Collection; +import java.util.Date; + +// CreditCard EJB's local home interface +public interface CreditCardHomeLocal extends javax.ejb.EJBLocalHome { + + public CreditCardLocal create(Date exp, String numb, String name, String org) + throws javax.ejb.CreateException; + + public CreditCardLocal findByPrimaryKey(Object primaryKey) + throws javax.ejb.FinderException; + + public Collection findAllCreditCards() throws FinderException; +} diff --git a/jonas_4_10/jonas/examples/cmp2/src/com/titan/customer/CreditCardLocal.java b/jonas_4_10/jonas/examples/cmp2/src/com/titan/customer/CreditCardLocal.java new file mode 100644 index 0000000000000000000000000000000000000000..0311d0b6a6d95c7c02f78e265d5733ed3b24793c --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/src/com/titan/customer/CreditCardLocal.java @@ -0,0 +1,21 @@ +package com.titan.customer; + +import java.util.Date; + +// Credit Card EJB's local interface +public interface CreditCardLocal extends javax.ejb.EJBLocalObject { + + public Date getExpirationDate(); + public void setExpirationDate(Date date); + public String getNumber(); + public void setNumber(String number); + public String getNameOnCard(); + public void setNameOnCard(String name); + public String getCreditOrganization(); + public void setCreditOrganization(String org); + + public CustomerLocal getCustomer(); + public void setCustomer(CustomerLocal cust); + +} + diff --git a/jonas_4_10/jonas/examples/cmp2/src/com/titan/customer/CustomerBean.java b/jonas_4_10/jonas/examples/cmp2/src/com/titan/customer/CustomerBean.java new file mode 100644 index 0000000000000000000000000000000000000000..df280a52077f0409e535bab8aad538aabf084c98 --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/src/com/titan/customer/CustomerBean.java @@ -0,0 +1,182 @@ +package com.titan.customer; + +import com.titan.phone.*; +import com.titan.address.AddressLocal; +import com.titan.address.AddressHomeLocal; + +import javax.naming.InitialContext; +import javax.ejb.EJBException; +import javax.ejb.EntityContext; +import javax.ejb.CreateException; +import javax.naming.NamingException; +import java.util.Date; +import java.util.Collection; +import java.util.Iterator; +import java.util.Vector; + +public abstract class CustomerBean implements javax.ejb.EntityBean { + + public Integer ejbCreate(Integer id) throws javax.ejb.CreateException{ + this.setId(id); + return null; + } + + public void ejbPostCreate(Integer id){ + } + + + // business methods + + public Name getName() { + Name name = new Name(getLastName(),getFirstName()); + return name; + } + public void setName(Name name) { + setLastName(name.getLastName()); + setFirstName(name.getFirstName()); + } + + public void setAddress(String street, String city, String state, String zip) + throws EJBException { + + AddressLocal addr = this.getHomeAddress( ); + + try { + + if (addr == null) { + // Customer doesn't have an address yet. Create a new one. + InitialContext cntx = new InitialContext( ); + AddressHomeLocal addrHome = + (AddressHomeLocal)cntx.lookup("java:comp/env/ejb/AddressHomeLocal"); + addr = addrHome.createAddress(street, city, state, zip); + this.setHomeAddress(addr); + } else { + // Customer already has an address. Change its fields + addr.setStreet(street); + addr.setCity(city); + addr.setState(state); + addr.setZip(zip); + } + } catch (NamingException ne) { + throw new EJBException(ne); + } catch (CreateException ce) { + throw new EJBException(ce); + } + } + + public void setAddress(AddressDO addrValue) throws CreateException, NamingException { + String street = addrValue.getStreet(); + String city = addrValue.getCity(); + String state = addrValue.getState(); + String zip = addrValue.getZip(); + + setAddress(street,city,state,zip); + } + + + public AddressDO getAddress() { + + AddressLocal addrLocal = this.getHomeAddress(); + if (addrLocal == null) return null; + String street = addrLocal.getStreet(); + String city = addrLocal.getCity(); + String state = addrLocal.getState(); + String zip = addrLocal.getZip(); + AddressDO addrValue = new AddressDO(street,city,state,zip); + return addrValue; + } + + public void addPhoneNumber(String number, byte type) + throws NamingException, CreateException { + InitialContext jndiEnc = new InitialContext( ); + PhoneHomeLocal phoneHome = (PhoneHomeLocal)(jndiEnc.lookup("java:comp/env/ejb/PhoneHomeLocal")); + + PhoneLocal phone = phoneHome.create(number,type); + Collection phoneNumbers = this.getPhoneNumbers( ); + phoneNumbers.add(phone); + } + + public void removePhoneNumber(byte typeToRemove) { + + Collection phoneNumbers = this.getPhoneNumbers( ); + Iterator iterator = phoneNumbers.iterator(); + + while(iterator.hasNext()){ + PhoneLocal phone = (PhoneLocal)iterator.next(); + if (phone.getType() == typeToRemove) { + phoneNumbers.remove(phone); + break; + } + + } + } + + public void updatePhoneNumber(String number, byte typeToUpdate) { + + + Collection phoneNumbers = this.getPhoneNumbers( ); + Iterator iterator = phoneNumbers.iterator(); + while(iterator.hasNext()){ + PhoneLocal phone = (PhoneLocal)iterator.next(); + if (phone.getType() == typeToUpdate) { + phone.setNumber(number); + break; + } + } + } + + public Vector getPhoneList() { + + Vector vv = new Vector(); + Collection phoneNumbers = this.getPhoneNumbers(); + + Iterator iterator = phoneNumbers.iterator(); + while(iterator.hasNext()) { + PhoneLocal phone = (PhoneLocal)iterator.next(); + String ss = "type = '" + phone.getType() + "', number = '" + phone.getNumber() + "'"; + vv.add(ss); + } + + return vv; + } + + + // persistent relationships + + public abstract AddressLocal getHomeAddress(); + public abstract void setHomeAddress(AddressLocal address); + + public abstract CreditCardLocal getCreditCard(); + public abstract void setCreditCard(CreditCardLocal card); + + public abstract java.util.Collection getPhoneNumbers( ); + public abstract void setPhoneNumbers(java.util.Collection phones); + + public abstract java.util.Collection getReservations(); + public abstract void setReservations(java.util.Collection reservations); + + + // abstract accessor methods + public abstract Integer getId(); + public abstract void setId(Integer id); + + public abstract String getLastName( ); + public abstract void setLastName(String lname); + + public abstract String getFirstName( ); + public abstract void setFirstName(String fname); + + public abstract boolean getHasGoodCredit(); + public abstract void setHasGoodCredit(boolean flag); + + // standard call back methods + + public void setEntityContext(EntityContext ec){} + public void unsetEntityContext(){} + public void ejbLoad(){} + public void ejbStore(){} + public void ejbActivate(){} + public void ejbPassivate(){} + public void ejbRemove() throws javax.ejb.RemoveException {} + +} diff --git a/jonas_4_10/jonas/examples/cmp2/src/com/titan/customer/CustomerHomeLocal.java b/jonas_4_10/jonas/examples/cmp2/src/com/titan/customer/CustomerHomeLocal.java new file mode 100644 index 0000000000000000000000000000000000000000..ec021688a65fd0750e71b03f0d5c88ba4a876da6 --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/src/com/titan/customer/CustomerHomeLocal.java @@ -0,0 +1,48 @@ +package com.titan.customer; + +import java.rmi.RemoteException; +import javax.ejb.CreateException; +import javax.ejb.FinderException; +import java.util.Collection; +import com.titan.cruise.CruiseLocal; + +public interface CustomerHomeLocal extends javax.ejb.EJBLocalHome { + + public CustomerLocal create(Integer id) + throws CreateException; + public CustomerLocal findByPrimaryKey(Integer id) + throws FinderException; + + public Collection findAllCustomers() + throws FinderException; + + public Collection findByName(String lastName, String firstName) + throws FinderException; + + public CustomerLocal findByExactName(String lastName, String firstName) + throws FinderException; + + public Collection findByNameAndState(String lastName, String firstName, String state) + throws FinderException; + + public CustomerLocal findSmith90() + throws FinderException; + + public Collection findByGoodCredit() + throws FinderException; + + public Collection findByCity(String city, String state) + throws FinderException; + + public Collection findInHotStates() + throws FinderException; + + public Collection findWithNoReservations() + throws FinderException; + + public Collection findOnCruise(CruiseLocal cruise) + throws FinderException; + + public Collection findByState(String state) + throws FinderException; +} diff --git a/jonas_4_10/jonas/examples/cmp2/src/com/titan/customer/CustomerHomeRemote.java b/jonas_4_10/jonas/examples/cmp2/src/com/titan/customer/CustomerHomeRemote.java new file mode 100644 index 0000000000000000000000000000000000000000..d240be88ab6484a9cab3b98b5c8ba0a041c972d6 --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/src/com/titan/customer/CustomerHomeRemote.java @@ -0,0 +1,13 @@ +package com.titan.customer; + +import java.rmi.RemoteException; +import javax.ejb.CreateException; +import javax.ejb.FinderException; + +public interface CustomerHomeRemote extends javax.ejb.EJBHome { + + public CustomerRemote create(Integer id) throws CreateException, RemoteException; + public CustomerRemote findByPrimaryKey(Integer id) throws FinderException, RemoteException; + +} + diff --git a/jonas_4_10/jonas/examples/cmp2/src/com/titan/customer/CustomerLocal.java b/jonas_4_10/jonas/examples/cmp2/src/com/titan/customer/CustomerLocal.java new file mode 100644 index 0000000000000000000000000000000000000000..8238a42dd77a4ea3a0c1275e56d539e73b5db0f8 --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/src/com/titan/customer/CustomerLocal.java @@ -0,0 +1,35 @@ +package com.titan.customer; + +import com.titan.address.*; + +import javax.ejb.CreateException; +import javax.naming.NamingException; +import java.util.Date; +import java.util.Vector; +import java.util.Collection; + +public interface CustomerLocal extends javax.ejb.EJBLocalObject { + + public Name getName(); + public void setName(Name name); + + public boolean getHasGoodCredit(); + public void setHasGoodCredit(boolean flag); + + public void addPhoneNumber(String number, byte type) + throws NamingException, CreateException; + public void removePhoneNumber(byte typeToRemove); + public void updatePhoneNumber(String number, byte typeToUpdate); + + public Vector getPhoneList(); + + public AddressLocal getHomeAddress(); + public void setHomeAddress(AddressLocal address); + + public CreditCardLocal getCreditCard(); + public void setCreditCard(CreditCardLocal card); + + public Collection getPhoneNumbers( ); + public void setPhoneNumbers(Collection phones); + +} diff --git a/jonas_4_10/jonas/examples/cmp2/src/com/titan/customer/CustomerRemote.java b/jonas_4_10/jonas/examples/cmp2/src/com/titan/customer/CustomerRemote.java new file mode 100644 index 0000000000000000000000000000000000000000..c35c1193a7eb392f48980330432a35e44be7b01c --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/src/com/titan/customer/CustomerRemote.java @@ -0,0 +1,26 @@ +package com.titan.customer; + +import java.rmi.RemoteException; +import javax.ejb.CreateException; +import javax.naming.NamingException; + +public interface CustomerRemote extends javax.ejb.EJBObject { + + public void setAddress(String street, String city, String state, String zip) + throws RemoteException, CreateException, NamingException; + + public void setAddress(AddressDO address) + throws RemoteException, CreateException, NamingException; + + public AddressDO getAddress() throws RemoteException; + + public Name getName() throws RemoteException; + public void setName(Name name) throws RemoteException; + + public boolean getHasGoodCredit() throws RemoteException; + public void setHasGoodCredit(boolean flag) throws RemoteException; + // public String getHasGoodCredit() throws RemoteException; + // public void setHasGoodCredit(String flag) throws RemoteException; + // public double getHasGoodCredit() throws RemoteException; + //public void setHasGoodCredit(double flag) throws RemoteException; +} diff --git a/jonas_4_10/jonas/examples/cmp2/src/com/titan/customer/Name.java b/jonas_4_10/jonas/examples/cmp2/src/com/titan/customer/Name.java new file mode 100644 index 0000000000000000000000000000000000000000..33e856a46106e4e2555e5fab753581d7c4dde0c6 --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/src/com/titan/customer/Name.java @@ -0,0 +1,18 @@ +package com.titan.customer; + +public class Name implements java.io.Serializable { + + private String lastName; + private String firstName; + + public Name(String lname, String fname){ + lastName = lname; + firstName = fname; + } + public String getLastName() { + return lastName; + } + public String getFirstName() { + return firstName; + } +} diff --git a/jonas_4_10/jonas/examples/cmp2/src/com/titan/phone/PhoneBean.java b/jonas_4_10/jonas/examples/cmp2/src/com/titan/phone/PhoneBean.java new file mode 100644 index 0000000000000000000000000000000000000000..7b40bead9250900b659c33207904d3661c4ad5ad --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/src/com/titan/phone/PhoneBean.java @@ -0,0 +1,36 @@ +package com.titan.phone; + +import javax.ejb.EntityContext; +import java.util.Date; +import javax.naming.InitialContext; +import javax.naming.NamingException; + +public abstract class PhoneBean implements javax.ejb.EntityBean { + + public Object ejbCreate(String number, byte type) throws javax.ejb.CreateException { + setNumber(number); + setType(type); + + return null; + } + + public void ejbPostCreate(String number, byte type) { + } + + // persistent fields + public abstract String getNumber(); + public abstract void setNumber(String number); + public abstract byte getType(); + public abstract void setType(byte type); + + // standard call back methods + + public void setEntityContext(EntityContext ec){} + public void unsetEntityContext(){} + public void ejbLoad(){} + public void ejbStore(){} + public void ejbActivate(){} + public void ejbPassivate(){} + public void ejbRemove() throws javax.ejb.RemoveException{} + +} diff --git a/jonas_4_10/jonas/examples/cmp2/src/com/titan/phone/PhoneHomeLocal.java b/jonas_4_10/jonas/examples/cmp2/src/com/titan/phone/PhoneHomeLocal.java new file mode 100644 index 0000000000000000000000000000000000000000..1bbae830ef4b6016dcb9619aeba824bc3f6e8049 --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/src/com/titan/phone/PhoneHomeLocal.java @@ -0,0 +1,19 @@ +package com.titan.phone; + +import javax.ejb.CreateException; +import javax.ejb.FinderException; +import java.util.Collection; + +// Phone EJB's local home interface +public interface PhoneHomeLocal extends javax.ejb.EJBLocalHome { + + public PhoneLocal create(String number, byte type) + throws javax.ejb.CreateException; + + public PhoneLocal findByPrimaryKey(Object primaryKey) + throws javax.ejb.FinderException; + + public Collection findAllPhones() + throws javax.ejb.FinderException; + +} diff --git a/jonas_4_10/jonas/examples/cmp2/src/com/titan/phone/PhoneLocal.java b/jonas_4_10/jonas/examples/cmp2/src/com/titan/phone/PhoneLocal.java new file mode 100644 index 0000000000000000000000000000000000000000..59f03b92d043bbe6d313d260d3b778dac034fed1 --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/src/com/titan/phone/PhoneLocal.java @@ -0,0 +1,11 @@ +package com.titan.phone; + +// Phone EJB's local interface +public interface PhoneLocal extends javax.ejb.EJBLocalObject { + + public String getNumber(); + public void setNumber(String number); + public byte getType(); + public void setType(byte type); + +} diff --git a/jonas_4_10/jonas/examples/cmp2/src/com/titan/reservation/ReservationBean.java b/jonas_4_10/jonas/examples/cmp2/src/com/titan/reservation/ReservationBean.java new file mode 100644 index 0000000000000000000000000000000000000000..46b011bbd09d40af8dbca0362b8b3a0b753ca69e --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/src/com/titan/reservation/ReservationBean.java @@ -0,0 +1,52 @@ +package com.titan.reservation; + +import com.titan.cruise.*; + +import javax.ejb.CreateException; +import javax.ejb.RemoveException; +import javax.ejb.EntityContext; +import java.util.Date; +import java.util.Set; +import java.util.Collection; +import javax.naming.InitialContext; +import javax.naming.NamingException; + +public abstract class ReservationBean implements javax.ejb.EntityBean { + public Object ejbCreate(CruiseLocal cruise, Collection customers) throws CreateException { + return null; + } + + public void ejbPostCreate(CruiseLocal cruise, Collection customers) { + setCruise(cruise); + Collection myCustomers = this.getCustomers(); + myCustomers.addAll(customers); + } + + // relationship fields + + public abstract CruiseLocal getCruise(); + public abstract void setCruise(CruiseLocal cruise); + + public abstract Set getCabins( ); + public abstract void setCabins(Set cabins); + + public abstract Set getCustomers( ); + public abstract void setCustomers(Set customers); + + // persistent fields + public abstract Date getDate(); + public abstract void setDate(Date date); + public abstract double getAmountPaid(); + public abstract void setAmountPaid(double amount); + + // standard call back methods + + public void setEntityContext(EntityContext ec){} + public void unsetEntityContext(){} + public void ejbLoad(){} + public void ejbStore(){} + public void ejbActivate(){} + public void ejbPassivate(){} + public void ejbRemove() throws RemoveException {} + +} diff --git a/jonas_4_10/jonas/examples/cmp2/src/com/titan/reservation/ReservationHomeLocal.java b/jonas_4_10/jonas/examples/cmp2/src/com/titan/reservation/ReservationHomeLocal.java new file mode 100644 index 0000000000000000000000000000000000000000..9c649f0081c9b58108e26715c3bc90574c762ba0 --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/src/com/titan/reservation/ReservationHomeLocal.java @@ -0,0 +1,20 @@ +package com.titan.reservation; + +import com.titan.cruise.*; + +import java.util.Collection; +import javax.ejb.CreateException; +import javax.ejb.FinderException; + +// Reservation EJB's local home interface +public interface ReservationHomeLocal extends javax.ejb.EJBLocalHome { + + public ReservationLocal create(CruiseLocal cruise, Collection customers) + throws javax.ejb.CreateException; + + public ReservationLocal findByPrimaryKey(Object primaryKey) + throws javax.ejb.FinderException; + + public Collection findAllReservations() throws FinderException; + +} diff --git a/jonas_4_10/jonas/examples/cmp2/src/com/titan/reservation/ReservationLocal.java b/jonas_4_10/jonas/examples/cmp2/src/com/titan/reservation/ReservationLocal.java new file mode 100644 index 0000000000000000000000000000000000000000..9a4442856c33b7be0f5b72448dd77b33152ed22c --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/src/com/titan/reservation/ReservationLocal.java @@ -0,0 +1,25 @@ +package com.titan.reservation; + +import com.titan.cruise.*; + +import java.util.Date; +import java.util.Set; + +// Reservation EJB's local interface +public interface ReservationLocal extends javax.ejb.EJBLocalObject { + + public Date getDate(); + public void setDate(Date date); + public double getAmountPaid(); + public void setAmountPaid(double amount); + + public CruiseLocal getCruise(); + public void setCruise(CruiseLocal cruise); + + public Set getCabins( ); + public void setCabins(Set customers); + + public Set getCustomers( ); + public void setCustomers(Set customers); + +} diff --git a/jonas_4_10/jonas/examples/cmp2/src/com/titan/ship/ShipBean.java b/jonas_4_10/jonas/examples/cmp2/src/com/titan/ship/ShipBean.java new file mode 100644 index 0000000000000000000000000000000000000000..b3923d703ce0c52c0c24c727a3f17e4ceb459757 --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/src/com/titan/ship/ShipBean.java @@ -0,0 +1,38 @@ +package com.titan.ship; + +import javax.ejb.EntityContext; +import javax.ejb.CreateException; +import javax.ejb.RemoveException; + +public abstract class ShipBean implements javax.ejb.EntityBean { + + public Integer ejbCreate(Integer primaryKey, String name, double tonnage) throws CreateException { + setId(primaryKey); + setName(name); + setTonnage(tonnage); + return null; + } + + public void ejbPostCreate(Integer primaryKey, String name, double tonnage) { + } + + // persistent fields + + public abstract void setId(Integer id); + public abstract Integer getId(); + public abstract void setName(String name); + public abstract String getName( ); + public abstract void setTonnage(double tonnage); + public abstract double getTonnage( ); + + // standard call back methods + + public void setEntityContext(EntityContext ec){} + public void unsetEntityContext(){} + public void ejbLoad(){} + public void ejbStore(){} + public void ejbActivate(){} + public void ejbPassivate(){} + public void ejbRemove() throws RemoveException {} + +} diff --git a/jonas_4_10/jonas/examples/cmp2/src/com/titan/ship/ShipHomeLocal.java b/jonas_4_10/jonas/examples/cmp2/src/com/titan/ship/ShipHomeLocal.java new file mode 100644 index 0000000000000000000000000000000000000000..80028c831fba8dfd456a2acb076f09515e6100d2 --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/src/com/titan/ship/ShipHomeLocal.java @@ -0,0 +1,25 @@ +package com.titan.ship; + +import javax.ejb.CreateException; +import javax.ejb.FinderException; +import java.util.Collection; + +// Ship EJB's local home interface +public interface ShipHomeLocal extends javax.ejb.EJBLocalHome { + + public ShipLocal create(Integer primaryKey, String name, double tonnage) + throws javax.ejb.CreateException; + + public ShipLocal findByPrimaryKey(Object primaryKey) + throws javax.ejb.FinderException; + + public Collection findAllShips() + throws FinderException; + + public Collection findByTonnage(Double tonnage) + throws javax.ejb.FinderException; + + public Collection findByTonnage(Double tonnage1, Double tonnage2) + throws javax.ejb.FinderException; + +} diff --git a/jonas_4_10/jonas/examples/cmp2/src/com/titan/ship/ShipLocal.java b/jonas_4_10/jonas/examples/cmp2/src/com/titan/ship/ShipLocal.java new file mode 100644 index 0000000000000000000000000000000000000000..539b05b1d3feb1081c92825f1485b2922c569630 --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/src/com/titan/ship/ShipLocal.java @@ -0,0 +1,13 @@ +package com.titan.ship; + +// Ship EJB's local interface +public interface ShipLocal extends javax.ejb.EJBLocalObject { + + public Integer getId(); + public void setId(Integer id); + public String getName(); + public void setName(String name); + public double getTonnage(); + public void setTonnage(double tonnage); + +} diff --git a/jonas_4_10/jonas/examples/cmp2/src/com/titan/travelagent/RTravelAgentBean.java b/jonas_4_10/jonas/examples/cmp2/src/com/titan/travelagent/RTravelAgentBean.java new file mode 100644 index 0000000000000000000000000000000000000000..e33e41900f70073af3914d75612f93022c87407a --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/src/com/titan/travelagent/RTravelAgentBean.java @@ -0,0 +1,63 @@ +package com.titan.travelagent; + +import com.titan.cabin.CabinRemote; +import com.titan.cabin.CabinHomeRemote; +import java.rmi.RemoteException; +import javax.naming.InitialContext; +import javax.naming.Context; +import javax.ejb.EJBException; +import java.util.Properties; +import java.util.Vector; + +public class RTravelAgentBean implements javax.ejb.SessionBean { + + public void ejbCreate() throws javax.ejb.CreateException { + // Do nothing. + } + + public String [] listCabins(int shipID, int bedCount) { + + try { + + javax.naming.Context jndiContext = new InitialContext(); + Object obj = + jndiContext.lookup("java:comp/env/ejb/CabinHomeRemote"); + + + CabinHomeRemote home = (CabinHomeRemote) + javax.rmi.PortableRemoteObject.narrow(obj,CabinHomeRemote.class); + + Vector vect = new Vector(); + for (int i = 1; ; i++) { + Integer pk = new Integer(i); + CabinRemote cabin = null; + try { + cabin = home.findByPrimaryKey(pk); + } catch(javax.ejb.FinderException fe) { + System.out.println(">>>> Caught exception: "+fe.getMessage()+" for pk="+i); + break; + } + + // Check to see if the bed count and ship ID match + if (cabin != null && + cabin.getShipId() == shipID && + cabin.getBedCount() == bedCount) { + String details = i+","+cabin.getName()+","+cabin.getDeckLevel(); + vect.addElement(details); + } + } + + String [] list = new String[vect.size()]; + vect.copyInto(list); + return list; + + } catch(Exception e) { + throw new EJBException(e); + } + } + + public void ejbRemove() {} + public void ejbActivate(){} + public void ejbPassivate(){} + public void setSessionContext(javax.ejb.SessionContext cntx){} +} diff --git a/jonas_4_10/jonas/examples/cmp2/src/com/titan/travelagent/RTravelAgentHomeRemote.java b/jonas_4_10/jonas/examples/cmp2/src/com/titan/travelagent/RTravelAgentHomeRemote.java new file mode 100644 index 0000000000000000000000000000000000000000..398027d8bfbb84c85a73955016297fc5548685e1 --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/src/com/titan/travelagent/RTravelAgentHomeRemote.java @@ -0,0 +1,11 @@ +package com.titan.travelagent; + +import java.rmi.RemoteException; +import javax.ejb.CreateException; + +public interface RTravelAgentHomeRemote extends javax.ejb.EJBHome { + + public RTravelAgentRemote create() + throws RemoteException, CreateException; + +} diff --git a/jonas_4_10/jonas/examples/cmp2/src/com/titan/travelagent/RTravelAgentRemote.java b/jonas_4_10/jonas/examples/cmp2/src/com/titan/travelagent/RTravelAgentRemote.java new file mode 100644 index 0000000000000000000000000000000000000000..d374852dcecc2b3248c624907fc265aa340365d8 --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/src/com/titan/travelagent/RTravelAgentRemote.java @@ -0,0 +1,12 @@ +package com.titan.travelagent; + +import java.rmi.RemoteException; +import javax.ejb.FinderException; + +public interface RTravelAgentRemote extends javax.ejb.EJBObject { + + // String elements follow the format "id, name, deck level" + public String [] listCabins(int shipID, int bedCount) + throws RemoteException; + +} diff --git a/jonas_4_10/jonas/examples/cmp2/src/com/titan/travelagent/TravelAgentBean.java b/jonas_4_10/jonas/examples/cmp2/src/com/titan/travelagent/TravelAgentBean.java new file mode 100644 index 0000000000000000000000000000000000000000..429d50148b500e37a481359db63514c9c7b7db97 --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/src/com/titan/travelagent/TravelAgentBean.java @@ -0,0 +1,63 @@ +package com.titan.travelagent; + +import com.titan.cabin.CabinLocal; +import com.titan.cabin.CabinHomeLocal; +import java.rmi.RemoteException; +import javax.naming.InitialContext; +import javax.naming.Context; +import javax.ejb.EJBException; +import java.util.Properties; +import java.util.Vector; + +public class TravelAgentBean implements javax.ejb.SessionBean { + + public void ejbCreate() throws javax.ejb.CreateException { + // Do nothing. + } + + public String [] listCabins(int shipID, int bedCount) { + + try { + + javax.naming.Context jndiContext = new InitialContext(); + Object obj = + jndiContext.lookup("java:comp/env/ejb/CabinHomeLocal"); + + + CabinHomeLocal home = (CabinHomeLocal) + javax.rmi.PortableRemoteObject.narrow(obj,CabinHomeLocal.class); + + Vector vect = new Vector(); + for (int i = 1; ; i++) { + Integer pk = new Integer(i); + CabinLocal cabin = null; + try { + cabin = home.findByPrimaryKey(pk); + } catch(javax.ejb.FinderException fe) { + System.out.println(">>>> Caught exception: "+fe.getMessage()+" for pk="+i); + break; + } + + // Check to see if the bed count and ship ID match + if (cabin != null && + // cabin.getShipId() == shipID && //getShipId only exist in Remote interface + cabin.getBedCount() == bedCount) { + String details = i+","+cabin.getName()+","+cabin.getDeckLevel(); + vect.addElement(details); + } + } + + String [] list = new String[vect.size()]; + vect.copyInto(list); + return list; + + } catch(Exception e) { + throw new EJBException(e); + } + } + + public void ejbRemove() {} + public void ejbActivate(){} + public void ejbPassivate(){} + public void setSessionContext(javax.ejb.SessionContext cntx){} +} diff --git a/jonas_4_10/jonas/examples/cmp2/src/com/titan/travelagent/TravelAgentHomeRemote.java b/jonas_4_10/jonas/examples/cmp2/src/com/titan/travelagent/TravelAgentHomeRemote.java new file mode 100644 index 0000000000000000000000000000000000000000..9ff3a8a764bf17b09e6852935270d46c5ecbbfe4 --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/src/com/titan/travelagent/TravelAgentHomeRemote.java @@ -0,0 +1,11 @@ +package com.titan.travelagent; + +import java.rmi.RemoteException; +import javax.ejb.CreateException; + +public interface TravelAgentHomeRemote extends javax.ejb.EJBHome { + + public TravelAgentRemote create() + throws RemoteException, CreateException; + +} diff --git a/jonas_4_10/jonas/examples/cmp2/src/com/titan/travelagent/TravelAgentRemote.java b/jonas_4_10/jonas/examples/cmp2/src/com/titan/travelagent/TravelAgentRemote.java new file mode 100644 index 0000000000000000000000000000000000000000..4b41e145c3d6143188a5e6ad66081a292e844a50 --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/src/com/titan/travelagent/TravelAgentRemote.java @@ -0,0 +1,12 @@ +package com.titan.travelagent; + +import java.rmi.RemoteException; +import javax.ejb.FinderException; + +public interface TravelAgentRemote extends javax.ejb.EJBObject { + + // String elements follow the format "id, name, deck level" + public String [] listCabins(int shipID, int bedCount) + throws RemoteException; + +} diff --git a/jonas_4_10/jonas/examples/cmp2/src/servlets/ServletTest.java b/jonas_4_10/jonas/examples/cmp2/src/servlets/ServletTest.java new file mode 100644 index 0000000000000000000000000000000000000000..0efa9b1d8cbf76c277e539a4f9cd07053469eace --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/src/servlets/ServletTest.java @@ -0,0 +1,410 @@ +/** + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2004 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer(s): + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ + +package servlets; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Calendar; +import java.util.Vector; + +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.titan.address.AddressHomeLocal; +import com.titan.address.AddressLocal; +import com.titan.customer.CreditCardHomeLocal; +import com.titan.customer.CreditCardLocal; +import com.titan.customer.CustomerHomeLocal; +import com.titan.customer.CustomerLocal; +import com.titan.customer.Name; +import com.titan.phone.PhoneLocal; + + + +/** + * This servlet is used to test O'Reilly examples + * @author JOnAS team + */ +public class ServletTest extends HttpServlet { + + /** + * Called by the server (via the service method) to allow a servlet to + * handle a GET request. + * @param request an HttpServletRequest object that contains the request + * the client has made of the servlet + * @param response an HttpServletResponse object that contains the + * response the servlet sends to the client + * @throws IOException if an input or output error is detected when the + * servlet handles the GET request + * @throws ServletException if the request for the GET could not be handled + */ + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws IOException, ServletException { + + boolean ok = true; + response.setContentType("text/html"); + PrintWriter out = response.getWriter(); + + out.println(""); + out.println(""); + out.println(""); + out.println("O'Reilly Examples"); + out.println(""); + out.println(""); + out.println(""); + out.println("

Examples 1:1 Relationships

"); + + Context initialContext = null; + try { + initialContext = new InitialContext(); + } catch (Exception e) { + out.println("

ERROR: Cannot get initial context for JNDI: " + e + "

"); + return; + } + + out.println("Back to Menu"); + + + out.println("

Example showing CreditCard/Customer relationship

"); + + out.println("

(ie Setting reference in a one-to-one bidirectional relationship)

"); + + // Connecting to CustomerHomeLocal and CreditCardHomeLocal thru JNDI + CustomerHomeLocal customerhome = null; + CreditCardHomeLocal cardhome = null; + AddressHomeLocal addresshome = null; + + try { + customerhome = (CustomerHomeLocal) + initialContext.lookup("java:comp/env/ejb/CustomerHomeLocal"); + cardhome = (CreditCardHomeLocal) + initialContext.lookup("java:comp/env/ejb/CreditCardHomeLocal"); + addresshome = (AddressHomeLocal) + initialContext.lookup("java:comp/env/ejb/AddressHomeLocal"); + } catch (Exception e) { + out.println("

ERROR: Cannot lookup java:comp/env/ejb/XXHomeLocal: " + + e + "

"); + return; + } + + out.println("

Creating Customer 'Smith'.

"); + Integer primaryKey = new Integer(71); + CustomerLocal customer = null; + try { + customer = customerhome.create(primaryKey); + } catch (javax.ejb.CreateException ex) { + out.println("

Cannot create customer: " + + ex + "

"); + return; + } + customer.setName(new Name("Smith", "John")); + + out.println("

Creating CreditCard.

"); + // set Credit Card info + Calendar now = Calendar.getInstance(); + CreditCardLocal card = null; + try { + card = cardhome.create(now.getTime(), "370000000000001", "John Smith", "O'Reilly"); + } catch (javax.ejb.CreateException ex) { + out.println("

ERROR: Cannot create creditcard : " + ex + "

"); + return; + } + + out.println("

Linking CreditCard and Customer.

"); + customer.setCreditCard(card); + + out.println("

Testing both directions on relationship:

"); + String cardname = customer.getCreditCard().getNameOnCard(); + out.println("customer.getCreditCard().getNameOnCard() = '" + cardname + "'
"); + Name name = card.getCustomer().getName(); + String custfullname = name.getFirstName() + " " + name.getLastName(); + out.println("card.getCustomer().getName() = '" + custfullname + "'
"); + if (!cardname.equals(custfullname)) { + out.println("

ERROR: The name must be the same

"); + ok = false; + } + out.println("

Content of Tables:

"); + try { + listCustomers(out, customerhome); + listCreditcards(out, cardhome); + } catch (Exception e) { + out.println("

ERROR: exception caught = " + e + "

"); + } + + out.println("

Unlink the beans using CreditCard, test Customer side:

"); + card.setCustomer(null); + CreditCardLocal newcardref = customer.getCreditCard(); + if (newcardref == null) { + out.print("

Card is properly unlinked from customer bean

"); + } else { + out.print("

ERROR: Whoops, customer still thinks it has a card !

"); + ok = false; + } + // relink to avoid side effect on further test + card.setCustomer(customer); + + + out.println("

Example Showing Customer/Address Relationship

"); + out.println("

(ie Setting reference in a one-to-one unidirectional relationship)

"); + + // Find Customer 71 + primaryKey = new Integer(71); + try { + customer = customerhome.findByPrimaryKey(primaryKey); + } catch (Exception e) { + out.println("

ERROR: Exception : " + e + "

"); + return; + } + + AddressLocal addr = customer.getHomeAddress(); + if (addr == null) { + out.println("

Address reference is NULL, Creating one and setting in Customer:

"); + try { + addr = addresshome.createAddress("333 North Washington", "Minneapolis", "MN", "55401"); + } catch (Exception e) { + out.println("

ERROR: Exception : " + e + "

"); + return; + } + customer.setHomeAddress(addr); + } + out.println("

Address Info: " + + addr.getStreet() + ", " + + addr.getCity() + ", " + + addr.getState() + ", " + + addr.getZip() + "

"); + // Modifying Address + + out.println("

Modifying Address through address reference:

"); + addr.setStreet("445 East Lake Street"); + addr.setCity("Wayzata"); + addr.setState("MN"); + addr.setZip("55432"); + out.println("

Address Info: " + + addr.getStreet() + ", " + + addr.getCity() + ", " + + addr.getState() + ", " + + addr.getZip() + "

"); + + out.print("

Creating New Address and calling setHomeAddress():

"); + AddressLocal addrold = addr; + try { + addr = addresshome.createAddress("700 Main Street", "St. Paul", "MN", "55302"); + } catch (Exception e) { + out.println("

ERROR: Exception : " + e + "

"); + return; + } + out.println("

Address Info: " + + addr.getStreet() + ", " + + addr.getCity() + ", " + + addr.getState() + ", " + + addr.getZip() + "

"); + customer.setHomeAddress(addr); + + // Note: Original Address remains in database, orphaned by setHomeAddress call.. + + + out.print("

Retrieving Address reference from Customer via getHomeAddress():

"); + addr = customer.getHomeAddress(); + out.print("

Address Info: " + + addr.getStreet() + ", " + + addr.getCity() + ", " + + addr.getState() + ", " + + addr.getZip() + "

"); + + out.print("

Content of Tables:

"); + try { + listCustomers(out, customerhome); + listAddress(out, addresshome); + } catch (Exception e) { + out.println("

ERROR: exception caught = " + e + "

"); + return; + } + + + out.println("

Example Showing Customer/Phone Relationship

"); + + // Display current phone numbers and types + out.println("

Starting content of phone list:

"); + + Vector vv = customer.getPhoneList(); + listPhones(out, vv); + + // add a new phone number + out.println("

Adding a new type '1' phone number to Customer 'John Smith'.

"); + try { + customer.addPhoneNumber("612-555-1212", (byte) 1); + } catch (Exception e) { + out.println("

ERROR: Exception : " + e + "

"); + return; + } + + out.println("

New content of phone list for customer 'John Smith':

"); + vv = customer.getPhoneList(); + listPhones(out, vv); + + // add a new phone number + out.println("

Adding a new type '2' phone number to Customer 'John Smith'.

"); + try { + customer.addPhoneNumber("800-333-3333", (byte) 2); + } catch (Exception e) { + out.println("

ERROR: Exception : " + e + "

"); + return; + } + out.println("

New content of phone list for customer 'John Smith':

"); + vv = customer.getPhoneList(); + listPhones(out, vv); + + // update a phone number + out.println("

Updating type '1' phone numbers.

"); + try { + customer.updatePhoneNumber("763-555-1212", (byte) 1); + } catch (Exception e) { + out.println("

ERROR: Exception : " + e + "

"); + return; + } + + out.println("

New content of phone list for customer 'John Smith':

"); + vv = customer.getPhoneList(); + listPhones(out, vv); + + // delete a phone number + out.print("

Removing type '1' phone numbers from this Customer.

"); + customer.removePhoneNumber((byte) 1); + + out.println("

Final content of phone list:

"); + vv = customer.getPhoneList(); + listPhones(out, vv); + // Note that the phone is still in the database, + // but it is no longer related to this customer bean + + // Remove newly created beans for clean + out.println("

Remove newly created beans for cleaning.

"); + try { + customer.remove(); + addrold.remove(); + } catch (Exception e) { + out.println("

Exception : " + e + "

"); + return; + } + + if (ok) { + out.println("

Servlet is OK.

"); + } + + out.println("Back to Menu"); + out.println(""); + out.println(""); + } + + private void listCustomers (PrintWriter out, CustomerHomeLocal chl) throws Exception { + out.println("

Customers Table Content:

"); + out.println("
    "); + java.util.Collection clc = chl.findAllCustomers(); + if (clc == null) { + out.println("
  • Customers table is empty
  • "); + } else { + java.util.Iterator iterator = clc.iterator(); + while (iterator.hasNext()) { + CustomerLocal cl = (CustomerLocal) iterator.next(); + String name = cl.getName().getLastName(); + String number = cl.getCreditCard().getNumber(); + out.print("
  • customerLastName = '" + name + "', creditCardNumber = '" + number); + if (cl.getHomeAddress() != null) { + String city = cl.getHomeAddress().getCity(); + out.print("', city = '" + city); + } + out.println("'
  • "); + java.util.Collection phoneNumbers = cl.getPhoneNumbers(); + java.util.Iterator phiterator = phoneNumbers.iterator(); + out.println("
      "); + while (phiterator.hasNext()) { + PhoneLocal phone = (PhoneLocal) phiterator.next(); + out.println("
    • phoneType = '" + phone.getType() + + "', phoneNumber = '" + phone.getNumber() + "'
    • "); + } + out.println("
    "); + + } + } + out.println("
"); + } + + private void listCreditcards (PrintWriter out, CreditCardHomeLocal cchl) throws Exception { + out.println("

Creditcards Table Content:

"); + out.println("
    "); + java.util.Collection clc = cchl.findAllCreditCards(); + if (clc == null) { + out.println("
  • CreditCards table is empty
  • "); + } else { + java.util.Iterator iterator = clc.iterator(); + while (iterator.hasNext()) { + CreditCardLocal ccl = (CreditCardLocal) iterator.next(); + String number = ccl.getNumber(); + String name = ccl.getNameOnCard(); + out.println("
  • creditCardNumber = '" + number + + "', nameOnCard = '" + name + "'
  • "); + } + } + out.println("
"); + } + + private void listAddress (PrintWriter out, AddressHomeLocal cchl) throws Exception { + out.println("

Addresses Table Content:

"); + out.println("
    "); + java.util.Collection clc = cchl.findAllAddress(); + if (clc == null) { + out.println("
  • Addresses table is empty
  • "); + } else { + java.util.Iterator iterator = clc.iterator(); + while (iterator.hasNext()) { + AddressLocal al = (AddressLocal) iterator.next(); + String city = al.getCity(); + String street = al.getStreet(); + out.println("
  • city = '" + city + "', street = '" + street + "'
  • "); + } + } + out.println("
"); + } + + private void listPhones(PrintWriter out, Vector vv) { + out.println("
    "); + if (vv.size() == 0) { + out.println("
  • phones list is empty
  • "); + } else { + for (int jj = 0; jj < vv.size(); jj++) { + String ss = (String) (vv.get(jj)); + out.println("
  • " + ss + "
  • "); + } + } + out.println("
"); + } + +} diff --git a/jonas_4_10/jonas/examples/cmp2/src/servlets/ServletTest2.java b/jonas_4_10/jonas/examples/cmp2/src/servlets/ServletTest2.java new file mode 100644 index 0000000000000000000000000000000000000000..c6d8f96452f31a4154d4a3bc1f8125120efda243 --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/src/servlets/ServletTest2.java @@ -0,0 +1,857 @@ +/** + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2004 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer(s): + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ + +package servlets; + +import java.io.IOException; +import java.io.PrintWriter; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Collection; +import java.util.Date; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.transaction.UserTransaction; + +import com.titan.cabin.CabinHomeLocal; +import com.titan.cabin.CabinLocal; +import com.titan.cruise.CruiseHomeLocal; +import com.titan.cruise.CruiseLocal; +import com.titan.customer.CustomerHomeLocal; +import com.titan.customer.CustomerLocal; +import com.titan.customer.Name; +import com.titan.reservation.ReservationHomeLocal; +import com.titan.reservation.ReservationLocal; +import com.titan.ship.ShipHomeLocal; +import com.titan.ship.ShipLocal; + +/** + * This servlet is used to test O'Reilly examples + * @author JOnAS team + */ +public class ServletTest2 extends HttpServlet { + + /** + * Called by the server (via the service method) to allow a servlet to + * handle a GET request. + * @param request an HttpServletRequest object that contains the request the + * client has made of the servlet + * @param response an HttpServletResponse object that contains the response + * the servlet sends to the client + * @throws IOException if an input or output error is detected when the + * servlet handles the GET request + * @throws ServletException if the request for the GET could not be handled + */ + public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { + + boolean ok = true; + response.setContentType("text/html"); + PrintWriter out = response.getWriter(); + out.println(""); + out.println(""); + out.println(""); + out.println("O'Reilly Examples (Suite)"); + out.println(""); + out.println(""); + out.println(""); + out.println("

Example Showing Cruise/Ship and Cruise/Reservation Relationships

"); + Context initialContext = null; + try { + initialContext = new InitialContext(); + } catch (Exception e) { + out.println("

ERROR: Cannot get initial context for JNDI: " + e + "

"); + return; + } + + // Connecting to ShipHomeLocal thru JNDI + ShipHomeLocal shiphome = null; + CruiseHomeLocal cruisehome = null; + ReservationHomeLocal reservationhome = null; + CustomerHomeLocal customerhome = null; + CabinHomeLocal cabinhome = null; + UserTransaction tran = null; + try { + shiphome = (ShipHomeLocal) initialContext.lookup("java:comp/env/ejb/ShipHomeLocal"); + cruisehome = (CruiseHomeLocal) initialContext.lookup("java:comp/env/ejb/CruiseHomeLocal"); + reservationhome = (ReservationHomeLocal) initialContext.lookup("java:comp/env/ejb/ReservationHomeLocal"); + customerhome = (CustomerHomeLocal) initialContext.lookup("java:comp/env/ejb/CustomerHomeLocal"); + cabinhome = (CabinHomeLocal) initialContext.lookup("java:comp/env/ejb/CabinHomeLocal"); + tran = (UserTransaction) initialContext.lookup("java:comp/UserTransaction"); + } catch (Exception e) { + out.println("

ERROR: Cannot lookup java:comp/env/ejb/XXHomeLocal: " + e + "

"); + return; + + } + + out.println("Back to Menu"); + + out.println("

Example Showing Cruise/Ship Relationship (Fig 7-12)

"); + out.println("

(ie Sharing a bean reference in a Many-to-One Relationship)

"); + + out.println("

Creating Ships

"); + // Create some Ship beans - manually set key + ShipLocal shipA = null; + ShipLocal shipB = null; + try { + shipA = shiphome.create(new Integer(1001), "Ship A", 30000.0); + shipB = shiphome.create(new Integer(1002), "Ship B", 40000.0); + } catch (Exception e) { + out.println("

ERROR: Exception caught " + e + "

"); + return; + } + out.println("
    "); + out.println("
  • id = '" + shipA.getId() + "', name = '" + shipA.getName() + "', tonnage = '" + + shipA.getTonnage() + "'
  • "); + out.println("
  • id = '" + shipB.getId() + "', name=" + shipB.getName() + "', tonnage = '" + shipB.getTonnage() + + "
  • "); + out.println("
"); + + out.println("

Creating Cruises

"); + // Create some Cruise beans - automatic key generation by CMP engine + // Link 1-3 to Ship A, 4-6 to Ship B + CruiseLocal[] cruises = new CruiseLocal[7]; + try { + cruises[1] = cruisehome.create("Cruise 1", shipA); + cruises[2] = cruisehome.create("Cruise 2", shipA); + cruises[3] = cruisehome.create("Cruise 3", shipA); + cruises[4] = cruisehome.create("Cruise 4", shipB); + cruises[5] = cruisehome.create("Cruise 5", shipB); + cruises[6] = cruisehome.create("Cruise 6", shipB); + } catch (Exception e) { + out.println("

ERROR: Exception caught " + e + "

"); + return; + } + out.println("
    "); + for (int jj = 1; jj < 7; jj++) { + CruiseLocal cc = cruises[jj]; + out.println("
  • '" + cc.getName() + "' is using '" + cc.getShip().getName() + "'
  • "); + } + out.println("
"); + + out.print("

Changing 'Cruise 1' to use same ship as 'Cruise 4'

"); + ShipLocal newship = cruises[4].getShip(); + cruises[1].setShip(newship); + out.println("
    "); + for (int jj = 1; jj < 7; jj++) { + CruiseLocal cc = cruises[jj]; + out.println("
  • '" + cc.getName() + "' is using '" + cc.getShip().getName() + "'
  • "); + } + out.println("
"); + + out.println("

Content of Tables

"); + try { + listCruises(out, cruisehome); + listShips(out, shiphome); + } catch (Exception e) { + out.println("

ERROR: exception caught = " + e + "

"); + } + + out.println("

Example Showing Cruise/Reservation Relationship Using set() (Fig 7-14)

"); + out + .println("

(ie Sharing an entire collection in a One-to-Many bidirectional Relationship Using set() )

"); + out.println("

Creating some Cruise beans

"); + // Create some Cruise beans - leave ship reference empty since we don't + // care + CruiseLocal cruiseA = null; + CruiseLocal cruiseB = null; + try { + cruiseA = cruisehome.create("Cruise A", null); + cruiseB = cruisehome.create("Cruise B", null); + } catch (Exception e) { + out.println("

ERROR: exception caught = " + e + "

"); + } + out.println("
    "); + out.print("
  • name = '" + cruiseA.getName() + "'
  • "); + out.print("
  • name = '" + cruiseB.getName() + "'
  • "); + out.println("
"); + + out.print("

Creating Reservations

"); + // Create some Reservation beans - automatic key generation by CMP + // engine + // Link 1-3 to Cruise A, 4-6 to Cruise B + ReservationLocal reservations[] = new ReservationLocal[7]; + Calendar date = Calendar.getInstance(); + date.set(2002, 10, 1); + // Leave the Customers collection null in the create() call, + // we don't care about it right now + try { + reservations[1] = reservationhome.create(cruiseA, null); + reservations[1].setDate(date.getTime()); + reservations[1].setAmountPaid(4000.0); + date.add(Calendar.DAY_OF_MONTH, 7); + + reservations[2] = reservationhome.create(cruiseA, null); + reservations[2].setDate(date.getTime()); + reservations[2].setAmountPaid(5000.0); + date.add(Calendar.DAY_OF_MONTH, 7); + + reservations[3] = reservationhome.create(cruiseA, null); + reservations[3].setDate(date.getTime()); + reservations[3].setAmountPaid(6000.0); + date.add(Calendar.DAY_OF_MONTH, 7); + + reservations[4] = reservationhome.create(cruiseB, null); + reservations[4].setDate(date.getTime()); + reservations[4].setAmountPaid(7000.0); + date.add(Calendar.DAY_OF_MONTH, 7); + + reservations[5] = reservationhome.create(cruiseB, null); + reservations[5].setDate(date.getTime()); + reservations[5].setAmountPaid(8000.0); + date.add(Calendar.DAY_OF_MONTH, 7); + + reservations[6] = reservationhome.create(cruiseB, null); + reservations[6].setDate(date.getTime()); + reservations[6].setAmountPaid(9000.0); + date.add(Calendar.DAY_OF_MONTH, 7); + + } catch (Exception e) { + out.println("

ERROR: Exception caught " + e + "

"); + return; + } + out.println("
    "); + DateFormat df = new SimpleDateFormat("MM/dd/yyyy"); + for (int jj = 1; jj < 7; jj++) { + ReservationLocal rr = reservations[jj]; + CruiseLocal thiscruise = rr.getCruise(); + String cruisename = (thiscruise != null ? thiscruise.getName() : "No Cruise!"); + out.println("
  • reservationDate = '" + df.format(rr.getDate()) + "', amountPaid = '" + rr.getAmountPaid() + + "', for '" + cruisename + "'
  • "); + } + out.println("
"); + + out.println("

Testing CruiseB.setReservations(CruiseA.getReservations())

"); + // show the effect of a simple "setReservations" on a cruise + Collection areservations = cruiseA.getReservations(); + cruiseB.setReservations(areservations); + // Report information on the 6 reservations + String[] cruisename = new String[7]; + out.println("
    "); + for (int jj = 1; jj < 7; jj++) { + ReservationLocal rr = reservations[jj]; + CruiseLocal thiscruise = rr.getCruise(); + cruisename[jj] = (thiscruise != null ? thiscruise.getName() : "No Cruise!"); + out.print("
  • reservationDate = '" + df.format(rr.getDate()) + "', amount paid = '" + rr.getAmountPaid() + + "', for '" + cruisename[jj] + "'
  • "); + } + out.println("
"); + if (!cruisename[4].equals("No Cruise!") || !cruisename[5].equals("No Cruise!") + || !cruisename[6].equals("No Cruise!")) { + ok = false; + } + + out.print("

Content of Tables

"); + try { + listCruises(out, cruisehome); + listReservations(out, reservationhome); + } catch (Exception e) { + out.println("

ERROR: exception caught = " + e + "

"); + return; + } + + out.println("

Example Showing Cruise/Reservation Relationship Using addAll(..) (Fig 7-15)

"); + out.print("

(ie Using Collection.addAll() in a One-to-Many bidirectional relationship)

"); + // Show how to combine reservations using Collection methods + // Operations such as this must be done in a transaction, usually done + // within a + // stateless session EJB using declarative transactions rather than + // manually like this + + date.set(2002, 10, 1); + // Remove previous reservation + for (int jj = 1; jj < 7; jj++) { + try { + reservations[jj].remove(); + } catch (Exception ex) { + out.println("

ERROR: exception caught = " + ex + "

"); + } + } + // Reinit the reservation as before the previous test + try { + reservations[1] = reservationhome.create(cruiseA, null); + reservations[1].setDate(date.getTime()); + reservations[1].setAmountPaid(4000.0); + date.add(Calendar.DAY_OF_MONTH, 7); + + reservations[2] = reservationhome.create(cruiseA, null); + reservations[2].setDate(date.getTime()); + reservations[2].setAmountPaid(5000.0); + date.add(Calendar.DAY_OF_MONTH, 7); + + reservations[3] = reservationhome.create(cruiseA, null); + reservations[3].setDate(date.getTime()); + reservations[3].setAmountPaid(6000.0); + date.add(Calendar.DAY_OF_MONTH, 7); + + reservations[4] = reservationhome.create(cruiseB, null); + reservations[4].setDate(date.getTime()); + reservations[4].setAmountPaid(7000.0); + date.add(Calendar.DAY_OF_MONTH, 7); + + reservations[5] = reservationhome.create(cruiseB, null); + reservations[5].setDate(date.getTime()); + reservations[5].setAmountPaid(8000.0); + date.add(Calendar.DAY_OF_MONTH, 7); + + reservations[6] = reservationhome.create(cruiseB, null); + reservations[6].setDate(date.getTime()); + reservations[6].setAmountPaid(9000.0); + date.add(Calendar.DAY_OF_MONTH, 7); + + } catch (Exception e) { + out.println("

ERROR: Exception caught " + e + "

"); + return; + } + + Collection breservations = null; + try { + tran.begin(); + areservations = cruiseA.getReservations(); + breservations = cruiseB.getReservations(); + breservations.addAll(areservations); + tran.commit(); + } catch (Exception e) { + e.printStackTrace(); + try { + tran.rollback(); + } catch (Exception ex) { + ex.printStackTrace(); + return; + } + return; + } + // Report information on the 6 reservations + out.println("

    "); + for (int jj = 1; jj < 7; jj++) { + ReservationLocal rr = reservations[jj]; + CruiseLocal thiscruise = rr.getCruise(); + cruisename[jj] = (thiscruise != null ? thiscruise.getName() : "No Cruise!"); + out.print("
  • reservationDate = '" + df.format(rr.getDate()) + "', amount paid = '" + rr.getAmountPaid() + + "', for '" + cruisename[jj] + "'
  • "); + } + out.println("
"); + + out.print("

Contents of Tables

"); + try { + listCruises(out, cruisehome); + listReservations(out, reservationhome); + } catch (Exception e) { + out.println("

ERROR: exception caught = " + e + "

"); + return; + } + + out.println("

Example Showing Reservation/Customer Relationships (Fig 7-17)

"); + out.print("

(ie Using Collection.addAll() in a Many-to-Many bidirectional relationship)

"); + + out.println("

Using 'ShipA' and 'CruiseA'

"); + cruiseA.setShip(shipA); + out.println("
    "); + out.println("
  • cruise.getName() = '" + cruiseA.getName() + "'
  • "); + out.println("
  • ship.getName() = '" + shipA.getName() + "'
  • "); + out.println("
  • cruise.getShip().getName() = '" + cruiseA.getShip().getName() + "'
  • "); + out.println("
"); + + out.println("

Creating two sets of customers, one with 1-3, and one with 4-6

"); + // create two sets of customers, one with customers 1-3 and one with 4-6 + Set lowcustomers = new HashSet(); + Set highcustomers = new HashSet(); + CustomerLocal cust = null; + out.println("
    "); + for (int kk = 1; kk < 7; kk++) { + try { + cust = customerhome.create(new Integer(kk)); + } catch (Exception e) { + out.println("

    ERROR: exception caught = " + e + "

    "); + } + cust.setName(new Name("Customer " + kk, "mike")); + if (kk <= 3) { + lowcustomers.add(cust); + } else { + highcustomers.add(cust); + } + out.print("
  • customer '" + cust.getName().getLastName() + "' created
  • "); + } + out.println("
"); + // Remove previous reservation + for (int jj = 1; jj < 7; jj++) { + try { + reservations[jj].remove(); + } catch (Exception ex) { + out.println("

ERROR: exception caught = " + ex + "

"); + } + } + + out.print("

Creating Reservations '1' and '2', each with 3 customers

"); + try { + reservations[1] = reservationhome.create(cruiseA, lowcustomers); + reservations[1].setDate(date.getTime()); + reservations[1].setAmountPaid(4000.0); + date.add(Calendar.DAY_OF_MONTH, 7); + + reservations[2] = reservationhome.create(cruiseA, highcustomers); + reservations[2].setDate(date.getTime()); + reservations[2].setAmountPaid(5000.0); + date.add(Calendar.DAY_OF_MONTH, 7); + } catch (Exception e) { + out.println("

ERROR: Exception caught " + e + "

"); + return; + } + // report information on the reservations + reportReservations(out, reservations, 2, tran); + + out.print("

Performing customers_a.addAll(customers_b) test

"); + // Finally we can perform the test shown in Figure 7-17 + // Operations such as this must be done in a transaction, usually done + // within a + // stateless session EJB using declarative transactions rather than + // manually like this + try { + tran.begin(); + Set customers_a = reservations[1].getCustomers(); + Set customers_b = reservations[2].getCustomers(); + customers_a.addAll(customers_b); + tran.commit(); + } catch (Exception e) { + e.printStackTrace(); + try { + tran.rollback(); + } catch (Exception ex) { + out.println("

ERROR: Exception caught " + ex + "

"); + return; + } + } + // report information on the reservations + reportReservations(out, reservations, 2, tran); + + out.print("

Sharing an entire collection in a Many-to-Many bidirectional relationship (Fig 7-18)

"); + out.println("

Creating four sets of customers 1-3, 2-4, 3-5, 4-6

"); + // create four sets of customers, 1-3, 2-4, 3-5, 4-6 + Set customers13 = new HashSet(); + Set customers24 = new HashSet(); + Set customers35 = new HashSet(); + Set customers46 = new HashSet(); + out.println("
    "); + for (int kk = 1; kk < 7; kk++) { + try { + cust = customerhome.create(new Integer(kk + 500)); + cust.setName(new Name("Customer_1 " + kk, "bill")); + } catch (Exception e) { + out.println("

    ERROR: exception caught = " + e + "

"); + return; + } + if (kk <= 3) { + customers13.add(cust); + } + if (kk >= 2 && kk <= 4) { + customers24.add(cust); + } + if (kk >= 3 && kk <= 5) { + customers35.add(cust); + } + if (kk >= 4) { + customers46.add(cust); + } + out.print("
  • customer '" + cust.getName().getLastName() + "' created
  • "); + } + out.println(""); + + out.print("

    Creating Reservations 1-4 using three customers each

    "); + ReservationLocal reservations1[] = new ReservationLocal[5]; + try { + reservations1[1] = reservationhome.create(cruiseA, customers13); + reservations1[1].setDate(date.getTime()); + reservations1[1].setAmountPaid(4000.0); + date.add(Calendar.DAY_OF_MONTH, 7); + + reservations1[2] = reservationhome.create(cruiseA, customers24); + reservations1[2].setDate(date.getTime()); + reservations1[2].setAmountPaid(5000.0); + date.add(Calendar.DAY_OF_MONTH, 7); + + reservations1[3] = reservationhome.create(cruiseA, customers35); + reservations1[3].setDate(date.getTime()); + reservations1[3].setAmountPaid(6000.0); + date.add(Calendar.DAY_OF_MONTH, 7); + + reservations1[4] = reservationhome.create(cruiseA, customers46); + reservations1[4].setDate(date.getTime()); + reservations1[4].setAmountPaid(7000.0); + date.add(Calendar.DAY_OF_MONTH, 7); + } catch (Exception e) { + out.println("

    ERROR: Exception caught " + e + "

    "); + return; + } + reportReservations(out, reservations1, 4, tran); + + out.print("

    Performing reservationD.setCustomers(customersA) (Fig 7-18)

    "); + try { + tran.begin(); + Set customers_a = reservations1[1].getCustomers(); + reservations1[4].setCustomers(customers_a); + tran.commit(); + } catch (Exception e) { + e.printStackTrace(); + try { + tran.rollback(); + } catch (Exception ex) { + out.println("

    ERROR: Exception caught " + ex + "

    "); + return; + } + } + reportReservations(out, reservations1, 4, tran); + + out.print("

    Example Showing Reservation/Cabin Relationships (Fig 7-20)

    "); + out.print("

    (ie Removing beans in a Many-to-Many unidirectional relationship)

    "); + out.print("

    Creating Cabins four sets of cabins, 1-3, 2-4, 3-5, 4-6

    "); + // create four sets of cabins, 1-3, 2-4, 3-5, 4-6 + Set cabins13 = new HashSet(); + Set cabins24 = new HashSet(); + Set cabins35 = new HashSet(); + Set cabins46 = new HashSet(); + CabinLocal cabin = null; + out.println("
      "); + for (int kk = 1; kk < 7; kk++) { + try { + cabin = cabinhome.create(new Integer(kk)); + } catch (Exception e) { + out.println("

      ERROR: exception caught = " + e + "

    "); + } + cabin.setName("Cabin " + kk); + if (kk <= 3) { + cabins13.add(cabin); + } + if (kk >= 2 && kk <= 4) { + cabins24.add(cabin); + } + if (kk >= 3 && kk <= 5) { + cabins35.add(cabin); + } + if (kk >= 4) { + cabins46.add(cabin); + } + out.print("
  • cabin '" + cabin.getName() + "' created
  • "); + } + out.println(""); + + out.print("

    Creating Reservations 1-4 using three cabins each

    "); + ReservationLocal reservations2[] = new ReservationLocal[5]; + // leave Customers collection null, we dont care about it for this + // example + try { + reservations2[1] = reservationhome.create(cruiseA, null); + reservations2[1].setCabins(cabins13); + reservations2[1].setDate(date.getTime()); + reservations2[1].setAmountPaid(4000.0); + date.add(Calendar.DAY_OF_MONTH, 7); + + reservations2[2] = reservationhome.create(cruiseA, null); + reservations2[2].setCabins(cabins24); + reservations2[2].setDate(date.getTime()); + reservations2[2].setAmountPaid(5000.0); + date.add(Calendar.DAY_OF_MONTH, 7); + + reservations2[3] = reservationhome.create(cruiseA, null); + reservations2[3].setCabins(cabins35); + reservations2[3].setDate(date.getTime()); + reservations2[3].setAmountPaid(6000.0); + date.add(Calendar.DAY_OF_MONTH, 7); + + reservations2[4] = reservationhome.create(cruiseA, null); + reservations2[4].setCabins(cabins46); + reservations2[4].setDate(date.getTime()); + reservations2[4].setAmountPaid(7000.0); + date.add(Calendar.DAY_OF_MONTH, 7); + } catch (Exception e) { + out.println("

    ERROR: Exception caught " + e + "

    "); + return; + } + reportReservations(out, reservations2, 4, tran); + + out.print("

    Performing cabins_a collection iterator.remove() test

    "); + // Finally we can perform the test shown in Figure 7-20 + try { + tran.begin(); + Set cabins_a = reservations2[1].getCabins(); + Iterator iterator = cabins_a.iterator(); + out.print("
      "); + while (iterator.hasNext()) { + CabinLocal cc = (CabinLocal) iterator.next(); + out.print("
    • Removing '" + cc.getName() + "' from 'cabins_a'" + "
    • "); + iterator.remove(); + } + out.print("
    "); + tran.commit(); + } catch (Exception e) { + try { + tran.rollback(); + } catch (Exception ex) { + out.println("

    ERROR: Exception caught " + ex + "

    "); + return; + } + } + reportReservations(out, reservations2, 4, tran); + + out.print("

    Example Showing Reservation/Cabin Relationships

    "); + + out.print("

    Creating Cabins in ShipA

    "); + CabinLocal cabins[] = new CabinLocal[4]; + try { + cabins[1] = cabinhome.create(new Integer(10)); + cabins[1].setShip(shipA); + cabins[1].setDeckLevel(1); + cabins[1].setName("Minnesota Suite"); + cabins[1].setBedCount(2); + + cabins[2] = cabinhome.create(new Integer(11)); + cabins[2].setShip(shipA); + cabins[2].setDeckLevel(2); + cabins[2].setName("California Suite"); + cabins[2].setBedCount(2); + + cabins[3] = cabinhome.create(new Integer(12)); + cabins[3].setShip(shipA); + cabins[3].setDeckLevel(3); + cabins[3].setName("Missouri Suite"); + cabins[3].setBedCount(2); + } catch (Exception e) { + out.println("

    ERROR: Exception caught " + e + "

    "); + return; + } + out.println("
      "); + for (int jj = 1; jj < 4; jj++) { + CabinLocal cc = cabins[jj]; + out.print("
    • cabin '" + cc.getName() + "' is on ship '" + cc.getShip().getName() + "'
    • "); + } + out.println("
    "); + + out.print("

    Creating Reservations

    "); + ReservationLocal reservations3[] = new ReservationLocal[3]; + try { + reservations3[1] = reservationhome.create(cruiseA, null); + reservations3[1].setDate(date.getTime()); + reservations3[1].setAmountPaid(4000.0); + date.add(Calendar.DAY_OF_MONTH, 7); + + reservations3[2] = reservationhome.create(cruiseA, null); + reservations3[2].setDate(date.getTime()); + reservations3[2].setAmountPaid(5000.0); + date.add(Calendar.DAY_OF_MONTH, 7); + } catch (Exception e) { + out.println("

    ERROR: Exception caught " + e + "

    "); + return; + } + reportReservations(out, reservations3, 2, tran); + + out.print("

    Creating Links from Reservations to Cabins

    "); + Set cabins1 = new HashSet(2); + cabins1.add(cabins[1]); + cabins1.add(cabins[2]); + Set cabins2 = new HashSet(2); + cabins2.add(cabins[2]); + cabins2.add(cabins[3]); + reservations3[1].setCabins(cabins1); + reservations3[2].setCabins(cabins2); + reportReservations(out, reservations3, 2, tran); + + out.print("

    Testing reservation_b.setCabins(reservation_a.getCabins())

    "); + try { + tran.begin(); + Set cabins_a = reservations3[1].getCabins(); + reservations3[2].setCabins(cabins_a); + tran.commit(); + } catch (Exception e) { + try { + tran.rollback(); + } catch (Exception ex) { + out.println("

    ERROR: Exception caught " + ex + "

    "); + return; + } + } + reportReservations(out, reservations3, 2, tran); + + out.print("

    Cleaning all tables

    "); + try { + Collection clc = customerhome.findAllCustomers(); + java.util.Iterator iterator = clc.iterator(); + while (iterator.hasNext()) { + CustomerLocal cl = (CustomerLocal) iterator.next(); + cl.remove(); + } + clc = shiphome.findAllShips(); + iterator = clc.iterator(); + while (iterator.hasNext()) { + ShipLocal sl = (ShipLocal) iterator.next(); + sl.remove(); + } + clc = cruisehome.findAllCruises(); + iterator = clc.iterator(); + while (iterator.hasNext()) { + CruiseLocal cl = (CruiseLocal) iterator.next(); + cl.remove(); + } + + clc = reservationhome.findAllReservations(); + iterator = clc.iterator(); + while (iterator.hasNext()) { + ReservationLocal rl = (ReservationLocal) iterator.next(); + rl.remove(); + } + clc = cabinhome.findAllCabins(); + iterator = clc.iterator(); + while (iterator.hasNext()) { + CabinLocal cl = (CabinLocal) iterator.next(); + cl.remove(); + } + + } catch (Exception ex) { + out.println("

    ERROR: during cleaning exception caught = " + ex + "

    "); + } + if (ok) { + out.println("

    Servlet is OK.

    "); + } + out.println("Back to Menu"); + out.println(""); + out.println(""); + } + + private void listCruises(PrintWriter out, CruiseHomeLocal chl) throws Exception { + out.println("

    Cruises Table Content:

    "); + out.println("
      "); + java.util.Collection clc = chl.findAllCruises(); + if (clc == null) { + out.println("
    • Cruises table is empty
    • "); + } else { + java.util.Iterator iterator = clc.iterator(); + while (iterator.hasNext()) { + CruiseLocal cl = (CruiseLocal) iterator.next(); + String cname = cl.getName(); + String sname = (cl.getShip() != null ? cl.getShip().getName() : "No Ship!"); + out.println("
    • cruiseName = '" + cname + "', shipName = '" + sname + "'
    • "); + + } + } + out.println("
    "); + } + + private void listShips(PrintWriter out, ShipHomeLocal cchl) throws Exception { + out.println("

    Ships Table Content:

    "); + out.println("
      "); + java.util.Collection clc = cchl.findAllShips(); + if (clc == null) { + out.println("
    • Ships table is empty
    • "); + } else { + java.util.Iterator iterator = clc.iterator(); + while (iterator.hasNext()) { + ShipLocal ccl = (ShipLocal) iterator.next(); + double tonnage = ccl.getTonnage(); + String name = ccl.getName(); + out.println("
    • shipName = '" + name + "', tonnage = '" + tonnage + "'
    • "); + } + } + out.println("
    "); + } + + private void listReservations(PrintWriter out, ReservationHomeLocal cchl) throws Exception { + out.println("

    Reservations Table Content:

    "); + out.println("
      "); + java.util.Collection clc = cchl.findAllReservations(); + if (clc == null) { + out.println("
    • Reservations table is empty
    • "); + out.println("
    "); + } else { + java.util.Iterator iterator = clc.iterator(); + while (iterator.hasNext()) { + ReservationLocal ccl = (ReservationLocal) iterator.next(); + Date date = ccl.getDate(); + out.println("
  • reservation date = '" + date + "'
  • "); + } + out.println(""); + } + } + + private void reportReservations(PrintWriter out, ReservationLocal reservations[], int nb, UserTransaction tran) { + DateFormat df = new SimpleDateFormat("MM/dd/yyyy"); + // report information on the reservations + out.println("
      "); + for (int jj = 1; jj < nb + 1; jj++) { + ReservationLocal rr = reservations[jj]; + CruiseLocal thiscruise = rr.getCruise(); + String cruisename = (thiscruise != null ? thiscruise.getName() : "No Cruise!"); + // Operations such as this must be done in a transaction, usually + // done within a + // stateless session EJB using declarative transactions rather than + // manually like this + String customerinfo = ""; + CustomerLocal cust = null; + String cabininfo = ""; + try { + tran.begin(); + Set customerset = rr.getCustomers(); + Iterator iterator = customerset.iterator(); + while (iterator.hasNext()) { + cust = (CustomerLocal) iterator.next(); + customerinfo += cust.getName().getLastName() + " "; + } + Set cabinset = rr.getCabins(); + iterator = cabinset.iterator(); + while (iterator.hasNext()) { + CabinLocal cabin = (CabinLocal) iterator.next(); + cabininfo += cabin.getName() + " "; + } + tran.commit(); + } catch (Exception e) { + e.printStackTrace(); + try { + tran.rollback(); + } catch (Exception ex) { + out.println("

      ERROR: Exception caught " + ex + "

      "); + return; + } + } + out.print("
    • reservationDate = '" + df.format(rr.getDate()) + "', amountPaid = '" + rr.getAmountPaid() + + "', for '" + cruisename + "' with :
    • "); + out.print("
        "); + if (!customerinfo.equals("")) { + out.print("
      • customers: " + customerinfo); + } + if (!cabininfo.equals("")) { + out.print("
      • cabins: " + cabininfo + "
      • "); + } + out.print("
      "); + } + out.println("
    "); + } + +} \ No newline at end of file diff --git a/jonas_4_10/jonas/examples/cmp2/src/servlets/ServletTest3.java b/jonas_4_10/jonas/examples/cmp2/src/servlets/ServletTest3.java new file mode 100644 index 0000000000000000000000000000000000000000..661cf4eae430ca2e29004057a17373efec0d2b62 --- /dev/null +++ b/jonas_4_10/jonas/examples/cmp2/src/servlets/ServletTest3.java @@ -0,0 +1,777 @@ +/** + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2005 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer(s): + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ + +package servlets; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; +import java.util.Vector; + +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.titan.address.AddressHomeLocal; +import com.titan.address.AddressLocal; +import com.titan.cabin.CabinHomeLocal; +import com.titan.cabin.CabinLocal; +import com.titan.cruise.CruiseHomeLocal; +import com.titan.cruise.CruiseLocal; +import com.titan.customer.CreditCardHomeLocal; +import com.titan.customer.CreditCardLocal; +import com.titan.customer.CustomerHomeLocal; +import com.titan.customer.CustomerLocal; +import com.titan.customer.Name; +import com.titan.phone.PhoneHomeLocal; +import com.titan.reservation.ReservationHomeLocal; +import com.titan.reservation.ReservationLocal; +import com.titan.ship.ShipHomeLocal; +import com.titan.ship.ShipLocal; + +/** + * This servlet is used to test O'Reilly examples + * @author JOnAS team + */ +public class ServletTest3 extends HttpServlet { + + /** + * Called by the server (via the service method) to allow a servlet to + * handle a GET request. + * @param request an HttpServletRequest object that contains the request the + * client has made of the servlet + * @param response an HttpServletResponse object that contains the response + * the servlet sends to the client + * @throws IOException if an input or output error is detected when the + * servlet handles the GET request + * @throws ServletException if the request for the GET could not be handled + */ + public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { + + boolean ok = true; + response.setContentType("text/html"); + PrintWriter out = response.getWriter(); + + out.println(""); + out.println(""); + out.println(""); + out.println("O'Reilly Examples"); + out.println(""); + out.println(""); + out.println(""); + out.println("

    EJB QL Examples from Chapter 8

    "); + + Context initialContext = null; + try { + initialContext = new InitialContext(); + } catch (Exception e) { + out.print("

    ERROR: Cannot get initial context for JNDI: " + e + "

    "); + return; + } + + out.println("Back to Menu"); + + // Connecting to CustomerHomeLocal and CreditCardHomeLocal thru JNDI + CustomerHomeLocal customerhome = null; + CreditCardHomeLocal cardhome = null; + AddressHomeLocal addresshome = null; + ShipHomeLocal shiphome = null; + CruiseHomeLocal cruisehome = null; + ReservationHomeLocal reservationhome = null; + CabinHomeLocal cabinhome = null; + PhoneHomeLocal phonehome = null; + try { + customerhome = (CustomerHomeLocal) initialContext.lookup("java:comp/env/ejb/CustomerHomeLocal"); + cardhome = (CreditCardHomeLocal) initialContext.lookup("java:comp/env/ejb/CreditCardHomeLocal"); + addresshome = (AddressHomeLocal) initialContext.lookup("java:comp/env/ejb/AddressHomeLocal"); + shiphome = (ShipHomeLocal) initialContext.lookup("java:comp/env/ejb/ShipHomeLocal"); + cruisehome = (CruiseHomeLocal) initialContext.lookup("java:comp/env/ejb/CruiseHomeLocal"); + reservationhome = (ReservationHomeLocal) initialContext.lookup("java:comp/env/ejb/ReservationHomeLocal"); + cabinhome = (CabinHomeLocal) initialContext.lookup("java:comp/env/ejb/CabinHomeLocal"); + phonehome = (PhoneHomeLocal) initialContext.lookup("java:comp/env/ejb/PhoneHomeLocal"); + } catch (Exception e) { + out.println("

    ERROR: Cannot lookup java:comp/env/ejb/XXHomeLocal: " + e + "

    "); + return; + } + + String cities[] = new String[6]; + cities[0] = "Minneapolis"; + cities[1] = "St. Paul"; + cities[2] = "Rochester"; + cities[3] = "Winona"; + cities[4] = "Wayzata"; + cities[5] = "Eagan"; + + out.println("

    Example showing Sample EJB-QL

    "); + + out.print("

    Creating a Ship and Cruise

    "); + ShipLocal shipA = null; + CruiseLocal cruiseA = null; + try { + shipA = shiphome.create(new Integer(10772), "Ship A", 30000.0); + cruiseA = cruisehome.create("Cruise A", shipA); + } catch (Exception ex) { + ok = false; + out.print("

    ERROR: Exception caught : " + ex + "

    "); + } + out.println("
      "); + out.println("
    • cruise.getName() = '" + cruiseA.getName() + "'
    • "); + out.println("
    • ship.getName() = '" + shipA.getName() + "'
    • "); + out.println("
    • cruise.getShip().getName() = '" + cruiseA.getShip().getName() + "'
    • "); + out.println("
    "); + + out.print("

    Creating Ship Beans with Various Tonnage Values

    "); + out.print("
      "); + for (int jj = 1; jj <= 10; jj++) { + try { + ShipLocal ship = shiphome.create(new Integer(jj), "Ship " + jj, 30000.0 + (10000.0 * jj)); + printShip(out, ship); + } catch (Exception ex) { + ok = false; + out.print("

      ERROR: Exception caught : " + ex + "

      "); + } + + } + out.print("
    "); + + out.print("

    Finding Ships with Exactly 100K Tonnage

    "); + out.print("

    SELECT OBJECT(s) FROM JE2_Ship AS s WHERE s.tonnage = ?1

    "); + Collection ships100k = null; + try { + ships100k = shiphome.findByTonnage(new Double(100000.0)); + } catch (Exception ex) { + ok = false; + out.print("

    ERROR: Exception caught : " + ex + "

    "); + } + out.print("

    Number of ships = " + ships100k.size() + "
    Expected = 1 ships

    "); + if (ships100k.size() != 1) { + ok = false; + } + Iterator iterator = ships100k.iterator(); + out.print("
      "); + while (iterator.hasNext()) { + ShipLocal ship = (ShipLocal) (iterator.next()); + printShip(out, ship); + } + out.print("
    "); + + out.print("

    Finding Ships with Tonnage between 50K and 110K

    "); + out.print("

    SELECT OBJECT(s) FROM JE2_Ship AS s WHERE s.tonnage BETWEEN ?1 AND ?2

    "); + Collection ships50110k = null; + try { + ships50110k = shiphome.findByTonnage(new Double(50000.0), new Double(110000.0)); + } catch (Exception ex) { + ok = false; + out.print("

    ERROR: Exception caught : " + ex + "

    "); + } + out.print("

    Number of ships = " + ships50110k.size() + "
    Expected = 7 ships

    "); + if (ships50110k.size() != 7) { + ok = false; + } + iterator = ships50110k.iterator(); + out.print("
      "); + while (iterator.hasNext()) { + ShipLocal ship = (ShipLocal) (iterator.next()); + printShip(out, ship); + } + out.print("
    "); + + // creating cruise for future use + cruiseA = null; + CruiseLocal cruiseB = null; + try { + ShipLocal ship1 = shiphome.findByPrimaryKey(new Integer(1)); + cruiseA = cruisehome.create("Alaska Cruise", ship1); + cruiseB = cruisehome.create("Bohemian Cruise", ship1); + } catch (Exception ex) { + ok = false; + out.print("

    ERROR: Exception caught : " + ex + "

    "); + } + + out.println("

    Creating Customers

    "); + for (int kk = 80; kk <= 99; kk++) { + CustomerLocal customer = null; + AddressLocal addr = null; + try { + customer = customerhome.create(new Integer(kk)); + customer.setName(new Name("Smith" + kk, "John")); + customer.addPhoneNumber("612-555-12" + kk, (byte) 1); + addr = addresshome.createAddress("10" + kk + " Elm Street", cities[(kk - 80) % 6], (kk % 2 == 0 ? "MN" + : "CA"), "5540" + (kk % 5 + 1)); + } catch (Exception e) { + ok = false; + out.println("

    ERROR: exception caught = " + e + "

    "); + } + customer.setHomeAddress(addr); + customer.setHasGoodCredit((kk % 4 == 0)); + //printCustomer(out, customer, addr); + } + + // Creating Customers 1-6, each with 2 reservations for 2 cabins + Calendar date = Calendar.getInstance(); + date.set(2002, 10, 1); + try { + + for (int kk = 201; kk < 207; kk++) { + Collection customers = new ArrayList(); + CustomerLocal cust = customerhome.create(new Integer(kk)); + cust.setName(new Name("Customer " + kk, "Mike")); + cust.setHasGoodCredit((kk % 2 == 0)); // odds are bums + AddressLocal addr = addresshome.createAddress("50" + kk + " Main Street", "Minneapolis", "MN", "5510" + + kk); + cust.setHomeAddress(addr); + //out.print("

  • Customer name= + // "+cust.getName().getLastName()+"
  • "); + customers.add(cust); // put this single customer in the + // collection + + //printCustomer(out, cust,addr); + + Collection reservations = new ArrayList(); + + for (int jj = 0; jj < 2; jj++) { + + ReservationLocal reservation = reservationhome.create(cruiseA, customers); + reservation.setDate(date.getTime()); + reservation.setAmountPaid(1000 * kk + 100 * jj + 2000); + date.add(Calendar.DAY_OF_MONTH, 7); + + Set cabins = new HashSet(); + CabinLocal cabin = cabinhome.create(new Integer(1000 + kk * 100 + jj)); + cabin.setDeckLevel(kk - 200); + cabin.setName("Cabin " + kk + "0" + jj + "1"); + + cabins.add(cabin); + cabin = cabinhome.create(new Integer(1000 + kk * 100 + 10 + jj)); + cabin.setDeckLevel(kk - 200); + cabin.setName("Cabin " + kk + "0" + jj + "2"); + + cabins.add(cabin); + + reservation.setCabins(cabins); // this reservation has 2 + // cabins + //out.print("
      "); + //printReservation(out, reservation); + //out.print("
    "); + } + } + } catch (Exception ex) { + ok = false; + out.print("

    ERROR: Exception caught : " + ex + "

    "); + } + + String fnames[] = new String[5]; + fnames[0] = "John"; + fnames[1] = "Paul"; + fnames[2] = "Ringo"; + fnames[3] = "Joe"; + fnames[4] = "Roger"; + + String[] lnames = new String[3]; + lnames[0] = "Smith"; + lnames[1] = "Johnson"; + lnames[2] = "Star"; + + // Creating Customers 50-69 + try { + for (int kk = 50; kk <= 69; kk++) { + CustomerLocal customer = customerhome.create(new Integer(kk)); + customer.setName(new Name(lnames[(kk - 50) % 3], fnames[(kk - 50) % 5])); + customer.addPhoneNumber("612-555-12" + kk, (byte) 1); + AddressLocal addr = addresshome.createAddress("10" + kk + " Elm Street", cities[(kk - 50) % 6], + (kk % 2 == 0 ? "MN" : "CA"), "5540" + (kk % 5 + 1)); + customer.setHomeAddress(addr); + customer.setHasGoodCredit((kk % 4 == 0)); + + //printCustomer(out, customer, addr); + + // Some customers will have reservations already on one of the + // two cruises.. + if (kk % 3 != 0) { + Collection customers = new ArrayList(); + customers.add(customer); // put this single customer in the + // collection + ReservationLocal reservation = reservationhome.create((kk % 3 == 1 ? cruiseA : cruiseB), customers); + reservation.setDate(date.getTime()); + reservation.setAmountPaid(10 * kk + 2000); + //out.print("
      "); + //printReservation(out, reservation); + //out.print("
    "); + + date.add(Calendar.DAY_OF_MONTH, 7); + } + } + } catch (Exception ex) { + ok = false; + out.print("

    ERROR: Exception caught : " + ex + "

    "); + } + + // Creating Customers 100-109 + try { + for (int kk = 100; kk <= 109; kk++) { + CustomerLocal customer = customerhome.create(new Integer(kk)); + customer.setName(new Name("Lennon" + kk, "Paul")); + customer.addPhoneNumber("666-543-12" + kk, (byte) 1); + AddressLocal addr = addresshome.createAddress("10" + kk + " Abbey Road", cities[(kk - 100) % 6], + (kk % 2 == 0 ? "FL" : "WA"), "5540" + (kk % 5 + 1)); + + customer.setHomeAddress(addr); + customer.setHasGoodCredit((kk % 4 == 0)); + + //printCustomer(out, customer, addr); + } + } catch (Exception ex) { + ok = false; + out.print("

    ERROR: Exception caught : " + ex + "

    "); + } + + try { + listCustomers(out, customerhome); + } catch (Exception e) { + ok = false; + out.println("

    ERROR: exception caught = " + e + "

    "); + } + + out.print("

    Finding Customer having name 'John Smith85'

    "); + out + .print("

    SELECT OBJECT(c) FROM JE2_Customer AS c WHERE c.lastName = ?1 AND c.firstName = ?2

    "); + CustomerLocal customer85 = null; + try { + customer85 = customerhome.findByExactName("Smith85", "John"); + } catch (Exception ex) { + ok = false; + out.print("

    ERROR: Exception caught : " + ex + "

    "); + } + AddressLocal addr85 = customer85.getHomeAddress(); + printCustomer(out, customer85, addr85); + + out.print("

    Finding Customer 'Smith90'

    "); + out.print("

    SELECT OBJECT(c) FROM JE2_Customer AS c WHERE c.lastName = 'Smith90'

    "); + CustomerLocal customer90 = null; + try { + customer90 = customerhome.findSmith90(); + } catch (Exception ex) { + ok = false; + out.print("

    ERROR: Exception caught : " + ex + "

    "); + } + + AddressLocal addr90 = customer90.getHomeAddress(); + printCustomer(out, customer90, addr90); + + out.print("

    Finding Customers having GoodCredit

    "); + out.print("

    SELECT OBJECT(c) FROM JE2_Customer AS c WHERE c.hasGoodCredit = TRUE

    "); + Collection mplscustomers = null; + try { + mplscustomers = customerhome.findByGoodCredit(); + } catch (Exception ex) { + ok = false; + out.print("

    ERROR: Exception caught : " + ex + "

    "); + } + + iterator = mplscustomers.iterator(); + out.print("

    Number of customers = " + mplscustomers.size() + "
    Expected = 16 customers

    "); + if (mplscustomers.size() != 16) { + ok = false; + } + while (iterator.hasNext()) { + CustomerLocal customer = (CustomerLocal) (iterator.next()); + AddressLocal addr = customer.getHomeAddress(); + printCustomer(out, customer, addr); + } + + out.print("

    Finding Customers having City = 'Minneapolis' and State = 'MN'

    "); + out + .print("

    SELECT OBJECT(c) FROM JE2_Customer AS c WHERE c.homeAddress.city = ?1 AND c.homeAddress.state = ?2

    "); + try { + mplscustomers = customerhome.findByCity("Minneapolis", "MN"); + } catch (Exception ex) { + ok = false; + out.print("

    ERROR: Exception caught : " + ex + "

    "); + } + out.print("

    Number of customers = " + mplscustomers.size() + "
    Expected = 14 customers

    "); + if (mplscustomers.size() != 14) { + ok = false; + } + iterator = mplscustomers.iterator(); + while (iterator.hasNext()) { + CustomerLocal customer = (CustomerLocal) (iterator.next()); + AddressLocal addr = customer.getHomeAddress(); + printCustomer(out, customer, addr); + } + + out.print("

    Cabins Table Content

    "); + try { + listCabins(out, cabinhome); + } catch (Exception ex) { + ok = false; + out.print("

    ERROR: Exception caught : " + ex + "

    "); + } + + out.print("

    Retrieve a collection of all cabins on deck '3'

    "); + out.print("

    SELECT OBJECT(c) FROM Cabin AS c WHERE c.deckLevel = ?1

    "); + Collection cabins = null; + try { + cabins = cabinhome.findAllOnDeckLevel(new Integer(3)); + out.print("

    Number of cabins = " + cabins.size() + "
    Expected = 4 cabins

    "); + Iterator iter = cabins.iterator(); + out.print("
      "); + while (iter.hasNext()) { + CabinLocal cabin = (CabinLocal) (iter.next()); + out.print("
    • cabin '" + cabin.getName() + "' on deck '" + cabin.getDeckLevel() + "'
    • "); + } + out.print("
    "); + } catch (Exception ex) { + ok = false; + out.print("

    ERROR: Exception caught : " + ex + "

    "); + } + + try { + out.print("

    Finding Customer having a name exactly matching 'Joe Star'

    "); + out + .print("

    SELECT OBJECT(c) FROM JE2_Customer AS c WHERE c.lastName = ?1 AND c.firstName = ?2

    "); + CustomerLocal customer = customerhome.findByExactName("Star", "Joe"); + AddressLocal addr = customer.getHomeAddress(); + printCustomer(out, customer, addr); + Collection customers = null; + + out.print("

    Finding Customers having a name like 'Jo S' (no wildcards)

    "); + out + .print("

    SELECT OBJECT(c) FROM JE2_Customer AS c WHERE c.lastName LIKE ?1 AND c.firstName LIKE ?2

    "); + + customers = customerhome.findByName("S", "Jo"); + iterator = customers.iterator(); + while (iterator.hasNext()) { + customer = (CustomerLocal) (iterator.next()); + addr = customer.getHomeAddress(); + printCustomer(out, customer, addr); + } + out.print("

    Number of customers = " + customers.size() + "
    Expected = 0 customers

    "); + if (customers.size() != 0) { + ok = false; + } + + out.print("

    Finding Customers having a name like 'Jo% S%' (with wildcards)

    "); + out + .print("

    SELECT OBJECT(c) FROM JE2_Customer AS c WHERE c.lastName LIKE ?1 AND c.firstName LIKE ?2

    "); + customers = customerhome.findByName("S%", "Jo%"); + iterator = customers.iterator(); + out.print("

    Number of customers = " + customers.size() + "
    Expected = 26 customers

    "); + if (customers.size() != 26) { + ok = false; + } + while (iterator.hasNext()) { + customer = (CustomerLocal) (iterator.next()); + addr = customer.getHomeAddress(); + printCustomer(out, customer, addr); + } + + out.print("

    Finding Customers having a name like 'Jo% S%' and living in 'MN'

    "); + out + .print("

    SELECT OBJECT(c) FROM JE2_Customer AS c
    WHERE c.lastName LIKE ?1 AND c.firstName LIKE ?2 AND c.homeAddress.state = ?3

    "); + customers = customerhome.findByNameAndState("S%", "Jo%", "MN"); + iterator = customers.iterator(); + out.print("

    Number of customers = " + customers.size() + "
    Expected = 13 customers

    "); + if (customers.size() != 13) { + ok = false; + } + while (iterator.hasNext()) { + customer = (CustomerLocal) (iterator.next()); + addr = customer.getHomeAddress(); + printCustomer(out, customer, addr); + } + + out.print("

    Finding Customers Living in Warm Climates

    "); + out + .print("

    SELECT OBJECT(c) FROM JE2_Customer AS c WHERE c.homeAddress.state IN ('FL','TX','AZ','CA')

    "); + customers = customerhome.findInHotStates(); + out.print("

    Number of customers = " + customers.size() + "
    Expected = 25 customers

    "); + if (customers.size() != 25) { + ok = false; + } + iterator = customers.iterator(); + while (iterator.hasNext()) { + customer = (CustomerLocal) (iterator.next()); + addr = customer.getHomeAddress(); + printCustomer(out, customer, addr); + } + + out.print("

    Finding Customers With No Reservation

    "); + out.print("

    SELECT OBJECT(c) FROM JE2_Customer AS c WHERE c.reservations IS EMPTY

    "); + customers = customerhome.findWithNoReservations(); + out.print("

    Number of customers = " + customers.size() + "
    Expected = 37 customers

    "); + if (customers.size() != 37) { + ok = false; + } + iterator = customers.iterator(); + while (iterator.hasNext()) { + customer = (CustomerLocal) (iterator.next()); + addr = customer.getHomeAddress(); + printCustomer(out, customer, addr); + } + + out.print("

    Finding Customers On Alaska Cruise

    "); + out + .print("

    SELECT OBJECT(c) FROM JE2_Customer AS cust, Cruise AS cr, IN (cr.reservations) AS res
    WHERE cr = ?1 AND cust MEMBER OF res.customers

    "); + CruiseLocal crA = cruisehome.findByName("Alaska Cruise"); + customers = customerhome.findOnCruise(cruiseA); + out.print("

    Number of customers = " + customers.size() + "
    Expected = 12 customers

    "); + if (customers.size() != 12) { + ok = false; + } + iterator = customers.iterator(); + while (iterator.hasNext()) { + customer = (CustomerLocal) (iterator.next()); + addr = customer.getHomeAddress(); + printCustomer(out, customer, addr); + } + + out.print("

    Select the zip codes of the state 'FL'

    "); + out.print("

    SELECT a.zip FROM JE2_Address AS a WHERE a.state = ?1

    "); + Collection zipCodes = null; + zipCodes = addresshome.selectZipCodes("FL"); + out.print("

    Number of zip codes = " + zipCodes.size() + + "
    Expected = 5 zip codes (from 55401 to 55405)

    "); + if (zipCodes.size() != 5) { + ok = false; + } + Iterator iZipCodes = zipCodes.iterator(); + out.println("
      "); + while (iZipCodes.hasNext()) { + out.print("
    • zip code = '" + iZipCodes.next() + "'
    • "); + } + out.println("
    "); + + out.print("

    Select the customer which have the address 'addr85'

    "); + out.print("

    SELECT OBJECT(c) FROM JE2_Customer AS c WHERE c.homeAddress = ?1

    "); + CustomerLocal cust = null; + cust = addresshome.selectCustomer(addr85); + addr = cust.getHomeAddress(); + printCustomer(out, cust, addr); + + } catch (Exception ex) { + ok = false; + out.print("

    ERROR: Exception caught : " + ex + "

    "); + } + out.print("

    Cleaning all tables

    "); + + try { + Collection clc = customerhome.findAllCustomers(); + iterator = clc.iterator(); + while (iterator.hasNext()) { + CustomerLocal cl = (CustomerLocal) iterator.next(); + cl.remove(); + } + clc = shiphome.findAllShips(); + iterator = clc.iterator(); + while (iterator.hasNext()) { + ShipLocal sl = (ShipLocal) iterator.next(); + sl.remove(); + } + clc = cruisehome.findAllCruises(); + iterator = clc.iterator(); + while (iterator.hasNext()) { + CruiseLocal cl = (CruiseLocal) iterator.next(); + cl.remove(); + } + clc = reservationhome.findAllReservations(); + iterator = clc.iterator(); + while (iterator.hasNext()) { + ReservationLocal rl = (ReservationLocal) iterator.next(); + rl.remove(); + } + clc = cabinhome.findAllCabins(); + iterator = clc.iterator(); + while (iterator.hasNext()) { + CabinLocal cl = (CabinLocal) iterator.next(); + cl.remove(); + } + } catch (Exception ex) { + ok = false; + out.println("

    ERROR: during cleaning exception caught = " + ex + "

    "); + } + + if (ok) { + out.println("

    Servlet is OK.

    "); + } + out.println("Back to Menu"); + out.println(""); + out.println(""); + + } + + private void listCabins(PrintWriter out, CabinHomeLocal chl) throws Exception { + out.println("

    Cabins Table Content:

    "); + out.println("
      "); + Collection clc = chl.findAllCabins(); + if (clc == null) { + out.println("
    • Cabins table is empty
    • "); + } else { + Iterator iterator = clc.iterator(); + while (iterator.hasNext()) { + CabinLocal cl = (CabinLocal) iterator.next(); + String name = cl.getName(); + int deck = cl.getDeckLevel(); + int bd = cl.getBedCount(); + out.println("
    • cabinName = '" + name + "', deckLevel = '" + deck + "', bedCount = '" + bd + "'
    • "); + } + } + out.println("
    "); + } + + private void listCustomers(PrintWriter out, CustomerHomeLocal chl) throws Exception { + out.println("

    Customers Table Content:

    "); + out.println("
      "); + java.util.Collection clc = chl.findAllCustomers(); + if (clc == null) { + out.println("
    • Customers table is empty
    • "); + } else { + java.util.Iterator iterator = clc.iterator(); + while (iterator.hasNext()) { + CustomerLocal cl = (CustomerLocal) iterator.next(); + String name = cl.getName().getLastName(); + String fname = cl.getName().getFirstName(); + String number = " No Card! "; + boolean gc = cl.getHasGoodCredit(); + if (cl.getCreditCard() != null) { + number = cl.getCreditCard().getNumber(); + } + out.print("
    • firstName = '" + fname + "', lastName = '" + name + "'"); + out.println("
        "); + out.print("
      • creditCardNumber = '" + number + "', goodCredit = '" + gc + "'
      • "); + if (cl.getHomeAddress() != null) { + String city = cl.getHomeAddress().getCity(); + String state = cl.getHomeAddress().getState(); + out.print("
      • city> = '" + city + "', state = '" + state + "'
      • "); + } + out.println(""); + out.println("
      "); + } + } + out.println("
    "); + } + + private void listCreditcards(PrintWriter out, CreditCardHomeLocal cchl) throws Exception { + out.println("

    CreditCards Table Content:

    "); + out.println("
      "); + java.util.Collection clc = cchl.findAllCreditCards(); + if (clc == null) { + out.println("
    • CreditCards table is empty
    • "); + } else { + java.util.Iterator iterator = clc.iterator(); + while (iterator.hasNext()) { + CreditCardLocal ccl = (CreditCardLocal) iterator.next(); + String number = ccl.getNumber(); + String name = ccl.getNameOnCard(); + out.println("
    • creditCardNumber = '" + number + "', nameOnCard '= '" + name + "'
    • "); + } + } + out.println("
    "); + } + + private void listAddress(PrintWriter out, AddressHomeLocal cchl) throws Exception { + out.println("

    Addresses Table Content:

    "); + out.println("
      "); + java.util.Collection clc = cchl.findAllAddress(); + if (clc == null) { + out.println("
    • Addresses table is empty
    • "); + } else { + java.util.Iterator iterator = clc.iterator(); + while (iterator.hasNext()) { + AddressLocal al = (AddressLocal) iterator.next(); + String city = al.getCity(); + String street = al.getStreet(); + out.println("
    • adressCity = '" + city + "', street = '" + street + "'
    • "); + } + } + out.println("
    "); + } + + private void listPhones(PrintWriter out, Vector vv) { + out.println("
      "); + for (int jj = 0; jj < vv.size(); jj++) { + String ss = (String) (vv.get(jj)); + out.println("
    • " + ss + "
    • "); + } + out.println("
    "); + } + + private void printShip(PrintWriter out, ShipLocal ship) { + out.print("
  • shipId = '" + ship.getId() + "', name = '" + ship.getName() + "', tonnage = '" + + ship.getTonnage() + "'
  • "); + } + + private void printCustomer(PrintWriter out, CustomerLocal customer, AddressLocal addr) { + out.print("
      "); + out.print("
    • firstName = '" + customer.getName().getFirstName() + "', lastName = '" + + customer.getName().getLastName() + "', goodCredit = '" + customer.getHasGoodCredit() + "'
    • "); + out.print("
    • street = '" + addr.getStreet() + "', city = '" + addr.getCity() + "', state = '" + + addr.getState() + "', zip = '" + addr.getZip() + "'
    • "); + out.print("
    "); + } + + private void printReservation(PrintWriter out, ReservationLocal reservation) { + out.print("
      "); + String cru = "no Cruise!"; + if (reservation.getCruise() != null) { + cru = reservation.getCruise().getName(); + } + out.print("
    • reservationDate: '" + reservation.getDate() + "' on '" + cru + "' amountPaid: '" + + reservation.getAmountPaid() + "'
    • "); + Set cabinset = reservation.getCabins(); + String customerinfo = ""; + CustomerLocal cust = null; + String cabininfo = ""; + Set customerset = reservation.getCustomers(); + Iterator iterator = customerset.iterator(); + while (iterator.hasNext()) { + cust = (CustomerLocal) iterator.next(); + customerinfo += cust.getName().getLastName() + " "; + } + iterator = cabinset.iterator(); + while (iterator.hasNext()) { + CabinLocal cabin = (CabinLocal) iterator.next(); + cabininfo += cabin.getName() + " "; + } + out.print("
        "); + if (!customerinfo.equals("")) { + out.print("
      • customers: " + customerinfo); + } + if (!cabininfo.equals("")) { + out.print("
      • cabins: " + cabininfo + "
      • "); + } + out.print("
      "); + out.print("
    "); + } + +} \ No newline at end of file diff --git a/jonas_4_10/jonas/examples/earsample/README b/jonas_4_10/jonas/examples/earsample/README new file mode 100644 index 0000000000000000000000000000000000000000..995b6c5576f08f5320e901f518a25839d42c01c3 --- /dev/null +++ b/jonas_4_10/jonas/examples/earsample/README @@ -0,0 +1,94 @@ + +Example Overview: +----------------- + +This example shows how to access an EJB deployed in a JOnAS EJB container, from + - a servlet deployed in a Tomcat/Jetty container (thin client) + - a client running inside the client container (heavy client) + +It also shows how to use security in Tomcat or Jetty to authentificate the user and in JOnAS +to authorize the user to access the EJB methods. This aspect is described in details +in the "Use Security in JOnAS with TOMCAT" howto of the JOnAS documentation. + +Besides, this example shows the uniform naming resource access supported in JOnAS. +The servlet gets a javax.transaction.UserTransaction object reference from the JNDI +using the "java:comp/UserTransaction" name. Moreover, it gets a reference on the +bean's home using an environment entry: "java:comp/env/ejb/". + +This sample contains an example of using ejb-link which allows to link the EJB to the +servlet. It is used in the web.xml file for both the ejb-ref and +ejb-local-ref tags. It implies that when the servlet performs a lookup on the bean, +the web classloader has got the visibility of the ejb class. +This is due to the classloader hierarchy between the ear classloader, ejb +classloader and the web classloader. + +Finally, this example shows how to add a resource adapter in an ear. + +The "src" directory contains + - An EJB that mimics $JONAS_ROOT/examples/src/sb with the addition of + security access to the bean methods. + - The servlet source of ServletOp. + - The source of a client which run inside the client container with uniform naming available + - The resource adapter source. + +The "etc" directory contains + - the "xml" directory which contains all the deployment descriptors used for this example : + * application.xml (ear file) + * ejb-jar.xml and jonas-ejb-jar.xml (jar file) + * web.xml, jonas-web.xml and web-jetty.xml (war file) + * ra.xml (rar file) + * application-client.xml, jonas-client1.xml and jonas-client2.xml (two clients jar file) + - the "resources" directory which contains all the resources for this application + * "web" directory contains all resources used by the servlet + + +Compiling this example creates an .ear file that represents an application including : + - a session bean used by the web application + - a web application that will be used by Tomcat or Jetty to run the servlet. + - a resource adapter. + +Prerequisites +------------- +First, you must have installed a web container (ie : Catalina or Jetty) +as the web container service or you will use the heavy client + +You have to set the environment variables + CATALINA_HOME and CATALINA_BASE as indicated in the Tomcat 5.x documentation. +or JETTY_HOME for Jetty 5.x + +Compiling and installing this example: +-------------------------------------- + ant install + +Running this example: +-------------------- +Commands are given for an Unix system. +(Similar commands can be done on Windows) + +1) Run a jonas server: + jonas start + +2) Load earsample.ear (if you have not added it in the ear service descriptors list) using the jonasAadmin +management application (http://:/jonasAdmin) or the 'jonas admin' command. + +3a) Run your web browser (e.g., netscape): + netscape http://:/earsample + where is the name of your machine (localhost by default) + and the port number (9000 by default) + +3b) You can also lookup the Bean by using one of the client of the ear + + Use the default client (first found) + java -jar $JONAS_ROOT/lib/client.jar ($JONAS_ROOT |$JONAS_BASE)/apps/earsample.ear -carolFile ($JONAS_ROOT |$JONAS_BASE)/conf/carol.properties + + Use a specific client + java -jar $JONAS_ROOT/lib/client.jar ($JONAS_ROOT |$JONAS_BASE)/apps/earsample.ear -jarClient client2.jar -carolFile ($JONAS_ROOT |$JONAS_BASE)/conf/carol.properties + + +Notes : + a) that when you use the packages JOnAS-Tomcat and JOnAS-Jetty the earsample.ear is found $JONAS_BASE/apps/autoload directory. + b) the argument -carolFile is useless if you have rebuilt this example because in this + case the carol.properties of your environment is inserted in earsample.ear + +4) Stop the jonas server + jonas stop diff --git a/jonas_4_10/jonas/examples/earsample/build.xml b/jonas_4_10/jonas/examples/earsample/build.xml new file mode 100644 index 0000000000000000000000000000000000000000..75f4346700e809113a54fc426edf92d3437a5793 --- /dev/null +++ b/jonas_4_10/jonas/examples/earsample/build.xml @@ -0,0 +1,207 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jonas_4_10/jonas/examples/earsample/etc/resources/jaas/jaas.config b/jonas_4_10/jonas/examples/earsample/etc/resources/jaas/jaas.config new file mode 100644 index 0000000000000000000000000000000000000000..86999b42d3bcb05190652c3d4575773e2e32150c --- /dev/null +++ b/jonas_4_10/jonas/examples/earsample/etc/resources/jaas/jaas.config @@ -0,0 +1,13 @@ +earsample { + // Login Module to use for the example earsample. + + //First, use a LoginModule for the authentication + // Use the resource memrlm_1 + org.objectweb.jonas.security.auth.spi.JResourceLoginModule required + resourceName="memrlm_1" + ; + + // Use the login module to propagate security to the JOnAS server + org.objectweb.jonas.security.auth.spi.ClientLoginModule required + ; +}; \ No newline at end of file diff --git a/jonas_4_10/jonas/examples/earsample/etc/resources/web/img/jetty.gif b/jonas_4_10/jonas/examples/earsample/etc/resources/web/img/jetty.gif new file mode 100644 index 0000000000000000000000000000000000000000..01f44a87f6801b200f142513d0d02b12cea0fb46 Binary files /dev/null and b/jonas_4_10/jonas/examples/earsample/etc/resources/web/img/jetty.gif differ diff --git a/jonas_4_10/jonas/examples/earsample/etc/resources/web/img/ow_jonas_logo.gif b/jonas_4_10/jonas/examples/earsample/etc/resources/web/img/ow_jonas_logo.gif new file mode 100644 index 0000000000000000000000000000000000000000..1b56943a721f82a8cb81776030567772265433f2 Binary files /dev/null and b/jonas_4_10/jonas/examples/earsample/etc/resources/web/img/ow_jonas_logo.gif differ diff --git a/jonas_4_10/jonas/examples/earsample/etc/resources/web/img/ow_logo.png b/jonas_4_10/jonas/examples/earsample/etc/resources/web/img/ow_logo.png new file mode 100644 index 0000000000000000000000000000000000000000..60617270bf0c0d21c9f40e4f7c85ef5bfdbda548 Binary files /dev/null and b/jonas_4_10/jonas/examples/earsample/etc/resources/web/img/ow_logo.png differ diff --git a/jonas_4_10/jonas/examples/earsample/etc/resources/web/img/tomcat.gif b/jonas_4_10/jonas/examples/earsample/etc/resources/web/img/tomcat.gif new file mode 100644 index 0000000000000000000000000000000000000000..61756736b82350f64b5ea1b2bfc31ac57e30a3d3 Binary files /dev/null and b/jonas_4_10/jonas/examples/earsample/etc/resources/web/img/tomcat.gif differ diff --git a/jonas_4_10/jonas/examples/earsample/etc/resources/web/img/valid-xhtml11.png b/jonas_4_10/jonas/examples/earsample/etc/resources/web/img/valid-xhtml11.png new file mode 100644 index 0000000000000000000000000000000000000000..2c63d93f8868d574b9e69eda2727b7e7bf7fc8ec Binary files /dev/null and b/jonas_4_10/jonas/examples/earsample/etc/resources/web/img/valid-xhtml11.png differ diff --git a/jonas_4_10/jonas/examples/earsample/etc/resources/web/img/vcss.png b/jonas_4_10/jonas/examples/earsample/etc/resources/web/img/vcss.png new file mode 100644 index 0000000000000000000000000000000000000000..9b2f596e016533327216d98a0a927738fe17384f Binary files /dev/null and b/jonas_4_10/jonas/examples/earsample/etc/resources/web/img/vcss.png differ diff --git a/jonas_4_10/jonas/examples/earsample/etc/resources/web/index.html b/jonas_4_10/jonas/examples/earsample/etc/resources/web/index.html new file mode 100644 index 0000000000000000000000000000000000000000..51fea3aaac4364c60e369361b173f3a9428e6f31 --- /dev/null +++ b/jonas_4_10/jonas/examples/earsample/etc/resources/web/index.html @@ -0,0 +1,52 @@ + + + + + + + EarSample Example + + + + +
    + Jakarta Tomcat + Mortbay Jetty + JOnAS WebSite +
    + +
    + Earsample : Example of servlet accessing a protected EJB +
    + + + + + + \ No newline at end of file diff --git a/jonas_4_10/jonas/examples/earsample/etc/resources/web/ow_jonas.css b/jonas_4_10/jonas/examples/earsample/etc/resources/web/ow_jonas.css new file mode 100644 index 0000000000000000000000000000000000000000..3c5d6ab29f0827060a77172f37688b01704a7fd3 --- /dev/null +++ b/jonas_4_10/jonas/examples/earsample/etc/resources/web/ow_jonas.css @@ -0,0 +1,222 @@ +/* + Context Root css. based on css from http://jonas.objectweb.org + XHTML by Florent BENOIT +*/ + +.bodywelcome +{ + background-color: #FFFFFF; + color: #000000; + background-image: url(img/ow_logo.png); + background-repeat: no-repeat; + margin: 0; +} + + +img { + margin: 5px; + border:0; +} + +body +{ + background-color: #FFFFFF; + margin: 10px; + color: black; + font-family: Arial,Helvetica, sans-serif; + font-size: 12px; + line-height: 16px; + font-weight: normal; + +} + +div.logos { + top: 5px; + width: 99%; + text-align: right; +} + + +div.links { + font-size: 14px; + margin-top : 40px; + margin-left : 100px; +} + + +div.titlepage { + margin-left: 200px; + color: #E06611; + font-family: Arial, Helvetica, sans-serif; + font-size: 22px; + line-height: 27px; + font-weight: bold; + border-color: #99C; + border-width: 0 0 4px 0; + border-style: none none solid none; +} + + +div.footer { + margin-top : 50px; + color: #FFFFFF; + font-size: 8pt; + text-align: center; +} + + +/*HTML elements */ + + + +ul, ol, dl +{ + color: black; + font-family: Arial,Helvetica, sans-serif; + font-size: 12px; + line-height: 16px; + font-weight: normal; +} + +li +{ + color: black; + font-family: Arial, Helvetica, sans-serif; + font-size: 14px; + font-weight: normal; + margin: 10px 0px 5px 0px; + +} +a +{ + color: #3F3975; + background-color: transparent; + text-decoration: underline; +} + +a:visited +{ + color: #9898CB; + background-color: transparent; + text-decoration: underline; +} + +a:hover +{ + color: #E06611; + background-color: transparent; + text-decoration: underline; +} + + +a:active +{ + color: #FFFFFF; + background-color: #E06611; + text-decoration: underline; +} + + +h1 +{ + color: #E06611; + font-family: Arial, Helvetica, sans-serif; + font-size: 22px; + line-height: 27px; + font-weight: bold; + border-color: #99C; + border-width: 0 0 4px 0; + border-style: none none solid none; + margin: 10px 0px 5px 0px; +} + +h2 +{ + color: #99C; + font-family: Arial, Helvetica, sans-serif; + font-size: 20px; + line-height: 27px; + font-weight: normal; + border-color: #E06611; + border-width: 0 0 4px 0; + border-style: none none solid none; + margin: 10px 0px 5px 0px; + +} + +h3 +{ + color: #E06611; + font-family: Arial, Helvetica, sans-serif; + font-size: 16px; + line-height: 27px; + font-weight: bold; + border-color: #E8EAF0; + border-width: 0 0 2px 0; + border-style: none none solid none; + margin: 10px 0px 5px 0px; + +} +h4 +{ + color: #99C; + font-family: Arial, Helvetica, sans-serif; + font-size: 16px; + line-height: 24px; + font-weight: normal; + border-color: #E8EAF0; + border-width: 0 0 2px 0; + border-style: none none solid none; + margin: 10px 0px 5px 0px; + +} +h5 +{ + color: #E06611; + font-family: Arial, Helvetica, sans-serif; + font-size: 14px; + line-height: 24px; + font-weight: normal; + border-color: #E8EAF0; + border-width: 0 0 2px 0; + border-style: none none solid none; + margin: 10px 0px 5px 0px; + +} +h6 +{ + color: #99C; + font-family: Arial, Helvetica, sans-serif; + font-size: 14px; + line-height: 22px; + font-weight: normal; + border-color: #E8EAF0; + border-width: 0 0 2px 0; + border-style: none none solid none; + margin: 10px 0px 5px 0px; + +} + +td +{ + color: black; + font-family: Arial,Helvetica, sans-serif; + font-size: 12px; + font-weight: normal; +} + +p +{ + color: black; + font-family: Arial,Helvetica, sans-serif; + font-size: 12px; + line-height: 16px; + font-weight: normal; + margin: 10px 10px 5px 0px; +} + +p.error +{ + color: red; +} + diff --git a/jonas_4_10/jonas/examples/earsample/etc/xml/application-client.xml b/jonas_4_10/jonas/examples/earsample/etc/xml/application-client.xml new file mode 100644 index 0000000000000000000000000000000000000000..433ce1c78a16d55e7bd95507c1f365f1b50d9e2a --- /dev/null +++ b/jonas_4_10/jonas/examples/earsample/etc/xml/application-client.xml @@ -0,0 +1,42 @@ + + + + Client of the earsample + + + envEntryString + java.lang.String + Test of envEntry of application-client.xml file + + + + + ejb/Op + Session + org.objectweb.earsample.beans.secusb.OpHome + org.objectweb.earsample.beans.secusb.Op + secusb.jar#EarOp + + + + + ejb/OpLink + Session + org.objectweb.earsample.beans.secusb.OpHome + org.objectweb.earsample.beans.secusb.Op + EarOp + + + + url/jonas + java.net.URL + Container + + + org.objectweb.jonas.security.auth.callback.LoginCallbackHandler + + diff --git a/jonas_4_10/jonas/examples/earsample/etc/xml/application.xml b/jonas_4_10/jonas/examples/earsample/etc/xml/application.xml new file mode 100644 index 0000000000000000000000000000000000000000..76696d559e2a3f6749d3d89278f6aa84528d38e4 --- /dev/null +++ b/jonas_4_10/jonas/examples/earsample/etc/xml/application.xml @@ -0,0 +1,35 @@ + + + + + + ear example secusb/servlet + earsample secusb/servlet + + + secusb.jar + + + + + earsample.war + earsample + + + + + client1.jar + + + client2.jar + + + + ra-sample.rar + + + diff --git a/jonas_4_10/jonas/examples/earsample/etc/xml/jonas-client1.xml b/jonas_4_10/jonas/examples/earsample/etc/xml/jonas-client1.xml new file mode 100644 index 0000000000000000000000000000000000000000..b7b0d3fdd13c014c9c8c4007d5d15a71cc6e97f8 --- /dev/null +++ b/jonas_4_10/jonas/examples/earsample/etc/xml/jonas-client1.xml @@ -0,0 +1,19 @@ + + + + + url/jonas + http://jonas.objectweb.org + + + + jaas.config + earsample + jonas + jonas + + + diff --git a/jonas_4_10/jonas/examples/earsample/etc/xml/jonas-client2.xml b/jonas_4_10/jonas/examples/earsample/etc/xml/jonas-client2.xml new file mode 100644 index 0000000000000000000000000000000000000000..1cf3ead28217b38d9d294e14fe42339981790f47 --- /dev/null +++ b/jonas_4_10/jonas/examples/earsample/etc/xml/jonas-client2.xml @@ -0,0 +1,18 @@ + + + + + + url/jonas + http://jonas.objectweb.org + + + + jaas.config + earsample + + + diff --git a/jonas_4_10/jonas/examples/earsample/etc/xml/jonas-secusb.xml b/jonas_4_10/jonas/examples/earsample/etc/xml/jonas-secusb.xml new file mode 100644 index 0000000000000000000000000000000000000000..ca04b169dbabb1e2aa96fb0c0cab7e7d16639f07 --- /dev/null +++ b/jonas_4_10/jonas/examples/earsample/etc/xml/jonas-secusb.xml @@ -0,0 +1,12 @@ + + + + + + EarOp + EarOpHome + + diff --git a/jonas_4_10/jonas/examples/earsample/etc/xml/jonas-web.xml b/jonas_4_10/jonas/examples/earsample/etc/xml/jonas-web.xml new file mode 100644 index 0000000000000000000000000000000000000000..069066e888db6286da168edf096d60786379f63e --- /dev/null +++ b/jonas_4_10/jonas/examples/earsample/etc/xml/jonas-web.xml @@ -0,0 +1,13 @@ + + + + + + url/URL + http://jonas.objectweb.org + + + diff --git a/jonas_4_10/jonas/examples/earsample/etc/xml/ra.xml b/jonas_4_10/jonas/examples/earsample/etc/xml/ra.xml new file mode 100755 index 0000000000000000000000000000000000000000..73edde1b462012273682391d0c085db6c9d60bc5 --- /dev/null +++ b/jonas_4_10/jonas/examples/earsample/etc/xml/ra.xml @@ -0,0 +1,40 @@ + + + rar sample + rar sample + ObjectWeb + + 1.0 + + false + + + + + org.objectweb.earsample.resourceadapters.ResourceAdapterImpl + + + + JNDI name + jndiName + + java.lang.String + + + eisName + + + + URL for EIS instance + EisURL + + java.lang.String + + + EIS_URL + + + + \ No newline at end of file diff --git a/jonas_4_10/jonas/examples/earsample/etc/xml/secusb.xml b/jonas_4_10/jonas/examples/earsample/etc/xml/secusb.xml new file mode 100644 index 0000000000000000000000000000000000000000..531d055c2d0855cc4b401414651493bb6859d2f4 --- /dev/null +++ b/jonas_4_10/jonas/examples/earsample/etc/xml/secusb.xml @@ -0,0 +1,60 @@ + + + + + secured session bean JOnAS example + + secusb (earsample) + + + + EarOp + org.objectweb.earsample.beans.secusb.OpHome + org.objectweb.earsample.beans.secusb.Op + org.objectweb.earsample.beans.secusb.OpLocalHome + org.objectweb.earsample.beans.secusb.OpLocal + org.objectweb.earsample.beans.secusb.OpBean + Stateful + Container + + + + + + tomcat + + + jetty + + + + tomcat + + EarOp + * + + + + + jetty + + EarOp + * + + + + + + EarOp + * + + Supports + + + + + diff --git a/jonas_4_10/jonas/examples/earsample/etc/xml/web-jetty.xml b/jonas_4_10/jonas/examples/earsample/etc/xml/web-jetty.xml new file mode 100644 index 0000000000000000000000000000000000000000..20da7c6c4358001627433dbfb0ef3e0db07ddb40 --- /dev/null +++ b/jonas_4_10/jonas/examples/earsample/etc/xml/web-jetty.xml @@ -0,0 +1,25 @@ + + + + + + + + + Example Basic Authentication Area + + + + + Example Basic Authentication Area + memrlm_1 + + + + + diff --git a/jonas_4_10/jonas/examples/earsample/etc/xml/web.xml b/jonas_4_10/jonas/examples/earsample/etc/xml/web.xml new file mode 100644 index 0000000000000000000000000000000000000000..e3fb7330937e2a05f29a66750ab81658df3f7cd4 --- /dev/null +++ b/jonas_4_10/jonas/examples/earsample/etc/xml/web.xml @@ -0,0 +1,80 @@ + + + + + + Op + org.objectweb.earsample.servlets.ServletOp + + + + Op + /secured/Op + + + + url/URL + java.net.URL + Application + + + + + Protected Area + + /secured/* + + DELETE + GET + POST + PUT + + + + tomcat + jetty + + + + + + BASIC + Example Basic Authentication Area + + + + + tomcat + + + + jetty + + + + + envEntryString + java.lang.String + This is a string from the env-entry + + + + ejb/Op + Session + org.objectweb.earsample.beans.secusb.OpHome + org.objectweb.earsample.beans.secusb.Op + EarOp + + + + ejb/OpLocal + Session + org.objectweb.earsample.beans.secusb.OpLocalHome + org.objectweb.earsample.beans.secusb.OpLocal + secusb.jar#EarOp + + + diff --git a/jonas_4_10/jonas/examples/earsample/src/org/objectweb/earsample/beans/secusb/Op.java b/jonas_4_10/jonas/examples/earsample/src/org/objectweb/earsample/beans/secusb/Op.java new file mode 100644 index 0000000000000000000000000000000000000000..f4c31355da190939db1e8ed0d68a4bcde03aebc2 --- /dev/null +++ b/jonas_4_10/jonas/examples/earsample/src/org/objectweb/earsample/beans/secusb/Op.java @@ -0,0 +1,52 @@ +/** + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2004 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer(s): + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ + +package org.objectweb.earsample.beans.secusb; + +import javax.ejb.EJBObject; +import java.rmi.RemoteException; + +/** + * Remote interface for the bean Op + * @author JOnAS team + */ +public interface Op extends EJBObject { + + /** + * Business method implementation. + * @param shares nb of shares to be bought + * @throws RemoteException if RMI failed. + */ + void buy (int shares) throws RemoteException; + + /** + * Business method implementation. + * @return the nb of shares bought + * @throws RemoteException if RMI failed. + */ + int read () throws RemoteException; + +} \ No newline at end of file diff --git a/jonas_4_10/jonas/examples/earsample/src/org/objectweb/earsample/beans/secusb/OpBean.java b/jonas_4_10/jonas/examples/earsample/src/org/objectweb/earsample/beans/secusb/OpBean.java new file mode 100644 index 0000000000000000000000000000000000000000..65afb2722cda36514c984ac4afc906ad7343e3a3 --- /dev/null +++ b/jonas_4_10/jonas/examples/earsample/src/org/objectweb/earsample/beans/secusb/OpBean.java @@ -0,0 +1,247 @@ +/** + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2004 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer(s): + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ + +package org.objectweb.earsample.beans.secusb; + +import javax.ejb.EJBException; +import javax.ejb.SessionBean; +import javax.ejb.SessionContext; +import javax.ejb.SessionSynchronization; + +/** + * This is an example of Session Bean, statefull, and synchronized. + * @author JOnAS team + */ +public class OpBean implements SessionBean, SessionSynchronization { + + /** + * Actual state of the bean + */ + private int total = 0; + + /** + * value inside Tx, not yet committed. + */ + private int newtotal = 0; + + /** + * User client + */ + private String clientUser = null; + + /** + * Session context that the container provides for a session enterprise Bean + * instance. + */ + private SessionContext sessionContext = null; + + /* ========================= ejbCreate methods ============================ */ + + /** + * There must be one ejbCreate() method per create() method on the Home + * interface, and with the same signature. + * @param user the user name + */ + public void ejbCreate(String user) { + total = 0; + // in case we are outside transactions + newtotal = total; + clientUser = user; + } + + /* =============== javax.ejb.SessionBean 2.0 implementation ============== */ + + /** + * The activate method is called when the instance is activated from its + * "passive" state. The instance should acquire any resource that it has + * released earlier in the ejbPassivate() method. This method is called with + * no transaction context. + * @throws EJBException Thrown by the method to indicate a failure caused by + * a system-level error. + * @throws java.rmi.RemoteException This exception is defined in the method + * signature to provide backward compatibility for enterprise beans + * written for the EJB 1.0 specification. Enterprise beans written + * for the EJB 1.1 specification should throw the + * javax.ejb.EJBException instead of this exception. Enterprise + * beans written for the EJB2.0 and higher specifications must throw + * the javax.ejb.EJBException instead of this exception. + */ + public void ejbActivate() throws EJBException, java.rmi.RemoteException { + // Nothing to do for this simple example + } + + /** + * The passivate method is called before the instance enters the "passive" + * state. The instance should release any resources that it can re-acquire + * later in the ejbActivate() method. After the passivate method completes, + * the instance must be in a state that allows the container to use the Java + * Serialization protocol to externalize and store away the instance's + * state. This method is called with no transaction context. + * @throws EJBException Thrown by the method to indicate a failure caused by + * a system-level error. + * @throws java.rmi.RemoteException This exception is defined in the method + * signature to provide backward compatibility for enterprise beans + * written for the EJB 1.0 specification. Enterprise beans written + * for the EJB 1.1 specification should throw the + * javax.ejb.EJBException instead of this exception. Enterprise + * beans written for the EJB2.0 and higher specifications must throw + * the javax.ejb.EJBException instead of this exception. + */ + public void ejbPassivate() throws EJBException, java.rmi.RemoteException { + // Nothing to do for this simple example + } + + /** + * A container invokes this method before it ends the life of the session + * object. This happens as a result of a client's invoking a remove + * operation, or when a container decides to terminate the session object + * after a timeout. This method is called with no transaction context. + * @throws EJBException Thrown by the method to indicate a failure caused by + * a system-level error. + * @throws java.rmi.RemoteException This exception is defined in the method + * signature to provide backward compatibility for enterprise beans + * written for the EJB 1.0 specification. Enterprise beans written + * for the EJB 1.1 specification should throw the + * javax.ejb.EJBException instead of this exception. Enterprise + * beans written for the EJB2.0 and higher specifications must throw + * the javax.ejb.EJBException instead of this exception. + */ + public void ejbRemove() throws EJBException, java.rmi.RemoteException { + // Nothing to do for this simple example + } + + /** + * Set the associated session context. The container calls this method after + * the instance creation. The enterprise Bean instance should store the + * reference to the context object in an instance variable. This method is + * called with no transaction context. + * @param sessionContext A SessionContext interface for the instance. + * @throws EJBException Thrown by the method to indicate a failure caused by + * a system-level error. + * @throws java.rmi.RemoteException This exception is defined in the method + * signature to provide backward compatibility for applications + * written for the EJB 1.0 specification. Enterprise beans written + * for the EJB 1.1 specification should throw the + * javax.ejb.EJBException instead of this exception. Enterprise + * beans written for the EJB2.0 and higher specifications must throw + * the javax.ejb.EJBException instead of this exception. + */ + public void setSessionContext(SessionContext sessionContext) throws EJBException, java.rmi.RemoteException { + this.sessionContext = sessionContext; + } + + /* + * ============== javax.ejb.SessionSynchronization implementation + * ============= + */ + + /** + * The afterBegin method notifies a session Bean instance that a new + * transaction has started, and that the subsequent business methods on the + * instance will be invoked in the context of the transaction. The instance + * can use this method, for example, to read data from a database and cache + * the data in the instance fields. This method executes in the proper + * transaction context. + * @throws EJBException Thrown by the method to indicate a failure caused by + * a system-level error. + * @throws java.rmi.RemoteException - This exception is defined in the + * method signature to provide backward compatibility for enterprise + * beans written for the EJB 1.0 specification. Enterprise beans + * written for the EJB 1.1 and higher specifications should throw + * the javax.ejb.EJBException instead of this exception. Enterprise + * beans written for the EJB 2.0 and higher specifications must not + * throw the java.rmi.RemoteException. + */ + public void afterBegin() throws EJBException, java.rmi.RemoteException { + newtotal = total; + } + + /** + * The beforeCompletion method notifies a session Bean instance that a + * transaction is about to be committed. The instance can use this method, + * for example, to write any cached data to a database. This method executes + * in the proper transaction context. Note: The instance may still + * cause the container to rollback the transaction by invoking the + * setRollbackOnly() method on the instance context, or by throwing an + * exception. + * @throws EJBException Thrown by the method to indicate a failure caused by + * a system-level error. + * @throws java.rmi.RemoteException - This exception is defined in the + * method signature to provide backward compatibility for enterprise + * beans written for the EJB 1.0 specification. Enterprise beans + * written for the EJB 1.1 and higher specifications should throw + * the javax.ejb.EJBException instead of this exception. Enterprise + * beans written for the EJB 2.0 and higher specifications must not + * throw the java.rmi.RemoteException. + */ + public void beforeCompletion() throws EJBException, java.rmi.RemoteException { + } + + /** + * The afterCompletion method notifies a session Bean instance that a + * transaction commit protocol has completed, and tells the instance whether + * the transaction has been committed or rolled back. This method executes + * with no transaction context. + * @param committed - True if the transaction has been committed, false if + * is has been rolled back. + * @throws EJBException Thrown by the method to indicate a failure caused by + * a system-level error. + * @throws java.rmi.RemoteException - This exception is defined in the + * method signature to provide backward compatibility for enterprise + * beans written for the EJB 1.0 specification. Enterprise beans + * written for the EJB 1.1 and higher specifications should throw + * the javax.ejb.EJBException instead of this exception. Enterprise + * beans written for the EJB 2.0 and higher specifications must not + * throw the java.rmi.RemoteException. + */ + public void afterCompletion(boolean committed) throws EJBException, java.rmi.RemoteException { + + if (committed) { + total = newtotal; + } else { + newtotal = total; + } + } + + /* ========================= Op implementation ============================ */ + + /** + * Business method implementation. + * @param s nb of shares to be bought + */ + public void buy(int s) { + newtotal = newtotal + s; + return; + } + + /** + * Business method implementation. + * @return the nb of shares bought + */ + public int read() { + return newtotal; + } +} \ No newline at end of file diff --git a/jonas_4_10/jonas/examples/earsample/src/org/objectweb/earsample/beans/secusb/OpHome.java b/jonas_4_10/jonas/examples/earsample/src/org/objectweb/earsample/beans/secusb/OpHome.java new file mode 100644 index 0000000000000000000000000000000000000000..c27269138dc8324e83f469aa2c43f14e96c48a67 --- /dev/null +++ b/jonas_4_10/jonas/examples/earsample/src/org/objectweb/earsample/beans/secusb/OpHome.java @@ -0,0 +1,47 @@ +/** + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2004 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer(s): + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ + +package org.objectweb.earsample.beans.secusb; + +import java.rmi.RemoteException; +import javax.ejb.CreateException; +import javax.ejb.EJBHome; + +/** + * Home interface for the bean Op + * @author JOnAS team + */ +public interface OpHome extends EJBHome { + + /** + * Create an instance of the Op bean. + * @param user the user name. + * @return the Remote interface of the bean Op. + * @throws CreateException if the creation failed. + * @throws RemoteException if the RMI call failed. + */ + Op create(String user) throws CreateException, RemoteException; +} diff --git a/jonas_4_10/jonas/examples/earsample/src/org/objectweb/earsample/beans/secusb/OpLocal.java b/jonas_4_10/jonas/examples/earsample/src/org/objectweb/earsample/beans/secusb/OpLocal.java new file mode 100644 index 0000000000000000000000000000000000000000..f65b4b5543bae448569205b9d69987da2ffbec01 --- /dev/null +++ b/jonas_4_10/jonas/examples/earsample/src/org/objectweb/earsample/beans/secusb/OpLocal.java @@ -0,0 +1,48 @@ +/** + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2004 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer(s): + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ + +package org.objectweb.earsample.beans.secusb; + +import javax.ejb.EJBLocalObject; + +/** + * Local interface for the bean Op + * @author JOnAS team + */ +public interface OpLocal extends EJBLocalObject { + + /** + * Business method implementation. + * @param shares nb of shares to be bought + */ + void buy(int shares); + + /** + * Business method implementation. + * @return the nb of shares bought + */ + int read(); +} \ No newline at end of file diff --git a/jonas_4_10/jonas/examples/earsample/src/org/objectweb/earsample/beans/secusb/OpLocalHome.java b/jonas_4_10/jonas/examples/earsample/src/org/objectweb/earsample/beans/secusb/OpLocalHome.java new file mode 100644 index 0000000000000000000000000000000000000000..730e9966246da30e8a5241a6098d55fef3521cf9 --- /dev/null +++ b/jonas_4_10/jonas/examples/earsample/src/org/objectweb/earsample/beans/secusb/OpLocalHome.java @@ -0,0 +1,45 @@ +/** + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2004 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer(s): + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ + +package org.objectweb.earsample.beans.secusb; + +import javax.ejb.CreateException; +import javax.ejb.EJBLocalHome; + +/** + * Local home interface for the bean Op + * @author JOnAS team + */ +public interface OpLocalHome extends EJBLocalHome { + + /** + * Create an instance of the Op bean. + * @param user the user name. + * @return the Remote interface of the bean Op. + * @throws CreateException if the creation failed. + */ + OpLocal create(String user) throws CreateException; +} \ No newline at end of file diff --git a/jonas_4_10/jonas/examples/earsample/src/org/objectweb/earsample/clients/Client.java b/jonas_4_10/jonas/examples/earsample/src/org/objectweb/earsample/clients/Client.java new file mode 100644 index 0000000000000000000000000000000000000000..87aa7e493a303d3ff2cfd9686f2db3982feb75ff --- /dev/null +++ b/jonas_4_10/jonas/examples/earsample/src/org/objectweb/earsample/clients/Client.java @@ -0,0 +1,189 @@ +/** + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2004 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer: Florent Benoit + * + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ + +package org.objectweb.earsample.clients; + +import java.net.URL; + +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.transaction.UserTransaction; +import javax.rmi.PortableRemoteObject; + +import org.objectweb.earsample.beans.secusb.Op; +import org.objectweb.earsample.beans.secusb.OpHome; + +/** + * Heavy client doing some operations on a bean + * @author jonas team + */ +public class Client { + + /** + * First amount to buy + */ + private static final int FIRST_BUY_AMOUNT = 10; + + /** + * Second amount to buy + */ + private static final int SECOND_BUY_AMOUNT = 20; + + /** + * Third amount to buy (will be rollback) + */ + private static final int THIRD_BUY_AMOUNT = 50; + + /** + * Constructor. Hide constructor as it is an utility class + */ + private Client() { + + } + + /** + * Main method + * @param args arguments of the client + */ + public static void main(String[] args) { + + Context initialContext = null; + System.out.print("Building a new InitialContext..."); + try { + initialContext = new InitialContext(); + } catch (Exception e) { + System.err.println("Cannot get initial context for JNDI: " + e); + System.exit(2); + } + System.out.println("done !"); + + System.out.print("Looking up java:comp/UserTransaction ..."); + // We want to start transactions from client: get UserTransaction + UserTransaction utx = null; + try { + utx = (UserTransaction) initialContext.lookup("java:comp/UserTransaction"); + } catch (Exception e) { + System.err.println("Cannot lookup UserTransaction: " + e); + System.exit(2); + } + System.out.println("done !"); + + String envEntry = null; + System.out.print("Looking up java:comp/env/envEntryString ..."); + try { + envEntry = (String) initialContext.lookup("java:comp/env/envEntryString"); + } catch (Exception e) { + System.err.println("Cannot get env-entry on JNDI " + e); + System.exit(2); + } + System.out.println("done !"); + System.out.println("Env entry is : " + envEntry); + + URL url = null; + System.out.print("Looking up java:comp/env/url/jonas ..."); + try { + url = (URL) initialContext.lookup("java:comp/env/url/jonas"); + } catch (Exception e) { + System.err.println("Cannot get URL on JNDI " + e); + System.exit(2); + } + System.out.println("done !"); + System.out.println("Web site of jonas is at :" + url); + + System.out.print("Looking up java:comp/env/ejb/Op ..."); + // Connecting to OpHome thru JNDI + OpHome home = null; + try { + home = (OpHome) PortableRemoteObject.narrow(initialContext.lookup("java:comp/env/ejb/Op"), OpHome.class); + System.out.println("done !"); + } catch (Exception e) { + e.printStackTrace(); + System.err.println("Cannot lookup OpHome: " + e); + System.exit(2); + } + + // OpBean creation + Op t1 = null; + try { + System.out.println("Create a bean"); + t1 = home.create("User1"); + } catch (Exception e) { + System.err.println("Cannot create OpBean: " + e); + System.exit(2); + } + + // First transaction (committed) + try { + System.out.println("Start a first transaction"); + utx.begin(); + System.out.println("First request on the new bean"); + t1.buy(FIRST_BUY_AMOUNT); + System.out.println("Second request on the bean"); + t1.buy(SECOND_BUY_AMOUNT); + System.out.println("Commit the transaction"); + utx.commit(); + } catch (Exception e) { + System.err.println("exception during 1st Tx: " + e); + System.exit(2); + } + // Start another transaction (rolled back) + try { + System.out.println("Start a second transaction"); + utx.begin(); + t1.buy(THIRD_BUY_AMOUNT); + System.out.println("Rollback the transaction"); + utx.rollback(); + } catch (Exception e) { + System.err.println("exception during 2nd Tx: " + e); + System.exit(2); + } + + // Get the total bought, outside the transaction + int val = 0; + try { + System.out.println("Request outside any transaction"); + val = t1.read(); + } catch (Exception e) { + System.err.println("Cannot read value on t1 : " + e); + System.exit(2); + } + if (val != FIRST_BUY_AMOUNT + SECOND_BUY_AMOUNT) { + System.err.println("Bad value read: " + val); + System.exit(2); + } + + // Remove Session bean + try { + t1.remove(); + } catch (Exception e) { + System.out.println("Exception on buy: " + e); + System.exit(2); + } + System.out.println("ClientOp OK. Exiting."); + } +} + diff --git a/jonas_4_10/jonas/examples/earsample/src/org/objectweb/earsample/resourceadapters/ResourceAdapterImpl.java b/jonas_4_10/jonas/examples/earsample/src/org/objectweb/earsample/resourceadapters/ResourceAdapterImpl.java new file mode 100755 index 0000000000000000000000000000000000000000..001553566814a33cfcc0e3cf1da5d2c26b87ac75 --- /dev/null +++ b/jonas_4_10/jonas/examples/earsample/src/org/objectweb/earsample/resourceadapters/ResourceAdapterImpl.java @@ -0,0 +1,191 @@ +/** + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2005 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ + +package org.objectweb.earsample.resourceadapters; + + +import java.net.MalformedURLException; +import java.util.HashMap; + +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.resource.NotSupportedException; +import javax.resource.ResourceException; +import javax.resource.spi.ActivationSpec; +import javax.resource.spi.BootstrapContext; +import javax.resource.spi.ResourceAdapterInternalException; +import javax.resource.spi.endpoint.MessageEndpointFactory; +import javax.transaction.xa.XAResource; + +/** + * A Resource adapter + * @author kemlerp + * + */ +public class ResourceAdapterImpl implements javax.resource.spi.ResourceAdapter, java.io.Serializable { + + + /** + * serialVersionUID + */ + private static final long serialVersionUID = 3834312812943456568L; + + /** + * String should be the RA name when set, ie, EIS + */ + private String eisurl; + + /** + * The JNDI name + */ + private String jndiName; + + /** + * Initial context + */ + private InitialContext ictx; + + /** + * BootstrapContext + */ + private BootstrapContext bootstrapCtx = null; // set in start() + + /** + * EndpointFactories + */ + private transient HashMap endpointFactories = new HashMap(); + + + /** + * Start + * @param bootstrapCtx bootstrapCtx + * @throws ResourceAdapterInternalException if an error occurs + */ + public void start(BootstrapContext bootstrapCtx) throws ResourceAdapterInternalException { + this.bootstrapCtx = bootstrapCtx; + + try { + ictx = new InitialContext(); + ictx.bind(jndiName, eisurl); + } catch (NamingException e) { + e.printStackTrace(); + } + + } + + /** + * Stop + */ + public void stop() { + try { + ictx.unbind(jndiName); + } catch (NamingException e) { + e.printStackTrace(); + } + } + + + /** + * Called by the application server when a message-driven bean + * (MessageEndpoint) is deployed. + * @param factory MessageEndpointFactory + * @param spec activation spec + * @throws NotSupportedException if an error occurs + * @throws ResourceAdapterInternalException if an error occurs + */ + public void endpointActivation(MessageEndpointFactory factory, ActivationSpec spec) throws NotSupportedException, + ResourceAdapterInternalException { + endpointFactories.put(spec, factory); + } + + /** + * Endpoint Deactivation + * @param factory MessageEndpointFactory + * @param spec activation spec + */ + public void endpointDeactivation(MessageEndpointFactory factory, ActivationSpec spec) { + endpointFactories.remove(spec); + } + + /** + * Get XAResources + * @param specs A tab of specs + * @throws ResourceException if an error occurs + * @return Tab of XAResources + */ + public XAResource[] getXAResources(ActivationSpec[] specs) throws ResourceException { + return null; + } + + /** + * Get Eis URL + * @return Eis URL + */ + public String getEisURL() { + return eisurl.toString(); + } + + /** + * Set Eis URL + * @param eisURL Eis URL + * @throws MalformedURLException if 'eisURL' is not a URL + */ + public void setEisURL(String eisURL) throws MalformedURLException { + // ra.xml deployment supplies value + this.eisurl = eisURL; + } + + /** + * Get BootstrapContext + * @return bootstrapCtx + */ + public BootstrapContext getBootstrapCtx() { + return bootstrapCtx; + } + + /** + * Set BootstrapContext + * @param bootstrapCtx bootstrapContext + */ + public void setBootstrapCtx(BootstrapContext bootstrapCtx) { + this.bootstrapCtx = bootstrapCtx; + } + + /** + * Get used JNDI name + * @return A string + */ + public String getJndiName() { + return jndiName; + } + + /** + * Set JNDI name + * @param jndiName a string + */ + public void setJndiName(String jndiName) { + this.jndiName = jndiName; + } +} diff --git a/jonas/examples/earsample/src/org/objectweb/earsample/servlets/ServletOp.java b/jonas_4_10/jonas/examples/earsample/src/org/objectweb/earsample/servlets/ServletOp.java similarity index 100% rename from jonas/examples/earsample/src/org/objectweb/earsample/servlets/ServletOp.java rename to jonas_4_10/jonas/examples/earsample/src/org/objectweb/earsample/servlets/ServletOp.java diff --git a/jonas_4_10/jonas/examples/emb-sample/.cvsignore b/jonas_4_10/jonas/examples/emb-sample/.cvsignore new file mode 100644 index 0000000000000000000000000000000000000000..378eac25d311703f3f2cd456d8036da525cd0366 --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/.cvsignore @@ -0,0 +1 @@ +build diff --git a/jonas_4_10/jonas/examples/emb-sample/README b/jonas_4_10/jonas/examples/emb-sample/README new file mode 100644 index 0000000000000000000000000000000000000000..e4a673003b5d18261c6625a9c530871f673a5ade --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/README @@ -0,0 +1,70 @@ +$Id: README,v 1.3 2005/07/08 14:02:52 pasmith Exp $ + +============================================================================== +ENTERPRISE MEDIA BEANS SAMPE README +============================================================================== + +As a pre-requisite, please deploy the emb-sample application. + +To visit the emb-sample Application visit: + + http://localhost:9000/emb-sample + +First you have to had some media to the database : + - to add default samples select Load + - to add your own samples by uploading it + +All your sample will be remove after session timeout + + +====================================== +DIRECTORY STRUCTURE: +====================================== + +emb-core/ customizes preset core application of EMB +etc/ all deployment descriptor +lib/ upload lib +resources/ JSPs, samples, images, html files. +src/ java files + + +====================================== +KNOWN ISSUES: +====================================== + +Here are some known issues about the emb-sample demo: + +1) By default the application is set to work only on localhost + +2) Cookies have to be accepted in order to use this sample + +3) If the user's session times out or if the user removes their + cookies, all generated media will be removed + +4) This sample needs some memory under quite heavy load, I advice you to start + JOnAS more memory than default (64MB). (if you got OutOfMemoryError) + To do this set JAVA_OPTS environment variable to -Xmx128m, in order to + set the maximum memory of the JVM to 128MB. + + +====================================== +HOW TO CUSTOMIZE EMB-SAMPLE SETTING: +====================================== + +Customize application : + emb sample have some few setting in order to limit the load of the server + in case of an on line demo. + + - in etc/web.xml : set the session timeout (in minutes + - in etc/embSampleSession.xml : + - set the env entry ejb/embSample/isCopyAllowed in order to copy or + to modify the media when using some conversion (limit numbers of ejb + entity). + - set the env entry ejb/embSample/maxMediaPerSession to set the + maximum of media that can be created (upload, convert if copy is + allowed) + + Some features are only avaiable by using some plugins such has streaming + capabilities, video conversion or more image format support. + For using this sample through a network (not localhost) see the + Enterprise Media Beans documentation. diff --git a/jonas_4_10/jonas/examples/emb-sample/build.xml b/jonas_4_10/jonas/examples/emb-sample/build.xml new file mode 100644 index 0000000000000000000000000000000000000000..c196385d908c86ade396c3b2081c298102d4af6e --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/build.xml @@ -0,0 +1,183 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jonas_4_10/jonas/examples/emb-sample/emb-core/README b/jonas_4_10/jonas/examples/emb-sample/emb-core/README new file mode 100644 index 0000000000000000000000000000000000000000..e057cf6e18ba6777e0b7f187969a8a11254a9054 --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/emb-core/README @@ -0,0 +1,9 @@ +$Id: README,v 1.3 2005/07/08 14:02:52 pasmith Exp $ + +============================================================================== + EMB CORE +============================================================================== + +In this directory put your customized emb-core.ear +(orginal is in $JONAS_ROOT/lib/commons/jonas/emb/emb-core) + diff --git a/jonas_4_10/jonas/examples/emb-sample/etc/application.xml b/jonas_4_10/jonas/examples/emb-sample/etc/application.xml new file mode 100644 index 0000000000000000000000000000000000000000..5d6f36240c24dac150a999e1bb02df49bb846864 --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/etc/application.xml @@ -0,0 +1,67 @@ + + + + + JOnAS EMB sample + JOnAS EMB sample + + + + + emb-core-ejb.jar + + + + + emb-plugin-publisher-servlet-jonas.rar + + + + emb-plugin-publisher-servlet-jonas.war + + emb-plugin-publisher-servlet-jonas + + + + + + + + + emb-sample-ejb.jar + + + + + + emb-sample.war + emb-sample + + + + + + + + + + + + diff --git a/jonas_4_10/jonas/examples/emb-sample/etc/embSampleSession.xml b/jonas_4_10/jonas/examples/emb-sample/etc/embSampleSession.xml new file mode 100644 index 0000000000000000000000000000000000000000..ae2c91129c7b35d588c9357d985473e702ba032e --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/etc/embSampleSession.xml @@ -0,0 +1,56 @@ + + + + + EMB Sample Session Bean + + + MediaSampleSession + + emb.sample.session.MediaSampleSessionLocalHome + + emb.sample.session.MediaSampleSessionLocal + + emb.sample.session.MediaSampleSessionBean + + Stateful + Container + + This permit to copy media content instead of mdified it. It create more mediaEntityBean + + ejb/embSample/isCopyAllowed + + java.lang.Boolean + true + + + Maximum media per session, to avoid server over load. The demo has at least 10 media by default. 0 is no limit + + ejb/embSample/maxMediaPerSession + + java.lang.Integer + 0 + + + ejb/emb/MediaEntity + Entity + javax.emb.MediaEntityLocalHome + javax.emb.MediaEntityLocal + emb-core-ejb.jar#MediaEntity + + + + + + + MediaSampleSession + * + + Supports + + + + diff --git a/jonas_4_10/jonas/examples/emb-sample/etc/jonas-embSampleSession.xml b/jonas_4_10/jonas/examples/emb-sample/etc/jonas-embSampleSession.xml new file mode 100644 index 0000000000000000000000000000000000000000..23c3e122cce53ebaaecc15e6528ac7f54b4c74d3 --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/etc/jonas-embSampleSession.xml @@ -0,0 +1,8 @@ + + + + + diff --git a/jonas_4_10/jonas/examples/emb-sample/etc/web.xml b/jonas_4_10/jonas/examples/emb-sample/etc/web.xml new file mode 100644 index 0000000000000000000000000000000000000000..ee709397325322a762bea1decfb198fcfe661c32 --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/etc/web.xml @@ -0,0 +1,230 @@ + + + + + + + + 10 + + + + + ActionDispatcher + + emb.sample.servlet.ActionDispatcher + + + + LoadSampleMedia + + emb.sample.servlet.LoadSampleMedia + + + + UploadSampleMedia + + emb.sample.servlet.UploadSampleMedia + + + + HomeSample + emb.sample.servlet.HomeSample + + + ListSampleMedia + + emb.sample.servlet.ListSampleMedia + + + + ExtractHeaderData + + emb.sample.servlet.ExtractHeaderData + + + + RetrieveSampleMedia + + emb.sample.servlet.RetrieveSampleMedia + + + + ConvertSampleImageBW + + emb.sample.servlet.ConvertSampleImageBW + + + + ConvertSampleImageHalfSize + + emb.sample.servlet.ConvertSampleImageHalfSize + + + + JAIConvertSampleImageBW + + emb.sample.servlet.ConvertSampleImageBW + + + + JAIConvertSampleImageHalfSize + + emb.sample.servlet.ConvertSampleImageHalfSize + + + + ConvertSampleImageFormat + + emb.sample.servlet.ConvertSampleImageFormat + + + + ConvertSampleImageChained + + emb.sample.servlet.ConvertSampleImageChained + + + + ConvertSampleImageSvgToPng + + emb.sample.servlet.ConvertSampleImageSvgToPng + + + + ConvertSampleVideoTo3GPP + + emb.sample.servlet.ConvertSampleVideoTo3GPP + + + + + ConvertSampleVideoToMpegTs + + emb.sample.servlet.ConvertSampleVideoToMpegTs + + + + ConvertSampleVideoToMpeg + + emb.sample.servlet.ConvertSampleVideoToMpeg + + + + ConvertSampleImageOverlayed + + emb.sample.servlet.ConvertSampleImageOverlayed + + + + ConvertSampleImageFrame + + emb.sample.servlet.ConvertSampleImageFrame + + + + + + ActionDispatcher + /index.jsp + + + HomeSample + /HomeSample + + + ActionDispatcher + /ActionDispatcher + + + UploadSampleMedia + /UploadSampleMedia + + + LoadSampleMedia + /LoadSampleMedia + + + ListSampleMedia + /ListSampleMedia + + + ExtractHeaderData + /ExtractHeaderData + + + RetrieveSampleMedia + /RetrieveSampleMedia + + + ConvertSampleImageBW + /ConvertSampleImageBW + + + ConvertSampleImageHalfSize + /ConvertSampleImageHalfSize + + + ConvertSampleImageFormat + /ConvertSampleImageFormat + + + ConvertSampleImageChained + /ConvertSampleImageChained + + + ConvertSampleImageSvgToPng + /ConvertSampleImageSvgToPng + + + ConvertSampleVideoTo3GPP + /ConvertSampleVideoTo3GPP + + + ConvertSampleVideoToMpegTs + /ConvertSampleVideoToMpegTs + + + ConvertSampleVideoToMpeg + /ConvertSampleVideoToMpeg + + + ConvertSampleImageOverlayed + /ConvertSampleImageOverlayed + + + ConvertSampleImageFrame + /ConvertSampleImageFrame + + + 404 + /ActionDispatcher + + + ejb/emb/MediaEntity + Entity + javax.emb.MediaEntityLocalHome + javax.emb.MediaEntityLocal + emb-core-ejb.jar#MediaEntity + + + ejb/embSample/MediaSampleSession + Session + + emb.sample.session.MediaSampleSessionLocalHome + + emb.sample.session.MediaSampleSessionLocal + emb-sample-ejb.jar#MediaSampleSession + + + + + + emb.sample.servlet.HttpSessionMgr + + + + diff --git a/jonas_4_10/jonas/examples/emb-sample/plugins/README b/jonas_4_10/jonas/examples/emb-sample/plugins/README new file mode 100644 index 0000000000000000000000000000000000000000..88ee43011fed783c17e246d42d44652703c47dba --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/plugins/README @@ -0,0 +1,8 @@ +$Id$ + +============================================================================== + Plugins +============================================================================== + +In this directory put the plugins you want to use (*.rar) + diff --git a/jonas_4_10/jonas/examples/emb-sample/resources/icons/valid-xhtml11.png b/jonas_4_10/jonas/examples/emb-sample/resources/icons/valid-xhtml11.png new file mode 100644 index 0000000000000000000000000000000000000000..2c63d93f8868d574b9e69eda2727b7e7bf7fc8ec Binary files /dev/null and b/jonas_4_10/jonas/examples/emb-sample/resources/icons/valid-xhtml11.png differ diff --git a/jonas_4_10/jonas/examples/emb-sample/resources/icons/vcss.png b/jonas_4_10/jonas/examples/emb-sample/resources/icons/vcss.png new file mode 100644 index 0000000000000000000000000000000000000000..9b2f596e016533327216d98a0a927738fe17384f Binary files /dev/null and b/jonas_4_10/jonas/examples/emb-sample/resources/icons/vcss.png differ diff --git a/jonas_4_10/jonas/examples/emb-sample/resources/jsps/footer.jsp b/jonas_4_10/jonas/examples/emb-sample/resources/jsps/footer.jsp new file mode 100644 index 0000000000000000000000000000000000000000..6abe0bfbf5b7b873b1cb929180d6535190115817 --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/resources/jsps/footer.jsp @@ -0,0 +1,6 @@ + + + + + + diff --git a/jonas_4_10/jonas/examples/emb-sample/resources/jsps/header.jsp b/jonas_4_10/jonas/examples/emb-sample/resources/jsps/header.jsp new file mode 100644 index 0000000000000000000000000000000000000000..fa91d53b214aec135b8ecfb8b962fb6f9b0a6a45 --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/resources/jsps/header.jsp @@ -0,0 +1,31 @@ + + +<%@ page errorPage="templatePage.jsp" %> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %> + + + +JOnAS Enterprise Media Beans (JSR 86) - Sample + + + +
    + + +

    JOnAS Enterprise Media Beans (JSR 86) - Sample

    + + + + +
    + diff --git a/jonas_4_10/jonas/examples/emb-sample/resources/jsps/mediaList.jsp b/jonas_4_10/jonas/examples/emb-sample/resources/jsps/mediaList.jsp new file mode 100644 index 0000000000000000000000000000000000000000..31920bbc7e8321cc1205a457404ddd28010d132b --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/resources/jsps/mediaList.jsp @@ -0,0 +1,109 @@ + + +<%@ page import="emb.sample.servlet.BaseSampleServlet"%> +<%@ page errorPage="templatePage.jsp"%> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + +JOnAS Enterprise Media Beans (JSR 86) - Sample + + + +
    +
    +

    JOnAS Enterprise Media Beans (JSR 86) - Sample

    + + + + +
    + + + + + + + + <% + boolean lineParity = true; + + // get medias + javax.emb.MediaEntityLocal[] medias = (javax.emb.MediaEntityLocal[]) request.getAttribute("samplesMedia"); + String[] proxiesUrl = (String[]) request.getAttribute("proxiesUrl"); + + for (int i = 0; i < medias.length; i++) { + + String lineKind = "even"; + if (lineParity) { + lineKind = "odd"; + } + lineParity = !lineParity; + + %> + + + + + + + + + + + <%}%> + +
    Usable Media List
    + + + + <%= medias[i].getName() %> + + <%=medias[i].getName()%><%=medias[i].getMimeType()%><%= BaseSampleServlet.SIZE_FORMAT.format(medias[i].getSize() / BaseSampleServlet.BYTE_IN_KB) %> kB
    <%=(medias[i].getDescription() == null ? "" : medias[i].getDescription())%>
    +
    + + +
    +
    + + diff --git a/jonas_4_10/jonas/examples/emb-sample/resources/jsps/navigation.jsp b/jonas_4_10/jonas/examples/emb-sample/resources/jsps/navigation.jsp new file mode 100644 index 0000000000000000000000000000000000000000..d560f25e71284c68696a0334505831f791b369dd --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/resources/jsps/navigation.jsp @@ -0,0 +1,12 @@ + diff --git a/jonas_4_10/jonas/examples/emb-sample/resources/jsps/templatePage.jsp b/jonas_4_10/jonas/examples/emb-sample/resources/jsps/templatePage.jsp new file mode 100644 index 0000000000000000000000000000000000000000..6a397249a5c988df4e6390b6b059446358290993 --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/resources/jsps/templatePage.jsp @@ -0,0 +1,67 @@ + + +<%@ page isErrorPage="true"%> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %> + + + +JOnAS Enterprise Media Beans (JSR 86) - Sample + + + +
    + + +

    JOnAS Enterprise Media Beans (JSR 86) - Sample

    + + + + + +
    +<% +if (exception != null) { + out.println("

    There was an Error

    "); + out.println("
    ");
    +    java.io.ByteArrayOutputStream ostr = new java.io.ByteArrayOutputStream();
    +    exception.printStackTrace(new java.io.PrintStream(ostr));
    +    out.print(ostr);
    +    out.println("
    "); +} + +Object workspaceContent = request.getAttribute("workspaceContent"); +if (workspaceContent != null) { + out.println(workspaceContent.toString()); +} + +Object errorMessage = request.getAttribute("errorMessage"); +if (errorMessage != null) { + out.println("

    There was an Error

    "); + out.println("
    ");
    +    out.println(errorMessage.toString());
    +    out.println("
    "); +} +%> +
    + +
    + + + diff --git a/jonas_4_10/jonas/examples/emb-sample/resources/jsps/uploadForm.jsp b/jonas_4_10/jonas/examples/emb-sample/resources/jsps/uploadForm.jsp new file mode 100644 index 0000000000000000000000000000000000000000..eb98a700d394f6cb6dff688ded4e9502593034f3 --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/resources/jsps/uploadForm.jsp @@ -0,0 +1,85 @@ + + +<%@ page errorPage="templatePage.jsp" %> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %> + + + +JOnAS Enterprise Media Beans (JSR 86) - Sample + + + +
    + + +

    JOnAS Enterprise Media Beans (JSR 86) - Sample

    + + + + + +
    + + +

    Upload a new Media

    +

    +Choose a media to import, the media can be either a file or an URL location.
    +You can had a description if want to.
    +The file extension must supported (see below) +

    +
    + + +
    + +
    +
    + ("file://" or "http://" only) +
    +
    + +
    +
    + +
    +
    + +
    +

    Supported formats

    +<% +Object workspaceContent = request.getAttribute("fromatSupported"); +if (workspaceContent != null) { + out.println(workspaceContent.toString()); +} +%> +
    + + +
    + +
    + + + + + + + + + + + + + + + diff --git a/jonas_4_10/jonas/examples/emb-sample/resources/samples/Java_CompatEE.gif b/jonas_4_10/jonas/examples/emb-sample/resources/samples/Java_CompatEE.gif new file mode 100644 index 0000000000000000000000000000000000000000..10997dfc3cb998e1d78c13183ea1f7fc26752bd2 Binary files /dev/null and b/jonas_4_10/jonas/examples/emb-sample/resources/samples/Java_CompatEE.gif differ diff --git a/jonas_4_10/jonas/examples/emb-sample/resources/samples/apache.svg b/jonas_4_10/jonas/examples/emb-sample/resources/samples/apache.svg new file mode 100644 index 0000000000000000000000000000000000000000..f12b00a67c596c87908c3a48687264a14e635690 --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/resources/samples/apache.svg @@ -0,0 +1,759 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jonas_4_10/jonas/examples/emb-sample/resources/samples/frame.png b/jonas_4_10/jonas/examples/emb-sample/resources/samples/frame.png new file mode 100644 index 0000000000000000000000000000000000000000..af8a33d61e3fb90dc8ad7b6366d3cb4563af8844 Binary files /dev/null and b/jonas_4_10/jonas/examples/emb-sample/resources/samples/frame.png differ diff --git a/jonas_4_10/jonas/examples/emb-sample/resources/samples/iss-fireworks.mp3 b/jonas_4_10/jonas/examples/emb-sample/resources/samples/iss-fireworks.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..8a54177ea5cb6dd71cf20528e0fd4fe33ac25982 Binary files /dev/null and b/jonas_4_10/jonas/examples/emb-sample/resources/samples/iss-fireworks.mp3 differ diff --git a/jonas_4_10/jonas/examples/emb-sample/resources/samples/jonas.mp4 b/jonas_4_10/jonas/examples/emb-sample/resources/samples/jonas.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..b8e0d71d9f9eb23aa959394d20b51ca967e785bc Binary files /dev/null and b/jonas_4_10/jonas/examples/emb-sample/resources/samples/jonas.mp4 differ diff --git a/jonas_4_10/jonas/examples/emb-sample/resources/samples/jonas.png b/jonas_4_10/jonas/examples/emb-sample/resources/samples/jonas.png new file mode 100644 index 0000000000000000000000000000000000000000..a19da9ca20bbc9a242ae198a0c2f6b4dcd37c11a Binary files /dev/null and b/jonas_4_10/jonas/examples/emb-sample/resources/samples/jonas.png differ diff --git a/jonas_4_10/jonas/examples/emb-sample/resources/samples/mask.png b/jonas_4_10/jonas/examples/emb-sample/resources/samples/mask.png new file mode 100644 index 0000000000000000000000000000000000000000..882e474f477a9e56cb22aa5e7af41b65d422d661 Binary files /dev/null and b/jonas_4_10/jonas/examples/emb-sample/resources/samples/mask.png differ diff --git a/jonas_4_10/jonas/examples/emb-sample/resources/samples/objectweb.png b/jonas_4_10/jonas/examples/emb-sample/resources/samples/objectweb.png new file mode 100644 index 0000000000000000000000000000000000000000..f3334f55091a554a7708a65c5aae9369384f4850 Binary files /dev/null and b/jonas_4_10/jonas/examples/emb-sample/resources/samples/objectweb.png differ diff --git a/jonas_4_10/jonas/examples/emb-sample/resources/samples/samples.properties b/jonas_4_10/jonas/examples/emb-sample/resources/samples/samples.properties new file mode 100644 index 0000000000000000000000000000000000000000..46d62a0d285b3f6a948250c5080d17381355977d --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/resources/samples/samples.properties @@ -0,0 +1,83 @@ +# --------------------------------------------------------------------------- +# JOnAS: Java(TM) Open Application Server +# Copyright (C) 2005 Bull S.A. +# Contact: jonas-team@objectweb.org +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +# USA +# +# Initial developer: Brice Ruzand +# --------------------------------------------------------------------------- +# $Id$ +# --------------------------------------------------------------------------- +# +# This contains the Initial information for the sample media database +# + +# sample MP3 audio file +sampleAudio1.file iss-fireworks.mp3 +sampleAudio1.desc International Space Station crew responding to fireworks question. +sampleAudio1.show true + +# sample PNG file +sampleLogo1.file jonas.png +sampleLogo1.desc JOnAS logo +sampleLogo1.show true + +# sample PNG file +sampleLogo2.file objectweb.png +sampleLogo2.desc ObjectWeb logo +sampleLogo2.show true + +# sample GIF file +sampleLogo3.file Java_CompatEE.gif +sampleLogo3.desc Java EE Compatible logo +sampleLogo3.show true + +# sample SVG file +sampleDraw1.file apache.svg +sampleDraw1.desc Apache Logo +sampleDraw1.show true + +# sample JPG file +samplePhoto1.file snow.jpg +samplePhoto1.desc Going back home by skiing, in winter 2005 +samplePhoto1.show true + +# sample JPG file +samplePhoto2.file white-valley.jpg +samplePhoto2.desc White Valley (Chamonix, France) +samplePhoto2.show true + +# sample JPG file +samplePhoto3.file starfish.jpg +samplePhoto3.desc A starfish while scuba diving in Mediterranean See +samplePhoto3.show true + +# sample MPEG4 file +sampleVideo1.file jonas.mp4 +sampleVideo1.desc EMB with JOnAS promotion Trailer +sampleVideo1.show true + + +# sample for frame converter (frame) +sampleFrame1.file frame.png +sampleFrame1.desc Image used in frame generation (frame) +sampleFrame1.show false + +# sample for frame converter +sampleMask1.file mask.png +sampleMask1.desc Image used in frame generation (mask) +sampleMask1.show false diff --git a/jonas_4_10/jonas/examples/emb-sample/resources/samples/snow.jpg b/jonas_4_10/jonas/examples/emb-sample/resources/samples/snow.jpg new file mode 100644 index 0000000000000000000000000000000000000000..6b39d0c2adf4165cd62b4ca9f796350e9e108b25 Binary files /dev/null and b/jonas_4_10/jonas/examples/emb-sample/resources/samples/snow.jpg differ diff --git a/jonas_4_10/jonas/examples/emb-sample/resources/samples/starfish.jpg b/jonas_4_10/jonas/examples/emb-sample/resources/samples/starfish.jpg new file mode 100644 index 0000000000000000000000000000000000000000..c8786ca88ca3c483ad9c2903cbec2a699d1f1022 Binary files /dev/null and b/jonas_4_10/jonas/examples/emb-sample/resources/samples/starfish.jpg differ diff --git a/jonas_4_10/jonas/examples/emb-sample/resources/samples/white-valley.jpg b/jonas_4_10/jonas/examples/emb-sample/resources/samples/white-valley.jpg new file mode 100644 index 0000000000000000000000000000000000000000..ab51bb49107438d866804d4eaf239da0aabc4734 Binary files /dev/null and b/jonas_4_10/jonas/examples/emb-sample/resources/samples/white-valley.jpg differ diff --git a/jonas_4_10/jonas/examples/emb-sample/resources/theme/style.css b/jonas_4_10/jonas/examples/emb-sample/resources/theme/style.css new file mode 100644 index 0000000000000000000000000000000000000000..0b73165bd5efa440184fd4847d7901e33e28643a --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/resources/theme/style.css @@ -0,0 +1,132 @@ +body { + background: #eef7fd; + font-family: arial, helvetica, sans-serif; + font-size: 11pt; +} + +h1,h2,h3,h4,th { + color: #9f3e19; + font-weight: bold; + margin: 5pt; +} + +h1 { + font-size: 18pt; + padding-bottom: 10pt; +} + +h2 { + font-size: 13pt; +} + +h3,th { + text-align: center; + font-size: 12pt; + color: #42648e; + padding-top: 3pt; + padding-bottom: 3pt; +} + +h4 { + font-size: 12pt; +} + +#workspace { + overflow: auto; + margin-right: 10px; + margin-left: 0.5ex; + padding: 10px; + border-style: dotted; + border-width: 1px; + border-color: #42648e; + background-color: white; +} + +#workspace table { + width: 100%; + border-spacing: 0; +} + +.media-proxy { + height: 60px; + vertical-align: middle; + padding-top: 5px; +} + +img { + border-style: none; +} + +.media { + text-align: center; +} + +#menu { + float: left; + margin-right: 0.5ex; + width: 30ex; + height: 100%; + font-size: 11pt; +} + +#menu p { + text-align: center; +} + +.menu-box { + border-style: dashed; + border-width: 1px; + border-color: #42648e; + background-color: white; + margin-bottom: 1ex; + padding-left: 1ex; + padding-right: 1ex; + padding-bottom: 1ex; +} + +.menu-box .submit { + padding: 10px; + text-align: center; +} + +.media-size { + vertical-align: middle; +} + +.media-mimetype { + vertical-align: bottom; +} + +.media-desc { + font-size: medium; + vertical-align: top; +} + +.url { + font-size: 11pt; + font-stretch: ultra-condensed; +} + +label { + display: block; + float: left; + width: 8em; + padding-right: 1em; + text-align: right; +} + +.even { + background-color: #FFFFFF; +} + +.odd { + background-color: #F6F6F6; +} + +.error { + color: red; +} + +pre.error { + font-size: 10pt; +} \ No newline at end of file diff --git a/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/MediaSampleException.java b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/MediaSampleException.java new file mode 100644 index 0000000000000000000000000000000000000000..fb5eef0271c63da0c71055ab2265dc167b70e13f --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/MediaSampleException.java @@ -0,0 +1,75 @@ +/* + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2005 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer(s): Brice Ruzand + * + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ +package emb.sample; + +/** + * This exception extends {@link Exception} and is thrown whenever sample app + * got a trouble + */ +public class MediaSampleException extends Exception { + + /** + * serialVersionUID + */ + private static final long serialVersionUID = 493847692100239586L; + + /** + * This is the default constructor taking no arguments. + */ + public MediaSampleException() { + super(); + } + + /** + * This is the default exception constructor taking a String argument. + * + * @param message the message. + */ + public MediaSampleException(String message) { + super(message); + } + + /** + * This is the default exception constructor taking a Throwable argument. + * + * @param cause the throwable. + */ + public MediaSampleException(Throwable cause) { + super(cause); + } + + /** + * This is the default exception constructor taking both a Throwable and a + * String argument. + * + * @param message the message. + * @param cause the throwable. + */ + public MediaSampleException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/ActionDispatcher.java b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/ActionDispatcher.java new file mode 100644 index 0000000000000000000000000000000000000000..e91b6fca6ce878dbb4bd3a1a686ed7d5822f49b1 --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/ActionDispatcher.java @@ -0,0 +1,116 @@ +/** + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2005 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer(s): Brice Ruzand + * + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ +package emb.sample.servlet; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * Query dispatcher to implement an MVC model + * + * @author Brice Ruzand + */ +public class ActionDispatcher extends BaseSampleServlet { + + /** + * serialVersionUID + */ + private static final long serialVersionUID = 3257285816379389239L; + + /** + * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, + * javax.servlet.http.HttpServletResponse) + * @inheritDoc + */ + public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + try { + // get the task to perform + String action = request.getParameter("action"); + + // Query the media entity EJB instance. + String identity = request.getParameter("identity"); + + if (action == null) { + getServletContext().getRequestDispatcher("/HomeSample").forward(request, response); + } else if (action.equals("home")) { + getServletContext().getRequestDispatcher("/HomeSample").forward(request, response); + } else if (action.equals("load")) { + getServletContext().getRequestDispatcher("/LoadSampleMedia").forward(request, response); + } else if (action.equals("list")) { + getServletContext().getRequestDispatcher("/ListSampleMedia").forward(request, response); + } else if (action.equals("upload")) { + getServletContext().getRequestDispatcher("/UploadSampleMedia").forward(request, response); + } else { + + if (identity == null) { + + StringPrinter workspaceContent = new StringPrinter(); + + // message + workspaceContent.println("

    No media selected

    "); + workspaceContent.println("Please return to the list and select a media to process..."); + + request.setAttribute("workspaceContent", workspaceContent); + getServletConfig().getServletContext().getRequestDispatcher(TEMPLATE_JSP) + .forward(request, response); + + } else if (action.equals("retrieve")) { + getServletContext().getRequestDispatcher("/RetrieveSampleMedia").forward(request, response); + } else if (action.equals("extractHeader")) { + getServletContext().getRequestDispatcher("/ExtractHeaderData").forward(request, response); + } else if (action.equals("convertBW")) { + getServletContext().getRequestDispatcher("/ConvertSampleImageBW").forward(request, response); + } else if (action.equals("convertHalfSize")) { + getServletContext().getRequestDispatcher("/ConvertSampleImageHalfSize").forward(request, response); + } else if (action.equals("convertFormat")) { + getServletContext().getRequestDispatcher("/ConvertSampleImageFormat").forward(request, response); + } else if (action.equals("convertChained")) { + getServletContext().getRequestDispatcher("/ConvertSampleImageChained").forward(request, response); + } else if (action.equals("convertSvgToPng")) { + getServletContext().getRequestDispatcher("/ConvertSampleImageSvgToPng").forward(request, response); + } else if (action.equals("convertVideoTo3GPP")) { + getServletContext().getRequestDispatcher("/ConvertSampleVideoTo3GPP").forward(request, response); + } else if (action.equals("convertVideoToMpegTs")) { + getServletContext().getRequestDispatcher("/ConvertSampleVideoToMpegTs").forward(request, response); + } else if (action.equals("convertVideoToMpeg")) { + getServletContext().getRequestDispatcher("/ConvertSampleVideoToMpeg").forward(request, response); + } else if (action.equals("convertOverlayed")) { + getServletContext().getRequestDispatcher("/ConvertSampleImageOverlayed").forward(request, response); + } else if (action.equals("convertFrame")) { + getServletContext().getRequestDispatcher("/ConvertSampleImageFrame").forward(request, response); + } else { + throw new Exception("Invalid Action dispatecher param."); + } + } + } catch (Throwable e) { + exceptionHandler(e, getClass(), request, response); + } + } +} diff --git a/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/BaseSampleServlet.java b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/BaseSampleServlet.java new file mode 100644 index 0000000000000000000000000000000000000000..b6f1f4c784f15dd9ed7dde15e26d950283939d13 --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/BaseSampleServlet.java @@ -0,0 +1,335 @@ +/* + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2005 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer(s): Brice Ruzand + * + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ +package emb.sample.servlet; + +import java.io.Serializable; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Random; + +import javax.emb.MediaEntityLocal; +import javax.emb.MediaEntityLocalHome; +import javax.emb.MediaException; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import emb.sample.MediaSampleException; +import emb.sample.session.MediaSampleSessionLocal; +import emb.sample.session.MediaSampleSessionLocalHome; + +/** + * Base classes for all sample + * + * @author Brice Ruzand + */ +public class BaseSampleServlet extends HttpServlet { + + /** + * serialVersionUID + */ + private static final long serialVersionUID = 428471464384262530L; + + /* + * ======================================================================= + * Sample apps + * ======================================================================= + */ + + /** + * Retrive servlet URI + */ + protected static final String RETRIEVE_SERVLET = "/RetrieveSampleMedia"; + + /** + * Retrive servlet URI + */ + protected static final String ACTION_DISPATCHER_SERVLET = "/ActionDispatcher"; + + /** + * template jsp URI + */ + protected static final String TEMPLATE_JSP = "/jsps/templatePage.jsp"; + + /** + * tranforme Byte in KB + */ + public static final double BYTE_IN_KB = 1024D; + + /** + * Random seed + */ + protected static final Random RANDOM = new Random(); + + /** + * Default format for time stamp + */ + public static final SimpleDateFormat TIME_STAMP_FORMAT = new SimpleDateFormat("yy-MM-dd HH:mm:ss.SSS"); + + /** + * Default format for size + */ + public static final DecimalFormat SIZE_FORMAT = new DecimalFormat("0.0"); + + /** + * Display medi info in XHTML + * + * @param sp StringPrinter + * @param meb The media entity + */ + protected void displayInfo(StringPrinter sp, MediaEntityLocal meb) { + + try { + sp.println("Name : " + meb.getName() + "
    "); + sp.println("MimeType : " + meb.getMimeType() + "
    "); + sp.println("Size : " + SIZE_FORMAT.format(meb.getSize() / BYTE_IN_KB) + " KB
    "); + String desc = meb.getDescription(); + if (desc == null) { + desc = ""; + } + sp.println("Description :
    " + meb.getDescription() + "

    "); + sp.println("LastModified :
    " + TIME_STAMP_FORMAT.format(new Date(meb.getLastModified())) + + "

    "); + } catch (MediaException e) { + sp.println("Error while retriving medi info"); + } + } + + /** + * Get a session bean to manage Media creation + * + * @param request the HttpServlet request + * @return the MediaSampleSessionLocal + * @throws MediaSampleException if session cannot be created + */ + protected static MediaSampleSessionLocal getSession(HttpServletRequest request) throws MediaSampleException { + try { + MediaSampleSessionLocal sessionBean = (MediaSampleSessionLocal) request.getSession().getAttribute( + "sessionBean"); + + if (sessionBean == null) { + sessionBean = getSessionHome().create(); + request.getSession().setAttribute("sessionBean", sessionBean); + throw new MediaSampleException("Your session has exprired, please reload some medias"); + } + return sessionBean; + } catch (MediaSampleException e) { + throw e; + } catch (Exception e) { + // e.printStackTrace(); + throw new MediaSampleException("Unable to create a new session", e); + + } + } + + /* + * ======================================================================= + * Errors + * ======================================================================= + */ + + /** + * Method to handle all exceptions of all Music Application Servlets in a + * uniform way using the specified error JSP (/jps/templatePage.jsp). + *

    + * In case of error a ServletException will be thrown. + * + * @param exception java.lang.Exception + * @param errorClass class where the error locate + * @param request com.sun.server.http.HttpServletRequest + * @param response com.sun.server.http.HttpServletResponse + * @throws ServletException This exception will be thrown if the + * errorhandling fails + */ + protected void exceptionHandler(Throwable exception, Class errorClass, HttpServletRequest request, + HttpServletResponse response) throws ServletException { + + StringPrinter errorMessage = new StringPrinter(); + + try { + + if (exception instanceof MediaSampleException) { + + errorMessage.println("

    There was an error

    "); + errorMessage.println(exception.getLocalizedMessage()); + request.setAttribute("workspaceContent", errorMessage); + getServletConfig().getServletContext().getRequestDispatcher(TEMPLATE_JSP).forward(request, response); + + } else { + + errorMessage.println(errorClass.getName() + ":"); + errorMessage.println(""); + errorMessage.println(exception.toString()); + errorMessage.println(""); + errorLog(errorClass.getName() + ": " + exception); + + StackTraceElement[] ste; + if (exception.getCause() != null) { + ste = exception.getCause().getStackTrace(); + } else { + ste = exception.getStackTrace(); + } + + for (int i = 0; i < ste.length; i++) { + + errorMessage.println(ste[i].toString()); + // when the source cause is found stop stack + if (ste[i].getClassName().startsWith("emb.sample")) { + break; + } + } + + request.setAttribute("errorMessage", errorMessage); + getServletConfig().getServletContext().getRequestDispatcher(TEMPLATE_JSP).forward(request, response); + + } + + } catch (Exception e) { + // if standard error reporter fails throw exception + throw new ServletException(errorMessage.toString(), e); + } + } + + /** + * Method to print error messages to stderr and for syschronisation purpose + * to stdout too. + * + * @param msg java.lang.String + */ + protected static void errorLog(String msg) { + final int defBuffer = 1024; + StringBuffer bfr = new StringBuffer(defBuffer); + + bfr.append("["); + bfr.append(TIME_STAMP_FORMAT.format(new Date(System.currentTimeMillis()))); + bfr.append("] EMB SAMPLE ERROR "); + bfr.append(msg); + + System.err.println(bfr.toString()); + } + + /** + * Class to use printer + * + * @author Brice Ruzand + */ + protected class StringPrinter implements Serializable { + + /** + * serialVersionUID + */ + private static final long serialVersionUID = -2865716341020911272L; + + /** + * The String Buffer + */ + private StringBuffer buffer; + + /** + * Default Constructor + */ + public StringPrinter() { + + final int newbuffsize = 128; + buffer = new StringBuffer(newbuffsize); + } + + /** + * Print a line in the printer + * + * @param str the string to print + */ + public void println(String str) { + buffer.append(str); + buffer.append("\r\n"); + } + + /** + * @see java.lang.Object#toString() + */ + public String toString() { + return buffer.toString(); + } + } + + /* + * ======================================================================= + * EJB TOOLS + * ======================================================================= + */ + + /** + * Media Enotity Bean Home reference + */ + private static final String SESSION_HOME_REF = "java:comp/env/ejb/embSample/MediaSampleSession"; + + /** + * Media Entity Bean Home reference + */ + private static final String MEB_HOME_REF = "java:comp/env/ejb/emb/MediaEntity"; + + /** + * cached Home + */ + private static MediaSampleSessionLocalHome mebSessionHome = null; + + /** + * cached Home + */ + private static MediaEntityLocalHome mebHome = null; + + /** + * Provide a cached Home access + * + * @return MediaEntityLocalHome + * @throws NamingException in case MediaEntityLocalHome is not found + */ + protected static MediaSampleSessionLocalHome getSessionHome() throws NamingException { + if (mebSessionHome == null) { + mebSessionHome = (MediaSampleSessionLocalHome) new InitialContext().lookup(SESSION_HOME_REF); + } + return mebSessionHome; + } + + /** + * Provide a cached Home access + * + * @return MediaEntityLocalHome + * @throws NamingException in case MediaEntityLocalHome is not found + */ + protected static MediaEntityLocalHome getMebHome() throws NamingException { + if (mebHome == null) { + mebHome = (MediaEntityLocalHome) new InitialContext().lookup(MEB_HOME_REF); + } + return mebHome; + } + +} diff --git a/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/ConvertSampleImageBW.java b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/ConvertSampleImageBW.java new file mode 100644 index 0000000000000000000000000000000000000000..7bc2da0b560be36a80be51f6e3e69855a85ede10 --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/ConvertSampleImageBW.java @@ -0,0 +1,84 @@ +/* + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2005 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer(s): Brice Ruzand + * + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ +package emb.sample.servlet; + +import javax.emb.MediaConverterSpec; +import javax.emb.MediaEntityLocal; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.objectweb.jonas.emb.mfb.converter.image.ImageRGBtoGrayscaleConverterSpec; +import org.objectweb.jonas.emb.mfb.formats.image.ImageMediaFormat; + +import emb.sample.MediaSampleException; +import emb.sample.session.MediaSampleSessionLocal; + +/** + * @author Brice Ruzand + */ +public class ConvertSampleImageBW extends BaseSampleServlet { + + /** + * serialVersionUID + */ + private static final long serialVersionUID = 3687815080511141944L; + + /** + * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, + * javax.servlet.http.HttpServletResponse) + * @inheritDoc + */ + public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException { + try { + MediaSampleSessionLocal session = getSession(request); + + // Query the media entity EJB instance. + String identity = request.getParameter("identity"); + MediaEntityLocal mediaEntity = session.getMediaFromPrimaryKey(identity); + + if (!(mediaEntity.getFormat() instanceof ImageMediaFormat)) { + throw new MediaSampleException("The selected media must be an image."); + } + + MediaEntityLocal media = session.copyMediaEntity(mediaEntity); + media.setDescription("Black and White conversion of: " + mediaEntity.getName()); + + // Convert the MediaEntityToBlack&White + MediaConverterSpec[] specs = new MediaConverterSpec[] {new ImageRGBtoGrayscaleConverterSpec()}; + media.convert(specs); + + // forward onto the retrieve servlet + request.setAttribute("identity", media.getPrimaryKey()); + this.getServletContext().getRequestDispatcher(RETRIEVE_SERVLET).forward(request, response); + + } catch (Throwable e) { + exceptionHandler(e, getClass(), request, response); + } + } + +} diff --git a/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/ConvertSampleImageChained.java b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/ConvertSampleImageChained.java new file mode 100644 index 0000000000000000000000000000000000000000..17c14a2dc33a9aa9267e6da773247d558583e215 --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/ConvertSampleImageChained.java @@ -0,0 +1,90 @@ +/* + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2005 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer(s): Brice Ruzand + * + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ +package emb.sample.servlet; + +import javax.emb.MediaConverterSpec; +import javax.emb.MediaEntityLocal; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.objectweb.jonas.emb.mfb.converter.image.ImageFormatConverterSpec; +import org.objectweb.jonas.emb.mfb.converter.image.ImageRGBtoGrayscaleConverterSpec; +import org.objectweb.jonas.emb.mfb.converter.image.ImageResizeConverterSpec; +import org.objectweb.jonas.emb.mfb.formats.image.ImageMediaFormat; + +import emb.sample.MediaSampleException; +import emb.sample.session.MediaSampleSessionLocal; + +/** + * @author Brice Ruzand + */ +public class ConvertSampleImageChained extends BaseSampleServlet { + + /** + * serialVersionUID + */ + private static final long serialVersionUID = 3761970445343076657L; + + /** + * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, + * javax.servlet.http.HttpServletResponse) + * @inheritDoc + */ + public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException { + try { + MediaSampleSessionLocal session = getSession(request); + + // Query the media entity EJB instance. + String identity = request.getParameter("identity"); + MediaEntityLocal mediaEntity = session.getMediaFromPrimaryKey(identity); + + if (!(mediaEntity.getFormat() instanceof ImageMediaFormat)) { + throw new MediaSampleException("The selected media must be an image."); + } + + // Create a copy + MediaEntityLocal media = session.copyMediaEntity(mediaEntity); + media.setDescription("Chained convertion of: " + mediaEntity.getName()); + + // Convert the media to PNG then to Grayscale then to Halfsize + final double resizeFactor = 0.5; + MediaConverterSpec[] specs = new MediaConverterSpec[] {new ImageFormatConverterSpec("png"), + new ImageRGBtoGrayscaleConverterSpec(), new ImageResizeConverterSpec(resizeFactor)}; + media.convert(specs); + identity = (String) media.getPrimaryKey(); + + // forward onto the retrieve servlet + request.setAttribute("identity", media.getPrimaryKey()); + this.getServletContext().getRequestDispatcher(RETRIEVE_SERVLET).forward(request, response); + + } catch (Throwable e) { + exceptionHandler(e, getClass(), request, response); + } + } + +} diff --git a/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/ConvertSampleImageFormat.java b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/ConvertSampleImageFormat.java new file mode 100644 index 0000000000000000000000000000000000000000..05e89c3270879911fa8390c1973bfc53a4bbb84b --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/ConvertSampleImageFormat.java @@ -0,0 +1,88 @@ +/* + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2005 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer(s): Brice Ruzand + * + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ +package emb.sample.servlet; + +import javax.emb.MediaConverterSpec; +import javax.emb.MediaEntityLocal; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.objectweb.jonas.emb.mfb.converter.image.ImageFormatConverterSpec; +import org.objectweb.jonas.emb.mfb.formats.image.ImageMediaFormat; + +import emb.sample.MediaSampleException; +import emb.sample.session.MediaSampleSessionLocal; + +/** + * @author Brice Ruzand + */ +public class ConvertSampleImageFormat extends BaseSampleServlet { + + /** + * serialVersionUID + */ + private static final long serialVersionUID = 3687815080511141944L; + + /** + * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, + * javax.servlet.http.HttpServletResponse) + * @inheritDoc + */ + public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException { + try { + MediaSampleSessionLocal session = getSession(request); + + // Query the media entity EJB instance. + String identity = request.getParameter("identity"); + MediaEntityLocal mediaEntity = session.getMediaFromPrimaryKey(identity); + + if (!(mediaEntity.getFormat() instanceof ImageMediaFormat)) { + throw new MediaSampleException("The selected media must be an image."); + } + + // Create a copy + MediaEntityLocal media = session.copyMediaEntity(mediaEntity); + String targetFormat = "png"; + media.setDescription(targetFormat + " conversion of: " + mediaEntity.getName()); + + // Convert the media to an other format + MediaConverterSpec[] specs = new MediaConverterSpec[] {new ImageFormatConverterSpec(targetFormat)}; + media.convert(specs); + + identity = (String) media.getPrimaryKey(); + + // forward onto the retrieve servlet + request.setAttribute("identity", media.getPrimaryKey()); + this.getServletContext().getRequestDispatcher(RETRIEVE_SERVLET).forward(request, response); + + } catch (Throwable e) { + exceptionHandler(e, getClass(), request, response); + } + } + +} diff --git a/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/ConvertSampleImageFrame.java b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/ConvertSampleImageFrame.java new file mode 100644 index 0000000000000000000000000000000000000000..e2661a3f2f2365104e423a5f427cf3926cb4b3b6 --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/ConvertSampleImageFrame.java @@ -0,0 +1,112 @@ +/* + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2005 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer(s): Brice Ruzand + * + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ +package emb.sample.servlet; + +import javax.emb.MediaConverterSpec; +import javax.emb.MediaEntityLocal; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.objectweb.jonas.emb.mfb.converter.image.ImageFrameConverterSpec; +import org.objectweb.jonas.emb.mfb.formats.image.ImageMediaFormat; + +import emb.sample.MediaSampleException; +import emb.sample.session.MediaSampleSessionLocal; + +/** + * @author Brice Ruzand + */ +public class ConvertSampleImageFrame extends BaseSampleServlet { + + /** + * serialVersionUID + */ + private static final long serialVersionUID = -3697654416111319491L; + + /** + * The quick acces to the frame, name in the property file + */ + private static final String FRAME_ACCESS = "sampleFrame1"; + + /** + * The quick acces to the mask, name in the property file + */ + private static final String MASK_ACCESS = "sampleMask1"; + + /** + * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, + * javax.servlet.http.HttpServletResponse) + * @inheritDoc + */ + public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException { + try { + MediaSampleSessionLocal session = getSession(request); + + // Query the media entity EJB instance. + String identity = request.getParameter("identity"); + MediaEntityLocal mediaEntity = session.getMediaFromPrimaryKey(identity); + + // name in th property file + MediaEntityLocal frame = null; + MediaEntityLocal mask = null; + + try { + frame = session.getMediaFromRegistredName(FRAME_ACCESS); + mask = session.getMediaFromRegistredName(MASK_ACCESS); + } catch (MediaSampleException e) { + throw new MediaSampleException("(no mask and frame in the dataBase). Please init the database."); + + } + + if (!(mediaEntity.getFormat() instanceof ImageMediaFormat)) { + throw new MediaSampleException("The selected media must be an image."); + } + + // Create a copy + MediaEntityLocal media = session.copyMediaEntity(mediaEntity); + media.setDescription("Added frame to: " + mediaEntity.getName()); + + // Convert the add specifed frame to the other image + + // well know position offset + final int posX = 50; + final int posY = 58; + + MediaConverterSpec[] specs = new MediaConverterSpec[] {new ImageFrameConverterSpec(frame, mask, posX, posY)}; + media.convert(specs); + identity = (String) media.getPrimaryKey(); + + // forward onto the retrieve servlet + request.setAttribute("identity", media.getPrimaryKey()); + this.getServletContext().getRequestDispatcher(RETRIEVE_SERVLET).forward(request, response); + + } catch (Throwable e) { + exceptionHandler(e, getClass(), request, response); + } + } +} diff --git a/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/ConvertSampleImageHalfSize.java b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/ConvertSampleImageHalfSize.java new file mode 100644 index 0000000000000000000000000000000000000000..e33d037ff5105c2382c959b3e2e2723517366b49 --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/ConvertSampleImageHalfSize.java @@ -0,0 +1,87 @@ +/* + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2005 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer(s): Brice Ruzand + * + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ +package emb.sample.servlet; + +import javax.emb.MediaConverterSpec; +import javax.emb.MediaEntityLocal; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.objectweb.jonas.emb.mfb.converter.image.ImageResizeConverterSpec; +import org.objectweb.jonas.emb.mfb.formats.image.ImageMediaFormat; + +import emb.sample.MediaSampleException; +import emb.sample.session.MediaSampleSessionLocal; + +/** + * @author Brice Ruzand + */ +public class ConvertSampleImageHalfSize extends BaseSampleServlet { + + /** + * serialVersionUID + */ + private static final long serialVersionUID = 36899150987141944L; + + /** + * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, + * javax.servlet.http.HttpServletResponse) + * @inheritDoc + */ + public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException { + try { + MediaSampleSessionLocal session = getSession(request); + + // Query the media entity EJB instance. + String identity = request.getParameter("identity"); + MediaEntityLocal mediaEntity = session.getMediaFromPrimaryKey(identity); + + if (!(mediaEntity.getFormat() instanceof ImageMediaFormat)) { + throw new MediaSampleException("The selected media must be an image."); + } + + // Create a copy + MediaEntityLocal media = session.copyMediaEntity(mediaEntity); + media.setDescription("Half-size conversion of: " + mediaEntity.getName()); + + // Convert the MediaEntityToHalfsize + final double resizeFactor = 0.5; + MediaConverterSpec[] specs = new MediaConverterSpec[] {new ImageResizeConverterSpec(resizeFactor)}; + media.convert(specs); + identity = (String) media.getPrimaryKey(); + + // forward onto the retrieve servlet + request.setAttribute("identity", media.getPrimaryKey()); + this.getServletContext().getRequestDispatcher(RETRIEVE_SERVLET).forward(request, response); + + } catch (Throwable e) { + exceptionHandler(e, getClass(), request, response); + } + } + +} diff --git a/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/ConvertSampleImageOverlayed.java b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/ConvertSampleImageOverlayed.java new file mode 100644 index 0000000000000000000000000000000000000000..ffe2a67786c0ae14a2f1a26c3873c991ff415b83 --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/ConvertSampleImageOverlayed.java @@ -0,0 +1,102 @@ +/* + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2005 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer(s): Brice Ruzand + * + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ +package emb.sample.servlet; + +import javax.emb.MediaConverterSpec; +import javax.emb.MediaEntityLocal; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.objectweb.jonas.emb.mfb.converter.image.ImageOverlayConverterSpec; +import org.objectweb.jonas.emb.mfb.formats.image.ImageMediaFormat; + +import emb.sample.MediaSampleException; +import emb.sample.session.MediaSampleSessionLocal; + +/** + * @version 1.0 + * @author + */ +public class ConvertSampleImageOverlayed extends BaseSampleServlet { + + /** + * serialVersionUID + */ + private static final long serialVersionUID = -3697654416111319491L; + + /** + * The quick acces to the logo, name in the property file + */ + private static final String LOGO_ACCESS = "sampleLogo1"; + + /** + * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, + * javax.servlet.http.HttpServletResponse) + * @inheritDoc + */ + public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException { + try { + + MediaSampleSessionLocal session = getSession(request); + + // Query the media entity EJB instance. + String identity = request.getParameter("identity"); + MediaEntityLocal mediaEntity = session.getMediaFromPrimaryKey(identity); + + // name in th property file + MediaEntityLocal logo = null; + + try { + logo = session.getMediaFromRegistredName(LOGO_ACCESS); + } catch (MediaSampleException e) { + throw new MediaSampleException("(no logo in the dataBase). Please init the database."); + + } + + if (!(mediaEntity.getFormat() instanceof ImageMediaFormat)) { + throw new MediaSampleException("The selected media must be an image."); + } + + // Create a copy + MediaEntityLocal media = session.copyMediaEntity(mediaEntity); + media.setDescription("Added Logo to: " + mediaEntity.getName()); + + // Convert the add specifed logo to the other image + MediaConverterSpec[] specs = new MediaConverterSpec[] {new ImageOverlayConverterSpec(logo)}; + media.convert(specs); + identity = (String) media.getPrimaryKey(); + + // forward onto the retrieve servlet + request.setAttribute("identity", media.getPrimaryKey()); + this.getServletContext().getRequestDispatcher(RETRIEVE_SERVLET).forward(request, response); + + } catch (Throwable e) { + exceptionHandler(e, getClass(), request, response); + } + } +} diff --git a/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/ConvertSampleImageSvgToPng.java b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/ConvertSampleImageSvgToPng.java new file mode 100644 index 0000000000000000000000000000000000000000..18e004722d40c85c910854b6f280ca96be835501 --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/ConvertSampleImageSvgToPng.java @@ -0,0 +1,89 @@ +/* + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2005 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer(s): Brice Ruzand + * + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ +package emb.sample.servlet; + +import javax.emb.MediaConverterSpec; +import javax.emb.MediaEntityLocal; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.objectweb.jonas.emb.mfb.formats.draw.DrawMediaFormat; + +import emb.sample.MediaSampleException; +import emb.sample.session.MediaSampleSessionLocal; + +/** + * @author Brice Ruzand + */ +public class ConvertSampleImageSvgToPng extends BaseSampleServlet { + + /** + * serialVersionUID + */ + private static final long serialVersionUID = 3688503298940548148L; + + /** + * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, + * javax.servlet.http.HttpServletResponse) + * @inheritDoc + */ + public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException { + try { + MediaSampleSessionLocal session = getSession(request); + + // Query the media entity EJB instance. + String identity = request.getParameter("identity"); + MediaEntityLocal mediaEntity = session.getMediaFromPrimaryKey(identity); + + if (!(mediaEntity.getFormat() instanceof DrawMediaFormat)) { + throw new MediaSampleException("The selected media must be a drawing."); + } + + // Create a copy + MediaEntityLocal media = session.copyMediaEntity(mediaEntity); + media.setDescription("PNG conversion using batik of: " + mediaEntity.getName()); + + // Convert the convert SVG to PNG + Class converterSpecClass = getClass().getClassLoader().loadClass( + "org.objectweb.jonas.emb.mfb.plugins.svg.batik.Svg2PngConverterSpec"); + MediaConverterSpec converterSpec = (MediaConverterSpec) converterSpecClass.newInstance(); + MediaConverterSpec[] specs = new MediaConverterSpec[] {converterSpec}; + media.convert(specs); + + identity = (String) media.getPrimaryKey(); + + // forward onto the retrieve servlet + request.setAttribute("identity", media.getPrimaryKey()); + this.getServletContext().getRequestDispatcher(RETRIEVE_SERVLET).forward(request, response); + + } catch (Throwable e) { + exceptionHandler(e, getClass(), request, response); + } + } + +} diff --git a/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/ConvertSampleVideoTo3GPP.java b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/ConvertSampleVideoTo3GPP.java new file mode 100644 index 0000000000000000000000000000000000000000..b7393e05acad3df433ecb2ca98b251bb2caf8faa --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/ConvertSampleVideoTo3GPP.java @@ -0,0 +1,89 @@ +/* + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2005 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer(s): Brice Ruzand + * + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ +package emb.sample.servlet; + +import javax.emb.MediaConverterSpec; +import javax.emb.MediaEntityLocal; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.objectweb.jonas.emb.mfb.formats.video.VideoMediaFormat; + +import emb.sample.MediaSampleException; +import emb.sample.session.MediaSampleSessionLocal; + +/** + * @author Brice Ruzand + */ +public class ConvertSampleVideoTo3GPP extends BaseSampleServlet { + + /** + * serialVersionUID + */ + private static final long serialVersionUID = 3687815080511141944L; + + /** + * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, + * javax.servlet.http.HttpServletResponse) + * @inheritDoc + */ + public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException { + try { + MediaSampleSessionLocal session = getSession(request); + + // Query the media entity EJB instance. + String identity = request.getParameter("identity"); + MediaEntityLocal mediaEntity = session.getMediaFromPrimaryKey(identity); + + if (!(mediaEntity.getFormat() instanceof VideoMediaFormat)) { + throw new MediaSampleException("The selected media must be an Video format."); + } + + // Create a copy + MediaEntityLocal media = session.copyMediaEntity(mediaEntity); + media.setDescription("Video to 3GPP conversion using ffmpeg of : " + mediaEntity.getName()); + + // Convert the Video to 3GPP with FFMPEG + Class converterSpecClass = getClass().getClassLoader().loadClass( + "org.objectweb.jonas.emb.mfb.plugins.video.ffmpeg.converter.VideoTo3GPPConverterSpec"); + MediaConverterSpec converterSpec = (MediaConverterSpec) converterSpecClass.newInstance(); + MediaConverterSpec[] specs = new MediaConverterSpec[] {converterSpec}; + media.convert(specs); + + identity = (String) media.getPrimaryKey(); + + // forward onto the retrieve servlet + request.setAttribute("identity", media.getPrimaryKey()); + this.getServletContext().getRequestDispatcher(RETRIEVE_SERVLET).forward(request, response); + + } catch (Throwable e) { + exceptionHandler(e, getClass(), request, response); + } + } + +} diff --git a/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/ConvertSampleVideoToMpeg.java b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/ConvertSampleVideoToMpeg.java new file mode 100644 index 0000000000000000000000000000000000000000..edf01ecd945486fdd22c76aef72307c46f50a4cb --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/ConvertSampleVideoToMpeg.java @@ -0,0 +1,90 @@ +/* + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2005 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer(s): Brice Ruzand + * + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ +package emb.sample.servlet; + +import javax.emb.MediaConverterSpec; +import javax.emb.MediaEntityLocal; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.objectweb.jonas.emb.mfb.formats.video.VideoMediaFormat; + +import emb.sample.MediaSampleException; +import emb.sample.session.MediaSampleSessionLocal; + +/** + * @author Brice Ruzand + */ +public class ConvertSampleVideoToMpeg extends BaseSampleServlet { + + + /** + * serialVersionUID + */ + private static final long serialVersionUID = 1823390929291730344L; + + /** + * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, + * javax.servlet.http.HttpServletResponse) + * @inheritDoc + */ + public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException { + try { + MediaSampleSessionLocal session = getSession(request); + + // Query the media entity EJB instance. + String identity = request.getParameter("identity"); + MediaEntityLocal mediaEntity = session.getMediaFromPrimaryKey(identity); + + if (!(mediaEntity.getFormat() instanceof VideoMediaFormat)) { + throw new MediaSampleException("The selected media must be an Video format."); + } + + // Create a copy + MediaEntityLocal media = session.copyMediaEntity(mediaEntity); + media.setDescription("Mpeg conversion using ffmpeg of : " + mediaEntity.getName()); + + // Convert the Video to MPEG with FFMPEG + Class converterSpecClass = getClass().getClassLoader().loadClass( + "org.objectweb.jonas.emb.mfb.plugins.video.ffmpeg.converter.VideoToMpegConverterSpec"); + MediaConverterSpec converterSpec = (MediaConverterSpec) converterSpecClass.newInstance(); + MediaConverterSpec[] specs = new MediaConverterSpec[] {converterSpec}; + media.convert(specs); + + identity = (String) media.getPrimaryKey(); + + // forward onto the retrieve servlet + request.setAttribute("identity", media.getPrimaryKey()); + this.getServletContext().getRequestDispatcher(RETRIEVE_SERVLET).forward(request, response); + + } catch (Throwable e) { + exceptionHandler(e, getClass(), request, response); + } + } + +} diff --git a/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/ConvertSampleVideoToMpegTs.java b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/ConvertSampleVideoToMpegTs.java new file mode 100644 index 0000000000000000000000000000000000000000..0102c4512e2f68cf8e94e7adc82bf01f8e37d24a --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/ConvertSampleVideoToMpegTs.java @@ -0,0 +1,89 @@ +/* + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2005 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer(s): Brice Ruzand + * + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ +package emb.sample.servlet; + +import javax.emb.MediaConverterSpec; +import javax.emb.MediaEntityLocal; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.objectweb.jonas.emb.mfb.formats.video.VideoMediaFormat; + +import emb.sample.MediaSampleException; +import emb.sample.session.MediaSampleSessionLocal; + +/** + * @author Brice Ruzand + */ +public class ConvertSampleVideoToMpegTs extends BaseSampleServlet { + + /** + * serialVersionUID + */ + private static final long serialVersionUID = 3687815080511141944L; + + /** + * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, + * javax.servlet.http.HttpServletResponse) + * @inheritDoc + */ + public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException { + try { + MediaSampleSessionLocal session = getSession(request); + + // Query the media entity EJB instance. + String identity = request.getParameter("identity"); + MediaEntityLocal mediaEntity = session.getMediaFromPrimaryKey(identity); + + if (!(mediaEntity.getFormat() instanceof VideoMediaFormat)) { + throw new MediaSampleException("The selected media must be an Video format."); + } + + // Create a copy + MediaEntityLocal media = session.copyMediaEntity(mediaEntity); + media.setDescription("Mpeg TS conversion using ffmpeg of : " + mediaEntity.getName()); + + // Convert the Video to MPEG TS with FFMPEG + Class converterSpecClass = getClass().getClassLoader().loadClass( + "org.objectweb.jonas.emb.mfb.plugins.video.ffmpeg.converter.VideoToMpegTSConverterSpec"); + MediaConverterSpec converterSpec = (MediaConverterSpec) converterSpecClass.newInstance(); + MediaConverterSpec[] specs = new MediaConverterSpec[] {converterSpec}; + media.convert(specs); + + identity = (String) media.getPrimaryKey(); + + // forward onto the retrieve servlet + request.setAttribute("identity", media.getPrimaryKey()); + this.getServletContext().getRequestDispatcher(RETRIEVE_SERVLET).forward(request, response); + + } catch (Throwable e) { + exceptionHandler(e, getClass(), request, response); + } + } + +} diff --git a/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/ExtractHeaderData.java b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/ExtractHeaderData.java new file mode 100644 index 0000000000000000000000000000000000000000..abb1d7b272a112ca9f14b0a6d1ce6dbc37b24040 --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/ExtractHeaderData.java @@ -0,0 +1,110 @@ +/* + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2005 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer(s): Brice Ruzand + * + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ +package emb.sample.servlet; + +import java.io.IOException; + +import javax.emb.MediaEntityLocal; +import javax.emb.MediaHeader; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import emb.sample.session.MediaSampleSessionLocal; + +/** + * @author Brice Ruzand + */ +public class ExtractHeaderData extends BaseSampleServlet { + + /** + * serialVersionUID + */ + private static final long serialVersionUID = 3544675070548261174L; + + /** + * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, + * javax.servlet.http.HttpServletResponse) + * @inheritDoc + */ + public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + try { + MediaSampleSessionLocal session = getSession(request); + + // Query the media entity EJB instance. + String identity = request.getParameter("identity"); + MediaEntityLocal mediaEntity = session.getMediaFromPrimaryKey(identity); + + MediaHeader header = mediaEntity.getHeader(); + String[] fieldNames = header.getFieldNames(); + + StringPrinter newMenuBox = new StringPrinter(); + StringPrinter workspaceContent = new StringPrinter(); + + newMenuBox.println("
    \r\n" + "

    Media

    \r\n"); + // add info + displayInfo(newMenuBox, mediaEntity); + + workspaceContent.println("

    Header information for Media: " + mediaEntity.getName() + "

    \n"); + workspaceContent.println(""); + workspaceContent.println(""); + workspaceContent.println(""); + + if (fieldNames.length == 0) { + workspaceContent + .println("\n"); + } else { + + for (int index = 0; index < fieldNames.length; index++) { + String fieldName = fieldNames[index]; + String fieldContent = "null"; + if (header.getField(fieldNames[index]) != null) { + header.getField(fieldNames[index]).toString(); + } + workspaceContent.println("\n"); + } + } + workspaceContent.println(""); + workspaceContent.println("
    Header tag nameValue
    There is no specific header for this media
    "); + workspaceContent.println(fieldName); + workspaceContent.println(""); + workspaceContent.println(fieldContent); + workspaceContent.println("
    \n"); + + newMenuBox.println("
    "); + + request.setAttribute("newMenuBox", newMenuBox); + request.setAttribute("workspaceContent", workspaceContent); + getServletConfig().getServletContext().getRequestDispatcher(TEMPLATE_JSP).forward(request, + response); + + } catch (Throwable e) { + exceptionHandler(e, getClass(), request, response); + } + } + +} diff --git a/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/HomeSample.java b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/HomeSample.java new file mode 100644 index 0000000000000000000000000000000000000000..872386088751aad07c4270bf08cbbd6231536691 --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/HomeSample.java @@ -0,0 +1,85 @@ +/* + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2005 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer(s): Brice Ruzand + * + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ +package emb.sample.servlet; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import emb.sample.MediaSampleException; + +/** + * The Home of emb Sample + * + * @author Brice Ruzand + */ +public class HomeSample extends BaseSampleServlet { + + /** + * serialVersionUID + */ + private static final long serialVersionUID = -4450606249375127461L; + + /** + * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, + * javax.servlet.http.HttpServletResponse) + * @inheritDoc + */ + public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + try { + + try { + // init session + getSession(request); + } catch (MediaSampleException e) { + getSession(request); + } + + StringPrinter workspaceContent = new StringPrinter(); + + workspaceContent.println("

    Welcome to JOnAS Enterprise Media Beans Sample application

    "); + workspaceContent + .println("

    This application provide a small sample of Enterprise Media Beans use with JOnAS.

    "); + workspaceContent + .println("

    First you have to load media sample : Load

    "); + workspaceContent + .println("

    Then view the media list and work with it : Media list

    "); + workspaceContent + .println("

    Add your own media : Upload

    "); + + request.setAttribute("workspaceContent", workspaceContent); + getServletConfig().getServletContext().getRequestDispatcher(TEMPLATE_JSP).forward(request, + response); + + } catch (Throwable e) { + exceptionHandler(e, getClass(), request, response); + } + } + +} diff --git a/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/HttpSessionMgr.java b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/HttpSessionMgr.java new file mode 100644 index 0000000000000000000000000000000000000000..999ccf454d7a2bed8d08ac51ab2e415afde9eb16 --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/HttpSessionMgr.java @@ -0,0 +1,72 @@ +/* + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2005 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer(s): Brice Ruzand + * + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ +package emb.sample.servlet; + +import javax.ejb.RemoveException; +import javax.servlet.http.HttpSessionEvent; +import javax.servlet.http.HttpSessionListener; + +import emb.sample.session.MediaSampleSessionLocal; + +/** + * The session manager to destroy used media + */ +public class HttpSessionMgr implements HttpSessionListener { + + /** + * @see javax.servlet.http.HttpSessionListener#sessionCreated(javax.servlet.http.HttpSessionEvent) + * @inheritDoc + */ + public void sessionCreated(HttpSessionEvent se) { + // do nothing + } + + /** + * Remove all media created during this session + * + * @see javax.servlet.http.HttpSessionListener#sessionDestroyed(javax.servlet.http.HttpSessionEvent) + * @inheritDoc + */ + public void sessionDestroyed(HttpSessionEvent se) { + + // get session bean + MediaSampleSessionLocal sessionBean = (MediaSampleSessionLocal) se.getSession().getAttribute("sessionBean"); + + if (sessionBean != null) { + try { + + // the session bean + sessionBean.remove(); + + } catch (RemoveException e) { + // do nothing + } + se.getSession().setAttribute("sessionBean", null); + } + + } +} diff --git a/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/ListSampleMedia.java b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/ListSampleMedia.java new file mode 100644 index 0000000000000000000000000000000000000000..6109a75160e14c655fa472a40972d6819016c296 --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/ListSampleMedia.java @@ -0,0 +1,118 @@ +/* + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2005 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer(s): Brice Ruzand + * + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ +package emb.sample.servlet; + +import java.io.IOException; +import java.net.URL; + +import javax.emb.FormatNotFoundException; +import javax.emb.MediaEntityLocal; +import javax.emb.MediaEntityLocalHome; +import javax.emb.MediaFormatRegistry; +import javax.emb.ProtocolConstraints; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import emb.sample.session.MediaSampleSessionLocal; + +/** + * @version 1.0 + * @author + */ +public class ListSampleMedia extends BaseSampleServlet { + + /** + * serialVersionUID + */ + private static final long serialVersionUID = 3257289140767830576L; + + /** + * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, + * javax.servlet.http.HttpServletResponse) + * @inheritDoc + */ + public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + try { + + MediaSampleSessionLocal session = getSession(request); + + MediaEntityLocal[] medias = session.getMediaList(); + + if (medias.length > 0) { + try { + MediaFormatRegistry.SINGLETON.lookup("svg"); + request.setAttribute("drawConversion", Boolean.TRUE); + } catch (FormatNotFoundException e) { + request.setAttribute("drawConversion", Boolean.FALSE); + } + + try { + MediaFormatRegistry.SINGLETON.lookup("ts"); + request.setAttribute("videoConversion", Boolean.TRUE); + } catch (FormatNotFoundException e) { + request.setAttribute("videoConversion", Boolean.FALSE); + } + + String[] proxiesUrl = new String[medias.length]; + for (int i = 0; i < medias.length; i++) { + URL url = null; + try { + url = getMebHome().publishContent(medias[i].getProxy(), + MediaEntityLocalHome.TRANSFER_TYPE_STREAM, new ProtocolConstraints()); + } catch (Throwable e) { + // do nothing + } + + proxiesUrl[i] = ""; + if (url != null) { + proxiesUrl[i] = url.toExternalForm(); + } + } + + request.setAttribute("samplesMedia", medias); + request.setAttribute("proxiesUrl", proxiesUrl); + this.getServletContext().getRequestDispatcher("/jsps/mediaList.jsp").forward(request, response); + + } else { + + StringPrinter workspaceContent = new StringPrinter(); + + // message + workspaceContent.println("

    No Sample Media has been initialized.

    "); + + request.setAttribute("workspaceContent", workspaceContent); + getServletConfig().getServletContext().getRequestDispatcher(TEMPLATE_JSP).forward(request, response); + + } + + } catch (Throwable e) { + exceptionHandler(e, getClass(), request, response); + } + + } +} diff --git a/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/LoadSampleMedia.java b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/LoadSampleMedia.java new file mode 100644 index 0000000000000000000000000000000000000000..280840f851091cde4ee0ca5e34b55899d2cab44d --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/LoadSampleMedia.java @@ -0,0 +1,220 @@ +/* + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2005 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer(s): Brice Ruzand + * + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ +package emb.sample.servlet; + +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintWriter; +import java.util.Collections; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Properties; + +import javax.emb.MediaEntityLocal; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import emb.sample.MediaSampleException; +import emb.sample.session.MediaSampleSessionLocal; + +/** + * This servlet is intent to control requests to loading the sample media to the + * database. + */ +public class LoadSampleMedia extends BaseSampleServlet { + + /** + * serialVersionUID + */ + private static final long serialVersionUID = 3256441391566698802L; + + /** + * default dir where sample are stored + */ + private static final String SAMPLES_DIR = "/samples/"; + + /** + * The sample info file + */ + private static final String SAMPLES_PROPERTIES = "samples.properties"; + + /** + * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, + * javax.servlet.http.HttpServletResponse) + * @inheritDoc + */ + public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + response.setContentType("text/html;charset=ISO-8859-1"); + + getServletConfig().getServletContext().getRequestDispatcher("/jsps/header.jsp").include(request, response); + + PrintWriter out = response.getWriter(); + out.println("

    Initializing Sample DataBase

    "); + + // Create Samples in DB + try { + + MediaSampleSessionLocal session = getSession(request); + + // get all MEB stored with the same Partial Desc + if (session.getMediaList().length > 0) { + out.println("

    Samples already loaded... -> removing default Media

    "); + session.removeDefaultMedia(); + out.flush(); + } + + out.println("

    Adding new Samples to the DataBase...

    "); + out.println("
      "); + out.flush(); + + // get the properties stream + InputStream propStream = getServletContext().getResourceAsStream(SAMPLES_DIR + SAMPLES_PROPERTIES); + + if (propStream != null) { + try { + + // new properties + Properties prop = new Properties(); + + // load properties from stream + prop.load(propStream); + + List sortList = new LinkedList(prop.keySet()); + + Collections.sort(sortList); + + for (Iterator i = sortList.iterator(); i.hasNext();) { + + // Get class name and file extension + String sampleNameWSuffix = (String) i.next(); + + if (sampleNameWSuffix.endsWith(".file")) { + String sampleName = getPrefixFileName(sampleNameWSuffix); + + String sampleFile = prop.getProperty(sampleName + ".file"); + String sampleDesc = prop.getProperty(sampleName + ".desc"); + String sampleShowS = prop.getProperty(sampleName + ".show"); + boolean sampleShow = Boolean.valueOf(sampleShowS).booleanValue(); + + byte status = MediaSampleSessionLocal.DONT_SHOW; + if (sampleShow) { + status = MediaSampleSessionLocal.SHOW_IN_LIST; + } + + createNewSample(session, out, sampleFile, sampleDesc, getServletContext() + .getResourceAsStream(SAMPLES_DIR + sampleFile), sampleName, status); + + } + } + + } catch (IOException e) { + // error while loading properties + new MediaSampleException("Unable to load sample properties due to : " + e.getLocalizedMessage(), e); + } + } else { + // error while open properties stream + new MediaSampleException("Unable to load sample properties due to : " + SAMPLES_PROPERTIES + + " has no been found"); + } + + out.println("
    "); + out.println("

    Media loaded.

    "); + + getServletConfig().getServletContext().getRequestDispatcher("/jsps/footer.jsp").include(request, response); + + } catch (Throwable e) { + exceptionHandler(e, getClass(), request, response); + } + + } + + /** + * Create a MEB sample with given param + * + * @param session the session which control medi creation + * @param out out writer + * @param name name of the MEB + * @param description description desc of the MEB + * @param contentStream contentStream content of the EMB + * @param registeredName the name to access to it + * @param status status is ones of {@link MediaSampleSessionLocal#DONT_SHOW}, + * {@link MediaSampleSessionLocal#SHOW_IN_LIST}, + * {@link MediaSampleSessionLocal#USER_ADDED} + * @return the media entity + */ + private MediaEntityLocal createNewSample(MediaSampleSessionLocal session, PrintWriter out, String name, + String description, InputStream contentStream, String registeredName, byte status) { + // Create MEB sample + out.println("
  • "); + MediaEntityLocal meb = null; + try { + + meb = session.createMediaEntity(contentStream, name, description, status, registeredName); + + out.println(name); + + } catch (Throwable e) { + + try { + if (meb != null) { + meb.remove(); + } + } catch (Throwable e1) { + // do nothing + } + + meb = null; + + String err = "Error while creating sample \"" + name + "\" : " + e.getLocalizedMessage(); + out.println("" + err + ""); + // System.err.println("LoadSampleMedia : " + err); + // e.printStackTrace(); + } + out.println("
  • "); + out.flush(); + return meb; + } + + /** + * Get name of a file name without extension + * + * @param name name of the file + * @return file name without extension + */ + public static String getPrefixFileName(String name) { + int lastDotPosition = name.lastIndexOf('.'); + + if (lastDotPosition == -1) { + return name; + } + return name.substring(0, lastDotPosition); + + } +} diff --git a/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/RetrieveSampleMedia.java b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/RetrieveSampleMedia.java new file mode 100644 index 0000000000000000000000000000000000000000..8b3b4c6a6d1b88463e72960f270592cd7569e6ba --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/RetrieveSampleMedia.java @@ -0,0 +1,124 @@ +/* + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2005 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer(s): Brice Ruzand + * + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ +package emb.sample.servlet; + +import java.net.URL; + +import javax.emb.MediaEntityLocal; +import javax.emb.MediaEntityLocalHome; +import javax.emb.MediaFormatRegistry; +import javax.emb.ProtocolConstraints; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.objectweb.jonas.emb.mfb.formats.image.ImageMediaFormat; + +import emb.sample.session.MediaSampleSessionLocal; + +/** + * Generate an HTML web page to present the media + * + * @author Brice Ruzand + */ +public class RetrieveSampleMedia extends BaseSampleServlet { + + /** + * serialVersionUID + */ + private static final long serialVersionUID = 3762250859580634161L; + + /** + * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, + * javax.servlet.http.HttpServletResponse) + * @inheritDoc + */ + public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException { + try { + + // Query the media entity EJB instance. + String identity = (String) request.getAttribute("identity"); + if (identity == null) { + identity = request.getParameter("identity"); + } + + MediaSampleSessionLocal session = getSession(request); + + // Query the media entity EJB instance. + MediaEntityLocal mediaEntity = session.getMediaFromPrimaryKey(identity); + + // publish it + URL url = null; + + if (mediaEntity.getFormat().equals(MediaFormatRegistry.SINGLETON.lookup("mp4"))) { + url = getMebHome().publishContent(mediaEntity, MediaEntityLocalHome.TRANSFER_TYPE_STREAM, + new ProtocolConstraints()); + } else { + url = getMebHome().publishContent(mediaEntity, MediaEntityLocalHome.TRANSFER_TYPE_BURST, + new ProtocolConstraints()); + } + + StringPrinter newMenuBox = new StringPrinter(); + StringPrinter workspaceContent = new StringPrinter(); + + newMenuBox.println("
    \r\n" + "

    Media

    \r\n"); + + workspaceContent.println("

    Media content : " + mediaEntity.getName() + "

    "); + + workspaceContent.println(" URL : " + url + "
    "); + + if (mediaEntity.getFormat() instanceof ImageMediaFormat) { + newMenuBox.println("

    Image

    "); + workspaceContent.println("
    \""
    "); + } else { + newMenuBox.println("

    Standard Object

    "); + workspaceContent.println("
    " + + "Unfortunately your browser cannot display this media !!
    "); + } + + // add info in menu + displayInfo(newMenuBox, mediaEntity); + + newMenuBox + .println("If your browser can not display this media, please select the link below for accessing the media.... "); + newMenuBox.println("" + mediaEntity.getName() + ""); + + newMenuBox.println("
    "); + + request.setAttribute("newMenuBox", newMenuBox); + request.setAttribute("workspaceContent", workspaceContent); + getServletConfig().getServletContext().getRequestDispatcher(TEMPLATE_JSP).forward(request, response); + + } catch (Throwable e) { + exceptionHandler(e, getClass(), request, response); + } + } + +} diff --git a/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/UploadSampleMedia.java b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/UploadSampleMedia.java new file mode 100644 index 0000000000000000000000000000000000000000..9cdc4ea731230e5667c1f36e2478092c1a8d7e2d --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/servlet/UploadSampleMedia.java @@ -0,0 +1,160 @@ +/* + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2005 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer(s): Brice Ruzand + * + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ +package emb.sample.servlet; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.Iterator; +import java.util.List; + +import javax.emb.GenericMediaFormat; +import javax.emb.MediaEntityLocal; +import javax.emb.MediaFormat; +import javax.emb.MediaFormatRegistry; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.fileupload.DiskFileUpload; +import org.apache.commons.fileupload.FileItem; + +import emb.sample.session.MediaSampleSessionLocal; + +/** + * Generate an HTML web page to present the media + * + * @author Brice Ruzand + */ +public class UploadSampleMedia extends BaseSampleServlet { + + /** + * serialVersionUID + */ + private static final long serialVersionUID = 3762250859580634161L; + + /** + * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, + * javax.servlet.http.HttpServletResponse) + * @inheritDoc + */ + public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + try { + + response.setContentType("text/html;charset=ISO-8859-1"); + + StringPrinter fromatSupported = new StringPrinter(); + fromatSupported.println("
      "); + for (Iterator i = MediaFormatRegistry.SINGLETON.getFileExtensions(); i.hasNext();) { + String fileExt = (String) i.next(); + MediaFormat format = MediaFormatRegistry.SINGLETON.lookup(fileExt); + if (!(format == null || format instanceof GenericMediaFormat)) { + fromatSupported.println("
    • " + fileExt + " : " + MediaFormatRegistry.SINGLETON.lookup(fileExt) + + "
    • "); + } + } + fromatSupported.println("
    "); + + request.setAttribute("fromatSupported", fromatSupported); + getServletConfig().getServletContext().getRequestDispatcher("/jsps/uploadForm.jsp").include(request, response); + + } catch (Throwable e) { + exceptionHandler(e, getClass(), request, response); + } + } + + /** + * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, + * javax.servlet.http.HttpServletResponse) + * @inheritDoc + */ + public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + try { + + String mediaDesc = ""; + String mediaName = ""; + String mediaUrl = ""; + InputStream mediaInputStream = null; + + // Create a new file upload handler + DiskFileUpload upload = new DiskFileUpload(); + + // Parse the request + List /* FileItem */items = upload.parseRequest(request); + + // Process the uploaded items + Iterator iter = items.iterator(); + while (iter.hasNext()) { + FileItem item = (FileItem) iter.next(); + if (item.isFormField()) { + if (item.getFieldName().equals("desc")) { + mediaDesc = item.getString(); + } + if (item.getFieldName().equals("url")) { + mediaUrl = item.getString(); + } + } else { + if (item.getFieldName().equals("file")) { + mediaInputStream = item.getInputStream(); + mediaName = item.getName(); + } + } + } + + MediaSampleSessionLocal session = getSession(request); + + MediaEntityLocal meb = null; + if (mediaUrl != null && mediaUrl.length() > 0) { + // meb = createNewSample(mediaUrl, mediaDesc); + meb = session.createMediaEntity(new URL(mediaUrl), mediaDesc, MediaSampleSessionLocal.USER_ADDED); + } else if (mediaInputStream != null && mediaName != null && mediaName.length() > 0) { + meb = session.createMediaEntity(mediaInputStream, mediaName, mediaDesc, + MediaSampleSessionLocal.USER_ADDED, null); + } + + if (meb != null) { + + // forward onto the retrieve servlet + request.setAttribute("identity", meb.getPrimaryKey()); + this.getServletContext().getRequestDispatcher(RETRIEVE_SERVLET).forward(request, response); + + } else { + + StringPrinter workspaceContent = new StringPrinter(); + workspaceContent.println("

    Missing information to add media

    "); + workspaceContent.println("There were some missing information to add media, please retry."); + request.setAttribute("workspaceContent", workspaceContent); + this.getServletContext().getRequestDispatcher(TEMPLATE_JSP).forward(request, response); + + } + + } catch (Throwable e) { + exceptionHandler(e, getClass(), request, response); + } + } + +} diff --git a/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/session/HttpSessionMgr.java b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/session/HttpSessionMgr.java new file mode 100644 index 0000000000000000000000000000000000000000..34e4bb0f90c7068f8b6baf5e574a8abd309df68f --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/session/HttpSessionMgr.java @@ -0,0 +1,70 @@ +/* + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2005 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer(s): Brice Ruzand + * + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ +package emb.sample.session; + +import javax.ejb.RemoveException; +import javax.servlet.http.HttpSessionEvent; +import javax.servlet.http.HttpSessionListener; + +/** + * The session manager to destroy used media + */ +public class HttpSessionMgr implements HttpSessionListener { + + /** + * @see javax.servlet.http.HttpSessionListener#sessionCreated(javax.servlet.http.HttpSessionEvent) + * @inheritDoc + */ + public void sessionCreated(HttpSessionEvent se) { + // do nothing + } + + /** + * Remove all media created during this session + * + * @see javax.servlet.http.HttpSessionListener#sessionDestroyed(javax.servlet.http.HttpSessionEvent) + * @inheritDoc + */ + public void sessionDestroyed(HttpSessionEvent se) { + + // get session bean + MediaSampleSessionLocal sessionBean = (MediaSampleSessionLocal) se.getSession().getAttribute("sessionBean"); + + if (sessionBean != null) { + try { + + // the session bean + sessionBean.remove(); + + } catch (RemoveException e) { + // do nothing + } + se.getSession().setAttribute("sessionBean", null); + } + + } +} diff --git a/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/session/MediaSampleSessionBean.java b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/session/MediaSampleSessionBean.java new file mode 100644 index 0000000000000000000000000000000000000000..5e924b6993e87cfb1798a2c6cc873ebd7ca896ad --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/session/MediaSampleSessionBean.java @@ -0,0 +1,586 @@ +/* + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2005 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer(s): Brice Ruzand + * + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ + +package emb.sample.session; + +import java.io.InputStream; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import javax.ejb.FinderException; +import javax.ejb.RemoveException; +import javax.ejb.SessionBean; +import javax.ejb.SessionContext; +import javax.emb.Media; +import javax.emb.MediaEntityLocal; +import javax.emb.MediaEntityLocalHome; +import javax.emb.MediaException; +import javax.naming.InitialContext; +import javax.naming.NamingException; + +import emb.sample.MediaSampleException; + +/** + * This is an example of Session Bean, statefull, and synchronized. + * + * @author JOnAS team + */ +public class MediaSampleSessionBean implements SessionBean { + + /** + * serialVersionUID + */ + private static final long serialVersionUID = 2549701184925498878L; + + // ======================================================================= + // Refs + // ======================================================================= + + /** + * Media Enotity Bean Home reference + */ + private static final String MEB_HOME_REF = "java:comp/env/ejb/emb/MediaEntity"; + + /** + * Reference on the env entry isCopyAllowed + */ + public static final String IS_COPY_ALLOWED_REF = "java:comp/env/ejb/embSample/isCopyAllowed"; + + /** + * Reference on the env entry maxMediaPerSession + */ + public static final String MAX_MEDIA_PER_SESSION_REF = "java:comp/env/ejb/embSample/maxMediaPerSession"; + + // ======================================================================= + // Fields + // ======================================================================= + + /** + * cache of the env value + */ + private Boolean isCopyAllowed = null; + + /** + * cache of the env value + */ + private Integer maxMediaPerSession = null; + + /** + * list containing primary key of all generated media, use to remove them + */ + private final List mediaListAllCreated = new LinkedList(); + + /** + * list containing primary key of all media standart media that are beeing + * showed + */ + private final List mediaListStdShow = new LinkedList(); + + /** + * list containing primary key of all that have been upload by user + */ + private final List mediaListUpload = new LinkedList(); + + /** + * Map containing name and primary key of some media + */ + private final Map mediaRegistredName = new HashMap(); + + // ======================================================================= + // Medthods + // ======================================================================= + + /** + * There must be one ejbCreate() method per create() method on the Home + * interface, and with the same signature. + */ + public void ejbCreate() { + + // in case we are outside transactions + } + + /** + * Create a new MediaEntity from a stream + * + * @param contentStream content of the MediaEntity + * @param name name of the MediaEntity + * @param description description of the MediaEntity + * @param status is ones of {@link MediaSampleSessionLocal#DONT_SHOW}, + * {@link MediaSampleSessionLocal#SHOW_IN_LIST}, + * {@link MediaSampleSessionLocal#USER_ADDED} + * @param registeredName name to acces it with + * {@link #getMediaFromRegistredName(String)} + * @return MediaEntity + * @throws MediaSampleException if the mediaEntity cannot be create + */ +public MediaEntityLocal createMediaEntity(InputStream contentStream, String name, String description, byte status, + String registeredName) throws MediaSampleException { + + // check maxmedia + checkMaxMedia(); + + MediaEntityLocal meb = null; + try { + + meb = getMebHome().create(); + meb.setName(name); + + if (!meb.getFormat().isEmbedded()) { + throw new MediaSampleException("A not embedded media have to be imported and not upload in order to import its children too."); + } + + meb.setContent(contentStream); + meb.setDescription(description); + + + + try { + // publish proxy + Media proxy = meb.getProxy(); + getMebHome().publishContent(proxy, MediaEntityLocalHome.TRANSFER_TYPE_BURST, null); + } catch (MediaException e) { + // do nothing + } + + // store the key + addMedia(meb, status); + + if (registeredName != null) { + mediaRegistredName.put(registeredName, meb.getPrimaryKey()); + } + + return meb; + + } catch (Exception e) { + if (meb != null) { + try { + meb.remove(); + } catch (Throwable e1) { + // do nothing + } + } + throw new MediaSampleException("Unable to create Media : " + name + " : " + e, e); + } + } + /** + * Create a new MediaEntity from an URL + * + * @param urlToImport of the media to import + * @param description description of the MediaEntity + * @param status is ones of {@link MediaSampleSessionLocal#DONT_SHOW}, + * {@link MediaSampleSessionLocal#SHOW_IN_LIST}, + * {@link MediaSampleSessionLocal#USER_ADDED} + * @return MediaEntity + * @throws MediaSampleException if the mediaEntity cannot be create + */ + public MediaEntityLocal createMediaEntity(URL urlToImport, String description, byte status) + throws MediaSampleException { + + // check maxmedia + checkMaxMedia(); + + MediaEntityLocal meb = null; + try { + + MediaEntityLocal[] mebs = getMebHome().importMedia(new URL[] {urlToImport}, null); + + if (mebs.length > 0 && mebs[0] != null) { + + meb = mebs[0]; + meb.setDescription(description); + + try { + // publish proxy + Media proxy = meb.getProxy(); + getMebHome().publishContent(proxy, MediaEntityLocalHome.TRANSFER_TYPE_BURST, null); + } catch (MediaException e) { + // do nothing + } + + // store the key + addMedia(meb, status); + + return meb; + } + throw new MediaSampleException("Unable to import the media"); + } catch (Exception e) { + if (meb != null) { + // totdo use super remover + try { + meb.remove(); + } catch (Throwable e1) { + // do nothing + } + } + throw new MediaSampleException("Unable to import Media : " + urlToImport + " : " + e, e); + } + } + + /** + * Create a new MediaEntity from a Media + * + * @param media to copy + * @return MediaEntity + * @throws MediaSampleException if the mediaEntity cannot be create + */ + public MediaEntityLocal copyMediaEntity(Media media) throws MediaSampleException { + + if (!getCopyAllowed() && media instanceof MediaEntityLocal) { + return (MediaEntityLocal) media; + } + + // check maxmedia + checkMaxMedia(); + + try { + + MediaEntityLocal meb = getMebHome().create(); + + // store the key + addMedia(meb, MediaSampleSessionLocal.DONT_SHOW); + + meb.setName(media.getName()); + meb.setContent(media.getContent()); + meb.setMimeType(media.getMimeType()); + meb.setChildren(meb.getChildren()); + + return meb; + + } catch (Exception e) { + throw new MediaSampleException("Unable to copy Media", e); + } + } + + /** + * Get media list (only status {@link MediaSampleSessionLocal#SHOW_IN_LIST}, + * {@link MediaSampleSessionLocal#USER_ADDED} + * + * @return MediaEntity array + * @throws MediaSampleException if media cannot be retrive + */ + + public MediaEntityLocal[] getMediaList() throws MediaSampleException { + + try { + List mebs = new ArrayList(mediaListUpload.size() + mediaListStdShow.size()); + for (Iterator i = mediaListUpload.iterator(); i.hasNext();) { + String primaryKey = (String) i.next(); + try { + MediaEntityLocal meb = getMebHome().findByPrimaryKey(primaryKey); + mebs.add(meb); + } catch (FinderException e) { + // do nothing + } + } + for (Iterator i = mediaListStdShow.iterator(); i.hasNext();) { + String primaryKey = (String) i.next(); + try { + MediaEntityLocal meb = getMebHome().findByPrimaryKey(primaryKey); + mebs.add(meb); + } catch (FinderException e) { + // do nothing + } + } + + return (MediaEntityLocal[]) mebs.toArray(new MediaEntityLocal[mebs.size()]); + + } catch (NamingException e) { + throw new MediaSampleException("Unable to get MediaList due to " + e, e); + } + + } + + /** + * Get media from its premary key + * + * @param primaryKey the primary key of the wanted media + * @return MediaEntity + * @throws MediaSampleException if the mediaEntity cannot be retrive + */ + public MediaEntityLocal getMediaFromPrimaryKey(String primaryKey) throws MediaSampleException { + try { + MediaEntityLocal meb = getMebHome().findByPrimaryKey(primaryKey); + return meb; + } catch (FinderException e) { + throw new MediaSampleException("Media with this primary key does not exist : " + primaryKey, e); + } catch (NamingException e) { + throw new MediaSampleException("Unable to get Media due to " + e, e); + } + } + + /** + * Get media from registered name + * + * @param registeredName the registeredName of the wanted media + * @return MediaEntity + * @throws MediaSampleException if the mediaEntity cannot be retrive + */ + public MediaEntityLocal getMediaFromRegistredName(String registeredName) throws MediaSampleException { + + String primaryKey = (String) mediaRegistredName.get(registeredName); + if (primaryKey != null) { + return getMediaFromPrimaryKey(primaryKey); + } + throw new MediaSampleException("unable to find Media with registered name : " + registeredName); + + } + + /** + * Remove default media to reinit the database, except uploaded media + */ + public void removeDefaultMedia() { + + // copy the primary list + String[] primaryKeyToRemove = (String[]) mediaListAllCreated.toArray(new String[mediaListAllCreated.size()]); + + // remove al creating media during this session + for (int i = 0; i < primaryKeyToRemove.length; i++) { + + if (!mediaListUpload.contains(primaryKeyToRemove[i])) { + + try { + MediaEntityLocal meb = getMediaFromPrimaryKey(primaryKeyToRemove[i]); + removeMedia(meb); + } catch (MediaSampleException e) { + // do nothing + } + } + } + } + + // ======================================================================= + // Internals + // ======================================================================= + + /** + * Add meb to the right list + * + * @param meb the media to add + * @param status where the medi is added, is ones of {@link #DONT_SHOW}, + * {@link #SHOW_IN_LIST}, {@link #USER_ADDED} + */ + private synchronized void addMedia(MediaEntityLocal meb, byte status) { + + mediaListAllCreated.add(meb.getPrimaryKey()); + if (status == MediaSampleSessionLocal.SHOW_IN_LIST) { + mediaListStdShow.add(meb.getPrimaryKey()); + } else if (status == MediaSampleSessionLocal.USER_ADDED) { + mediaListUpload.add(meb.getPrimaryKey()); + } + + } + + /** + * Remove media from all media list + * + * @param meb the media to add + */ + private synchronized void removeMedia(MediaEntityLocal meb) { + + recusiveRemoveMedia(meb); + + mediaListAllCreated.remove(meb.getPrimaryKey()); + mediaListStdShow.remove(meb.getPrimaryKey()); + mediaListUpload.remove(meb.getPrimaryKey()); + + } + + /** + * Remove recurcively all preview version and children + * + * @param meb the media entity bean + */ + private void recusiveRemoveMedia(MediaEntityLocal meb) { + if (meb != null) { + + // recurcive call for children + + MediaEntityLocal[] children = meb.getChildren(); + for (int i = 0; i < children.length; i++) { + recusiveRemoveMedia(children[i]); + } + + // recurcive call for preview version + recusiveRemoveMedia(meb.getPreviousVersion()); + + try { + meb.remove(); + } catch (RemoveException e) { + // do nothing + } + } + } + + /** + * Get the iscopy allow + * + * @return if copy is allow + */ + private boolean getCopyAllowed() { + + Boolean cache = isCopyAllowed; + + if (cache == null) { + try { + cache = (Boolean) (new InitialContext()).lookup(IS_COPY_ALLOWED_REF); + isCopyAllowed = cache; + + } catch (NamingException e) { + return true; + } + } + return cache.booleanValue(); + } + + /** + * Get MaxMediaPerSession + * + * @return maxmedia per session + */ + private int getMaxMediaPerSession() { + + Integer cache = maxMediaPerSession; + + if (cache == null) { + try { + cache = (Integer) (new InitialContext()).lookup(MAX_MEDIA_PER_SESSION_REF); + maxMediaPerSession = cache; + + } catch (NamingException e) { + return 0; + } + } + return cache.intValue(); + } + + /** + * test if MaxMediaPerSession has been reach + * + * @throws MediaSampleException if MaxMediaPerSession has been reach + */ + private void checkMaxMedia() throws MediaSampleException { + + if (!(getMaxMediaPerSession() == 0)) { + if (mediaListAllCreated.size() >= getMaxMediaPerSession() - 1) { + throw new MediaSampleException( + "You have reach the maximum number per session. You cannot create more media."); + } + } + + } + + // ======================================================================= + // TOOLS + // ======================================================================= + + /** + * cached Home + */ + private MediaEntityLocalHome mebHome = null; + + /** + * Provide a cached Home access + * + * @return MediaEntityLocalHome + * @throws NamingException in case MediaEntityLocalHome is not found + */ + private MediaEntityLocalHome getMebHome() throws NamingException { + if (mebHome == null) { + mebHome = (MediaEntityLocalHome) new InitialContext().lookup(MEB_HOME_REF); + } + return mebHome; + } + + // ======================================================================= + // EJB contract + // ======================================================================= + + /** + * Session Context + */ + private SessionContext mySessionCtx; + + /** + * getSessionContext + * + * @return SessionContext + */ + public SessionContext getSessionContext() { + return mySessionCtx; + } + + /** + * @see javax.ejb.SessionBean#setSessionContext(javax.ejb.SessionContext) + * @inheritDoc + */ + public void setSessionContext(SessionContext ctx) { + mySessionCtx = ctx; + } + + /** + * @see javax.ejb.SessionBean#ejbActivate() + * @inheritDoc + */ + public void ejbActivate() { + // do nothing + } + + /** + * @see javax.ejb.SessionBean#ejbPassivate() + * @inheritDoc + */ + public void ejbPassivate() { + // do nothing + } + + /** + * @see javax.ejb.SessionBean#ejbRemove() + * @inheritDoc + */ + public void ejbRemove() { + + // copy the primary list + String[] primaryKeyToRemove = (String[]) mediaListAllCreated.toArray(new String[mediaListAllCreated.size()]); + + // remove al creating media during this session + for (int i = 0; i < primaryKeyToRemove.length; i++) { + try { + MediaEntityLocal meb = getMediaFromPrimaryKey(primaryKeyToRemove[i]); + removeMedia(meb); + } catch (MediaSampleException e) { + // do nothing + } + } + + } + +} \ No newline at end of file diff --git a/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/session/MediaSampleSessionLocal.java b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/session/MediaSampleSessionLocal.java new file mode 100644 index 0000000000000000000000000000000000000000..3c6b96ee08f0479b891022fcfea6ed6ee5c0c2a3 --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/session/MediaSampleSessionLocal.java @@ -0,0 +1,132 @@ +/* + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2004 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer(s): ____________________________________. + * Contributor(s): ______________________________________. + * + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ + +package emb.sample.session; + +import java.io.InputStream; +import java.net.URL; + +import javax.ejb.EJBLocalObject; +import javax.emb.Media; +import javax.emb.MediaEntityLocal; + +import emb.sample.MediaSampleException; + +/** + * Local interface for the bean MediaSampleSessionLocal + */ +public interface MediaSampleSessionLocal extends EJBLocalObject { + + /** + * Set if the media has to be show in media list + */ + byte SHOW_IN_LIST = 0; + + /** + * Set if the media has to be show in media list and if the media has been + * upload + */ + byte USER_ADDED = 1; + + /** + * Set if the media is not showed is media list + */ + byte DONT_SHOW = -1; + + /** + * Create a new MediaEntity from a stream + * + * @param contentStream content of the MediaEntity + * @param name name of the MediaEntity + * @param description description of the MediaEntity + * @param status is ones of {@link MediaSampleSessionLocal#DONT_SHOW}, + * {@link MediaSampleSessionLocal#SHOW_IN_LIST}, + * {@link MediaSampleSessionLocal#USER_ADDED} + * @param registeredName name to acces it with + * {@link #getMediaFromRegistredName(String)} + * @return MediaEntity + * @throws MediaSampleException if the mediaEntity cannot be create + */ + MediaEntityLocal createMediaEntity(InputStream contentStream, String name, String description, byte status, + String registeredName) throws MediaSampleException; + + /** + * Create a new MediaEntity from an URL + * + * @param urlToImport of the media to import + * @param description description of the MediaEntity + * @param status is ones of {@link MediaSampleSessionLocal#DONT_SHOW}, + * {@link MediaSampleSessionLocal#SHOW_IN_LIST}, + * {@link MediaSampleSessionLocal#USER_ADDED} + * @return MediaEntity + * @throws MediaSampleException if the mediaEntity cannot be create + */ + MediaEntityLocal createMediaEntity(URL urlToImport, String description, byte status) throws MediaSampleException; + + /** + * Create a new MediaEntity from a Media + * + * @param media to copy + * @return MediaEntity + * @throws MediaSampleException if the mediaEntity cannot be create + */ + MediaEntityLocal copyMediaEntity(Media media) throws MediaSampleException; + + /** + * Get media list (only status {@link MediaSampleSessionLocal#SHOW_IN_LIST}, + * {@link MediaSampleSessionLocal#USER_ADDED} + * + * @return MediaEntity array + * @throws MediaSampleException if media cannot be retrive + */ + + MediaEntityLocal[] getMediaList() throws MediaSampleException; + + /** + * Get media from its premary key + * + * @param primaryKey the primary key of the wanted media + * @return MediaEntity + * @throws MediaSampleException if the mediaEntity cannot be retrive + */ + MediaEntityLocal getMediaFromPrimaryKey(String primaryKey) throws MediaSampleException; + + /** + * Get media from registered name + * + * @param registeredName the registeredName of the wanted media + * @return MediaEntity + * @throws MediaSampleException if the mediaEntity cannot be retrive + */ + MediaEntityLocal getMediaFromRegistredName(String registeredName) throws MediaSampleException; + + /** + * Remove default media to reinit the database, except uploaded media + */ + void removeDefaultMedia(); +} \ No newline at end of file diff --git a/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/session/MediaSampleSessionLocalHome.java b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/session/MediaSampleSessionLocalHome.java new file mode 100644 index 0000000000000000000000000000000000000000..009ccd0369f12864448248b7a8919ff1a2d696af --- /dev/null +++ b/jonas_4_10/jonas/examples/emb-sample/src/emb/sample/session/MediaSampleSessionLocalHome.java @@ -0,0 +1,48 @@ +/* + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999-2005 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Initial developer(s): Brice Ruzand + * + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ + +package emb.sample.session; + +import javax.ejb.CreateException; +import javax.ejb.EJBLocalHome; + +/** + * Home interface for the bean MediaSampleSessionLocal + * + * @author Brice Ruzand + */ +public interface MediaSampleSessionLocalHome extends EJBLocalHome { + + /** + * Create an instance of the MediaSampleSessionLocal bean. + * + * @return the Remote interface of the bean MediaSampleSessionLocal. + * @throws CreateException if the creation failed. + */ + MediaSampleSessionLocal create() throws CreateException; + +} \ No newline at end of file diff --git a/jonas/examples/fdf/MyJOnASCluster.fdf b/jonas_4_10/jonas/examples/fdf/MyJOnASCluster.fdf similarity index 100% rename from jonas/examples/fdf/MyJOnASCluster.fdf rename to jonas_4_10/jonas/examples/fdf/MyJOnASCluster.fdf diff --git a/jonas_4_10/jonas/examples/hibernate/README b/jonas_4_10/jonas/examples/hibernate/README new file mode 100644 index 0000000000000000000000000000000000000000..fcff212dab8b76a1ed17c9cb2c5302cb1e4f7f5d --- /dev/null +++ b/jonas_4_10/jonas/examples/hibernate/README @@ -0,0 +1,93 @@ +# --------------------------------------------------------------------------- +# JOnAS: Java(TM) Open Application Server +# Copyright (C) 2005 Bull S.A. +# Contact: jonas-team@objectweb.org +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +# USA +# +# --------------------------------------------------------------------------- +# $Id$ +# --------------------------------------------------------------------------- + +Example Overview +================ +This example is the one provided with Hibernate documentation : +http://www.hibernate.org/hib_docs/reference/en/html_single/ + +The JOnAS hibernate war has been made by Stéphane TRAUMAT +for the Sourcebeat book : JOnAS Live +( http://www.sourcebeat.com/TitleAction.do?id=9 ) + +The ant script provided will create the needed table, package +the application in a .war file and deploy it to $JONAS_BASE/webapps. + +Directories structure +===================== +There is three directories : + +- src : Contains the servlet and the Cat class. + +- etc : Contains all non-java resources +- etc/resources : Hibernate configuration files +- etc/sql : HSQL init/reset scripts +- etc/xml : Deployment descriptors + +- lib : Contains all the needed librairies for Hibernate. + They will be added in the war. + +Building and running this example +===================== +Take care to change the hsql.port properties (in build.properties) +if you do not use default one (9001) + +To make the CAT example works, the first thing is to create +a table CAT to store the data in the HSQLDB engine included +with JOnAS. + +note : The SQL to create the needed table will be executed +by the ant script. + +1) To start the database, we need to run JOnAS using the +"jonas start" command. + +2) Init the HSQL Database, type "ant initdb". + +3) Then, under the hibernate sample directory, type: "ant". + That will compile, package the webapp and place it + under $JONAS_BASE/webapps. + +4) And, to deploy the war on JOnAS, just type: +"jonas admin -a hibernate-sample.war" +You should see a message looking like : +2004-11-19 12:29:37,405 : AbsJWebContainerServiceImpl.registerWar : +War /C:/java/plateforme/JONAS/webapps/hibernate-sample.war available +at the context /hibernate-sample on the host . + +5) Connect to http://localhost:9000/hibernate-sample/testHibernate/ + +Connecting to HSQLdb +===================== +1) type "ant dbmanager" +Press enter and you should be able to see the CAT table. + +Notes +===================== +To develop this sample, we used +- JOnAS 4.4.2 +- Hibernate 3.0.5 +Because of some conflicts, we had to replace cglib-2.1.jar +with cglib-nodep-2.1_2.jar which is the same library without +the dependencies on ASM. \ No newline at end of file diff --git a/jonas_4_10/jonas/examples/hibernate/build.properties b/jonas_4_10/jonas/examples/hibernate/build.properties new file mode 100644 index 0000000000000000000000000000000000000000..7774106d5c29eccea04159bd50863c4a83a4ee3b --- /dev/null +++ b/jonas_4_10/jonas/examples/hibernate/build.properties @@ -0,0 +1,28 @@ +# --------------------------------------------------------------------------- +# JOnAS: Java(TM) Open Application Server +# Copyright (C) 2005 Bull S.A. +# Contact: jonas-team@objectweb.org +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +# USA +# +# --------------------------------------------------------------------------- +# $Id$ +# --------------------------------------------------------------------------- + +# default HSQL port is 9001 +hsql.port 9001 +# Default Server name +jonas.server.name jonas \ No newline at end of file diff --git a/jonas_4_10/jonas/examples/hibernate/build.xml b/jonas_4_10/jonas/examples/hibernate/build.xml new file mode 100644 index 0000000000000000000000000000000000000000..abc0a5e0d8b7d44353573b90535a467fe58cdeed --- /dev/null +++ b/jonas_4_10/jonas/examples/hibernate/build.xml @@ -0,0 +1,238 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +---------------------------------------------------------------------+ + | init | + +---------------------------------------------------------------------+ + + + + + + + + + + + + + + + + + +---------------------------------------------------------------------+ + | clean | + +---------------------------------------------------------------------+ + + + + + + + +---------------------------------------------------------------------+ + | resetdb | + +---------------------------------------------------------------------+ + + + + + + +---------------------------------------------------------------------+ + | initdb | + +---------------------------------------------------------------------+ + + + + + + + +---------------------------------------------------------------------+ + | Starting HSQL DataBase Manager | + +---------------------------------------------------------------------+ + + + + + + + + + + + + +---------------------------------------------------------------------+ + | compile - compile the servlet | + +---------------------------------------------------------------------+ + + + + + + + + +---------------------------------------------------------------------+ + | war - package the servlet and the .xml files | + +---------------------------------------------------------------------+ + + + + + + + + + + + + + + + + + + + + +---------------------------------------------------------------------+ + | install - copy the war to JOnAS | + +---------------------------------------------------------------------+ + + + + + + ${hib.webapp.name} has been copied to ${jonas.base}/webapps. + + + + + +---------------------------------------------------------------------+ + | deploy - Deploy the war into a running JOnAS instance | + +---------------------------------------------------------------------+ + + + + + + \ No newline at end of file diff --git a/jonas_4_10/jonas/examples/hibernate/etc/resources/Cat.hbm.xml b/jonas_4_10/jonas/examples/hibernate/etc/resources/Cat.hbm.xml new file mode 100644 index 0000000000000000000000000000000000000000..5fad20831ab0d17ccfd19636701266be56f6b985 --- /dev/null +++ b/jonas_4_10/jonas/examples/hibernate/etc/resources/Cat.hbm.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jonas_4_10/jonas/examples/hibernate/etc/resources/hibernate.cfg.xml b/jonas_4_10/jonas/examples/hibernate/etc/resources/hibernate.cfg.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fe40a4c1b57296092c2bd2d8d9aeeed98de08ed --- /dev/null +++ b/jonas_4_10/jonas/examples/hibernate/etc/resources/hibernate.cfg.xml @@ -0,0 +1,20 @@ + + + + + + + + java:comp/env/jdbc/jdbc_1 + false + org.hibernate.dialect.HSQLDialect + create + + + + + + + \ No newline at end of file diff --git a/jonas_4_10/jonas/examples/hibernate/etc/sql/initdb.sql b/jonas_4_10/jonas/examples/hibernate/etc/sql/initdb.sql new file mode 100644 index 0000000000000000000000000000000000000000..e8766fea1f98e0c677e1b46fdb796ccc3592237b --- /dev/null +++ b/jonas_4_10/jonas/examples/hibernate/etc/sql/initdb.sql @@ -0,0 +1,8 @@ +create table CAT ( + + cat_id VARCHAR(32) NOT NULL, + name VARCHAR(255), + sex VARCHAR(1), + weight REAL, + PRIMARY KEY(cat_id) +); diff --git a/jonas_4_10/jonas/examples/hibernate/etc/sql/resetdb.sql b/jonas_4_10/jonas/examples/hibernate/etc/sql/resetdb.sql new file mode 100644 index 0000000000000000000000000000000000000000..19c86a77f599c90400682c1f123ee40bf3e85c71 --- /dev/null +++ b/jonas_4_10/jonas/examples/hibernate/etc/sql/resetdb.sql @@ -0,0 +1 @@ +DROP TABLE CAT IF EXISTS; \ No newline at end of file diff --git a/jonas_4_10/jonas/examples/hibernate/etc/xml/jonas-web.xml b/jonas_4_10/jonas/examples/hibernate/etc/xml/jonas-web.xml new file mode 100644 index 0000000000000000000000000000000000000000..f7274e1cd0122fbbf9f8d0767852ad7a0581b5b9 --- /dev/null +++ b/jonas_4_10/jonas/examples/hibernate/etc/xml/jonas-web.xml @@ -0,0 +1,9 @@ + + + + + + jdbc/jdbc_1 + jdbc_1 + + \ No newline at end of file diff --git a/jonas_4_10/jonas/examples/hibernate/etc/xml/web.xml b/jonas_4_10/jonas/examples/hibernate/etc/xml/web.xml new file mode 100644 index 0000000000000000000000000000000000000000..c0483a48163f8f48b338ebeb98898b661ae3fc08 --- /dev/null +++ b/jonas_4_10/jonas/examples/hibernate/etc/xml/web.xml @@ -0,0 +1,27 @@ + + + + + + + HibernateServlet + Hibernate test servlet + + org.hibernate.examples.quickstart.TestServlet + + 1 + + + + HibernateServlet + /testHibernate/* + + + + + jdbc/jdbc_1 + javax.sql.DataSource + Container + + + \ No newline at end of file diff --git a/jonas_4_10/jonas/examples/hibernate/src/org/hibernate/examples/quickstart/Cat.java b/jonas_4_10/jonas/examples/hibernate/src/org/hibernate/examples/quickstart/Cat.java new file mode 100644 index 0000000000000000000000000000000000000000..ff82ce98c3d166ce96652bff56bd6371f5b3b745 --- /dev/null +++ b/jonas_4_10/jonas/examples/hibernate/src/org/hibernate/examples/quickstart/Cat.java @@ -0,0 +1,43 @@ +package org.hibernate.examples.quickstart; + +public class Cat { + private String id; + private String name; + private char sex; + private float weight; + + public Cat() { + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public char getSex() { + return sex; + } + + public void setSex(char sex) { + this.sex = sex; + } + + public float getWeight() { + return weight; + } + + public void setWeight(float weight) { + this.weight = weight; + } +} diff --git a/jonas/examples/hibernate/src/org/hibernate/examples/quickstart/TestServlet.java b/jonas_4_10/jonas/examples/hibernate/src/org/hibernate/examples/quickstart/TestServlet.java similarity index 100% rename from jonas/examples/hibernate/src/org/hibernate/examples/quickstart/TestServlet.java rename to jonas_4_10/jonas/examples/hibernate/src/org/hibernate/examples/quickstart/TestServlet.java diff --git a/jonas_4_10/jonas/examples/j2eemanagement/README b/jonas_4_10/jonas/examples/j2eemanagement/README new file mode 100644 index 0000000000000000000000000000000000000000..519ccbb7a38efe1f8c5e666ac05730c91054bc10 --- /dev/null +++ b/jonas_4_10/jonas/examples/j2eemanagement/README @@ -0,0 +1,147 @@ + +Example Overview: +----------------- + +This is a sample management application which is using the +Management EJB (MEJB) accordingly to the J2EE Management +Specification (JSR77), to implement some management operations +described below. +The MEJB is an Enterprise Session bean implementing the +javax.management.j2ee.Management interface and provides access +to the platform's manageable objects through the EJB +interoperability protocol. + +The MEJB is automatically deployed in a JOnAS EJB container +at start-up because the ejb-jar file (mejb.jar) +is installed in (JONAS_ROOT | JONAS_BASE)/ejbjars/autoload directory. +(Note you can use "ant update_jonasbase" for updating JONAS_BASE +directory). + +The application's main component is a servlet which creates +a MEJB and calls the management methods defined in its remote interface. + +In order to create the MEJB, the servlet gets a reference on the +bean's home using a JNDI lookup with the "java:comp/env/ejb/mgmt/MEJB" name. + +Management operations +--------------------- +The management operations implemented in this example are: +1/ Find the servers which run in the current management domain. +2/ Register an event listener in order to receive notifications +emitted by a J2EE server. + +Example structure and packaging +------------------------------- + +This example is a J2EE application, so it is packaged in a EAR. +Compiling the example creates the j2eemanagement.ear file +that includes a web application (WAR). + +The servlet source code is contained in +$JONAS_ROOT/examples/j2eemanagement/src/.. directory. + +The "etc" directory contains + - the "xml" directory containing the application's deployment descriptors: + * application.xml (ear file) + * web.xml, jonas-web.xml (war file) + - the "resources" directory which contains the resources for this application + * "web" directory contains all resources used by the servlet + + +Prerequisites +------------- +First, you must have installed a web container (i.e.: Catalina or Jetty) +as the web container service. + + +Compiling and installing this example: +-------------------------------------- + ant install + +in JONAS_ROOT/examples/j2eemanagement. + +Running this example: +-------------------- +You will run a JOnAS server having at least a default configuration +(the ejb service, to deploy mejb.jar, and the web service, to +deploy jonasAdmin.war and j2eemanagement.ear). + +Commands are given for an Unix system. +(Similar commands can be done on Windows) + +0) Server configuration: +- Currently, if you wish to test the event notifications, you have to +be sure the mail service is in the services list in jonas.properties. +Otherwise, default configuration is sufficient. +- You may add j2eemanagement.ear in the ear descriptors list in jonas.properties; +this avoids executing step 2) + +1) Run a jonas server: + jonas start [-n name] [-Ddomain.name=domainName] + +2) Load j2eemanagement.ear if you haven't added j2eemanagement.ear to the ear +descriptors list: + jonas admin -a j2eemanagement.ear + + or via the jonasAdmin management application + (http://:/jonasAdmin) + +3) Run your web browser (e.g., netscape) with url: + http://:/j2eemanagement + where is the name of your machine (localhost by default) + and the port number (9000 by default) + +4) Run the servlet after providing the domain name. + + The displayed information traces out the executed management operations: + - initial naming context creation + - MEJB creation + - access to J2EEDomain MBean and listing the J2EEServer MBeans + (we have one server in the present case) + - the next operation is creation of a client notification listener and + its registration as listener on notifications emitted by the + J2EEServer MBean via the usage of a ListenerRegistration object + provided by the MEJB. + + As specified at step 0) the mail service has to be started in order +to test the event listener. + Make the following operations: + Run the JOnAS management application to add or remove a mail resource: + - open http://:/jonasAdmin url + - go in the Resources->Mail sub-tree + - deploy, or undeploy, a Mail Factory + + As a side effect of this action, the J2EEServer MBean sends a notification +to the registered notification listeners. The notification's type is + AttributeAddNotification or AttributeRemoveNotification. +It contains information about the added/removed resource. + The implementation of the MEJB's event listener requirement allow +the notification to be delivered to the client notification listener. +This can be verified by a click on one of the links allowing to list the +received notifications. + +5) Test the new domain management features: +5.1) Cluster creation + - Go back to the previous page (to /j2eemanagement) + - Provide the cluster name to create and run the cluster creation (2nd run button) + +5.2) Add additional server to the domain. +You may test one of the following scenarios: + +5.2.1) In the first scenario, you add an additional slave server which +is not running when the "addServer" operation is invoked. The server is added to the 'servers' +list in 'created' state. + - Go back to the previous page (to /j2eemanagement) + - Provide the server name, the connector server URL, and run by clicking on the last run button. +Later on, when starting the server, it passes in 'running' state. + - Start the server having the provided name and connector server URL + - Check the new server passed in the 'running' state by re-executing the servlet (first run button) + +5.2.2) In the second scenario, you add an additional server which doesn't has the discovery service +enabled. The server is added in the 'servers' list in 'running' state. + - Start the server to add + - Go back to the previous page (to /j2eemanagement) + - Provide the server name, the connector server URL, and run by clicking on the last run button. + +6) Stop the jonas server: + jonas stop [-n name] diff --git a/jonas_4_10/jonas/examples/j2eemanagement/build.xml b/jonas_4_10/jonas/examples/j2eemanagement/build.xml new file mode 100644 index 0000000000000000000000000000000000000000..090dd0ffe12808bef1b72d16efcc9682c6c31650 --- /dev/null +++ b/jonas_4_10/jonas/examples/j2eemanagement/build.xml @@ -0,0 +1,156 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jonas_4_10/jonas/examples/j2eemanagement/etc/resources/web/img/logo_jonas.jpg b/jonas_4_10/jonas/examples/j2eemanagement/etc/resources/web/img/logo_jonas.jpg new file mode 100644 index 0000000000000000000000000000000000000000..3fe9b43072176d2275d8725eb977b781a9730306 Binary files /dev/null and b/jonas_4_10/jonas/examples/j2eemanagement/etc/resources/web/img/logo_jonas.jpg differ diff --git a/jonas_4_10/jonas/examples/j2eemanagement/etc/resources/web/index.html b/jonas_4_10/jonas/examples/j2eemanagement/etc/resources/web/index.html new file mode 100644 index 0000000000000000000000000000000000000000..7bdb1e3e425ccb0f7ed3c3033b38022cd9590cc8 --- /dev/null +++ b/jonas_4_10/jonas/examples/j2eemanagement/etc/resources/web/index.html @@ -0,0 +1,109 @@ + + + + + j2eemanagement + + + + +

    j2eemanagement : example of Servlet accessing the MEJB (Management EJB)

    +JOnAS Logo + +

    +This new version of the application allows testing management of several JOnAS servers running in a domain,
    +via JSR 160 MBeanServerConnections.
    +It also tests new domain management features and even Joram management. +

    +

    +To test domain management, you may start before running the servlet, at least a second server in the domain.
    +For example, if the current server's name is jonas, to start a second server named jonas1 in the current server's domain use:
    +jonas start -n jonas1 -Ddomain.name=jonas +

    +

    +Please give the domain name to be managed and then click to run the servlet.
    +(the default name for the domain is the current server's name)

    +

    +

    Check the domain topology

    +

    +

    +

    + Domain name: +

    +

    + +

    +
    +

    +

    +

    Test cluster creation

    +

    +

    +

    + Domain name: +

    +

    + Cluster name: +

    +

    + +

    +
    +

    +

    Add a new server to the domain (a server which is not running or which is running without the discovery service)

    +

    +

    +

    + Domain name: +

    +

    + Cluster name: +

    +

    + Server name: +

    +

    + Connector server url: +

    +

    + +

    +
    +

    +

    +

    Test server start

    +

    +

    +

    + Domain name: +

    +

    + Daemon name: +

    +

    + Server name: +

    +

    + +

    +
    +

    +

    +

    Test joram management features

    +

    Create a topic on a Joram server

    +

    +

    +

    + Topic name: +

    +

    + Joram server id: +

    +

    + +

    +
    +

    + + + diff --git a/jonas_4_10/jonas/examples/j2eemanagement/etc/resources/web/style.css b/jonas_4_10/jonas/examples/j2eemanagement/etc/resources/web/style.css new file mode 100644 index 0000000000000000000000000000000000000000..4f852c2a87c8be61ad1e242e706f92197a35396c --- /dev/null +++ b/jonas_4_10/jonas/examples/j2eemanagement/etc/resources/web/style.css @@ -0,0 +1,13 @@ +body { + background : white; + color : black; +} +h1, h2, h3 {font-family : sans-serif; } +h1 {font-size : 175%; color : DarkCyan; text-align : center;} +h2 {font-size : 150%; color : DarkCyan; + border-bottom : solid; + border-bottom-width : 1; +} +h3 {font-size : 125%; } +strong { font-weight : bold; } +hr { size : 1; width : 100%; } diff --git a/jonas_4_10/jonas/examples/j2eemanagement/etc/xml/application.xml b/jonas_4_10/jonas/examples/j2eemanagement/etc/xml/application.xml new file mode 100644 index 0000000000000000000000000000000000000000..ca34ba01b007d0b67284e9531e8943f1bc14401e --- /dev/null +++ b/jonas_4_10/jonas/examples/j2eemanagement/etc/xml/application.xml @@ -0,0 +1,19 @@ + + + + + ear example for MEJB usage + j2eemanagement servlet + + + + j2eemanagement.war + j2eemanagement + + + + \ No newline at end of file diff --git a/jonas_4_10/jonas/examples/j2eemanagement/etc/xml/jonas-web.xml b/jonas_4_10/jonas/examples/j2eemanagement/etc/xml/jonas-web.xml new file mode 100644 index 0000000000000000000000000000000000000000..ade6500190db4d295436636e4ba424dce1ccd1e6 --- /dev/null +++ b/jonas_4_10/jonas/examples/j2eemanagement/etc/xml/jonas-web.xml @@ -0,0 +1,16 @@ + + + + + + ejb/mgmt/MEJB + ejb/mgmt/MEJB + + + ejb/mgmt/DomainMEJB + ejb/mgmt/DomainMEJB + + \ No newline at end of file diff --git a/jonas_4_10/jonas/examples/j2eemanagement/etc/xml/web.xml b/jonas_4_10/jonas/examples/j2eemanagement/etc/xml/web.xml new file mode 100644 index 0000000000000000000000000000000000000000..1c2956954838cfad73a9c60eda2a5d5f5e842e4e --- /dev/null +++ b/jonas_4_10/jonas/examples/j2eemanagement/etc/xml/web.xml @@ -0,0 +1,74 @@ + + + + + + mgmt + org.objectweb.j2eemanagement.servlets.MgmtServlet + + + + mgmt + /mgmt + + + + cmgmt + org.objectweb.j2eemanagement.servlets.ClustMgmtServlet + + + + cmgmt + /cmgmt + + + + dmgmt + org.objectweb.j2eemanagement.servlets.ClusterDaemonServlet + + + + dmgmt + /dmgmt + + + + smgmt + org.objectweb.j2eemanagement.servlets.NewServerMgmtServlet + + + + smgmt + /smgmt + + + + jmsmgmt + org.objectweb.j2eemanagement.servlets.JmsAdminServlet + + mbeanName + joramClient:type=JoramAdmin + + + + + jmsmgmt + /jmsmgmt + + + + ejb/mgmt/MEJB + Session + javax.management.j2ee.ManagementHome + javax.management.j2ee.Management + + + ejb/mgmt/DomainMEJB + Session + org.objectweb.jonas.mejb.DomainManagementHome + org.objectweb.jonas.mejb.DomainManagement + + \ No newline at end of file diff --git a/jonas_4_10/jonas/examples/j2eemanagement/src/org/objectweb/j2eemanagement/servlets/ClustMgmtServlet.java b/jonas_4_10/jonas/examples/j2eemanagement/src/org/objectweb/j2eemanagement/servlets/ClustMgmtServlet.java new file mode 100644 index 0000000000000000000000000000000000000000..fb035ad748c9aaff032582ee8ea4961c7fe91f3f --- /dev/null +++ b/jonas_4_10/jonas/examples/j2eemanagement/src/org/objectweb/j2eemanagement/servlets/ClustMgmtServlet.java @@ -0,0 +1,238 @@ +/** + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 2006 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ + +package org.objectweb.j2eemanagement.servlets; + +//import java +import java.io.IOException; +import java.io.PrintWriter; + +import javax.management.ObjectName; +import javax.management.j2ee.Management; +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * This servlet is an example which shows how to access the MEJB from a servlet. + * @author JOnAS team + * @author Adriana Danes + */ +public class ClustMgmtServlet extends J2eemanagementBaseServlet { + + // ---------------------------------------------------------- Constants + /** Parameter */ + static final String PARAM_DOMAIN = "domainName"; + /** Parameter */ + static final String PARAM_CLUSTER = "clusterName"; + /** Parameter */ + static final String PARAM_VIEW = "view"; + /** Parameter */ + static final String VIEW_INIT = "init"; + + // ---------------------------------------------------------- Public methods + + /** + * Initialize the servlet. + * @param pConfig See HttpServlet + * @throws ServletException Could not execute request + */ + public void init(ServletConfig pConfig) throws ServletException { + super.init(pConfig); + } + + // ---------------------------------------------------------- Protected + // methods + + /** + * Response to the GET request. + * @param pRequest See HttpServlet + * @param pResponse See HttpServlet + * @throws IOException An input or output error is detected when the servlet handles the request + * @throws ServletException Could not execute request + */ + protected void doGet(HttpServletRequest pRequest, HttpServletResponse pResponse) throws IOException, + ServletException { + dispatch(pRequest, pResponse); + } + + /** + * Response to the POST request. + * @param pRequest See HttpServlet + * @param pResponse See HttpServlet + * @throws IOException An input or output error is detected when the servlet handles the request + * @throws ServletException Could not execute request + */ + protected void doPost(HttpServletRequest pRequest, HttpServletResponse pResponse) throws IOException, + ServletException { + dispatch(pRequest, pResponse); + } + + /** + * Dispatch the response. + * @param pRequest Request + * @param pResponse Response + * @throws IOException An input or output error is detected when the servlet handles the request + */ + protected void dispatch(HttpServletRequest pRequest, HttpServletResponse pResponse) throws IOException { + + pResponse.setContentType("text/html"); + PrintWriter out = pResponse.getWriter(); + + // Get parameters + String sParamDomain = pRequest.getParameter(PARAM_DOMAIN); + String sParamCluster = pRequest.getParameter(PARAM_CLUSTER); + String sParamView = pRequest.getParameter(PARAM_VIEW); + + // Dispatching + if ((sParamDomain == null) || (sParamDomain.length() == 0)) { + doViewError("Parameter Domain name not found", pRequest, out); + } else if ((sParamCluster == null) || (sParamCluster.length() == 0)) { + doViewError("Parameter Cluster name not found", pRequest, out); + } else if ((sParamView == null) || (sParamView.length() == 0) || VIEW_INIT.equals(sParamView)) { + doViewInit(pRequest, out); + doViewManagement(sParamDomain, sParamCluster, pRequest, out); + } else { + doViewError("Unknown View", pRequest, out); + } + + } + + /** + * Do management opeartions in this view. + * @param pDomainName Name of domain to access + * @param pClusterName Name of the cluster to manage in the domain + * @param pRequest Http request + * @param pOut Printer + */ + protected void doViewManagement(String pDomainName, String pClusterName, HttpServletRequest pRequest, PrintWriter pOut) { + Management mgmt = getMgmt(); + + // ------------------------------ + // Access to the J2EEDomain MBean + // ------------------------------ + ObjectName onDomain = accessJ2EEDomain(pDomainName, mgmt, pOut); + if (onDomain == null) { + return; + } + + // Create a cluster in the domain + // ------------------------------- + ObjectName onCluster = createCluster(onDomain, pClusterName, mgmt, pOut); + if (onCluster == null) { + return; + } + + // ----------------------------------------------------- + // Using the domain management EJB to list servers and clusters + // ----------------------------------------------------- + String[] serverNames = null; + String[] serverNamesDom = null; + String[] servers = null; + String[] clusters = null; + try { + + pOut.println("

    Getting the list of cluster MBeans

    "); + clusters = (String[]) mgmt.getAttribute(onDomain, "clusters"); + pOut.println("
      "); + for (int i = 0; i < clusters.length; i++) { + pOut.println("
    • " + clusters[i] + "
    • "); + } + pOut.println("
    "); + } catch (Exception e) { + pOut.println("
  • Could not make MEJB list servers or clusters.
  • " + e); + e.printStackTrace(pOut); + return; + } + + pOut.println("

    Application is OK

    "); + + // Footer + printNavigationFooter(pRequest, pOut); + } + + /** + * Create J2EEDomain MBean's ObjectName and test if MBean registered + * @param pDomainName the name provided by the user + * @param mgmt MEJB + * @param pOut output stream + * @return true if management operation succeeded + */ + private ObjectName accessJ2EEDomain(String pDomainName, Management mgmt, PrintWriter pOut) { + ObjectName onDomain = null; + pOut.println("

    Access the J2EEDomain MBean

    "); + pOut.println("
      "); + + // Get the J2EEDomain MBean's ObjectName + try { + String name = pDomainName + ":j2eeType=J2EEDomain,name=" + pDomainName; + onDomain = ObjectName.getInstance(name); + pOut.println("
    • J2EEDomain object name \"" + name.toString() + "\" created.
    • "); + } catch (Exception e) { + pOut.println("
    • Cannot create object name for J2EEDomain managed object: " + e + "
    • "); + pOut.println("
    "); + return null; + } + // Check that the J2EEDomain MBean registered + try { + boolean exists = mgmt.isRegistered(onDomain); + if (exists) { + pOut.println("
  • Found this J2EEDomain MBean in the current MBean server
  • "); + pOut.println("
    "); + } else { + pOut.println("
  • Can't find this J2EEDomain MBean in the current MBean server
  • "); + pOut.println(""); + return null; + } + } catch (Exception e) { + pOut.println("
  • Error when using this J2EEDomain MBean: " + e + "
  • "); + pOut.println(""); + return null; + } + return onDomain; + } + + private ObjectName createCluster(ObjectName pOnDomain, String pClusterName, Management mgmt, PrintWriter pOut) { + ObjectName on = null; + String domainName = pOnDomain.getDomain(); + pOut.println("

    Create cluster " + pClusterName + " in domain " + domainName + "

    "); + pOut.println("
      "); + try { + String[] signature = new String[1]; + signature[0] = "java.lang.String"; + Object[] params = new Object[1]; + params[0] = pClusterName; + String clusterOn = (String) mgmt.invoke(pOnDomain, "createCluster", params, signature); + on = ObjectName.getInstance(clusterOn); + pOut.println("
    • Cluster " + pClusterName + " created.
    • "); + pOut.println("

    "); + } catch (Exception e) { + pOut.println("
  • Cannot create cluster " + pClusterName + ": " + e + "
  • "); + pOut.println(""); + } + return on; + } +} \ No newline at end of file diff --git a/jonas_4_10/jonas/examples/j2eemanagement/src/org/objectweb/j2eemanagement/servlets/ClusterDaemonServlet.java b/jonas_4_10/jonas/examples/j2eemanagement/src/org/objectweb/j2eemanagement/servlets/ClusterDaemonServlet.java new file mode 100644 index 0000000000000000000000000000000000000000..38f04ac50a7e6ddfc74af49ee283437b1b621104 --- /dev/null +++ b/jonas_4_10/jonas/examples/j2eemanagement/src/org/objectweb/j2eemanagement/servlets/ClusterDaemonServlet.java @@ -0,0 +1,217 @@ +/** + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 2006 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * -------------------------------------------------------------------------- + * $Id: $ + * -------------------------------------------------------------------------- + */ + +package org.objectweb.j2eemanagement.servlets; + +//import java +import java.io.IOException; +import java.io.PrintWriter; + +import javax.management.ObjectName; +import javax.management.j2ee.Management; +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * This servlet is an example which shows how to access the MEJB from a servlet. + * @author JOnAS team + * @author Adriana Danes + */ +public class ClusterDaemonServlet extends J2eemanagementBaseServlet { + + // ---------------------------------------------------------- Constants + /** Parameter */ + static final String PARAM_DOMAIN = "domainName"; + /** Parameter */ + static final String PARAM_DAEMON = "daemonName"; + /** Parameter which gives the name of the server to be started by the daemon */ + static final String PARAM_SERVER = "serverName"; + /** Parameter */ + static final String PARAM_VIEW = "view"; + /** Parameter */ + static final String VIEW_INIT = "init"; + + // ---------------------------------------------------------- Public methods + + /** + * Initialize the servlet. + * @param pConfig See HttpServlet + * @throws ServletException Could not execute request + */ + public void init(ServletConfig pConfig) throws ServletException { + super.init(pConfig); + } + + // ---------------------------------------------------------- Protected + // methods + + /** + * Response to the GET request. + * @param pRequest See HttpServlet + * @param pResponse See HttpServlet + * @throws IOException An input or output error is detected when the servlet handles the request + * @throws ServletException Could not execute request + */ + protected void doGet(HttpServletRequest pRequest, HttpServletResponse pResponse) throws IOException, + ServletException { + dispatch(pRequest, pResponse); + } + + /** + * Response to the POST request. + * @param pRequest See HttpServlet + * @param pResponse See HttpServlet + * @throws IOException An input or output error is detected when the servlet handles the request + * @throws ServletException Could not execute request + */ + protected void doPost(HttpServletRequest pRequest, HttpServletResponse pResponse) throws IOException, + ServletException { + dispatch(pRequest, pResponse); + } + + /** + * Dispatch the response. + * @param pRequest Request + * @param pResponse Response + * @throws IOException An input or output error is detected when the servlet handles the request + */ + protected void dispatch(HttpServletRequest pRequest, HttpServletResponse pResponse) throws IOException { + + pResponse.setContentType("text/html"); + PrintWriter out = pResponse.getWriter(); + + // Get parameters + String sParamDomain = pRequest.getParameter(PARAM_DOMAIN); + String sParamDaemon = pRequest.getParameter(PARAM_DAEMON); + String sParamServer = pRequest.getParameter(PARAM_SERVER); + String sParamView = pRequest.getParameter(PARAM_VIEW); + + // Dispatching + if ((sParamDomain == null) || (sParamDomain.length() == 0)) { + doViewError("Parameter Domain name not found", pRequest, out); + } else if ((sParamDaemon == null) || (sParamDaemon.length() == 0)) { + doViewError("Parameter Daemon name not found", pRequest, out); + } else if ((sParamServer == null) || (sParamServer.length() == 0)) { + doViewError("Parameter Server name not found", pRequest, out); + } else if ((sParamView == null) || (sParamView.length() == 0) || VIEW_INIT.equals(sParamView)) { + doViewInit(pRequest, out); + doViewManagement(sParamDomain, sParamDaemon, sParamServer, pRequest, out); + } else { + doViewError("Unknown View", pRequest, out); + } + + } + + /** + * Do management opeartions in this view. + * @param pDomainName Name of domain to access + * @param pDaemonName Name of the deamon + * @param pServerName Name of the server to be started by the daemon + * @param pRequest Http request + * @param pOut Printer + */ + protected void doViewManagement(String pDomainName, String pDaemonName, String pServerName, HttpServletRequest pRequest, PrintWriter pOut) { + Management mgmt = getMgmt(); + + // ------------------------------ + // Access to the J2EEDomain MBean + // ------------------------------ + ObjectName onDomain = accessJ2EEDomain(pDomainName, mgmt, pOut); + if (onDomain == null) { + return; + } + + startServer(onDomain, pDaemonName, pServerName, mgmt, pOut); + pOut.println("

    Application is OK

    "); + + // Footer + printNavigationFooter(pRequest, pOut); + } + + /** + * Create J2EEDomain MBean's ObjectName and test if MBean registered + * @param pDomainName the name provided by the user + * @param mgmt MEJB + * @param pOut output stream + * @return true if management operation succeeded + */ + private ObjectName accessJ2EEDomain(String pDomainName, Management mgmt, PrintWriter pOut) { + ObjectName onDomain = null; + pOut.println("

    Access the J2EEDomain MBean

    "); + pOut.println("
      "); + + // Get the J2EEDomain MBean's ObjectName + try { + String name = pDomainName + ":j2eeType=J2EEDomain,name=" + pDomainName; + onDomain = ObjectName.getInstance(name); + pOut.println("
    • J2EEDomain object name \"" + name.toString() + "\" created.
    • "); + } catch (Exception e) { + pOut.println("
    • Cannot create object name for J2EEDomain managed object: " + e + "
    • "); + pOut.println("
    "); + return null; + } + // Check that the J2EEDomain MBean registered + try { + boolean exists = mgmt.isRegistered(onDomain); + if (exists) { + pOut.println("
  • Found this J2EEDomain MBean in the current MBean server
  • "); + pOut.println("
    "); + } else { + pOut.println("
  • Can't find this J2EEDomain MBean in the current MBean server
  • "); + pOut.println(""); + return null; + } + } catch (Exception e) { + pOut.println("
  • Error when using this J2EEDomain MBean: " + e + "
  • "); + pOut.println(""); + return null; + } + return onDomain; + } + /** + * Start a server in domain + * @param pOnDomain J2EEDomain MBean ObjectName + * @param pDaemonName daemon name - currently not used + * @param pServerName server name + * @param mgmt MEJB + * @param pOut output stream + */ + private void startServer(ObjectName pOnDomain, String pDaemonName, String pServerName, Management mgmt, PrintWriter pOut) { + pOut.println("

    Start the server " + pServerName + "

    "); + pOut.println("
      "); + try { + String[] signature = {"java.lang.String"}; + String[] params = {pServerName}; + mgmt.invoke(pOnDomain, "startServer", params, signature); + pOut.println("
    • Server " + pServerName + " started.
    • "); + pOut.println("

    "); + } catch (Exception e) { + pOut.println("
  • Cannot create cluster start the server
  • "); + pOut.println(""); + } + } +} \ No newline at end of file diff --git a/jonas_4_10/jonas/examples/j2eemanagement/src/org/objectweb/j2eemanagement/servlets/J2eemanagementBaseServlet.java b/jonas_4_10/jonas/examples/j2eemanagement/src/org/objectweb/j2eemanagement/servlets/J2eemanagementBaseServlet.java new file mode 100644 index 0000000000000000000000000000000000000000..728b9b625b8c30ff7afbe4cc12f2e6a39236ef42 --- /dev/null +++ b/jonas_4_10/jonas/examples/j2eemanagement/src/org/objectweb/j2eemanagement/servlets/J2eemanagementBaseServlet.java @@ -0,0 +1,209 @@ +/** + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 2006 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ + +package org.objectweb.j2eemanagement.servlets; + +import java.io.PrintWriter; + +import javax.management.j2ee.Management; +import javax.management.j2ee.ManagementHome; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.rmi.PortableRemoteObject; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; + +import org.objectweb.jonas.mejb.DomainManagementHome; + +/** + * + * @author Adriana Danes + * + * Base classe containing common code for the j2eeManagement servlets + */ +public class J2eemanagementBaseServlet extends HttpServlet { + /** Printing constant*/ + static final String APP_TITLE = "J2EE Management sample"; + /** + * Standard J2EEManagement Bean + */ + private Management mgmt = null; + /** + * Naming context + */ + private Context initialContext = null; + + /** + * Header. + * @param pOut Printer + * @param pTitle Title to display + * @param pSubTitle Subtitle to display or null if not + */ + protected void printHeader(PrintWriter pOut, String pTitle, String pSubTitle) { + + pOut.println(""); + pOut.println(""); + pOut.println("" + pTitle); + if (pSubTitle != null) { + pOut.println(" - " + pSubTitle); + } + pOut.println(""); + pOut.println(""); + pOut.println(""); + printHeaderTitle(pOut, pTitle, pSubTitle); + } + /** + * Header title. + * @param pOut Printer + * @param pTitle Title to display + * @param pSubTitle Subtitle to display or null if not + */ + protected void printHeaderTitle(PrintWriter pOut, String pTitle, String pSubTitle) { + + pOut.println(""); + pOut.println(""); + pOut.println(""); + pOut.println(""); + pOut.println(""); + pOut.println(""); + if (pSubTitle != null) { + pOut.println(""); + } + pOut.println(""); + pOut.println("
    \"JOnAS

    " + pTitle + "

    " + pSubTitle + "

    "); + } + + /** + * Footer navigation. + * @param pRequest Http request + * @param pOut Printer + */ + protected void printNavigationFooter(HttpServletRequest pRequest, PrintWriter pOut) { + + // index + String sViewIndex = pRequest.getContextPath(); + + // Display + pOut.print(""); + pOut.print(""); + pOut.print(""); + pOut.println("
    Index
    "); + // Footer + printFooter(pOut); + } + /** + * Footer. + * @param pOut Printer + */ + protected void printFooter(PrintWriter pOut) { + pOut.println(""); + pOut.println(""); + } + + /** + * @param pRequest Client request + * @param pOut Writer for output + */ + protected void doViewInit(HttpServletRequest pRequest, PrintWriter pOut) { + // ----------------------------- + // Get initial context + // ----------------------------- + pOut.println("

    Initial context for domain management

    "); + pOut.println("
      "); + try { + initialContext = new InitialContext(); + pOut.println("
    • Initial context OK
    • "); + } catch (Exception e) { + pOut.print("
    • Cannot get initial context for JNDI: "); + pOut.println(e + "
    • "); + pOut.println("
    "); + printNavigationFooter(pRequest, pOut); + return; + } + pOut.println("
    "); + + // ----------------------------- + // Access to the MEJB + // ----------------------------- + pOut.println("

    Create MEJB

    "); + pOut.println("
      "); + + // Connecting to the MEJB home through JNDI + ManagementHome mgmtHome = null; + DomainManagementHome domainMgmtHome = null; + try { + mgmtHome = (ManagementHome) PortableRemoteObject.narrow(initialContext.lookup("java:comp/env/ejb/mgmt/MEJB"), + ManagementHome.class); + } catch (Exception e) { + pOut.println("
    • Cannot lookup java:comp/env/ejb/mgmt/MEJB: " + e + "
    • "); + pOut.println("
    "); + printNavigationFooter(pRequest, pOut); + return; + } + + // Management bean creation + try { + mgmt = mgmtHome.create(); + pOut.println("
  • MEJB created
  • "); + } catch (Exception e) { + pOut.println("
  • Cannot create MEJB: " + e + "
  • "); + pOut.println(""); + printNavigationFooter(pRequest, pOut); + return; + } + + pOut.println("
    "); + } + + /** + * Simply View error. + * @param pError Message error + * @param pRequest Http request + * @param pOut Printer + */ + protected void doViewError(String pError, HttpServletRequest pRequest, PrintWriter pOut) { + + // Header + printHeader(pOut, APP_TITLE, "Error"); + // Error message + pOut.println("

    " + pError + "

    "); + // Return + pOut.println("Return"); + // Footer + printFooter(pOut); + } + /** + * @return The management bean + */ + public Management getMgmt() { + return mgmt; + } + /** + * @return The initial naming context + */ + public Context getInitialContext() { + return initialContext; + } +} \ No newline at end of file diff --git a/jonas_4_10/jonas/examples/j2eemanagement/src/org/objectweb/j2eemanagement/servlets/JmsAdminServlet.java b/jonas_4_10/jonas/examples/j2eemanagement/src/org/objectweb/j2eemanagement/servlets/JmsAdminServlet.java new file mode 100644 index 0000000000000000000000000000000000000000..024986fd5bfca09d41c99661c9bc855ee3209f09 --- /dev/null +++ b/jonas_4_10/jonas/examples/j2eemanagement/src/org/objectweb/j2eemanagement/servlets/JmsAdminServlet.java @@ -0,0 +1,188 @@ +/** + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 2006 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ + +package org.objectweb.j2eemanagement.servlets; + +//import java +import java.io.IOException; +import java.io.PrintWriter; + +import javax.jms.Topic; +import javax.management.MalformedObjectNameException; +import javax.management.ObjectName; +import javax.management.j2ee.Management; +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * This servlet is an example which shows how to access the MEJB from a servlet. + * The MEJB is used to invoke JoramAdmin Bean operations. + * @author JOnAS team + * @author Adriana Danes + */ +public class JmsAdminServlet extends J2eemanagementBaseServlet { + /** Parameter */ + static final String PARAM_TOPIC = "topicName"; + /** Parameter */ + static final String PARAM_SERVER_ID = "serverId"; + /** Parameter */ + static final String PARAM_VIEW = "view"; + /** Parameter */ + static final String VIEW_INIT = "init"; + + // ---------------------------------------------------------- Public methods + + /** + * Initialize the servlet. + * @param pConfig See HttpServlet + * @throws ServletException Could not initialize servlet + */ + public void init(ServletConfig pConfig) throws ServletException { + super.init(pConfig); + } + + // ---------------------------------------------------------- Protected + // methods + + /** + * Response to the GET request. + * @param pRequest See HttpServlet + * @param pResponse See HttpServlet + * @throws IOException Could not execute request + * @throws ServletException An input or output error is detected when the servlet handles the request + */ + protected void doGet(HttpServletRequest pRequest, HttpServletResponse pResponse) + throws IOException, ServletException { + dispatch(pRequest, pResponse); + } + + /** + * Response to the POST request. + * @param pRequest See HttpServlet + * @param pResponse See HttpServlet + * @throws IOException An input or output error is detected when the servlet handles the request + * @throws ServletException Could not execute request + */ + protected void doPost(HttpServletRequest pRequest, HttpServletResponse pResponse) + throws IOException, ServletException { + dispatch(pRequest, pResponse); + } + + /** + * Dispatch the response. + * @param pRequest Request + * @param pResponse Response + * @throws IOException An input or output error is detected when the servlet handles the request + */ + protected void dispatch(HttpServletRequest pRequest, HttpServletResponse pResponse) throws IOException { + + pResponse.setContentType("text/html"); + PrintWriter out = pResponse.getWriter(); + + // Get parameters + String sParamTopic = pRequest.getParameter(PARAM_TOPIC); + String sParamServerId = pRequest.getParameter(PARAM_SERVER_ID); + String sParamView = pRequest.getParameter(PARAM_VIEW); + + // Dispatching + if ((sParamTopic == null) || (sParamTopic.length() == 0)) { + doViewError("Parameter Topic name not found", pRequest, out); + } else if ((sParamServerId == null) || (sParamServerId.length() == 0)) { + doViewError("Parameter Joram server id not found", pRequest, out); + } else if ((sParamView == null) || (sParamView.length() == 0) || VIEW_INIT.equals(sParamView)) { + doViewInit(pRequest, out); + doViewManagement(sParamTopic, sParamServerId, pRequest, out); + } else { + doViewError("Unknown View", pRequest, out); + } + + } + + + + /** + * View init MEJB and access to MBEans J2EEDomain and J2EEServer. + * @param pTopicName Name of topic to create + * @param pServerId Joram server Id + * @param pRequest Http request + * @param pOut Printer + */ + protected void doViewManagement(String pTopicName, String pServerId, HttpServletRequest pRequest, PrintWriter pOut) { + + // ------------------------------------------------------------- + // Use the Joram MBean via the MEJB to make jms admin operations + // ------------------------------------------------------------- + pOut.println("

    Get Joram admin MBean

    "); + pOut.println("
      "); + Management mgmt = getMgmt(); + + String joramON = getInitParameter("mbeanName"); + if (joramON == null) { + joramON = "joramClient:type=JoramAdmin"; + } else { + pOut.println("
    • Use servlet init param 'mbeanName': " + joramON + "
    • "); + } + ObjectName joramOn = null; + try { + joramOn = ObjectName.getInstance(joramON); + } catch (MalformedObjectNameException e1) { + pOut.println("
    • Couldn't get Joram MBean
    • " + e1); + pOut.println("
    "); + printNavigationFooter(pRequest, pOut); + return; + } + pOut.println("
    "); + pOut.println("

    Use Joram admin MBean

    "); + pOut.println("
      "); + + try { + if (mgmt.isRegistered(joramOn)) { + Object[] asParam = {new Integer(pServerId), pTopicName }; + String[] asSignature = { + "int", "java.lang.String" + }; + String op = "createTopic"; + Topic topic = (Topic) mgmt.invoke(joramOn, op, asParam, asSignature); + getInitialContext().rebind(pTopicName, topic); + pOut.println("
    • Topic " + pTopicName + " created on server " + pServerId + "
    • "); + } + } catch (Exception e) { + pOut.println("
    • Could not use use Joram MBean to administer jms
    • " + e); + pOut.println("
    "); + printNavigationFooter(pRequest, pOut); + return; + } + + pOut.println("
    "); + + pOut.println("

    Application is OK

    "); + + // Footer + printNavigationFooter(pRequest, pOut); + } + +} \ No newline at end of file diff --git a/jonas_4_10/jonas/examples/j2eemanagement/src/org/objectweb/j2eemanagement/servlets/MgmtServlet.java b/jonas_4_10/jonas/examples/j2eemanagement/src/org/objectweb/j2eemanagement/servlets/MgmtServlet.java new file mode 100644 index 0000000000000000000000000000000000000000..21613234799b2e7566b14201e18cf3dd44f53570 --- /dev/null +++ b/jonas_4_10/jonas/examples/j2eemanagement/src/org/objectweb/j2eemanagement/servlets/MgmtServlet.java @@ -0,0 +1,848 @@ +/** + * JOnAS: Java(TM) Open Application Server + * Copyright (C) 1999 Bull S.A. + * Contact: jonas-team@objectweb.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * -------------------------------------------------------------------------- + * $Id$ + * -------------------------------------------------------------------------- + */ + +package org.objectweb.j2eemanagement.servlets; + +//import java +import java.io.IOException; +import java.io.PrintWriter; +import java.net.MalformedURLException; +import java.rmi.RemoteException; +import java.util.List; + +import javax.management.MBeanException; +import javax.management.MBeanServerConnection; +import javax.management.MalformedObjectNameException; +import javax.management.ObjectName; +import javax.management.j2ee.ListenerRegistration; +import javax.management.j2ee.Management; +import javax.management.j2ee.ManagementHome; +import javax.management.remote.JMXConnector; +import javax.management.remote.JMXConnectorFactory; +import javax.management.remote.JMXServiceURL; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.rmi.PortableRemoteObject; +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.objectweb.jonas.mejb.DomainManagement; +import org.objectweb.jonas.mejb.DomainManagementHome; + +/** + * This servlet is an example which shows how to access the MEJB from a servlet. + * @author JOnAS team + * @author Adriana Danes + * @author Michel-Ange Anton + */ +public class MgmtServlet extends J2eemanagementBaseServlet { + + // ---------------------------------------------------------- Constants + /** Printing constant*/ + static final String APP_TITLE_LARGE = "J2EE Management sample with Servlet accessing the MEJB"; + /** Printing constant*/ + static final String APP_TITLE = "J2EE Management sample"; + /** Parameter */ + static final String PARAM_DOMAIN = "domainName"; + /** Parameter */ + static final String PARAM_VIEW = "view"; + /** Parameter */ + static final String VIEW_INIT = "init"; + /** Parameter */ + static final String VIEW_NOTIFICATIONS = "notifications"; + /** Parameter */ + static final String VIEW_OTHER = "other"; + /** Deploable module types */ + static final String JAR = "jar"; + /** Deploable module types */ + static final String WAR = "war"; + /** Deploable module types */ + static final String RAR = "rar"; + /** Deploable module types */ + static final String EAR = "ear"; + /** + * Listener object + */ + private MyListener mListener = null; + + // ---------------------------------------------------------- Public methods + + /** + * Initialize the servlet. + * @param pConfig See HttpServlet + * @throws ServletException + */ + public void init(ServletConfig pConfig) throws ServletException { + super.init(pConfig); + // Initialize variables + mListener = null; + } + + // ---------------------------------------------------------- Protected + // methods + + /** + * Response to the GET request. + * @param pRequest See HttpServlet + * @param pResponse See HttpServlet + * @throws IOException + * @throws ServletException + */ + protected void doGet(HttpServletRequest pRequest, HttpServletResponse pResponse) throws IOException, + ServletException { + dispatch(pRequest, pResponse); + } + + /** + * Response to the POST request. + * @param pRequest See HttpServlet + * @param pResponse See HttpServlet + * @throws IOException + * @throws ServletException + */ + protected void doPost(HttpServletRequest pRequest, HttpServletResponse pResponse) throws IOException, + ServletException { + dispatch(pRequest, pResponse); + } + + /** + * Dispatch the response. + * @param pRequest Request + * @param pResponse Response + * @throws IOException + */ + protected void dispatch(HttpServletRequest pRequest, HttpServletResponse pResponse) throws IOException { + + pResponse.setContentType("text/html"); + PrintWriter out = pResponse.getWriter(); + + // Get parameters + String sParamDomain = pRequest.getParameter(PARAM_DOMAIN); + String sParamView = pRequest.getParameter(PARAM_VIEW); + + // Dispatching + if ((sParamDomain == null) || (sParamDomain.length() == 0)) { + doViewError("Parameter domain not found", pRequest, out); + } else if ((sParamView == null) || (sParamView.length() == 0) || VIEW_INIT.equals(sParamView)) { + doViewInit(sParamDomain, pRequest, out); + } else if (VIEW_NOTIFICATIONS.equals(sParamView)) { + doViewNotifications(out); + } else if (VIEW_OTHER.equals(sParamView)) { + doViewOther(sParamDomain, pRequest, out); + } else { + doViewError("Unknown View", pRequest, out); + } + + } + + + /** + * Footer navigation. + * @param pDomainName Name of domain + * @param pRequest Http request + * @param pOut Printer + * @param pPrevious Previous view + * @param pNext Next view + */ + protected void printNavigationFooter(String pDomainName, HttpServletRequest pRequest, PrintWriter pOut, + String pPrevious, String pNext) { + + // index + String sViewIndex = pRequest.getContextPath(); + // Notifications + String sViewNotifications = pRequest.getRequestURI() + "?" + PARAM_DOMAIN + "=" + pDomainName + "&" + + PARAM_VIEW + "=" + VIEW_NOTIFICATIONS; + // Previous View + String sPrevView = null; + if (pPrevious != null) { + sPrevView = pRequest.getRequestURI() + "?" + PARAM_DOMAIN + "=" + pDomainName + "&" + PARAM_VIEW + "=" + + pPrevious; + } + // Next View + String sNextView = null; + if (pNext != null) { + sNextView = pRequest.getRequestURI() + "?" + PARAM_DOMAIN + "=" + pDomainName + "&" + PARAM_VIEW + "=" + + pNext; + } + + // Display + pOut.print(""); + pOut.print(""); + pOut.print(""); + pOut.print(""); + if (sPrevView != null) { + pOut.println(""); + } + if (sNextView != null) { + pOut.println(""); + } + pOut.println("
    Index Notifications Previous Next
    "); + // Footer + printFooter(pOut); + } + + /** + * View init MEJB and access to MBEans J2EEDomain and J2EEServer. + * @param pDomainName Name of domain to access + * @param pRequest Http request + * @param pOut Printer + */ + protected void doViewInit(String pDomainName, HttpServletRequest pRequest, PrintWriter pOut) { + + // Header + //printHeader(pOut, APP_TITLE_LARGE, "Init"); + + // ----------------------------- + // Get initial context + // ----------------------------- + pOut.println("

    Initial context

    "); + pOut.println("
      "); + Context initialContext = null; + try { + initialContext = new InitialContext(); + pOut.println("
    • Initial context OK
    • "); + } catch (Exception e) { + pOut.print("
    • Cannot get initial context for JNDI: "); + pOut.println(e + "
    • "); + pOut.println("
    "); + return; + } + pOut.println("
    "); + + // ----------------------------- + // Access to the MEJB + // ----------------------------- + pOut.println("

    Create MEJB

    "); + pOut.println("
      "); + + // Connecting to the MEJB home through JNDI + ManagementHome mgmtHome = null; + try { + mgmtHome = (ManagementHome) PortableRemoteObject.narrow(initialContext.lookup("java:comp/env/ejb/mgmt/MEJB"), + ManagementHome.class); + } catch (Exception e) { + pOut.println("
    • Cannot lookup java:comp/env/ejb/mgmt/MEJB: " + e + "
    • "); + pOut.println("
    "); + return; + } + + // Management bean creation + Management mgmt = null; + + try { + mgmt = mgmtHome.create(); + pOut.println("
  • MEJB created
  • "); + } catch (Exception e) { + pOut.println("
  • Cannot create MEJB: " + e + "
  • "); + return; + } + pOut.println("
    "); + + pOut.println("

    Create DomainMEJB

    "); + pOut.println("
      "); + + DomainManagementHome domainMgmtHome = null; + try { + domainMgmtHome = (DomainManagementHome) PortableRemoteObject.narrow(initialContext.lookup("java:comp/env/ejb/mgmt/DomainMEJB"), + DomainManagementHome.class); + } catch (Exception e) { + pOut.println("
    • Cannot lookup java:comp/env/ejb/mgmt/DomainMEJB: " + e + "
    • "); + pOut.println("
    "); + //return; + } + + // Domain management bean creation + DomainManagement dmgmt = null; + + try { + dmgmt = domainMgmtHome.create(); + pOut.println("
  • DomainMEJB created
  • "); + } catch (Exception e) { + pOut.println("
  • Cannot create DomainMEJB: " + e + "
  • "); + return; + } + pOut.println("
    "); + + // ------------------------------ + // Access to the J2EEDomain MBean + // ------------------------------ + + ObjectName onDomain = accessJ2EEDomain(pDomainName, mgmt, pOut); + if (onDomain == null) { + return; + } + + boolean master = checkIfMaster(onDomain, mgmt, pOut); + + // ----------------------------------------------------- + // Check for J2EEServer MBeans in the current J2EEDomain + // ----------------------------------------------------- + ObjectName onServer = accessJ2EEServer(onDomain, mgmt, pOut); + if (onServer == null) { + return; + } + + // ------------------------------ + // Test domain deployment + // ------------------------------ + if (master) { + pOut.println("

    Try to manage the current domain: deploy/undeploy on all servers in the domain

    "); + pOut.println("
      "); + pOut.println("
    • Use the J2EEDomain object name: \"" + onDomain.toString() + "\"
    • "); + String[] serverNames = null; + try { + serverNames = (String[]) mgmt.getAttribute(onDomain, "serverNames"); + } catch (Exception e) { + pOut.println("
    • Can't get serverNames attribute: " + e + "
    • "); + } + if (serverNames.length > 1) { + String fileName = null; + // Use deployJar, unDeployJar + // (suppose sb.jar was installed under JONAS_BASE/ejbjars directory) + fileName = "sb.jar"; + deployModuleWithTarget(JAR, onDomain, serverNames, mgmt, fileName, pOut); + + // Use deployEar, unDeployEar + // (suppose earsample.ear was installed under JONAS_BASE/apps directory) + fileName = "earsample.ear"; + deployModuleWithTarget(EAR, onDomain, serverNames, mgmt, fileName, pOut); + } else { + pOut.println("
    • Can't find server names in this domain
    • "); + } + pOut.println("

    "); + } else { + // ------------------------------ + // Test current server management + // ------------------------------ + pOut.println("

    Try to manage the current server

    "); + pOut.println("
      "); + pOut.println("
    • Using the J2EEServer object name: \"" + onServer.toString() + "\"
    • "); + + // Use deployJar, unDeployJar, isJarDeployed management opearations + // (suppose sb.jar was installed under JONAS_BASE/ejbjars directory) + String jarFileName = "sb.jar"; + deployJarModule(onServer, mgmt, jarFileName, pOut); + + // Use deployEar, unDeployEar, isEarDeployed management opearations + // (suppose earsample.ear was installed under JONAS_BASE/apps directory) + String earFileName = "earsample.ear"; + deployEarModule(onServer, mgmt, earFileName, pOut); + + // (suppose autoload/earsample.ear was installed under JONAS_BASE/apps directory) + earFileName = "autoload/earsample.ear"; + deployEarModule(onServer, mgmt, earFileName, pOut); + + // Use deployRar, unDeployRar, isRarDeployed + // (suppose JDBC connection rar files installed under JONAS_BASE/rars directory) + /* + String rarFileName = "autoload/JOnAS_jdbcCP.rar"; + deployRarModule(onServer, mgmt, rarFileName, pOut); + */ + pOut.println("

    "); + } + // ----------------------------- + // Test Event Listener support + // ----------------------------- + + pOut.println("

    Register an event listener

    "); + pOut.println("
      "); + if (mListener == null) { + mListener = new MyListener(); + pOut.println("
    • MyListener created
    • "); + } + + // Get the ListenerRegistration object + try { + ListenerRegistration lr = mgmt.getListenerRegistry(); + if (lr != null) { + pOut.println("
    • Add listener on J2EEServer (" + onServer.toString() + ")
    • "); + String sHandler = "MEJBTester"; + lr.addNotificationListener(onServer, mListener, null, sHandler); + pOut.println("
    • Notification Listener added
    • "); + String sViewNotifications = pRequest.getRequestURI() + "?" + PARAM_DOMAIN + "=" + pDomainName + "&" + + PARAM_VIEW + "=" + VIEW_NOTIFICATIONS; + pOut.println("See list of notifications"); + pOut.println("
    "); + } else { + pOut.println("
  • Can't add remote listener for the moment
  • "); + pOut.println(""); + } + } catch (Exception e) { + pOut.println("
  • Can't add notification listener on " + onServer.toString() + " : " + e + "
  • "); + } + + pOut.println("

    Application is OK

    "); + + // Footer + printNavigationFooter(pDomainName, pRequest, pOut, null, VIEW_OTHER); + } + + /** + * Header. + * @param pOut Printer + * @param pTitle Title to display + * @param pSubTitle Subtitle to display or null if not + */ + protected void printHeaderAutoRefresh(PrintWriter pOut, String pTitle, String pSubTitle) { + + pOut.println(""); + pOut.println(""); + pOut.println("" + pTitle + ""); + pOut.println(""); + pOut.println(""); + pOut.println(""); + printHeaderTitle(pOut, pTitle, pSubTitle); + } + /** + * View notifications. + * @param pOut Printer + */ + protected void doViewNotifications(PrintWriter pOut) { + + // Header + printHeaderAutoRefresh(pOut, APP_TITLE, "Notifications"); + pOut.println("

    List of notifications

    "); + + // Verify listener + if (mListener == null) { + pOut.println("Listener not found !"); + } else { + // Display notifications + List list = mListener.getlistNotifications(); + if (list.size() > 0) { + pOut.println("
      "); + for (int i = 0; i < list.size(); i++) { + pOut.println("
    1. " + list.get(i) + "
    2. "); + } + pOut.println("
    "); + } else { + pOut.println("No notifications, the list is empty"); + } + } + + // Footer + printFooter(pOut); + } + + /** + * View example. + * @param pDomainName Name of domain to access + * @param pRequest Http request + * @param pOut Printer + */ + protected void doViewOther(String pDomainName, HttpServletRequest pRequest, PrintWriter pOut) { + + // Header + printHeader(pOut, APP_TITLE, "Other"); + + pOut.println("

    Other

    "); + + // Footer + printNavigationFooter(pDomainName, pRequest, pOut, VIEW_INIT, null); + } + + /** + * Create J2EEDomain MBean's ObjectName and test if MBean registered + * @param pDomainName the name provided by the user + * @param mgmt MEJB + * @param pOut output stream + * @return true if management operation succeeded + */ + private ObjectName accessJ2EEDomain(String pDomainName, Management mgmt, PrintWriter pOut) { + ObjectName onDomain = null; + pOut.println("

    Access the J2EEDomain MBean

    "); + pOut.println("
      "); + + // Get the J2EEDomain MBean's ObjectName + try { + String name = pDomainName + ":j2eeType=J2EEDomain,name=" + pDomainName; + onDomain = ObjectName.getInstance(name); + pOut.println("
    • J2EEDomain object name created: \"" + name.toString() + "\"
    • "); + } catch (Exception e) { + pOut.println("
    • Cannot create object name for J2EEDomain managed object: " + e + "
    • "); + pOut.println("
    "); + return null; + } + // Check that the J2EEDomain MBean registered + try { + boolean exists = mgmt.isRegistered(onDomain); + if (exists) { + pOut.println("
  • Found this J2EEDomain MBean in the current MBean server
  • "); + } else { + pOut.println("
  • Can't find this J2EEDomain MBean in the current MBean server
  • "); + pOut.println(""); + return null; + } + } catch (Exception e) { + pOut.println("
  • Error when using this J2EEDomain MBean: " + e + "
  • "); + pOut.println(""); + return null; + } + return onDomain; + } + + /** + * + * @param onDomain J2EEDomain MBean ObjectName + * @param mgmt Management EJB + * @param pOut output stream + * @return true if the current server is a master + */ + private boolean checkIfMaster(ObjectName onDomain, Management mgmt, PrintWriter pOut) { + try { + Boolean master = (Boolean) mgmt.getAttribute(onDomain, "master"); + if (master.booleanValue()) { + pOut.println("
  • The current server is a management master
  • "); + } + pOut.println(""); + return master.booleanValue(); + } catch (Exception e) { + pOut.println("
  • Error when using this J2EEDomain MBean: " + e + "
  • "); + } + pOut.println(""); + return false; + } + + /** + * Get a registered J2EEServer MBean + * @param onDomain J2EEDomain MBean's ObjectName + * @param mgmt MEJB + * @param pOut output stream + * @return true if management operation succeeded + */ + private ObjectName accessJ2EEServer(ObjectName onDomain, Management mgmt, PrintWriter pOut) { + pOut.println("

    Access the J2EEServer MBeans

    "); + pOut.println("
      "); + ObjectName onServer = null; + String[] listServers = null; + try { + listServers = (String[]) mgmt.getAttribute(onDomain, "servers"); + } catch (Exception e) { + pOut.println("
    • Cant' access the " + onDomain + " MBean's servers attribute
    • "); + pOut.println("

    "); + return null; + } + int nbServers = listServers.length; + if (nbServers == 0) { + pOut.println("
  • No J2EEServer MBeans in the " + onDomain + " MBean's servers list (problem with domain management !!)
  • "); + pOut.println("
    "); + return null; + } else { + if (nbServers == 1) { + String serverOn = (String) listServers[0]; + try { + onServer = ObjectName.getInstance(serverOn); + if (mgmt.isRegistered(onServer)) { + pOut.println("
  • Found one J2EEServer MBean registered in the current MBean server. Its OBJECT_NAME is: \"" + serverOn + "\"
  • "); + pOut.println("
    "); + return onServer; + } else { + pOut.println("
  • Can't find the J2EEServer MBean having OBJECT_NAME: " + serverOn + " in the current MBean server
  • "); + pOut.println("
    "); + return null; + } + } catch (Exception e) { + pOut.println("
  • Error witht OBJECT_NAME " + serverOn + ": " + e + "
  • "); + pOut.println("
    "); + return null; + } + } else { + pOut.println("
  • List of J2EEServer MBeans in the \"" + onDomain + "\" MBean's servers list:
  • "); + pOut.println("
      "); + for (int i = 0; i < nbServers; i++) { + String serverOn = listServers[i]; + ObjectName on = null; + try { + on = ObjectName.getInstance(serverOn); + } catch (MalformedObjectNameException e) { + pOut.print("
    1. Error witht OBJECT_NAME " + serverOn + ": " + e + "
    2. "); + continue; + } + pOut.print("
    3. \"" + serverOn + "\". "); + boolean isRegisterdServer = false; + try { + isRegisterdServer = mgmt.isRegistered(on); + } catch (RemoteException e) { + pOut.println("
        "); + pOut.println("
      • Error witht OBJECT_NAME " + serverOn + ": " + e + "
      • "); + pOut.println("
      "); + pOut.println("
    4. "); + continue; + } + if (isRegisterdServer) { + pOut.print("This MBean is registered in the current MBean server. It should correspond to the current server."); + pOut.println(""); + onServer = on; + } else { + pOut.println("This MBean is not registered in the current MBean server. It could correspond to a remote server."); + pOut.println(""); + pOut.println("
        "); + String name = on.getKeyProperty("name"); + String[] signature = {"java.lang.String"}; + String[] params = new String[1]; + params[0] = name; + String[] urls = null; + try { + urls = (String[]) mgmt.invoke(onDomain, "getConnectorServerURLs", params, signature); + } catch (Exception e) { + pOut.println("
      • Could not found a connector server URL for server " + name + ".
      • "); + pOut.println("
      "); + pOut.println(""); + continue; + } + if (urls == null) { + pOut.println("
    5. Could not found a connector server URL for server " + name + "
    6. "); + pOut.println(""); + pOut.println(""); + continue; + } + for (int j = 0; j < urls.length; j++) { + String url = urls[j]; + pOut.print("
    7. Try to connect to server " + name + " using connector server URL: " + url + "
    8. "); + MBeanServerConnection connection = createConnection(url); + if (connection != null) { + // Use connection directly