This project has retired. For details please refer to its Attic page.
BusinessServiceKeymismatch 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 org.apache.juddi.v3.client.config.UDDIClerk;
20  import org.apache.juddi.v3.client.config.UDDIClient;
21  import org.apache.juddi.v3.client.config.UDDIClientContainer;
22  import org.apache.juddi.v3.client.transport.Transport;
23  import org.apache.juddi.v3_service.JUDDIApiPortType;
24  import org.uddi.api_v3.AccessPoint;
25  import org.uddi.api_v3.AuthToken;
26  import org.uddi.api_v3.BindingTemplate;
27  import org.uddi.api_v3.BindingTemplates;
28  import org.uddi.api_v3.BusinessEntity;
29  import org.uddi.api_v3.BusinessService;
30  import org.uddi.api_v3.BusinessServices;
31  import org.uddi.api_v3.GetAuthToken;
32  import org.uddi.api_v3.Name;
33  import org.uddi.api_v3.SaveBusiness;
34  import org.uddi.api_v3.SaveTModel;
35  import org.uddi.api_v3.TModel;
36  import org.uddi.v3_service.UDDIPublicationPortType;
37  import org.uddi.v3_service.UDDISecurityPortType;
38  
39  /**
40   * This class was created to demonstrate that UDDI entities's keys do not need
41   * to be from the same key domain. I.e. Business key = "uddi:1234:business"
42   * which owns Service key "uddi:4567:service1"
43   *
44   * @author <a href="mailto:alexoree@apache.org">Alex O'Ree</a>
45   */
46  public class BusinessServiceKeymismatch {
47  
48          private static UDDISecurityPortType security = null;
49          private static JUDDIApiPortType juddiApi = null;
50          private static UDDIPublicationPortType publish = null;
51  
52          public static void main(String[] args) throws Exception {
53  
54                  // create a manager and read the config in the archive; 
55                  // you can use your config file name
56                  UDDIClient clerkManager = new UDDIClient("META-INF/simple-publish-uddi.xml");
57                  // The transport can be WS, inVM etc which is defined in the uddi.xml
58                  Transport transport = clerkManager.getTransport("default");
59                  // Now you create a reference to the UDDI API
60                  security = transport.getUDDISecurityService();
61                  publish = transport.getUDDIPublishService();
62  
63                  //step one, get a token
64                  GetAuthToken getAuthTokenRoot = new GetAuthToken();
65                  getAuthTokenRoot.setUserID("uddi");
66  
67                  getAuthTokenRoot.setCred("uddi");
68                  AuthToken authToken = security.getAuthToken(getAuthTokenRoot);
69                  TModel createKeyGenator = UDDIClerk.createKeyGenator("uddi:testdomain:keygenerator", "a name", "en");
70  
71                  TModel createKeyGenator2 = UDDIClerk.createKeyGenator("uddi:testdomain2:keygenerator", "a name", "en");
72  
73                  SaveTModel st = new SaveTModel();
74                  st.setAuthInfo(authToken.getAuthInfo());
75                  st.getTModel().add(createKeyGenator);
76                  st.getTModel().add(createKeyGenator2);
77                  publish.saveTModel(st);
78  
79                  SaveBusiness sb = new SaveBusiness();
80                  sb.setAuthInfo(authToken.getAuthInfo());
81                  BusinessEntity be = new BusinessEntity();
82                  be.setBusinessKey("uddi:testdomain:biz1");
83                  be.getName().add(new Name("test", "en"));
84                  be.setBusinessServices(new BusinessServices());
85                  BusinessService bs = new BusinessService();
86                  bs.setServiceKey("uddi:testdomain2:svc");
87                  bs.setBusinessKey("uddi:testdomain:biz1");
88                  bs.getName().add(new Name("svc", "en"));
89                  bs.setBindingTemplates(new BindingTemplates());
90                  BindingTemplate bt = new BindingTemplate();
91                  bt.setAccessPoint(new AccessPoint("http://localhost", "wsdlDeployment"));
92                  bt = UDDIClient.addSOAPtModels(bt);
93                  bs.getBindingTemplates().getBindingTemplate().add(bt);
94                  be.getBusinessServices().getBusinessService().add(bs);
95                  sb.getBusinessEntity().add(be);
96                  publish.saveBusiness(sb);
97          }
98  }