You are on page 1of 8

SOA Lab Manual[2014]

PRACTICAL NO. 01
AIM:
To write a program for parsing XML file.
PROGRAM:
XMLParsingExample.java
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import java.io.File;
public class XMLParsingExample
{
public static void main(String[] args)
{
try
{
File
xmlFile=new
File("F:/FinalBtechIT/SOA/student.xml");
///home/121080906/
DocumentBuilderFactory
dbf=DocumentBuilderFactory.newInstance();
DocumentBuilder db=dbf.newDocumentBuilder();
Document doc=db.parse(xmlFile);
doc.getDocumentElement().normalize();
System.out.println("Root
doc.getDocumentElement().getNodeName());

Element

-->

"+

NodeList nList=doc.getElementsByTagName("student");
for(int i=0;i<nList.getLength();i++)
{
Node nNode = nList.item(i);
System.out.println("\nCurrent

Element

-->"

nNode.getNodeName());
if (nNode.getNodeType() == Node.ELEMENT_NODE)

Veermata Jijabai Technological Institute, Mumbai

Page 1

SOA Lab Manual[2014]


{
Element eElement = (Element) nNode;
System.out.println("Student

id

"

"

"

eElement.getAttribute("id"));
System.out.println("First
Name
eElement.getElementsByTagName("firstname").item(0).getTextContent());
System.out.println("Last
Name
eElement.getElementsByTagName("lastname").item(0).getTextContent());
System.out.println("Address
:
eElement.getElementsByTagName("address").item(0).getTextContent());
System.out.println("Batch
:
eElement.getElementsByTagName("batch").item(0).getTextContent());

"
"

+
+

}
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
student.xml
<?xml version="1.0"?>
<vjti>
<student id="121081904">
<firstname>Geeta</firstname>
<lastname>Saraf</lastname>
<address>Nallasopara</address>
<batch>2</batch>
</student>
<student id="121081905">
<firstname>Neha</firstname>
<lastname>Madne</lastname>
<address>Vikroli</address>
<batch>2</batch>
</student>
<student id="121080906">
<firstname>Mangesh</firstname>
<lastname>Sawadkar</lastname>
Veermata Jijabai Technological Institute, Mumbai

Page 2

SOA Lab Manual[2014]


<address>Bhayandar</address>
<batch>2</batch>
</student>
</vjti>
OUTPUT:

CONCLUSION:
We have studied how to parse XML file for reading and writing in it. It was nice experience
to work on XML parsing using Java.
*****

Veermata Jijabai Technological Institute, Mumbai

Page 3

SOA Lab Manual[2014]

PRACTICAL NO. 02
AIM:
To Create a Web Service For Adding Few Numbers Using NetBeans IDE.
ALGORITHM:
1. Using the Netbeans API create a project of the type web application.
2. Create a web service in the project.
3. Click on the Design tab and design the prototype of the web service.
4. Click on source tab and modify the application logic of the web service.
5. Save the project.
6. Right click on the project and click on deploy and undeploy.
7. Then test the web service.
PROGRAM:
Web Service:
package AddWeb;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
@WebService()
public class addWeb {
@WebMethod(operationName = "Add")
public String Add(@WebParam(name = "input1")
int input1, @WebParam(name = "input2")
int input2) {
//TODO write your implementation code here:
int result=input1+input2;
return ""+result;
}
}

Veermata Jijabai Technological Institute, Mumbai

Page 4

SOA Lab Manual[2014]


OUTPUT:

CONCLUSION:
In this experiment, We have implemented simple web service making use of NetBeans IDE
6.1. Working on NetBeans is really easier in case of Web service implementation.

*****
Veermata Jijabai Technological Institute, Mumbai

Page 5

SOA Lab Manual[2014]

PRACTICAL NO. 03
AIM:
Creation Of Web Service Client.
ALGORITHM:
1. Using the Netbeans API create a project of the type web application.
2. Create a web service in the project.
3. Click on the Design tab and design the prototype of the web service.
4. Click on source tab and modify the application logic of the web service.
5. Save the project.
6. Right click on the project and click on deploy and undeploy.
7. Then test the web service.
8. Create another web application project and create a jsp file.
9. Right click on project and click on create web service client.
10. Browse and choose the web service created i.e wsdl url
11. Drag and drop the web service reference to the source code window.
12. Then pass the appropriate parameters to the web service client and invoke the web
service.
PROGRAM:
index.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h2>Hello World!</h2>
<form name="" action="action.jsp" method="post">
Enter first number: <input name="first" type="text"/> <br/>
Enter second number: <input name="second" type="text"/> <br/>
<input name="OK" type="submit" value="Add"/>
</form>
</body>
</html>
Veermata Jijabai Technological Institute, Mumbai

Page 6

SOA Lab Manual[2014]


action.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h2>Hello World!</h2>
<%
String a1=request.getParameter("first");
String b1=request.getParameter("second");
int aa=Integer.parseInt(a1);
int bb=Integer.parseInt(b1);
%>
<%-- start web service invocation --%><hr/>
<%
try {
addweb.AddWebService service = new addweb.AddWebService();
addweb.AddWeb port = service.getAddWebPort();
// TODO initialize WS operation arguments here
int input1 = aa;
int input2 = bb;
// TODO process result here
java.lang.String result = port.add(input1,input2);
out.println("Result = "+result);
} catch (Exception ex) {
// TODO handle custom exceptions here
}
%>
<%-- end web service invocation --%><hr/>
</body>
</html>

Veermata Jijabai Technological Institute, Mumbai

Page 7

SOA Lab Manual[2014]


OUTPUT:

CONCLUSION:
In this experiment, We have implemented a simple client for accessing the web service
implemented in previous experiment.

*****

Veermata Jijabai Technological Institute, Mumbai

Page 8

You might also like