Lab Programs
Lab Programs
for(int i=1;i<=a;i++)
fact=fact*i;
return fact;
}}
Fact.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>FACTORIAL OF A GIVEN NUMBER!</h1>
<hr/>
<%String a1=request.getParameter("fac");
int a=Integer.parseInt(a1);%>
<%-- start web service invocation --%><hr/>
<%
try {
fact.Fact_Service service = new fact.Fact_Service();
fact.Fact port = service.getFactPort();
int result = port.f1(a);
out.println("Result is = "+result);
} catch (Exception ex) {
// TODO handle custom exceptions here
}
%>
<%-- end web service invocation --%><hr/>
</body>
</html>
Index.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>factorial page</title>
</head>
<body>
<h1>FACTORIAL OF GIVEN NUMBER</h1>
<form name="frm" action="fact.jsp" method="post">
Enter the value:
<input type="text" name="fac" value="" /><br><br>
<input type="submit" value="click to get factorial" name="submit" />
</form>
</body>
</html>
OUTPUT:
RESULT:
Thus the creation of web service client for finding the factorial number was verified and
executed successfully.
Ex.No:04
AIM:
To create a login webpage for used to accessing the operations are add user, and test the
service, invoke the two operations using the JSPclient.
PROCEDURE:
1) Open Net beans IDE, which has the Glassfish server by default.
2) In Net beans take a new web project. Provide the web application name. and select the
server name. (Glassfish v2.1 (or) above version)
3) In the web service project, select new web service. And give web service name &
package name.
4) Now in design view of the web services, add the operation and parameters that are going
to be used in web services application.
5) Now in source view change the return value null into some string value.
6) Finally deploy it on the server and test the web service program.
7) Create a client file from web projects and specify the WSDL file of the web services.
8) Create a client environments for the web services in the project. (client.jsp).
9) Specify the operation name into web service client resources.
10) Execute the web service client file.
PROGRAM:
loginservice.java ( Server Side Webservice)
package loginpack;
import java.util.ArrayList;
import java.util.List;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
@WebService()
public class loginservice
{
List<User> users;
public loginservice()
{
}
users=new ArrayList<User>();
@WebMethod(operationName = "addUser")
public boolean addUser(@WebParam(name = "Login")
String Login, @WebParam(name = "Password")
String Password)
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final User other = (User) obj;
if ((this.Login == null) ? (other.Login != null) : !this.Login.equals(other.Login)) {
return false;
}
if ((this.Password == null) ? (other.Password != null) : !this.Password.equals(other.Password)) {
return false;}
return true;
}
@Override
public int hashCode() {
int hash = 7;
hash = 23 * hash + (this.Login != null ? this.Login.hashCode() : 0);
hash = 23 * hash + (this.Password != null ? this.Password.hashCode() : 0);
return hash;
}}
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>LOGIN WEB SERVICE!</h1>
<%-- start web service invocation --%><hr/>
<%
try { loginpack.LoginserviceService service = new loginpack.LoginserviceService();
loginpack.Loginservice port = service.getLoginservicePort();
java.lang.String login = request.getParameter("username");
java.lang.String password = request.getParameter("pwd");
boolean result = port.checkUser(login, password);
if(result)
{
out.println("Login Successfully");
}
else
{
out.println("Access Denied");
}
} catch (Exception ex) { out.println("Unable to operate the WebService");
} %>
<%-- end web service invocation --%>
<hr/>
</body>
</html>
RESULT:
Thus the creation of login webpage for used to accessing the operations are add user, and test the
service, invoke the two operations using the JSPclient was verified successfully.
Ex.No:05
AIM
To invoke EJB component as web service using Netbeans IDE.
PROCEDURE
1. Start -> all programs -> netbeans IDE 7.3.1.
2. Create Remote Interface.Select File->New Project->Java->Java Class Library.
3. Give Project Name as ejbsessionRemote.
4. Create Enterprise application project Select File-> New Project -> java EE -> enterprise
application.
5. Give the project name as testservice,select the glass fish server.
6. Next select the EJB Module project testservice-ejb,then right click and select New->Session
Bean.
7. Give the EJB name as ejbsessionBean and select session type as stateless and interface as
remote and select ejbsessionRemote. Give the package name as pac and click the finish
button.
8. Select testservice-ejb ,go to source package and select ejbsessionBean .java.Now go to the
source code window of it.
9. Then Right click in that window ,select insert code option-> Add Business Method, give the
Name as getmessage return type as string and Use in interface as Remote.Then click OK.
10. Now Insert the following code inside the getmessage() method return Invoke EJB
Component as Web Services.Save the file.
11. Next step is to select index.jsp from testservice.war/Web Pages. Insert the following code
into
the
index.jsp
<h1>MAKE
CALL
TO
EJB
COMPONENT!</h1><a
PROGRAMS
ejbsessionBean.java
package pac;
import javax.ejb.Stateless;
@Stateless
public class ejbsessionBean implements ejbsessionBeanRemote {
@Override
public String getmessage() {
return "Invoke EJB Component as Web Services";
}
}
ejbservlet.java
package pac;
import java.io.IOException;
import java.io.PrintWriter;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet(name = "ejbservlet", urlPatterns = {"/ejbservlet"})
public class ejbservlet extends HttpServlet {
@EJB
private ejbsessionBeanRemote ejbsessionBean;
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet ejbservlet</title>");
out.println("</head>");
out.println("<body>");
out.println(ejbsessionBean.getmessage());
out.println("</body>");
out.println("</html>");
} finally {
out.close();
}
}
index.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>MAKE CALL TO EJB COMPONENT!</h1>
<a href="ejbservlet">Click here to call the EJB component</a>
</body>
</html>
OUTPUT SCREENS
RESULT:
Thus the invoking of EJB component as web service using net beans IDE was verified and
executed successfully.
Ex.No:06
AIM
To write a program to invoke EJB component for finding power value using Netbeans
IDE.
PROCEDURE
1. Start -> all programs -> Netbeans IDE 7.3.1.
2. Create Remote Interface.Select File->New Project->Java->Java Class Library.
3. Give Project Name as powersessionRemote.
4. Create Enterprise application project Select File-> New Project -> java EE -> enterprise
application.
5. Give the project name as powerservice,select the glass fish server.
6. Next select the EJB Module project powerservice-ejb,then right click and select New>Session Bean.
7. Give the EJB name as powersessionBean and select session type as stateless and interface as
remote and select powersessionRemote. Give the package name as powerpack and click the
finish button.
8. Select powerservice-ejb ,go to source package and select powersessionBean .java.Now go to
the source code window of it.
9. Then Right click in that window ,select insert code option-> Add Business Method, give the
Name as findpower return type as int ,add two parameters x,y with data type as int and Use in
interface as Remote.Then click OK.
10. Now Insert the code given inside the findpower() method in the program.Save the file.
11. Next step is to select index.jsp from powerservice.war/Web Pages. Insert the given code in
the program into index.jsp.
12. Then under Web Project powerservice-war, Right click and select the New-> Servlet.Give
Name as powerservlet and package name as powerpack and click Next then click Finish.
13. Then inside the powerservlet class right click select insert code -> Call Enterprise Bean ->
select powerservice-ejb and select powersessionBean as a Reference Name ,select
Referenced interface as Remote and the click OK.
14. Add the code given in powerservlet.java within doget() try block.
15. Finally select powerservice Enterprise Application Project and click deploy and then run.
PROGRAM
powersessionBean.java:
package powerpack;
import javax.ejb.Stateless;
public class powersessionBean implements powersessionRemote {
public int findpower(int x, int y)
{
int result=1;
for(int i=0;i<y;i++)
{
result=result*x;
}
return result;
}
powerservlet.java:
package powerpack;
import java.io.*;
import javax.ejb.EJB;
import javax.servlet.*;
import javax.servlet.http.*;
import powerpack.powersessionRemote;
public class powerservlet extends HttpServlet {
@EJB
private powersessionRemote powersessionBean;
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet powerservlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet powerservlet at " + request.getContextPath () + "</h1>");
out.println("</body>");
out.println("</html>");
} finally {
out.close();
}
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws
ServletException, IOException {
int a,b;
a=Integer.parseInt(request.getParameter("xval"));
b=Integer.parseInt(request.getParameter("yval"));
response.setContentType("Text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
out.println("<html>");
out.println("<head>");
out.println("<title>Power value calculation</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>the result of"+a+"power"+b+"is"+powersessionBean.findpower(a,b)+"</h1>");
out.println("</body>");
out.println("</html>");
}
finally
{
out.close();
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
public String getServletInfo() {
return "Short description";
}}
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>Power servlet</title>
</head>
<body>
<h1>Welcome to Power Calculation</h1>
<form name="myform" action="powerservlet">
Enter the value of x:<input type="text" name="xval" value="" /><br/>
Enter the value of y:<input type="text" name="yval" value="" /><br/>
<input type="submit" value="calculate" name="cal" />
</form>
</body>
</html>
SAMPLE OUTPUT
RESULT
Thus the EJP components for finding power value was verified and executed
successfully.
Ex.No:07
AIM:
To Create a SOA project with BPEL Module to Compose A Web Service.
PROCEDURE:
STEPS TO CREATE A BPEL MODULE
Creating a new BPEL Module Project
The following sections use the Synchronous sample project, and provide step-by-step directions
for creating a simple BPEL module project, using the Synchronous sample project.
To Create a BPEL Module Project
1. In the NetBeans IDE, choose File -> New Project.The New Projects wizard appears.
2. Under Categories, select Service Oriented Architecture.
3. Under Projects, select BPEL Module and click Next.