properties.put("businessName", domain);
properties.put("serverName", domain);
properties.put("serverPort", port);
wsdlURL = wsdlDefinition.getDocumentBaseURI();
WSDL2UDDI wsdl2UDDI = new WSDL2UDDI(null, new URLLocalizerDefaultImpl(), properties);
BusinessServices businessServices = wsdl2UDDI.createBusinessServices(wsdlDefinition);
@SuppressWarnings("unchecked")
Map<QName, PortType> portTypes = (Map<QName, PortType>) wsdlDefinition.getAllPortTypes();
Set<TModel> portTypeTModels = wsdl2UDDI.createWSDLPortTypeTModels(wsdlURL, portTypes);
Map allBindings = wsdlDefinition.getAllBindings();
Set<TModel> createWSDLBindingTModels = wsdl2UDDI.createWSDLBindingTModels(wsdlURL, allBindings);
//When parsing a WSDL, there's really two things going on
//1) convert a bunch of stuff (the portTypes) to tModels
//2) convert the service definition to a BusinessService
//Since the service depends on the tModel, we have to save the tModels first
stm = new SaveTModel();
stm.setAuthInfo(token);
TModel[] tmodels = portTypeTModels.toArray(new TModel[0]);
for (int i = 0; i < tmodels.length; i++) {
stm.getTModel().add(tmodels[i]);
}
tmodels = createWSDLBindingTModels.toArray(new TModel[0]);
for (int i = 0; i < tmodels.length; i++) {
stm.getTModel().add(tmodels[i]);
}
//important, you'll need to save your new tModels first, or else saving the business/service may fail
System.out.println(new PrintUDDI<SaveTModel>().print(stm));
System.out.println("Saving " + stm.getTModel().size() + " tModels");
publish.saveTModel(stm);
System.out.println("Saved!");
if (businessKey == null || businessKey.length() == 0) {
SaveBusiness sb = new SaveBusiness();
sb.setAuthInfo(token);
BusinessEntity be = new BusinessEntity();
be.setBusinessKey(businessServices.getBusinessService().get(0).getBusinessKey());
be.getName().add(new Name());
be.getName().get(0).setValue(domain);
be.getName().get(0).setLang("en");
sb.getBusinessEntity().add(be);
BusinessDetail saveBusiness = publish.saveBusiness(sb);
businessKey = saveBusiness.getBusinessEntity().get(0).getBusinessKey();
System.out.println("new business created key= " + businessKey);
}
//finaly, we're ready to save all of the services defined in the WSDL
//again, we're creating a new business, if you have one already, look it up using the Inquiry getBusinessDetails
SaveService ss = new SaveService();
ss.setAuthInfo(token);
for (int i = 0; i < businessServices.getBusinessService().size(); i++) {
businessServices.getBusinessService().get(i).setBusinessKey(businessKey);
ss.getBusinessService().add(businessServices.getBusinessService().get(i));
}
System.out.println("Here's our new service(s): " + new PrintUDDI<SaveService>().print(ss));