View Javadoc
1   /*
2    * Copyright 2020 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  package org.apache.juddi.example.juddi.embedded;
17  
18  import java.io.File;
19  import java.util.HashSet;
20  import java.util.Set;
21  import org.apache.juddi.Registry;
22  import org.apache.juddi.api.impl.JUDDIApiImpl;
23  import org.apache.juddi.api.impl.UDDICustodyTransferImpl;
24  import org.apache.juddi.api.impl.UDDIInquiryImpl;
25  import org.apache.juddi.api.impl.UDDIPublicationImpl;
26  import org.apache.juddi.api.impl.UDDISecurityImpl;
27  import org.apache.juddi.api.impl.UDDISubscriptionImpl;
28  import org.apache.juddi.api.impl.UDDIValueSetCachingImpl;
29  import org.apache.juddi.api.impl.UDDIValueSetValidationImpl;
30  import static org.apache.juddi.config.AppConfig.JUDDI_CONFIGURATION_FILE_SYSTEM_PROPERTY;
31  import org.apache.juddi.v3.client.UDDIConstants;
32  import org.uddi.api_v3.BusinessList;
33  import org.uddi.api_v3.FindBusiness;
34  import org.uddi.api_v3.Name;
35  
36  /**
37   * In this case, we are not using juddi's client/clerk/transport apis, just
38   * using the instance classes directly
39   *
40   * @author Alex O'Ree
41   */
42  public class EmbeddedNoWebNoClerk {
43  
44      public static void main(String[] args) throws Exception {
45          //tell juddi to load this server configuration file from disk
46          File cfg = new File("juddi-server.xml").getCanonicalFile();
47          System.setProperty(JUDDI_CONFIGURATION_FILE_SYSTEM_PROPERTY, cfg.getCanonicalPath());
48  
49          //start up the services
50          Registry.start();
51          //note these instance classes will be used to server web requests
52          //do not share embedded access with web access classes due to context
53          //sharing issues.
54          JUDDIApiImpl juddi = new JUDDIApiImpl();
55          UDDIPublicationImpl publish = new UDDIPublicationImpl();
56          UDDIInquiryImpl inquiry = new UDDIInquiryImpl();
57          UDDISecurityImpl security = new UDDISecurityImpl();
58          UDDISubscriptionImpl subscription = new UDDISubscriptionImpl();
59          UDDICustodyTransferImpl custody = new UDDICustodyTransferImpl();
60          UDDIValueSetCachingImpl cache = new UDDIValueSetCachingImpl();
61          UDDIValueSetValidationImpl validation = new UDDIValueSetValidationImpl();
62  
63          //clients within this process can use invm transport
64          {
65              System.out.println("started, verifying embedded access");
66              FindBusiness fb = new FindBusiness();
67              fb.setMaxRows(200);
68              fb.setListHead(0);
69              // fb.setAuthInfo(GetToken());
70              org.uddi.api_v3.FindQualifiers fq = new org.uddi.api_v3.FindQualifiers();
71              fq.getFindQualifier().add(UDDIConstants.CASE_INSENSITIVE_MATCH);
72              fq.getFindQualifier().add(UDDIConstants.APPROXIMATE_MATCH);
73              fq.getFindQualifier().add(UDDIConstants.SORT_BY_NAME_ASC);
74              fb.setFindQualifiers(fq);
75              Name searchname = new Name();
76              searchname.setLang("%");
77              searchname.setValue("%");
78              fb.getName().add(searchname);
79  
80              BusinessList result = inquiry.findBusiness(fb);
81              System.out.println(result.getBusinessInfos().getBusinessInfo().size() + " businesses available");
82              //uddiClientHttp.stop();
83          }
84  
85          //for cases that require authentication...
86          //the authenticator should work the same as it is in tomcat
87          //except if you use http style authentication. in this case, you'll have 
88          //to do this....
89          //Set<String> roles = new HashSet<String>();
90          //Note: juddi doesn't use servlet container roles
91          //publish.setContext(new MyWebContext("uddi", roles));
92  
93          System.out.println("ready, press enter to stop");
94          //  System.console().readLine();
95  
96          //shutdown
97          Registry.stop();
98      }
99  }