import javax.wsdl.*; import javax.wsdl.extensions.*; import com.ibm.wsdl.extensions.soap.*; import com.ibm.wsdl.util.xml.*; import com.ibm.wsdl.xml.*; import com.ibm.uddi.client.*; import com.ibm.uddi.datatype.*; import com.ibm.uddi.datatype.binding.*; import com.ibm.uddi.datatype.business.*; import com.ibm.uddi.datatype.service.*; import com.ibm.uddi.response.*; import com.ibm.uddi.util.*; import org.w3c.dom.*; import java.util.*; /** * Publish a WSDL service implementation definition in a UDDI registry. * * NOTE: This application do not contain proper error checking. For example, * it is assumed the WSDL service implementation document contains at least * one service and port element, and the port element contains a documentation * element. Typically, you would check to verify that the elements exist before * trying to use them. * * @author: Peter Brittenham */ public class PublishServiceImplementation { /** * Publish a WSDL service implementaiton description in a UDDI registry as a businessService. * For this sample code, it is assumed that the WSDL document contains only one service element, * and it contains only one port element. Also, it is assumed the tModelKey for the tModel * associated with the service interface is already known. * * @param wsdlURL location of the WSDL service implementation definition * @param userid the userid that is registered at the UDDI registry * @param password the password associated with the userid * @param businessKey the key for the businessEntity that will be used to publish the businessService * @param tModelKey the key for the tModel that is associated with the WSDL service interface * @param inquiryURL the inquiry URL for the UDDI registry * @param publishURL the publish URL for the UDDI registry * * @return Returns the businessService that was published in the UDDI registry. */ public static BusinessService publishServiceImplementation ( String wsdlURL, String userid, String password, String businessKey, String tModelKey, String inquiryURL, String publishURL ) throws Exception { Element element; ServiceDetail serviceDetail; Vector tModelList = new Vector(); TModelInstanceInfo tModelInstanceInfo; TModelInstanceDetails tModelInstanceDetails = new TModelInstanceDetails(); Vector tModelInstanceInfoList = new Vector(); InstanceDetails instanceDetails = new InstanceDetails(); OverviewDoc overviewDoc = new OverviewDoc(); // Create UDDI proxy UDDIProxy uddiProxy = getUddiProxy(inquiryURL, publishURL); // Display progress message System.out.println("Requesting an authentication token..."); // Obtain authToken using get_authToken UDDI API AuthToken authToken = uddiProxy.get_authToken(userid, password); // Display progress message System.out.println("Received authentication token.\n"); // Display progress message System.out.println("Reading WSDL document [" + wsdlURL + "]...\n"); // Read WSDL service implementation document Definition wsdlDefinition = WSDLReader.readWSDL(null, wsdlURL); // Get the first service element only Service wsdlService = ((Service[]) wsdlDefinition.getServices().values().toArray(new Service[0]))[0]; // Display progress message System.out.println("WSDL document has been read."); System.out.println(" Service Name ... " + wsdlService.getQName().getLocalPart()); // Create businessService from WSDL service interface BusinessService businessService = new BusinessService(); // Set the business key businessService.setBusinessKey(businessKey); // [STEP 1: businessService] Set the businessService name from service name businessService.setName(wsdlService.getQName().getLocalPart()); // Get documentation element element = wsdlService.getDocumentationElement(); // [STEP 2: businessService] Set default businessService description businessService.setDefaultDescriptionString(DOMUtils.getChildCharacterData(element)); // Create a bindingTemplate BindingTemplate bindingTemplate = new BindingTemplate(); // Get the first port element Port wsdlPort = ((Port[]) wsdlService.getPorts().values().toArray(new Port[0]))[0]; // Get documentation element element = wsdlPort.getDocumentationElement(); // [STEP 1: bindingTemplate] Set default bindingTemplate description bindingTemplate.setDefaultDescriptionString(DOMUtils.getChildCharacterData(element)); // Get first extensibility element ExtensibilityElement ext = (ExtensibilityElement) wsdlPort.getExtensibilityElements().get(0); // Create access point (assume that it is always SOAP binding and HTTP protocol) AccessPoint accessPoint = new AccessPoint(((SOAPAddress)ext).getLocationURI(), "http"); // [STEP 2: bindingTemplate] Set the access point bindingTemplate.setAccessPoint(accessPoint); // [STEP 3: bindingTemplate] Create tModelInstanceInfo using the tModelKey tModelInstanceInfo = new TModelInstanceInfo(tModelKey); // Create overview URL OverviewURL overviewURL = new OverviewURL(wsdlURL); // Set overviewURL overviewDoc.setOverviewURL(overviewURL); // [STEP 4: bindingTemplate] Set the overview doc instanceDetails.setOverviewDoc(overviewDoc); // Set instance details tModelInstanceInfo.setInstanceDetails(instanceDetails); // Add to list tModelInstanceInfoList.addElement(tModelInstanceInfo); // Add tModel instance info tModelInstanceDetails.setTModelInstanceInfoVector(tModelInstanceInfoList); // Add tModelInstanceDetails to binding template bindingTemplate.setTModelInstanceDetails(tModelInstanceDetails); // Create vector and add bindingTemplate to it BindingTemplates bindingTemplates = new BindingTemplates(); Vector bindingTemplateVector = new Vector(); bindingTemplateVector.addElement(bindingTemplate); bindingTemplates.setBindingTemplateVector(bindingTemplateVector); // Add bindingTemplate to businessService businessService.setBindingTemplates(bindingTemplates); // Create a categoryBag and get the CategoryBag categoryBag = new CategoryBag(); // Create a keyedReference for the category of service // NOTE: This should vary depending upon the type of service that is being published Vector krList = new Vector(); KeyedReference kr = new KeyedReference("Stock market trading services", "84121801"); kr.setTModelKey("UUID:DB77450D-9FA8-45D4-A7BC-04411D14E384"); krList.add(kr); // Set keyed reference vector categoryBag.setKeyedReferenceVector(krList); // Set the category bag businessService.setCategoryBag(categoryBag); // Display progress message System.out.println("\nPublishing a WSDL Service Implementation as a UDDI businessService..."); // Create list of businessServices Vector businessServiceVector = new Vector(); businessServiceVector.addElement(businessService); // Save tModel serviceDetail = uddiProxy.save_service(authToken.getAuthInfoString(), businessServiceVector); // Display progress message System.out.println("UDDI businessService published.\n"); // Return businessService return (BusinessService) serviceDetail.getBusinessServiceVector().elementAt(0); } /** * Create the UDDI proxy for a UDDI registry. * @param inquiryURL the inquiry URL for the UDDI registry * @param publishURL the publish URL for the UDDI registry * @return Returns the UDDI proxy of the IBM test registry. */ public static UDDIProxy getUddiProxy(String inquiryURL, String publishURL) throws Exception { UDDIProxy uddiProxy = null; // Add SSL support (this is IBM's SSL support but it can be replaced with other implementations) System.setProperty("java.protocol.handler.pkgs", "com.ibm.net.ssl.internal.www.protocol"); java.security.Security.addProvider(new com.ibm.jsse.JSSEProvider()); // Create UDDI proxy uddiProxy = new UDDIProxy(); uddiProxy.setInquiryURL(inquiryURL); uddiProxy.setPublishURL(publishURL); // Return UDDI proxy return uddiProxy; } /** * Starts the application that will publish a WSDL service interface definition. * * @param args an array of command-line arguments */ public static void main(java.lang.String[] args) { // Set the default inquiry and publish URLs to the ones for the IBM UDDI Test Registry String inquiryURL = "http://www-3.ibm.com/services/uddi/testregistry/inquiryapi"; String publishURL= "https://www-3.ibm.com/services/uddi/testregistry/protect/publishapi"; try { // Verify that all required input arguments were specified if (args.length < 5) { throw new IllegalArgumentException("Usage: PublishServiceInteface " + " " + "[ ]"); } // Check if the inquiryURL was specified if (args.length >= 6) inquiryURL = args[5]; // Check if the inquiryURL was specified if (args.length >= 7) publishURL = args[6]; // Display input args System.out.println("PublishServiceImplementaton:\n" + " WSDL URL ........ " + args[0] + "\n" + " UDDI Userid ..... " + args[1] + "\n" + " UDDI Password ... " + args[2] + "\n" + " Business Key .... " + args[3] + "\n" + " tModel Key ...... " + args[4] + "\n" + " Inquiry URL ..... " + inquiryURL + "\n" + " Publish URL ..... " + publishURL + "\n"); // Publish the service implementation definition BusinessService businessService = publishServiceImplementation(args[0], args[1], args[2], args[3], args[4], inquiryURL, publishURL); // Display businessService information System.out.println("UDDI businessService created:\n" + " Name .......... " + businessService.getNameString() + "\n" + " Service Key ... " + businessService.getServiceKey()); } catch (Exception e) { // Display exception System.out.println("EXCEPTION:"); e.printStackTrace(); } // Exit System.exit(0); } }