This project has retired. For details please refer to its Attic page.
UddiCreatebulk xref
View Javadoc
1   /*
2    * Copyright 2001-2013 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   */
17  package org.apache.juddi.samples;
18  
19  import de.svenjacobs.loremipsum.LoremIpsum;
20  import java.util.GregorianCalendar;
21  import javax.xml.datatype.DatatypeFactory;
22  import javax.xml.datatype.XMLGregorianCalendar;
23  import org.apache.juddi.api_v3.AccessPointType;
24  import org.apache.juddi.v3.client.UDDIConstants;
25  import org.apache.juddi.v3.client.config.UDDIClient;
26  import org.apache.juddi.v3.client.transport.Transport;
27  import org.uddi.api_v3.*;
28  import org.uddi.v3_service.UDDIPublicationPortType;
29  import org.uddi.v3_service.UDDISecurityPortType;
30  
31  /**
32   * This class was used to identify performance issues when a given node has a
33   * large number of UDDI entities. It may not work on some commercial UDDI nodes
34   * due to licensing restrictions (some limit the number of business, services,
35   * etc)
36   *
37   * @author <a href="mailto:alexoree@apache.org">Alex O'Ree</a>
38   */
39  public class UddiCreatebulk {
40  
41          private UDDISecurityPortType security = null;
42          private UDDIPublicationPortType publish = null;
43          private String curretNode = null;
44  
45          public UddiCreatebulk(String node) {
46                  try {
47                          // create a manager and read the config in the archive; 
48                          // you can use your config file name
49                          UDDIClient clerkManager = new UDDIClient("META-INF/simple-publish-uddi.xml");
50                          Transport transport = clerkManager.getTransport(node);
51                          curretNode = node;
52                          // Now you create a reference to the UDDI API
53                          security = transport.getUDDISecurityService();
54                          publish = transport.getUDDIPublishService();
55                  } catch (Exception e) {
56                          e.printStackTrace();
57                  }
58          }
59  
60          public UddiCreatebulk(Transport transport, boolean notused, String node) {
61                  try {
62                          curretNode = node;
63                          security = transport.getUDDISecurityService();
64                          publish = transport.getUDDIPublishService();
65                  } catch (Exception e) {
66                          e.printStackTrace();
67                  }
68          }
69  
70          /**
71           * bulk creates businesses, services and binding templates
72           *
73           * @param token if null, root/root will be used to authenticate
74           * @param businesses
75           * @param servicesPerBusiness
76           * @param user purely for display purposes
77           */
78          public void publishBusiness(String token, int businesses, int servicesPerBusiness, String user) {
79                  try {
80                          // Setting up the values to get an authentication token for the 'root' user ('root' user has admin privileges
81                          // and can save other publishers).
82                          if (token == null) {
83                                  GetAuthToken getAuthTokenRoot = new GetAuthToken();
84                                  getAuthTokenRoot.setUserID("root");
85                                  getAuthTokenRoot.setCred("root");
86  
87                                  // Making API call that retrieves the authentication token for the 'root' user.
88                                  AuthToken rootAuthToken = security.getAuthToken(getAuthTokenRoot);
89                                  System.out.println("root AUTHTOKEN = " + "don't log auth tokens!");
90                                  token = rootAuthToken.getAuthInfo();
91                          }
92  
93                          LoremIpsum textgen = new LoremIpsum();
94                          DatatypeFactory df = DatatypeFactory.newInstance();
95                          GregorianCalendar gcal = new GregorianCalendar();
96                          gcal.setTimeInMillis(System.currentTimeMillis());
97                          XMLGregorianCalendar xcal = df.newXMLGregorianCalendar(gcal);
98                          for (int i = 0; i < businesses; i++) {
99                                  // Creating the parent business entity that will contain our service.
100                                 BusinessEntity myBusEntity = new BusinessEntity();
101                                 Name myBusName = new Name();
102                                 myBusName.setLang("en");
103                                 myBusName.setValue(user + "'s Business " + curretNode + " " + i + " " + xcal.toString() + " " + textgen.getWords(5, 2));
104                                 myBusEntity.getDescription().add(new Description(textgen.getWords(10, 2), null));
105                                 myBusEntity.getName().add(myBusName);
106 
107                                 // Adding the business entity to the "save" structure, using our publisher's authentication info and saving away.
108                                 SaveBusiness sb = new SaveBusiness();
109                                 sb.getBusinessEntity().add(myBusEntity);
110                                 sb.setAuthInfo(token);
111                                 BusinessDetail bd = publish.saveBusiness(sb);
112                                 String myBusKey = bd.getBusinessEntity().get(0).getBusinessKey();
113                                 System.out.println("saved: Business key:  " + myBusKey);
114                                 for (int k = 0; k < servicesPerBusiness; k++) {
115                                         // Creating a service to save.  Only adding the minimum data: the parent business key retrieved from saving the business 
116                                         // above and a single name.
117                                         BusinessService myService = new BusinessService();
118                                         myService.setBusinessKey(myBusKey);
119                                         Name myServName = new Name();
120                                         myServName.setLang("en");
121                                         myServName.setValue(user + "'s Service " + curretNode + " " + i + " " + k + " " + xcal.toString() + " " + textgen.getWords(5, 2));
122                                         myService.getName().add(myServName);
123                                         myService.getDescription().add(new Description(textgen.getWords(10, 2), null));
124 
125                                         // Add binding templates, etc...
126                                         BindingTemplate myBindingTemplate = new BindingTemplate();
127                                         myBindingTemplate.setCategoryBag(new CategoryBag());
128                                         KeyedReference kr = new KeyedReference();
129                                         kr.setTModelKey(UDDIConstants.TRANSPORT_HTTP);
130                                         kr.setKeyName("keyname1");
131                                         kr.setKeyValue("myvalue1");
132 
133                                         myBindingTemplate.getCategoryBag().getKeyedReference().add(kr);
134 
135                                         KeyedReferenceGroup krg = new KeyedReferenceGroup();
136                                         krg.setTModelKey(UDDIConstants.TRANSPORT_HTTP);
137                                         kr = new KeyedReference();
138                                         kr.setTModelKey(UDDIConstants.PROTOCOL_SSLv3);
139                                         kr.setKeyName("keyname1grp");
140                                         kr.setKeyValue("myvalue1grp");
141 
142                                         krg.getKeyedReference().add(kr);
143                                         myBindingTemplate.getCategoryBag().getKeyedReferenceGroup().add(krg);
144 
145                                         myService.setCategoryBag(new CategoryBag());
146 
147                                         kr = new KeyedReference();
148                                         kr.setTModelKey(UDDIConstants.TRANSPORT_HTTP);
149                                         kr.setKeyName("Servicekeyname2grp");
150                                         kr.setKeyValue("Servicemyvalue2grp");
151                                         myService.getCategoryBag().getKeyedReference().add(kr);
152 
153                                         krg = new KeyedReferenceGroup();
154                                         krg.setTModelKey(UDDIConstants.TRANSPORT_HTTP);
155                                         kr = new KeyedReference();
156                                         kr.setTModelKey(UDDIConstants.TRANSPORT_HTTP);
157                                         kr.setKeyName("keyname1grp");
158                                         kr.setKeyValue("myvalue1grp");
159 
160                                         krg.getKeyedReference().add(kr);
161                                         myService.getCategoryBag().getKeyedReferenceGroup().add(krg);
162 
163                                         AccessPoint accessPoint = new AccessPoint();
164                                         accessPoint.setUseType(AccessPointType.WSDL_DEPLOYMENT.toString());
165                                         accessPoint.setValue("http://example.org/services/myservice" + i + k + "?wsdl");
166                                         myBindingTemplate.setAccessPoint(accessPoint);
167                                         myBindingTemplate.setTModelInstanceDetails(new TModelInstanceDetails());
168                                         TModelInstanceInfo tii = new TModelInstanceInfo();
169                                         Description d = new Description();
170                                         d.setValue("Tmodel instance description");
171                                         tii.getDescription().add(d);
172                                         tii.setTModelKey(UDDIConstants.TRANSPORT_HTTP);
173                                         tii.setInstanceDetails(new InstanceDetails());
174                                         tii.getInstanceDetails().setInstanceParms("heres some useful stuff describing this endpoint, up to 4KB of data" + " " + textgen.getWords(20, 2));
175                                         tii.getInstanceDetails().getDescription().add(d);
176                                         OverviewDoc od = new OverviewDoc();
177                                         d = new Description();
178                                         d.setValue("ovweview doc description" + " " + textgen.getWords(5, 2));
179                                         od.getDescription().add(d);
180                                         od.setOverviewURL(new OverviewURL());
181                                         od.getOverviewURL().setUseType("www");
182                                         od.getOverviewURL().setValue("www.apache.org");
183                                         tii.getInstanceDetails().getOverviewDoc().add(od);
184                                         myBindingTemplate.getTModelInstanceDetails().getTModelInstanceInfo().add(tii);
185 
186                                         BindingTemplates myBindingTemplates = new BindingTemplates();
187                                         myBindingTemplate = UDDIClient.addSOAPtModels(myBindingTemplate);
188                                         myBindingTemplates.getBindingTemplate().add(myBindingTemplate);
189                                         myService.setBindingTemplates(myBindingTemplates);
190                                         try {
191                                                 // Adding the service to the "save" structure, using our publisher's authentication info and saving away.
192                                                 SaveService ss = new SaveService();
193                                                 ss.getBusinessService().add(myService);
194                                                 ss.setAuthInfo(token);
195                                                 ServiceDetail sd = publish.saveService(ss);
196                                                 String myServKey = sd.getBusinessService().get(0).getServiceKey();
197                                                 System.out.println("saved: service key:  " + myServKey);
198                                         } catch (Exception x) {
199                                                 x.printStackTrace();
200                                         }
201                                 }
202                         }
203                 } catch (Exception e) {
204                         e.printStackTrace();
205                 }
206         }
207 
208         public static void main(String args[]) {
209                 UddiCreatebulk sp = new UddiCreatebulk(null);
210                 sp.publishBusiness(null, 15, 20, "root");
211         }
212 }