mirror of
https://github.com/svek95/WST_Labs.git
synced 2026-05-17 18:44:02 +03:00
Add Lab7
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package Lab7;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class App {
|
||||
|
||||
|
||||
private static final String login = "uddiadmin";
|
||||
private static final String password = "12345";
|
||||
|
||||
public static void main(String[] args) {
|
||||
JuddiPubl publisher = new JuddiPubl(login, password);
|
||||
JuddiBrows browser = new JuddiBrows(login, password);
|
||||
String businessKey, serviceName, wsdl, serviceKey;
|
||||
|
||||
String menu = "Choose action: \n 1) publish service \n 2) call service \n 3) exit";
|
||||
|
||||
Scanner scan = new Scanner(System.in);
|
||||
String choice = "";
|
||||
while (!"3".equals(choice)) {
|
||||
System.out.println(menu);
|
||||
choice = scan.nextLine();
|
||||
switch (choice) {
|
||||
case "1":
|
||||
System.out.println("Enter business key: ");
|
||||
businessKey = scan.next().trim();
|
||||
System.out.println("Enter service name: ");
|
||||
serviceName = scan.next().trim();
|
||||
System.out.println("Enter wsdl url: ");
|
||||
wsdl = scan.next().trim();
|
||||
System.out.println("Service key: " + publisher.publish(businessKey, serviceName, wsdl));
|
||||
break;
|
||||
case "2":
|
||||
System.out.println("Enter service name: ");
|
||||
serviceName = scan.next().trim();
|
||||
System.out.println("Enter service key: ");
|
||||
serviceKey = scan.next().trim();
|
||||
browser.callService(serviceName, serviceKey);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package Lab7;
|
||||
|
||||
import org.apache.juddi.v3.client.UDDIConstants;
|
||||
import org.apache.juddi.v3.client.config.UDDIClient;
|
||||
import org.apache.juddi.v3.client.transport.Transport;
|
||||
import org.uddi.api_v3.*;
|
||||
import org.uddi.v3_service.UDDIInquiryPortType;
|
||||
import org.uddi.v3_service.UDDISecurityPortType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class JuddiBrows {
|
||||
|
||||
private static UDDISecurityPortType security = null;
|
||||
private static UDDIInquiryPortType inquiry = null;
|
||||
|
||||
private AuthToken authToken;
|
||||
|
||||
public JuddiBrows(String userName, String password) {
|
||||
try {
|
||||
UDDIClient uddiClient = new UDDIClient("META-INF/uddi.xml");
|
||||
Transport transport = uddiClient.getTransport("default");
|
||||
security = transport.getUDDISecurityService();
|
||||
inquiry = transport.getUDDIInquiryService();
|
||||
GetAuthToken getAuthTokenMyPub = new GetAuthToken();
|
||||
getAuthTokenMyPub.setUserID(userName);
|
||||
getAuthTokenMyPub.setCred(password);
|
||||
authToken = security.getAuthToken(getAuthTokenMyPub);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void callService(String serviceName, String serviceKey) {
|
||||
try {
|
||||
FindService fs = new FindService();
|
||||
fs.setAuthInfo(authToken.getAuthInfo());
|
||||
fs.setFindQualifiers(new FindQualifiers());
|
||||
fs.getFindQualifiers().getFindQualifier().add(UDDIConstants.APPROXIMATE_MATCH);
|
||||
|
||||
Name searchname = new Name();
|
||||
searchname.setValue("%" + serviceName);
|
||||
fs.getName().add(searchname);
|
||||
ServiceList serviceList = inquiry.findService(fs);
|
||||
|
||||
GetServiceDetail gsd = new GetServiceDetail();
|
||||
gsd.setAuthInfo(authToken.getAuthInfo());
|
||||
gsd.getServiceKey().add(serviceKey);
|
||||
ServiceDetail sd = inquiry.getServiceDetail(gsd);
|
||||
|
||||
if (sd == null || sd.getBusinessService() == null || sd.getBusinessService().isEmpty()) {
|
||||
System.out.println("Can not find service with key " + serviceKey);
|
||||
return;
|
||||
}
|
||||
|
||||
List<BusinessService> services = sd.getBusinessService();
|
||||
BusinessService businessService = services.get(0);
|
||||
BindingTemplates bindingTemplates = businessService.getBindingTemplates();
|
||||
if (bindingTemplates == null || bindingTemplates.getBindingTemplate().isEmpty()) {
|
||||
System.out.println("No binding template for service with key " + serviceKey);
|
||||
return;
|
||||
}
|
||||
for (BindingTemplate bindingTemplate : bindingTemplates.getBindingTemplate()) {
|
||||
AccessPoint accessPoint = bindingTemplate.getAccessPoint();
|
||||
System.out.println(accessPoint.getValue());
|
||||
}
|
||||
|
||||
security.discardAuthToken(new DiscardAuthToken(authToken.getAuthInfo()));
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package Lab7;
|
||||
|
||||
import org.apache.juddi.api_v3.AccessPointType;
|
||||
import org.apache.juddi.v3.client.config.UDDIClient;
|
||||
import org.apache.juddi.v3.client.transport.Transport;
|
||||
import org.uddi.api_v3.*;
|
||||
import org.uddi.v3_service.UDDIPublicationPortType;
|
||||
import org.uddi.v3_service.UDDISecurityPortType;
|
||||
|
||||
public class JuddiPubl {
|
||||
|
||||
private static UDDISecurityPortType security = null;
|
||||
private static UDDIPublicationPortType publish = null;
|
||||
|
||||
private AuthToken authToken;
|
||||
|
||||
public JuddiPubl(String userName, String password) {
|
||||
try {
|
||||
UDDIClient uddiClient = new UDDIClient("META-INF/uddi.xml");
|
||||
Transport transport = uddiClient.getTransport("default");
|
||||
|
||||
security = transport.getUDDISecurityService();
|
||||
publish = transport.getUDDIPublishService();
|
||||
|
||||
GetAuthToken getAuthTokenMyPub = new GetAuthToken();
|
||||
getAuthTokenMyPub.setUserID(userName);
|
||||
getAuthTokenMyPub.setCred(password);
|
||||
authToken = security.getAuthToken(getAuthTokenMyPub);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String publish(String businessName, String serviceName, String wsdlUrl) {
|
||||
try {
|
||||
|
||||
BusinessEntity myBusEntity = new BusinessEntity();
|
||||
Name myBusName = new Name();
|
||||
myBusName.setValue(businessName);
|
||||
myBusEntity.getName().add(myBusName);
|
||||
|
||||
SaveBusiness sb = new SaveBusiness();
|
||||
sb.getBusinessEntity().add(myBusEntity);
|
||||
sb.setAuthInfo(authToken.getAuthInfo());
|
||||
BusinessDetail bd = publish.saveBusiness(sb);
|
||||
String myBusKey = bd.getBusinessEntity().get(0).getBusinessKey();
|
||||
|
||||
BusinessService myService = new BusinessService();
|
||||
myService.setBusinessKey(myBusKey);
|
||||
Name myServName = new Name();
|
||||
myServName.setValue(serviceName);
|
||||
myService.getName().add(myServName);
|
||||
|
||||
BindingTemplate myBindingTemplate = new BindingTemplate();
|
||||
AccessPoint accessPoint = new AccessPoint();
|
||||
accessPoint.setUseType(AccessPointType.WSDL_DEPLOYMENT.toString());
|
||||
accessPoint.setValue(wsdlUrl);
|
||||
myBindingTemplate.setAccessPoint(accessPoint);
|
||||
BindingTemplates myBindingTemplates = new BindingTemplates();
|
||||
|
||||
myBindingTemplate = UDDIClient.addSOAPtModels(myBindingTemplate);
|
||||
myBindingTemplates.getBindingTemplate().add(myBindingTemplate);
|
||||
|
||||
myService.setBindingTemplates(myBindingTemplates);
|
||||
|
||||
SaveService ss = new SaveService();
|
||||
ss.getBusinessService().add(myService);
|
||||
ss.setAuthInfo(authToken.getAuthInfo());
|
||||
ServiceDetail sd = publish.saveService(ss);
|
||||
String myServKey = sd.getBusinessService().get(0).getServiceKey();
|
||||
|
||||
security.discardAuthToken(new DiscardAuthToken(authToken.getAuthInfo()));
|
||||
System.out.println("Success!");
|
||||
return myServKey;
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user