95-702 Organizational Communications and Distributed Object Technologies Installing and Testing Course Software 1. Make a directory for downloads. Call it c:\downloads. 2. Download the following files from www.andrew.cmu.edu/~mm6/95-702/downloads and place them in your c:\download directory: jdk-1_5_0_08-windows-i586-p (JDK and JRE from Sun) apache-tomcat-5.5.17.exe (Apache Tomcat Install) eclipse-SDK-3.2-win32.zip (Eclipse IDE) tomcatPluginV31 (Eclipse plugin from Sysdeo) Xerces-J-bin.2.8.0.zip (Xerces XML Parser from Apache) 3. Expand the Java to C:\Java Within this directory you should have C:\Java\jdk1.5.0_08 Note from TA: After the JDK and JRE have been installed (size: 118M), there may be a Japanese pop-up window, which allows you to install some Japanese support modules. You can choose to skip it. Expand Tomcat to C:\Tomcat 5.5 Within this directory you should have C:\Tomcat 5.5\bin, C:\Tomcat 5.5\common, etc. Note from TA: I suggest that we dont put any space in the install path of the web server. It is recommended to replace C:\Tomcat 5.5 with C:\Tomcat_5.5. Because there is a bug in the JDK which makes RMI fail if Tomcat is installed in directory containing spaces (e.g. C:\Program Files\Apache Group\Jakarta Tomcat 5.0). I met this issue before, which caused a JNDI lookup failure when I tried to connect to a JMS queue in JBoss. And it took me sometime to figure out this was because of a JDK bug actually. Include examples and webapps when prompted. Set Username and Password and remember these. Set the port to 6502 (to stay away from Oracle's Tomcat) Select the installed JRE that is under the new JDK that we just installed. Don't use any other JRE. Expand eclipse to C:\eclipse Within this directory you should have C:\eclipse\eclipse.exe, etc. Expand plugin to C:\EclipseTomcatPlugin Within this directory you should have C:\EclipseTomcatPlugin\com.sysdeo.eclipse.tomcat_3.1.0 Copy the entire directory com.sysdeo.eclipse.tomcat_3.1.0 to C:\eclipse\plugins. Expand Xerces to C:\Xerces Within this directory you should have xerces-2_8_0/xercesImpl.jar 4. Use Start/Control Panel/System/Advanced/Environment Variables/System Variables/New to set the following: JAVA_HOME C:\Java\jdk1.5.0_08 JRE_HOME C:\Java\jdk1.5.0_08\jre Path C:\Java\jdk1.5.0_08\jre\bin;C:\Java\jdk1.5.0_08\bin; {everything already there follows here} 5. Make a shortcut to eclipse and place it on your desktop. Right click on shortcut properties and set target to C:\eclipse\eclipse.exe -vm C:\Java\jdk1.5.0_08\jre\bin\javaw 6. Testing C:\>java -version java version "1.5.0_08" C:\>javac -version javac 1.5.0_08 C:\>echo %JAVA_HOME% C:\Java\jdk1.5.0_08 C:\>echo %JRE_HOME% C:\Java\jdk1.5.0_08\jre 7. Double click eclipse Choose a workspace like C:\95-702\homework Choose workbench Select Windows/Preferences/Tomcat and select * Version 5.0 and set Tomcat home to C:\Tomcat 5.5 8. Testing Start eclipse Select the little cat (Tomcat) without the x Note from TA: If you have chosen to start Tomcat after you finished Tomcat installation in step 3, here you may get an error from Eclipse IDE saying the Tomcat service has been started already. You can stop the Tomcat service outside of Eclipse IDE and try to restart it inside Eclipse, to experience the convenience of integration of Eclipse and Tomcat. Visit Tomcat with your browser at http://localhost:6502 Run the servlets and JSP's under Examples Select Tomcat Manager and see if your User Name and Password work 9. Publishing a Java Server Page Double click eclipse Choose a workspace like C:\95-702\homework Choose workbench Select Windows/Preferences/Tomcat and select * Version 5.0 and set Tomcat home to C:\Tomcat 5.5 and select OK Choose File/New/Other/Java/Tomcat Project/Next Project Name CoolJSP Finish On left pane expand the CoolJSP project (it should contain WEB-INF) On left pane select CoolJSP and Right Click and select new file. File Name MyCoolPage.jsp Finish Enter this document: <% java.util.Date d = new java.util.Date(); %> Today is <%= d.toString() %> Click the little disk to save everything. Start Tomcat with the little cat. Use a browser to visit http://localhost:6502/CoolJSP/MyCoolPage.jsp 10. Another tutorial covering this same topic is at http://www-128.ibm.com/developerworks/library/os-ectom/ 11. Publishing a servlet Double click eclipse Choose a workspace like C:\95-702\ServletExample Choose workbench Select Windows/Preferences/Tomcat and select * Version 5.0 and set Tomcat home to C:\Tomcat 5.5 and select OK Choose File/New/Other/Java/Tomcat Project/Next Project Name ANewApp Finish On left pane expand the ANewApp project (it should contain WEB-INF) On left pane select ANewApp and Right Click and select new file. File Name index.jsp Finish Enter this document: Introductions
Please enter name

Click the little disk to save everything. Select ANewApp and right click Select new/class and give it the name HandleForm Enter this java servlet // HandleForm.java // An introductory servlet import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class HandleForm extends HttpServlet{ public void doGet(HttpServletRequest req, HttpServletResponse response) throws ServletException, IOException { String personName = req.getParameter("personName"); response.setContentType("text/html"); PrintWriter out = response.getWriter(); String docType = "\n"; out.println(docType + "\n" + "Hi" + personName + "\n" + "\n" + "

Hi"+ personName + "

\n" + ""); } } In the left pane, select the WEB-INF folder Right click WEB-INF and select new file Enter file name web.xml and Finish Enter this web.xml file. This file associates the name ProcessForm with the servlet HandleForm. TestServlet HandleForm TestServlet /ProcessForm/* Start Tomcat with the little cat. Use a browser to visit http://localhost:6502/ANewApp/index.jsp Enter your name and hit submit. The servlet should execute. 12. Using the XML parser In Eclipse, select Window/Preferences/Tomcat/JVM Settings Add a classpath "(before generated) " C:\Xerces\xerces-2_8_0\xercesImpl.jar 13. For stand alone XML applications you may need to include the parser in XercesImpl.jar into your Eclipse classpath. File/New/Other/Java Project/ Next/UsingXerces File/New/Class/NotifyStr Copy NotifyStr.java into editor To place the URL on the command line: Run/Arguments enter URL in edit window To place XercesImp.jar on the classpath Window/Preferences/Java/Build Path/classpath Variables Assign Xerces_Home to XercesImpl.jar path. Select project name/Project/Properties/Java Build Path/Libraries/Add Variable and select Xerces_Home and path // ************************************************************* // NotifyStr.java // Adapted from XML and Java by Maruyama, Tamura and Uramoto import java.io.*; import org.xml.sax.*; import org.xml.sax.helpers.*; public class NotifyStr extends DefaultHandler { public static void main (String argv []) throws IOException, SAXException { if (argv.length != 1) { System.err.println ("Usage: java NotifyStr filename.xml or URL"); System.exit (1); } XMLReader reader = XMLReaderFactory.createXMLReader( "org.apache.xerces.parsers.SAXParser"); InputSource inputSource = new InputSource(argv[0]); reader.setContentHandler(new NotifyStr()); reader.parse(inputSource); System.exit (0); } public NotifyStr() {} public void startElement(String namespaceURI, String localName, String qName, Attributes aMap) throws SAXException { System.out.println(namespaceURI); System.out.println(localName); } public void characters(char[] ch, int start, int length) throws SAXException { // build String from char array String dataFound = new String(ch,start,length); System.out.println("characters called:" + dataFound); } } 14. To submit homework Select Project/File/Export/General/Archive File/Next/Name blackboard site/tools/Digital Dropbox/ send the zip file to blackboard 15. Using Apache Axis for web services a) Create a directory called c:\bats and place this path in your path variable. The path in the path variable is checked evry time you run a program from the DOS command line. We will be placing commands in batch files (with a .bat extension.) b) Download axis-bin-1_4.zip from www.andrew.cmu.edu/~mm6/95-702/downloads Unzip this file to a directory. I Unzipped this file to C:\ My Axis is now located here: C:\axis-1_4 Copy the directory C:\axis-1_4\webapps\axis to C:\Tomcat 5.5\webapps A directory named axis us now under my (Tomcat) webapps directory c) Download Apache Ant apache-ant-1.6.5-bin.zip from www.andrew.cmu.edu/~mm6/95-702/downloads Unzip this file to a directory. I Unzipped this file to C:\ My ant binaries are now located here: C:\ant\apache-ant-1.6.5\bin Add this path to the front of your path variable. See below on how to do this from Windows. d) Download Sun's jaf-1_1-fr.zip from www.andrew.cmu.edu/~mm6/95-702/downloads Unzip this file to a directory. I Unzipped this file to C:\ My java activation framework is now located here: C:\jaf\jaf-1.1 Copy C:\jaf\jaf-1.1\activation.jar to C:\Tomcat 5.5\common\lib Also copy C:\jaf\jaf-1.1\activation.jar to C:\axis-1_4\lib e) Download Sun's javamail-1_4.zip from www.andrew.cmu.edu/~mm6/95-702/downloads Unzip this file to a directory. I Unzipped this file to C:\javamail-1_4 My java mail api is now located here: C:\javamail-1_4\javamail-1.4 Copy C:\javamail-1_4\javamail-1.4\mail.jar to C:\Tomcat 5.5\common\lib Also copy C:\javamail-1_4\javamail-1.4\mail.jar to C:\axis-1_4\lib f) We will also need to use the wsdl2java program. This program is executed like this: java org.apache.axis.wsdl.WSDL2Java (WSDL-file-URL) I have a batch file called wsdl2java.bat (in c:\bats) with the contents shown: java org.apache.axis.wsdl.WSDL2Java %1 g) Set your environment variables: Use Start/Control Panel/System/Advanced/Environment Variables/System Variables/New or edit to set the following: JAVA_HOME C:\Java\jdk1.5.0_08 JRE_HOME C:\Java\jdk1.5.0_08\jre Path C:\ant\apache-ant-1.6.5\bin;{everything already there follows the semicolon} AXIS_HOME C:\axis-1_4 ANT_HOME C:\ant\apache-ant-1.6.5 AXISCLASSPATH C:\axis-1_4\lib\axis.jar;C:\axis-1_4\lib\axis-ant.jar; C:\axis-1_4\lib\commons-discovery-0.2.jar; C:\axis-1_4\lib\commons-logging-1.0.4.jar; C:\axis-1_4\lib\jaxrpc.jar; C:\axis-1_4\lib\log4j-1.2.8.jar; C:\axis-1_4\lib\saaj.jar; C:\axis-1_4\lib\wsdl4j-1.5.1.jar; C:\axis-1_4\lib\mail.jar; C:\axis-1_4\lib\activation.jar CLASSPATH %AXISCLASSPATH%;. h) Add a file to your bats directory called adminclient.bat. It should contain the single line: java org.apache.axis.client.AdminClient -lhttp://localhost:6502/axis/services/AdminService deploy.wsdd i) General Testing Stop the server and run Tomcat from the start menu. Visit Tomcat with a browser. My copy runs on port 6502. http:\\localhost:6502 See if axis is available. Visit http:\\localhost:6502\axis Click the Validate link for further testing If the hapiness page complains about security don't worry. Click the list services link. There should be two services: AdminService and Version One nice test to run is by pointing your browser at http://localhost:6502/axis/services/Version?method=getVersion You should see an xml document when you view the source. Type the command wsdl2java at the DOS prompt. You should see the command's help file displayed. Perhaps the best documentation is located at file:///C:/axis-1_4/docs/install.html j) Testing a web service. a) Create a file called Calculator.java public class Calculator { public int add(int i1, int i2) { return i1 + i2; } public int subtract(int i1, int i2) { return i1 - i2; } } b) compile the service javac Calculator.java c) Create a file called deploy.wsdd and place it in the same directory as Calculator.class. This is a deployment descriptor. Within this file you can modify the scope of your service. It defaults to "request" scope. But if you write you will have a session scope object. "Application" scope is also available to implement a singleton. d) Copy the class file to Tomcat copy Calculator.class C:\"Tomcat 5.5"\webapps\axis\WEB-INF\classes e) Start Tomcat f) Run the adminclient tool to notify axis that we want the calculator class installed. adminclient deploy.wsdd g) Testing Visit http://localhost:6502/axis/servlet/AxisServlet If all went well you should see a Calculator service but with the name "MyService". It should have a WSDL document and should advertise the add and subtract methods. 16. Writing and running a client. a) create a new directory for client side code. mkdir client b) Using a browser, get the WSDL document for the MyService web service and place it in your client directory. c) From the command line, run the command wsdl2java MyService.wsdl (the Microsoft version, wsdl.exe, insists on a ".wsdl" file extension for the wsdl document.) d) Examine your client directory. You should now have a new subdirectory called localhost. e) Save the following Java program in the client directory. Note that it imports the localhost package. f) Make sure Tomcat is running, Axis is running and the web service has been copied and deployed. g) Use javac MyIntegerClient.java h) Use java MyInteger i) The output should be 56 k) Note the comment in the code for those cases where you need to maintain state with an object whose scope is "session". // Running a simple client import localhost.axis.services.MyService.*; import java.math.*; public class MyIntegerClient{ public static void main(String[] args) throws Exception { CalculatorServiceLocator loc = new CalculatorServiceLocator(); // if working with a session loc.setMaintainSession(true); Calculator x = loc.getMyService(); int y = 22; int z = 34; y = x.add(y,z); System.out.println(y); } } 17. Install TcpMon to watch SOAP traffic a) TCPMon may be found at www.andrew.cmu.edu/~mm6/95-702/downloads/tcpmon-1.0-bin.zip I downloaded this file and de-compressed it to C:\tcpmon-1.0-bin. I created a new DOS batch file called tcpmon.bat and placed it in my c:\bats directory. This directory is in my path variable. The content of this file is java -cp C:\tcpmon-1.0-bin\tcpmon-1.0-bin\build\tcpmon-1.0.jar org.apache.ws.commons.tcpmon.TCPMon There is a very nice tutorial that comes with this install. b) Testing Enter tcpmon at the DOS prompt