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 at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * 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 and14 * limitations under the License.15 *16 */17package org.apache.juddi.samples;
1819import java.util.ArrayList;
20import java.util.GregorianCalendar;
21import java.util.List;
22import javax.xml.datatype.DatatypeFactory;
23import javax.xml.datatype.XMLGregorianCalendar;
24import javax.xml.ws.Holder;
25import org.apache.juddi.v3.client.config.UDDIClient;
26import org.apache.juddi.v3.client.transport.Transport;
27import org.uddi.api_v3.*;
28import org.uddi.v3_service.UDDIPublicationPortType;
29import org.uddi.v3_service.UDDISecurityPortType;
3031/**32 * This will create two businesses under different users, then setup a33 * relationship between the two34 *35 * @author <a href="mailto:alexoree@apache.org">Alex O'Ree</a>36 */37publicclassUddiRelatedBusinesses {
3839privateUDDISecurityPortType security = null;
40privateUDDIPublicationPortType publish = null;
4142publicUddiRelatedBusinesses() {
43try {
44// create a manager and read the config in the archive; 45// you can use your config file name46UDDIClient clerkManager = newUDDIClient("META-INF/simple-publish-uddi.xml");
47Transport transport = clerkManager.getTransport();
48// Now you create a reference to the UDDI API49 security = transport.getUDDISecurityService();
50 publish = transport.getUDDIPublishService();
51 } catch (Exception e) {
52 e.printStackTrace();
53 }
54 }
5556publicvoid fire(String businessKey, String authInfo, String businessKey1, String authInfo1, String relationship) throws Exception {
57try {
585960 GregorianCalendar gcal = new GregorianCalendar();
61 gcal.setTimeInMillis(System.currentTimeMillis());
626364//ROOT creates half of the relationship65//create a business relationship (publisher assertion)66 Holder<List<PublisherAssertion>> x = new Holder<List<PublisherAssertion>>();
67PublisherAssertion pa = newPublisherAssertion();
68 pa.setFromKey(businessKey);
69 pa.setToKey(businessKey1);
70 pa.setKeyedReference(newKeyedReference());
71 pa.getKeyedReference().setKeyName("Subsidiary");
72 pa.getKeyedReference().setKeyValue(relationship);
7374 pa.getKeyedReference().setTModelKey("uddi:uddi.org:relationships");
75 x.value = new ArrayList<PublisherAssertion>();
76 x.value.add(pa);
77 publish.setPublisherAssertions(authInfo, x);
7879//now "UDDI" the user, creates the other half. It has to be mirrored exactly80 x = new Holder<List<PublisherAssertion>>();
81 pa = newPublisherAssertion();
82 pa.setFromKey(businessKey);
83 pa.setToKey(businessKey1);
84 pa.setKeyedReference(newKeyedReference());
85 pa.getKeyedReference().setKeyName("Subsidiary");
86 pa.getKeyedReference().setKeyValue(relationship);
8788 pa.getKeyedReference().setTModelKey("uddi:uddi.org:relationships");
89 x.value = new ArrayList<PublisherAssertion>();
90 x.value.add(pa);
91 publish.setPublisherAssertions(authInfo1, x);
9293 System.out.println("Success!");
94/*95 * Here's some notes:96 * You can use97 * List<AssertionStatusItem> assertionStatusReport = publish.getAssertionStatusReport(UDDIAuthToken.getAuthInfo(), CompletionStatus.STATUS_FROM_KEY_INCOMPLETE);98 * to determine if there's any assertions/relationships requests that are pending99 * this should have one item it in, the relationship that's incomplete100 * 101 * There's also publish.deletePublisherAssertions();102 */103 } catch (Exception e) {
104 e.printStackTrace();
105 }
106 }
107108publicstaticvoid main(String args[]) throws Exception {
109UddiRelatedBusinesses sp = newUddiRelatedBusinesses();
110111GetAuthToken getAuthTokenRoot = newGetAuthToken();
112 getAuthTokenRoot.setUserID("root");
113 getAuthTokenRoot.setCred("root");
114115// Making API call that retrieves the authentication token for the 'root' user.116AuthToken rootAuthToken = sp.security.getAuthToken(getAuthTokenRoot);
117 System.out.println("root AUTHTOKEN = " + "don't log auth tokens!");
118BusinessEntity rootbiz = sp.createBusiness("root");
119120 getAuthTokenRoot = newGetAuthToken();
121 getAuthTokenRoot.setUserID("uddi");
122 getAuthTokenRoot.setCred("uddi");
123124// Making API call that retrieves the authentication token for the 'root' user.125AuthToken uddiAuthToken = sp.security.getAuthToken(getAuthTokenRoot);
126 System.out.println("uddi AUTHTOKEN = " + "don't log auth tokens!");
127BusinessEntity uddibiz = sp.createBusiness("uddi");
128129//save user uddi's business130SaveBusiness sb = newSaveBusiness();
131 sb.setAuthInfo(uddiAuthToken.getAuthInfo());
132 sb.getBusinessEntity().add(uddibiz);
133BusinessDetail uddibize = sp.publish.saveBusiness(sb);
134135 sb = newSaveBusiness();
136 sb.setAuthInfo(rootAuthToken.getAuthInfo());
137 sb.getBusinessEntity().add(rootbiz);
138BusinessDetail rootbize = sp.publish.saveBusiness(sb);
139140 sp.fire(rootbize.getBusinessEntity().get(0).getBusinessKey(), rootAuthToken.getAuthInfo(),
141 uddibize.getBusinessEntity().get(0).getBusinessKey(), uddiAuthToken.getAuthInfo(),
142"parent-child");
143 }
144145privateBusinessEntity createBusiness(String user) {
146BusinessEntity be = newBusinessEntity();
147 be.getName().add(new Name(user + "'s business", null));
148return be;
149 }
150151 }