Project Requirement
Develop a web service program for Square area calculation. Make this web service secured using security mechanism of “Username Authentication with Symmetric Keys”
Solution
Adding user to GlassFish
To add users to Glassfish using the Admin Console, follow these steps:
Figure. 1

Figure. 2

Figure. 3

Figure .4
as shown below in Figure. 5

Figure. 5

Figure. 6
Web Service Project Creation>
Figure. 7

Figure. 8
Web Service File Creation >
Figure 9

Figure.10

Figure. 11

Figure 12
In generated code edit some value as shown below
package pack1;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
/**
*
* @author roseindia
*/
@WebService()
public class square {
@WebMethod(operationName = "area")
public String area(@WebParam(name = "side")
int side) {
return "area of square of side"+side+" is "+(side*side);
}
}

Figure. 13

Figure. 14

Figure 15
Figure 16

Figure 17
Testing Web Service
Figure.18

Figure. 19

Figure. 20

Figure. 21
As shown below in Figure 22.

Figure. 22

Figure. 23

Figure 24
As shown below in Figure 25.

Figure. 25
Calling Web Service Client Resources
Figure. 26
<html>
<body>
<%-- start web service invocation --%><hr/>
<%
try {
pack1.SquareService service = new pack1.SquareService();
pack1.Square port = service.getSquarePort();
// TODO initialize WS operation arguments here
int side = 10;
// TODO process result here
java.lang.String result = port.area(side);
out.println("Result = "+result);
} catch (Exception ex) {
// TODO handle custom exceptions here
}
%>
<%-- end web service invocation --%><hr/>
</body>
</html>

Figure. 27

Figure. 28
Running Client Web service >
Figure. 29

Figure. 30
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Security in Web Service
Post your Comment