Web Services
Web Services
Web Services
COM
DATE:
AIM:
PROCEDURE:
STEP 4: Right click the application choose New->xml document to create the xml.
CODING:
XML:
<emp-details>
<staff1>
<staffname>Gowri.s</staffname>
<staffid>001</staffid>
<staffdesig>HR</staffdesig>
<staffsal>50000</staffsal>
</staff1>
<staff2>
<staffname>Priya.N</staffname>
<staffid>002</staffid>
<staffdesig>MANAGER</staffdesig>
<staffsal>30000</staffsal>
</staff2>
<staff3>
<staffname>Saranya.k</staffname>
<staffid>003</staffid>
<staffdesig>HR</staffdesig>
<staffsal>50000</staffsal>
</staff3>
<staff4>
<staffname>Anitha.M</staffname>
<staffid>005</staffid>
WWW.VIDYARTHIPLUS.COM
<staffdesig>ACCOUNTANT</staffdesig>
<staffsal>40000</staffsal>
</staff4>
</emp-details>
JAVA:
package parser;
import java.security.KeyStore.Entry.Attribute;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
try
SAXParserFactory factory=SAXParserFactory.newInstance();
SAXParser saxparser=factory.newSAXParser();
boolean bfname=false;
boolean blname=false;
boolean bnname=false;
WWW.VIDYARTHIPLUS.COM
boolean bsalary=false;
throws SAXException
System.out.println("startElement:"+qName);
if(qName.equalsIgnoreCase("staffname"))
bfname=true;
if(qName.equalsIgnoreCase("staffid"))
blname=true;
if(qName.equalsIgnoreCase("staffdesig"))
bnname=true;
if(qName.equalsIgnoreCase("staffsal"))
bsalary=true;
System.out.println("endelement:"+qName);
WWW.VIDYARTHIPLUS.COM
if(bfname)
System.out.println("staffname:"+new String(ch,start,length));
bfname=false;
if(blname)
System.out.println("staffid:"+new String(ch,start,length));
blname=false;
if(bnname)
System.out.println("staffdesig:"+new String(ch,start,length));
bnname=false;
if(bsalary)
System.out.println("staffsalary:"+new String(ch,start,length));
bsalary=false;
};
WWW.VIDYARTHIPLUS.COM
saxparser.parse("C:\\DocumentsandSettings\\PG-Student\\My
Documents\\NetBeansProjects\\parser\\newXMLDocument.xml",handler)
}
catch(Exception e)
e.printStackTrace();
}
WWW.VIDYARTHIPLUS.COM
OUTPUT:
run:
startElement:emp-details
startElement:staff1
startElement:staffname
staffname:Gowri.s
endelement:staffname
startElement:staffid
staffid:001
endelement:staffid
startElement:staffdesig
staffdesig:HR
endelement:staffdesig
startElement:staffsal
staffsalary:50000
endelement:staffsal
endelement:staff1
startElement:staff2
startElement:staffname
staffname:Priya.N
endelement:staffname
startElement:staffid
staffid:002
endelement:staffid
startElement:staffdesig
WWW.VIDYARTHIPLUS.COM
staffdesig:MANAGER
endelement:staffdesig
startElement:staffsal
staffsalary:30000
endelement:staffsal
endelement:staff2
startElement:staff3
startElement:staffname
staffname:Saranya.k
endelement:staffname
startElement:staffid
staffid:003
endelement:staffid
startElement:staffdesig
staffdesig:HR
endelement:staffdesig
startElement:staffsal
staffsalary:50000
endelement:staffsal
endelement:staff3
startElement:staff4
startElement:staffname
staffname:Anitha.M
endelement:staffname
startElement:staffid
WWW.VIDYARTHIPLUS.COM
staffid:004
endelement:staffid
startElement:staffdesig
staffdesig:ACCOUNTANT
endelement:staffdesig
startElement:staffsal
staffsalary:40000
endelement:staffsal
endelement:staff4
endelement:emp-details
RESULT:
DATE:
AIM:
PROCEDURE:
STEP 1: Right click on project name, click New->Web Service. A window will appear. In that
check the implement web service as stateless session bean and click finish.
STEP 2: To test a web service .go to project tab. Under web service folder. Select our web
STEP 3: To add parameters click Add button in the Add operation window and click ok.
CODING:
package add1;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.ejb.Stateless;
@WebService(serviceName = "add")
@Stateless()
@WebMethod(operationName = "hello")
@WebMethod(operationName = "add")
public int add(@WebParam(name = "i") final int i, @WebParam(name = "j") final int j) {
int k=i+j;
return k;
}
WWW.VIDYARTHIPLUS.COM
OUTPUT:
Method parameter(s)
Type Value
int 5
int 5
Method returned
int : "10"
SOAP Request
SOAP Response
RESULT:
Thus the above web service program has been executed successfully.
WWW.VIDYARTHIPLUS.COM
DATE:
AIM:
PROCEDURE:
STEP 1: Right click on project name, click New->Web Service. A window will appear. In that
check the implement web service as stateless session bean and click finish.
STEP 2: To test a web service .go to project tab. Under web service folder. Select our web
STEP 3: To add parameters click Add button in the Add operation window and click ok.
CODING:
package conversion;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.ejb.Stateless;
@WebService(serviceName = "currency1")
@Stateless()
@WebMethod(operationName = "hello")
@WebMethod(operationName = "rupee_to_euro")
return rate;
@WebMethod(operationName = "euro_to_rupee")
int rupee=1;
return (int)rate;
}
WWW.VIDYARTHIPLUS.COM
OUTPUT:
Method parameter(s)
Type Value
double 23
Method returned
double : "1518.0"
SOAP Request
SOAP Response
Method parameter(s)
Type Value
float 23.6776
Method returned
double : "23.0"
SOAP Request
SOAP Response
RESULT:
Thus the above currency conversion program has been executed successfully.