import javax.wsdl.*; 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.tmodel.*; import com.ibm.uddi.response.*; import com.ibm.uddi.util.*; import org.w3c.dom.*; import java.util.*; /** * Publish a WSDL service interface definition in a UDDI registry. * @author: Peter Brittenham */ public class PublishServiceInterface { /** * Publish a WSDL service interface description in a UDDI registry as a tModel. * * @param wsdlURL location of the WSDL service interface definition * @param userid the userid that is registered at the UDDI registry * @param password the password associated with the userid * @param inquiryURL the inquiry URL for the UDDI registry * @param publishURL the publish URL for the UDDI registry * * @return Returns the tModel that was published in the UDDI registry. */ public static TModel publishServiceInterface ( String wsdlURL, String userid, String password, String inquiryURL, String publishURL ) throws Exception { TModelDetail tModelDetail; Vector tModelList = new Vector(); // 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 interface document Definition def = WSDLReader.readWSDL(null, wsdlURL); // Display progress message System.out.println("WSDL document has been read."); System.out.println(" Target namespace ... " + def.getTargetNamespace()); // Create tModel from WSDL service interface TModel tModel = new TModel(); // [STEP 1: tModel} Set the businessService name from WSDL targetNamespace tModel.setName(def.getTargetNamespace()); // Get documentation element Element element = def.getDocumentationElement(); // [STEP 2: tModel] Set default tModel description String desc = DOMUtils.getChildCharacterData(element); tModel.setDefaultDescriptionString(desc); // Create overview doc OverviewDoc overviewDoc = new OverviewDoc(); // Create overview URL OverviewURL overviewURL = new OverviewURL(wsdlURL); // Set overviewURL overviewDoc.setOverviewURL(overviewURL); // [STEP 3: tModel] Set the overview doc tModel.setOverviewDoc(overviewDoc); // Create a categoryBag and get the CategoryBag categoryBag = new CategoryBag(); // Create a keyedReference for wsdlSpec Vector krList = new Vector(); KeyedReference kr = new KeyedReference("uddi-org:types", "wsdlSpec"); kr.setTModelKey("UUID:C1ACF26D-9672-4404-9D70-39B756E62AB4"); krList.add(kr); // Create a keyedReference for the category of service 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); // [STEP 4: tModel] Set the category bag tModel.setCategoryBag(categoryBag); // Add tModel to list tModelList.add(tModel); // Display progress message System.out.println("\nPublishing a WSDL Service Implementation as a UDDI businessService..."); // Save tModel tModelDetail = uddiProxy.save_tModel(authToken.getAuthInfoString(), tModelList); // Display progress message System.out.println("UDDI tModel published.\n"); // Return tModel return (TModel) tModelDetail.getTModelVector().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 { // Publish the WSDL service interface definition if (args.length < 3) { throw new IllegalArgumentException("Usage: PublishServiceImplementation " + " [ ]"); } // Check if the inquiryURL was specified if (args.length >= 4) inquiryURL = args[3]; // Check if the inquiryURL was specified if (args.length >= 5) publishURL = args[4]; // Display input args System.out.println("PublishServiceInterface:\n" + " WSDL URL ........ " + args[0] + "\n" + " UDDI Userid ..... " + args[1] + "\n" + " UDDI Password ... " + args[2] + "\n" + " Inquiry URL ..... " + inquiryURL + "\n" + " Publish URL ..... " + publishURL + "\n"); // Publish the service interface definition TModel tModel = publishServiceInterface(args[0], args[1], args[2], inquiryURL, publishURL); // Display tModel information System.out.println("UDDI tModel created:\n" + " Name ......... " + tModel.getNameString() + "\n" + " tModel Key ... " + tModel.getTModelKey()); } catch (Exception e) { // Display exception System.out.println("EXCEPTION:"); e.printStackTrace(); } // Exit System.exit(0); } }