0% found this document useful (0 votes)
7 views15 pages

Java Service Trust Evaluation Code

This Java code file contains code for discovering services from a UDDI registry based on functional requirements, evaluating the trust level of each discovered service using a fuzzy cognitive approach, and calculating the number of times each service has been used by the logged in user and other users. The code imports various UDDI API classes, connects to a MySQL database, discovers services from the UDDI registry matching a given category, calculates trust levels for each service using a fuzzy trust function, and forwards the results to a JSP page to display the information.

Uploaded by

sandeshgupta59
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views15 pages

Java Service Trust Evaluation Code

This Java code file contains code for discovering services from a UDDI registry based on functional requirements, evaluating the trust level of each discovered service using a fuzzy cognitive approach, and calculating the number of times each service has been used by the logged in user and other users. The code imports various UDDI API classes, connects to a MySQL database, discovers services from the UDDI registry matching a given category, calculates trust levels for each service using a fuzzy trust function, and forwards the results to a JSP page to display the information.

Uploaded by

sandeshgupta59
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

APPENDIX B

Source Code

Java Code:
File name: Trust_book.java
Function Performed:
 Discovery of services corresponding to the functional requirement using UDDI4J
API’S
 Evaluation of Trust level for each discovered service according to Fuzzy
Cognitive Approach.
 Calculation of number of time of usage for each service by logged in user and
other user
Code:
import [Link];
import [Link];
import [Link].*;
import [Link].*;
import [Link].*;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class Trust_book extends HttpServlet
{ static Connection con=null;
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{ String DRIVER = "[Link]";
String URL = "jdbc:mysql://localhost:3306/trust";
String user ="root";
String pwd ="root";
[Link]("text/html");
PrintWriter out = [Link]();
HttpSession session = [Link]();
String n=(String)[Link]("name");
String uuid=(String)[Link]("uuid");
ArrayList TrustList = new ArrayList();
try {
[Link](DRIVER); //driver is loaded
con = [Link](URL,user,pwd);
Properties config =null;
config = [Link]();
UDDIProxy proxy = new UDDIProxy();
[Link]([Link]("inquiryURL"));
[Link]([Link]("publishURL"));
Vector names = new Vector();
[Link](new Name("b"));
FindQualifiers findQualifiers = new FindQualifiers();
Vector qualifier = new Vector();
[Link](new FindQualifier("caseSensitiveMatch"));
[Link](qualifier);
String stream=[Link]("category");
TModelList tModelList = proxy.find_tModel(stream, null, null,null,5);
Vector tModelInfoVector = [Link]().getTModelInfoVector();
TModelInfo tModelInfo = (TModelInfo)[Link](0);
[Link]("The TModel Name: " + [Link]());
String tmodelKey = [Link]();
[Link]("The TModel Key : " + tmodelKey);
TModelBag tModelBag = new TModelBag();
Vector tModelKeyVector = new Vector();
[Link](tmodelKey);
[Link](tModelKeyVector);
BusinessList businessList = proxy.find_business(null, null, null, null, tModelBag,
findQualifiers, 5);
Vector businessInfoVector =
[Link]().getBusinessInfoVector();
for( int i = 0; i < [Link](); i++ )
BusinessInfo businessInfo = (BusinessInfo)[Link](i);
ServiceList serv_list=proxy.find_service(null, tModelBag, findQualifiers, 10);
Vector serviceinfoVector=serv_list.getServiceInfos().getServiceInfoVector();
ArrayList Serv_name=new ArrayList();
ArrayList ap=new ArrayList();
for( int i = 0; i < [Link](); i++ )
{ ServiceInfo serviceInfo = (ServiceInfo)[Link](i);
String sn=(String)[Link]();
String sk=[Link]();
[Link]([Link]()+" \t");
BindingDetail bindingDetailReturned = proxy.find_binding(null, sk, null, 10);
Vector bindingTemplatesFound =
[Link]();
BindingTemplate bindingTemplateFound = (BindingTemplate)
([Link](0));
String bk=(String)[Link]();
String a_pnt=[Link]().getText();
Serv_name.add(sn);
[Link](a_pnt);
}

//Calculate count
[Link](1);
String sname[]=new String[Serv_name.size()];
String uTimes[]=new String[[Link]];
String oTimes[]=new String[[Link]];
[Link](2);
for (int i=0;i<[Link];i++)
{
[Link](3);
sname[i]=(String)Serv_name.get(i);
String qry="select count from UserServiceLog where uuid='"+uuid+"'
and ServiceName='"+sname[i]+"'" ;
PreparedStatement pst=[Link](qry);
ResultSet rs=[Link]();
if([Link]())
uTimes[i]=[Link]("count");
//[Link]([Link]("count"));
[Link]();
[Link]();
[Link](4);
String qry1="select sum(count) from UserServiceLog where uuid != '
"+uuid+"' and ServiceName= '"+sname[i]+"'" ;
PreparedStatement pst1=[Link](qry1);
[Link](5);
ResultSet rs1=[Link]();
[Link](6);
if([Link]())
{[Link](7);
oTimes[i]=[Link]("sum(count)");
[Link](8);
//[Link]([Link]("sum(count)"));
}
[Link]();
[Link]();
[Link](5);
}

ArrayList UT=new ArrayList();


ArrayList OT=new ArrayList();
for(int i=0;i<[Link];i++)
{
[Link](uTimes[i]);
[Link](oTimes[i]);
}
for (int i=0;i<Serv_name.size();i++)
{
String serviceName = (String)Serv_name.get(i);
double trustLevel= fuzzyTrust(uuid,serviceName);
[Link](trustLevel);
[Link](serviceName+":"+trustLevel);
}
[Link]("name",n);
[Link]("Serv_name",Serv_name);
[Link]("ap",ap);
[Link]("category",stream);
[Link]("userTimes",UT);
[Link]("otherTimes",OT);
[Link]("TrustList",TrustList);

[Link]("/project/[Link]").forward(request,response);
}
// Handle possible errors
catch( UDDIException E )
{
DispositionReport dr = [Link]();
if( dr!=null )
{
[Link]("UDDIException faultCode:" + [Link]() +

"\n operator:" + [Link]() +

"\n generic:" + [Link]() );


Vector results = [Link]();
for( int i=0; i<[Link](); i++ )
{
Result r = (Result)[Link](i);
[Link]("\n errno:" + [Link]() );
if( [Link]()!=null )
{
[Link]("\n errCode:" +
[Link]().getErrCode() + "\n errInfoText:" +
[Link]().getText());
}
}
}
[Link]();
}
catch (ClassNotFoundException z)
{
[Link]("driver not found");
}
catch (SQLException z)
{
[Link]();
}

catch( Exception E )
{
[Link]();
}
finally{
try{
if (con!=null && [Link]())
[Link]();
}
catch (SQLException z)
{
[Link]();
}
}
}
public static double fuzzyTrust(String uuid,String service)
{
/* these influence values are taken from user's influence repository*/
double QoC_influence=0,
QoE_influence=0,
availability_Influence=0,
competence_Influence=0,
promptness_Influence=0,
cost_Influence=0;

/* these are the trust parameter feedbacks taken from feedback repository*/
double QoE_availability=0,
QoE_competence=0,
QoE_promptness=0,
QoE_cost=0;

/*these are the averages of the feedback*/


double QoC_availability=0,
QoC_competence=0,
QoC_promptness=0,
QoC_cost=0;

/* intialize all trust parameter's levels to 0 */


double trust_level=0;
double availability_level=0;
double competence_level=0;
double promptness_level=0;
double cost_level=0;

//con=getConnection();
//Statement statement=null;
try
{
PreparedStatement pst=[Link]("select
cost,availablity,competance,promptness,qoe,qoc from influence where
uuid=?");
[Link](1,uuid);
ResultSet rs=[Link]();
if([Link]())
{
promptness_Influence=[Link]("promptness");
cost_Influence=[Link]("cost");
availability_Influence=[Link]("availablity");
competence_Influence=[Link]("competance");
QoC_influence=[Link]("qoc");
QoE_influence=[Link]("qoe");
}
PreparedStatement pst2=[Link]("select
cost,availablity,promtness,competance from feedback where uuid=?
and SeriveName=?");
[Link](1,uuid);
[Link](2,service);
ResultSet rs2=[Link]();
if([Link]())
{
QoE_promptness=[Link]("promtness");
QoE_cost=[Link]("cost");
QoE_availability=[Link]("availablity");
QoE_competence=[Link]("competance");
}
PreparedStatement pst3=[Link]("select
avg(availablity)\"avga\",avg(competance)\"avgcom\",avg(promtness)\"
avgp\",avg(cost)\"avgc\" from feedback where not uuid=? and
SeriveName=?");
[Link](1,uuid);
[Link](2,service);
ResultSet rs3=[Link]();
if([Link]())
{
QoC_promptness=[Link]("avgp");
QoC_cost=[Link]("avgc");
QoC_availability=[Link]("avga");
QoC_competence=[Link]("avgcom");
}
[Link]("QoE_availability:"+QoE_availability+"
QoE_competence:"+QoE_competence+"
QoE_promptness:"+QoE_promptness+"
+QoE_cost:"+QoE_cost+"\n");
[Link]("QoC_availability:"+QoC_availability+"
QoC_competence:"+QoC_competence+"
QoC_promptness:"+QoC_promptness+"
+QoC_cost:"+QoC_cost+"\n\n");
availability_level=evaluateInfluence(QoC_availability,QoE_availabilit
y,QoC_influence,QoE_influence,availability_level);

[Link]("availability_level:"+availability_level+"\n.................................................
.......\n");

competence_level=evaluateInfluence(QoC_competence,QoE_competence,QoC_influence,Q
oE_influence,competence_level);

[Link]("competence_level:"+competence_level+"\n...............................................
.........\n");

promptness_level=evaluateInfluence(QoC_promptness,QoE_promptness,QoC_influence,Qo
E_influence,promptness_level);

[Link]("promptness_level:"+promptness_level+"\n................................................
........\n");

cost_level=evaluateInfluence(QoC_cost,QoE_cost,QoC_influence,QoE_influence,cost_level
);

[Link]("cost_level:"+cost_level+"\n........................................................\n");

trust_level=evaluateTrustLevel(availability_level,competence_level,promptness_level,cost_l
evel,availability_Influence,competence_Influence,promptness_Influence,cost_Influence);

[Link](trust_level+"\n........................................................\n");
}
catch (SQLException e)
{
[Link]();
}
finally
{
try
{
if (con!=null && [Link]())
[Link]();
}
catch (SQLException e)
{
[Link]();
}
}
return trust_level;
}
public static double evaluateInfluence(double QoC_param,double
QoE_param, double QoC_influence, double QoE_influence, double old_level)
{
int counter=0;
int max_loop=100;
double new_level=old_level;
do
{
old_level=new_level;
new_level=(
(
(old_level+(QoE_param-old_level)*(QoE_influence/100))
+ (old_level+(QoC_param-old_level)*(QoC_influence/100))
)/2
);
if(new_level<0)
{
new_level=0;
}
counter++;
[Link](counter+" new_level:"+new_level+"
old_level:"+old_level);
}while(counter < max_loop && new_level!=old_level);
return new_level;
}
public static double evaluateTrustLevel(double availability_level,double
competence_level,double promptness_level,double cost_level,double
availability_Influence,double competence_Influence,double
promptness_Influence,double cost_Influence)
{
int counter=0;
int max_loop=100;
double new_level=0,old_level=0;
do
{
old_level=new_level;
new_level=(
(
(old_level+(availability_level-old_level)*(availability_Influence/100))
+(old_level+(competence_level-old_level)*(competence_Influence/100))
+(old_level+(promptness_level-old_level)*(promptness_Influence/100))
+(old_level+(cost_level-old_level)*(cost_Influence/100)))/4);
if(new_level<0)
{
//[Link]("\n***********new_level="+new_level+"
****************\n");
new_level=0;
}
counter++;
[Link](counter+" new_level:"+new_level+"
old_level:"+old_level);
}while(counter < max_loop && new_level!=old_level);
return new_level;
}
}
class Configurator {
public static Properties load() {
Properties config = new Properties();
try {
[Link](new [Link]("[Link]"));
} catch (Exception e) {
[Link]("Error loading samples property file\n" + e);
}
// Configure UDDI4J system properties. Normally set on commandline or elsewhere
// SOAP transport being used
if ([Link](TransportFactory.PROPERTY_NAME)==null) {
[Link](TransportFactory.PROPERTY_NAME,
[Link]("TransportClassName"));

}
// Logging
if ([Link]("[Link]")==null) {

[Link]("[Link]", [Link]("logEnabled"));
}
// Configure JSSE support
try {
[Link]("[Link]",
[Link]("handlerPackageName"));
// Dynamically loads security provider based on properties. Typically configured in
JRE
[Link](([Link])
[Link]([Link]("securityClassName")).newInstance());
} catch (Exception e) {
[Link]("Error configuring JSSE provider. Make sure JSSE is in
classpath.\n" + e);
}
return config;
}
}

File name: [Link]


Function Performed:
 Obtain the name of book store to be used and call the corresponding book store
service.
 Obtain the result from the book store
Code:
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link].*;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link].*;
public class BookClient extends HttpServlet
{
public void init(ServletConfig config) throws ServletException
{
[Link](config);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
HttpSession session = [Link]();
PrintWriter out = [Link]();
ArrayList BookId = new ArrayList();
ArrayList BookName = new ArrayList();
ArrayList BookAuthor = new ArrayList();
ArrayList BookPrice = new ArrayList();
ArrayList BookQuantity = new ArrayList();
ArrayList BookCategory = new ArrayList();
String category = [Link]("category");
String BookStoreName = (String)[Link]("BookStoreName");
String name=(String)[Link]("name");
String uuid=(String)[Link]("uuid");
String operation="books";
try
{
String endpoint = [Link]("ServiceUrl");
Service service = new Service();
Call call = (Call) [Link]();
[Link](new [Link](endpoint));
[Link](operation);
[Link]("category", XMLType.XSD_STRING,
[Link]);
[Link](XMLType.XSD_STRING);
String rs = (String) [Link](new Object[] {category});
UpdateCount(uuid,BookStoreName,response );
[Link]("rs: "+rs);
String[] colonSplit = [Link] (":");
int rows=[Link](colonSplit[0]);
String[] bookrows = colonSplit[1].split (";");
[Link]("bookrows: "+[Link]);
for (int i=0; i <rows; i++)
{
String[] data = bookrows[i].split (",");
[Link](data[0]);
[Link](data[1]);
[Link](data[2]);
[Link](data[3]);
[Link](data[4]);
[Link](data[5]);
}
[Link]("before [Link]");
[Link]("name",name);
[Link]("BookId",BookId);
[Link]("BookName",BookName);
[Link]("BookAuthor",BookAuthor);
[Link]("BookPrice",BookPrice);
[Link]("BookQuantity",BookQuantity);
[Link]("BookCategory",BookCategory);
[Link]("BookStoreName",BookStoreName);
[Link]("endpoint",endpoint);
[Link]("after [Link] :"+BookStoreName);
[Link](5);
[Link]("/project/[Link]").forward(request,response);
}
catch(Exception e){
[Link]("Sorry, requested service is currently not available");
[Link]("<br><br><br><a
href=\"[Link]
}
}
void UpdateCount(String uuid,String BookStoreName,HttpServletResponse
response ){
PrintWriter out=null;
try{
out = [Link]();
Connection con=null;
[Link]("[Link]");
con =
[Link]("jdbc:mysql://localhost:3306/trust","root","root
");
String qry="select * from UserServiceLog where uuid='"+uuid+"' AND
ServiceName='"+BookStoreName+"'";
[Link](qry);
PreparedStatement pst=[Link](qry);
ResultSet rs=[Link]();
[Link]("db checked ");

if([Link]()){
qry="update userservicelog set Count=Count+1 where uuid='"+uuid+"' AND
ServiceName='"+BookStoreName+"'";
[Link](qry);
PreparedStatement pst1=[Link](qry);
int a=[Link]();
[Link]("updated count in userservicelog");
[Link]();
}
else{
qry="insert into UserServiceLog values
('"+uuid+"','"+BookStoreName+"',1)" ;
[Link](qry);
PreparedStatement pst2=[Link](qry);
int a=[Link]();
[Link]("new record inserted ");
//[Link]();
[Link]();
}
}
catch (ClassNotFoundException z)
{
[Link]("driver not found");
}

catch (SQLException z)
{
[Link]();
}
catch (Exception e)
{
[Link]();
}
}
}

File name: [Link]


Function Performed:
 Obtain the category of books from the Book Client, invoke its books function to
search for required books from its own database and then return the relevant .
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link].*;

public class BookStore1


{
public Connection con=null;
public int purchaseOrder(String bookId){
int order=0;
ResultSet rs=null;
try{
con = getConnection();
[Link]("connected");
String qry = "UPDATE services.BookStore1 set Quantity=Quantity-1
where BookId='"+bookId+"'";
PreparedStatement pst=[Link](qry);
order=[Link]();
if(order==1)
[Link]("Book Updated");
else
[Link]("Update Quary not worked");
}
catch (SQLException e){
[Link]();
}
finally{
try{
if (con!=null && [Link]())
[Link]();
}
catch (SQLException e){
[Link]();
}
}
return order;
}
public String books(String category) {
ResultSet rs=null;
int count=0;
String bookList="",qry="";
String BookStore="BookStore1";
try{
con = getConnection();
[Link]("connected");
if([Link]("all"))
qry="SELECT * FROM services.BookStore1 where
Quantity>0";
else
qry = "SELECT * FROM services.BookStore1 where
Quantity>0 AND Category='"+category+"'";
PreparedStatement pst=[Link](qry);
[Link](qry);
rs=[Link]();
while([Link]()){
count++;
[Link](" "+[Link](1)+" "+[Link](2)+"
"+[Link](3)+" "+[Link](4)+" "+[Link](6)+" "+[Link](5));

bookList=bookList+[Link](1)+","+[Link](2)+","+[Link](3)+","+[Link](
4)+","+[Link](6)+","+[Link](5)+";";
}
bookList=count+":"+bookList;
[Link]("************** "+bookList);
}
catch (SQLException e){
[Link]();
}
finally{
try {
if (con!=null && [Link]())
[Link]();
}
catch (SQLException e){
[Link]();
}
}
return bookList;
}

public Connection getConnection(){


try{
[Link]("[Link]");
con =
[Link]("jdbc:mysql://localhost:3306/services","root","root");
}
catch (ClassNotFoundException e){
[Link]("driver not found: "+e);
}
catch (SQLException e){
[Link]();
}
return con;
}
}

You might also like