Web Services using Tomcat and Eclipse Nauman [email protected] Security Engineering Research Group Institute of Management Sciences Peshawar, Pakistan http://recluze.wordpress.com http://serg.imsciences.edu.pk

Assumptions: 1. 2. 3. 4.

You’re using Windows. If you’re using Linux, you don’t need this tutorial. You can find enough stuff on the Internet to get going. You have downloaded Apache Tomcat (http://jakarta.apache.org), Axis (http://ws.apache.org/axis) and Eclipse Europa (http://www.eclipse.org) You’ve installed the java development kit (http://java.sun.com) You’re familiar with Java language and the Windows operating system.

Part I: Setting up the server 1. 2. 3. 4.

To use web services with apache, first you need to install Tomcat. We’ll assume you installed it in c:\tomcat. We’ll use for this directory. Extract the Axis binary archive to . sYou should get axis folder in \webapps\axis Copy tools.jar from \lib to /common/lib Set the following System Environment Variables (from Control Panel -> System -> Advanced -> Evironment Variables): AXIS_HOME: c:\tomcat AXIS_LIB: %AXIS_HOME%\lib AXISCLASSPATH: %AXIS_LIB%\axis.jar;%AXIS_LIB%\commonsdiscovery.jar;%AXIS_LIB%\commonslogging.jar;%AXIS_LIB%\jaxrpc.jar;%AXIS_LIB%\saaj.jar;%AXIS_LIB%\log4j1.2.8.jar;%AXIS_LIB%\xml-apis.jar;%AXIS_LIB%\xercesImpl.jar

(Also make sure your CLASSPATH variable is set to include java bin and lib directories) CLASSPATH: .;c:\Program Files\Java\jdk1.6.0_02\bin;c:\Program Files\Java\jdk1.6.0_02\lib;%AXISCLASSPATH%;C:\Program Files\Java\jre1.6.0_02\lib\ext\QTJava.zip

5. 6.

You may find it useful to copy this text to notepad and set it according to your own installation directories. You’re all set up to use web services! Now, let’s create a simple Java Web Service. Create a new java file called BasicMath.java with the following code: public class BasicMath { public int add(int n1, int n2){ return n1+n2;

} } 7. 8. 9. 10.

Save it as a JWS file in /axis/BasicMath.jws Start apache server using Apache Monitor from the program menu. Call the service from http://localhost:8080/axis/BasicMath.jws And look at the wsdl on: http://localhost:8080/axis/BasicMath.jws?wsdl 11. You can also call the method using: http://localhost:8080/axis/BasicMath.jws?method=add&n1=4&n2=3

Part II: Using Eclipse 1. 2.

3.

Install Eclipse If you downloaded the default Eclipse Europa package, it does not include Web Tools Platform (WTP). You need to Help->Software Updates->Find and Install. Alternatively, you can download the MDT and WTP bundle provided by the Security Engineering Research Group at http://serg.imsciences.edu.pk/pub/softwares/eclipse3.3-win32-wtp-mdt.rar Start Eclipse and setup a new installed runtime (Windows->Preferences->Server>Installed Runtimes->Add). Select Apache Tomcat 5.5 as the new runtime.

4.

Create a new “Dynamic Web Project” from the “Web” node with the following settings.

5.

In the Servers View, [right-click] New->Server.

6.

Add the project to configured projects. Then, right click the server and start it.

7.

8.

In the project explorer, add a new class file called Echo in package edu.serg.tutorials.soa:

Enter the following code for the class: package edu.serg.tutorials.soa; public class Echo { public int[] getNums(int n, int m){ int a[] = new int[10]; for (int i=0; i < 10; i++){ a[i] = m * n * i; } return a; } public int[] getNums2(int n, int m){ int a[] = new int[10]; for (int i=0; i < 10; i++){ a[i] = m * n * i * 2; } return a; } }

9.

Build the Project. Then Right-Click Echo.java in project explorer and select Web Services -> Create Web Service. Select the following options (Make sure you set the sliders as in the screenshot.) You can select the default settings in the following dialogs.

10. Run-> Launch Web Services Explorer. Select WSDL Page from the buttons on the top right of the view.

11. Select WSDL Main from the Navigator. Then click Browse. Select Category “Workspace Documents”, Project “SOATest” and hit Go.

12. Hit Go in the WSDL Main page and you get a list of operations. Click on getNums(). Enter values for variables n and m. Hit Go.

13. In the Status pane, see the result. Hit Source and take a look at SOAP request and response. 14. Notice also that the web service creation procedure has created a SOATestClient project for you. If you don’t understand why, see the client slider in Step 9 above. You asked eclipse to Assemble a client for you. Anyway, let’s open this client project and write a java client. 15. In SOATestClient project, create a file EchoClient.java in the src folder. Enter the following code for it: package edu.serg.tutorials.soa; import org.apache.axis.AxisFault; import java.net.URL; public class EchoClient { public static void main(String[] args) throws AxisFault ,Exception { EchoSoapBindingStub srv = new EchoSoapBindingStub( new URL("http://localhost:8080/SOATest/services/Echo"), new EchoServiceLocator()); int a[] = srv.getNums(3, 4); for(int x:a) System.out.println(x); } }

16. Run the client and see the results.

You may also test the client using the browser at: http://localhost:8080/SOATest/services/Echo Assuming, of course, that your server is running at port 8080. Feel free to contact me if you need help with this stuff.

Web Services using Tomcat and Eclipse - Recluze - WordPress.com

Create a new java file called BasicMath.java with the following code: ... Start apache server using Apache Monitor from the program menu. ... EchoSoapBindingStub srv = new EchoSoapBindingStub( new URL("http://localhost:8080/SOATest/services/Echo"), new EchoServiceLocator()); int a[] = srv.getNums(3, 4); for(int x:a).

349KB Sizes 0 Downloads 186 Views

Recommend Documents

java web services tutorial eclipse pdf
java web services tutorial eclipse pdf. java web services tutorial eclipse pdf. Open. Extract. Open with. Sign In. Main menu. Displaying java web services tutorial ...

Developing Interoperable Business Processes Using Web Services ...
Abstract. A Web service is an accessible application that other appli- cations and humans can discover and trigger to satisfy various needs. Thus, Web services ...

Eclipse for Web App.pdf
Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. Eclipse for Web App.pdf. Eclipse for Web App.pdf. Open. Extract.

Backing Composite Web Services Using Formal ...
way, a formal context of Web services and operations becomes K = (W,O,I), where: .... context that corresponds to θ = 0.75 is shown in Table 4, we call it SimCxt. ..... 2006, Amsterdam, The Netherlands, IOS Press (2006) 220–231 .... tional Confere

Backing Composite Web Services Using Formal ...
Key words: Web service classification, Formal Concept Analysis (FCA), service .... context that corresponds to θ = 0.75 is shown in Table 4, we call it SimCxt. ..... Reuse of Plans, Proofs, and Programs, Montréal, Canada (1995) 21–25 ... tional C

Towards Behavioral Web Services Using Policies
ditional integration middleware (e.g., CORBA, Java RMI) [4]. This lack of ...... [15] F. Curbera, M. Duftler, R. Khalaf, W. Nagy, N. Mukhi, and S. Weerawarana.

Authoring intelligent tutoring system using Web services
application architecture (see Fig. 1). Web .... use cases designates xTEx-Sys Web services (see Fig. 4). .... passes all elements of domain knowledge using XML.

By using Responsive Web Design, The Japan ... Services
Hiromitsu Chifuri (Deputy Manager, Digital Enterprise Division, The Japan Times). To date, Mark Thompson and Hiromitsu Chifuri have received extremely positive feedback from users regarding the site redesign. “Our next challenge is to further incre

Apache Tomcat - F5 Networks
Deploying the BIG-IP LTM with Tomcat application servers and Apache web servers .... In today's three-tiered application environments a typical architecture has a series of web and ..... by the application developer with functions specific to the.

Catalog
18: Studio Visit: SEO. 17: Terry Haggerty: Angle ...... 19: Interview with Vera Cortês / Vera Cortês Art Agency / ARCO 2008 Madrid, Spain. 18: Dan Perjovschi: Stu ...

DataCite2RDF
Feb 4, 2016 - class pro:Role in PRO, or of its sub-classes in SCORO: • scoro:contact-person. • scoro:data-creator. • scoro:data-curator. • scoro:data-manager. • pro:distributor. • pro:editor. • scoro:funder. • scoro:host-institution.

negative
Jun 3, 2016 - Oil near USD50/bbl but industry players not excited ... should disconnect oil services players' stock price with oil price as ..... Software Technology • Telcos ..... constituting legal, accounting or tax advice, and that for accurate

Web Services Annotation and Reasoning
handle and to manipulate them by introducing Semantic Web technologies and additional logical formalisms into the annotation process. The annotation proc-.

negative
Jun 3, 2016 - stronger confidence on oil price sustainability, there is little hope for a .... year, the sentiment from oil companies remains negative and capital .... Automotive • Semiconductor • Technology ..... Structured securities are comple

Catalog
18: Studio Visit: SEO. 17: Terry Haggerty: Angle of Response / Kuttner Siebert Gallery, Berlin. 14: Interview with Dan Perjovschi at Fumetto Festival Lucerne.

Catalog
10: Urs Fischer: Service à la Française (2009) / Luma Westbau / Pool etc. ...... 10: Claes Oldenburg & Coosje van Bruggen: The European Desktop / Ivorypress ...

Creating and Consuming Web Services
No part of this work may be reproduced or transmitted in any form or by any means, electronic ... Phone 510-549-5930, fax 510-549-5939, email [email protected], or visit ...... After that, a customer looking for a service of that type can find it in ..

Creating and Consuming Web Services
Outside the United States: fax +49 6221 345229, email [email protected], or ...... Google API. .

Course Handout - Web Programming and Services Theory.pdf ...
Course Handout - Web Programming and Services Theory.pdf. Course Handout - Web Programming and Services Theory.pdf. Open. Extract. Open with. Sign In.

DataCite2RDF
Feb 4, 2016 - Changes the examples used for 6 Subject, and for 11 AlternateIdentifier. 5. Corrected an RDF term duplication in 7.2 contributorName. 6. Improvement to the formatting of the exemplar RDF statements, to enhance clarity. 7. Added “data

Java Web Services
It uses technology available from Apache, IBM, BEA, Sonic .... By using XML as the data representation layer for all web services protocols and .... However, one of the big promises of web services is seamless, automatic business integration:.