1 / 14

Setting Up

Setting Up. First, install tomcat and axis as described elsewhere. Then copy Tomcat into a second folder. I’ve named mine jakarta-tomcat-server and jakarta-tomcat-client. I’ll refer to these as the “Client” and the “Server” folders afterwards.

roweg
Download Presentation

Setting Up

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Setting Up • First, install tomcat and axis as described elsewhere. • Then copy Tomcat into a second folder. • I’ve named mine jakarta-tomcat-server and jakarta-tomcat-client. • I’ll refer to these as the “Client” and the “Server” folders afterwards. • Edit the Client’s conf/server.xml to use the ports 9005, 9090, and 9009.

  2. Starting Servers • Go into both the Client’s and the Server’s bin folder and start both servers. • I will assume the Client runs on 9090 and the server runs on 8080. • Open 2 browsers and point one at localhost:8080 and the other at localhost:9090. You should see Tomcat splash screens in both cases.

  3. Deploy Service • Deploy your web service onto the Server. • Verify that it works. • I’m using the Echo Service as an example, so it is deployed as a JWS on http://localhost:8080/. • I have a file called echoService.jws, and I can view the wsdl at • http://localhost:8080/axis/echoService.jws?wsdl

  4. Save WSDL • After viewing the WSDL file from your browser, save it into your Client folder. • Not required to be in this folder, but a convenient place to put it. • Open the WSDL file with WordPad and make sure that it is correct • That is, you saved it as WSDL, not HTML • You may also have to rename the file to get the extension correct. • Mine saved as echoService.jws, so I renamed it to echoService.wsdl.

  5. Compile Client Stubs • As with all java programs, you MUST get the classpath correct. • This is almost always the cause of any compilation errors. • The simplest thing to do is put all of the axis/WEB-INF/lib jars into your classpath. • If you work in the jakarta-tomcat-client folder, you can use the following command C:\Documents and Settings\Marlon Pierce\Desktop\jakarta-tomcat-5.0.19\jakarta-to mcat-client>java -classpath .\webapps\axis\WEB-INF\lib\axis.jar;.\webapps\axis\W EB-INF\lib\log4j-1.2.8.jar;.\webapps\axis\WEB-INF\lib\commons-discovery.jar;.\we bapps\axis\WEB-INF\lib\commons-logging.jar;.\webapps\axis\WEBINF\lib\wsdl4j.jar ;.\webapps\axis\WEB-INF\lib\activation.jar;.\webapps\axis\WEB-INF\lib\saaj.jar;. \webapps\axis\WEB-INF\lib\axis-ant.jar;.\webapps\axis\WEB-INF\lib\jaxrpc.jar org .apache.axis.wsdl.WSDL2Java echoService.wsdl

  6. Some Common Errors • If you mistype WSDL2Java, you will get • Exception in thread “main” java.lang.NoClassDefFoundError: org.apache.axis.WSDL.WSDL2java • Or similar. • If you have a typo in your classpath, you will get • Java.lang.NoClassDefFoundError: {some class} • Both of these can be corrected by checking the classpath and the command.

  7. Success • If you have successfully created your stubs, they will be located in the folder • Jakarta-tomcat-client/localhost/axis/echoService_jws • You should see four files there. • WSDL2Java has options that can change this default location.

  8. Now Compile the Java Stubs • First, look at the generated code. • You will notice the 4 stub classes all have package name that matches its directory. • You need to compile the stub classes into Client’s WEB-INF/classes directory. • You need to use the same classpath as before (all the jars in WEB-INF/lib). • But also you need WEB-INF/classes in your classpath now, too. • Some of the stubs depend upon other stubs.

  9. The Full Javac Command C:> javac -d webapps\axis\WEB-INF\classes -classpath webapps\axis\WEB-INF\classes;.\webapps\axis\WEB-INF\lib\axis.jar;.\webapps\axis\WEB-INF\lib\log4j-1.2.8.jar;.\webapps\axis\WEB-INF\lib\commons-discovery.jar;.\webapps\axis\WEB-INF\lib\commons-logging.jar;.\webapps\axis\WEB-INF\lib\wsdl4j.jar;.\webapps\axis\WEB-INF\lib\activation.jar;.\webapps\axis\WEB-INF\lib\saaj.jar;.\webapps\axis\WEB-INF\lib\axis-ant.jar; .\webapps\axis\WEB-INF\lib\jaxrpc.jar localhost/axis/echoService_jws/*.java

  10. Note the -d option • This tells the compiler where to put your classes. • I’ve specified the classes directory. • The classes will be created in • axis/WEB-INF/classes/localhost/axis/echoService_jws/ • Check the above folder in the Client tomcat to verify. • You must verify this before proceeding.

  11. Designing the JSP • First, shutdown and restart the Client tomcat host. • Easiest way to force it to load your new classes. • Next, create a new file, MyClient.jsp • Name doesn’t matter, but should have .jsp extension • MUST put this in jakarta-tomcat-client’s webapp/axis directory. • It may also be in any subfolder of axis except WEB-INF. • It must be in the axis folder so that it can access all of the axis jars and the stub classes you just compiled.

  12. MyClient.jsp <%@ page import="localhost.axis.echoService_jws.*"%> <%@ page import="java.net.URL"%> <% String host="http://localhost:8080/axis/echoService.jws"; EchoService myEcho=new EchoServiceServiceLocator().getechoService(new URL(host)); String message=myEcho.echo("Hello World"); %> <html><body> The echo message is <%=message%> </body></html>

  13. Notes • We had to import the packages of the client stubs that we created. • We also needed java.net.URL. • The client side steps are • First, create a locator instance for your service (EchoServiceServiceLocator). • Second, create the local proxy class instance of EchoService, myEcho. • Now use myEcho as if it were local. It has all the methods (wsdl operations) of your service.

  14. Final Comments • Why did we go to so much trouble? • Now you can run the service independently from the client. • To test, zip up your client and give it to someone else. • Have them invoke your service. • You must run your Server tomcat. • Your victim should modify localhost:8080 to your.real.machine.name:8080.

More Related