This project has retired. For details please refer to its Attic page.
EmbeddedWithWeb xref
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 com.sun.net.httpserver.HttpServer;
19  import java.io.File;
20  import java.net.InetAddress;
21  import java.net.InetSocketAddress;
22  import javax.xml.ws.Endpoint;
23  import org.apache.commons.configuration.ConfigurationException;
24  import org.apache.juddi.Registry;
25  import org.apache.juddi.api.impl.JUDDIApiImpl;
26  import org.apache.juddi.api.impl.UDDICustodyTransferImpl;
27  import org.apache.juddi.api.impl.UDDIInquiryImpl;
28  import org.apache.juddi.api.impl.UDDIPublicationImpl;
29  import org.apache.juddi.api.impl.UDDISecurityImpl;
30  import org.apache.juddi.api.impl.UDDISubscriptionImpl;
31  import org.apache.juddi.api.impl.UDDIValueSetCachingImpl;
32  import org.apache.juddi.api.impl.UDDIValueSetValidationImpl;
33  import static org.apache.juddi.config.AppConfig.JUDDI_CONFIGURATION_FILE_SYSTEM_PROPERTY;
34  import org.apache.juddi.v3.client.UDDIConstants;
35  import org.apache.juddi.v3.client.config.UDDIClient;
36  import org.apache.juddi.v3.client.config.UDDIClientContainer;
37  import org.apache.juddi.v3.client.transport.Transport;
38  import org.uddi.api_v3.BusinessList;
39  import org.uddi.api_v3.FindBusiness;
40  import org.uddi.api_v3.FindQualifiers;
41  import org.uddi.api_v3.Name;
42  import org.uddi.v3_service.UDDIInquiryPortType;
43  import org.uddi.v3_service.UDDIPublicationPortType;
44  import org.uddi.v3_service.UDDISecurityPortType;
45  
46  /**
47   * Another example using juddi as an embedded standalone process.
48   * <ul>
49   * <li>This will only use uddi style authentication (http auth not
50   * supported).</li>
51   * <li>juddi gui will not start embedded using this sample code.</li>
52   * <li>juddi rest services will not start with this sample code, only the soap
53   * services</li>
54   * </ul>
55   *
56   * @author Alex O'Ree
57   */
58  public class EmbeddedWithWeb {
59      
60      public static void main(String[] args) throws Exception {
61  
62          //tell juddi to load this server configuration file from disk
63          File cfg = new File("juddi-server.xml").getCanonicalFile();
64          System.setProperty(JUDDI_CONFIGURATION_FILE_SYSTEM_PROPERTY, cfg.getCanonicalPath());
65  
66          //start up the services
67          Registry.start();
68          //note these instance classes will be used to server web requests
69          //do not share embedded access with web access classes due to context
70          //sharing issues.
71          JUDDIApiImpl juddi = new JUDDIApiImpl();
72          UDDIPublicationImpl publish = new UDDIPublicationImpl();
73          UDDIInquiryImpl inquiry = new UDDIInquiryImpl();
74          UDDISecurityImpl security = new UDDISecurityImpl();
75          UDDISubscriptionImpl subscription = new UDDISubscriptionImpl();
76          UDDICustodyTransferImpl custody = new UDDICustodyTransferImpl();
77          UDDIValueSetCachingImpl cache = new UDDIValueSetCachingImpl();
78          UDDIValueSetValidationImpl validation = new UDDIValueSetValidationImpl();
79          
80          
81  
82          final HttpServer httpServer = HttpServer.create(new InetSocketAddress(InetAddress.getByName("0.0.0.0"), 8080), 16);
83          //TODO tls setup
84          
85          Endpoint endpointJuddi = Endpoint.create(juddi);
86          Endpoint endpointPublish = Endpoint.create(publish);
87          Endpoint endpointInquiry = Endpoint.create(inquiry);
88          Endpoint endpointSecurity = Endpoint.create(security);
89          Endpoint endpointSubscription = Endpoint.create(subscription);
90          Endpoint endpointCustody = Endpoint.create(custody);
91          Endpoint endpointCache = Endpoint.create(cache);
92          Endpoint endpointValidation = Endpoint.create(validation);
93          
94          endpointJuddi.publish(httpServer.createContext("/juddiv3/services/juddi"));
95          endpointPublish.publish(httpServer.createContext("/juddiv3/services/publish"));
96          endpointInquiry.publish(httpServer.createContext("/juddiv3/services/inquiry"));
97          endpointSecurity.publish(httpServer.createContext("/juddiv3/services/security"));
98          endpointSubscription.publish(httpServer.createContext("/juddiv3/services/subscription"));
99          endpointCustody.publish(httpServer.createContext("/juddiv3/services/custody-transfer"));
100         endpointCache.publish(httpServer.createContext("/juddiv3/services/valueset-caching"));
101         endpointValidation.publish(httpServer.createContext("/juddiv3/services/valueset-validation"));
102         
103         httpServer.start();
104         System.out.println("started, verifying http access");
105 
106         //clients can access the services via http
107         {
108             cfg = new File("uddi-http.xml");
109             UDDIClient uddiClientHttp = new UDDIClient(cfg.getCanonicalPath());
110             uddiClientHttp.start();
111             Transport transport = uddiClientHttp.getTransport("default");
112             UDDISecurityPortType clientSecurity = transport.getUDDISecurityService();
113             UDDIInquiryPortType clientInquiry = transport.getUDDIInquiryService();
114             
115             System.out.println("started, verifying embedded access");
116             FindBusiness fb = new FindBusiness();
117             fb.setMaxRows(200);
118             fb.setListHead(0);
119             // fb.setAuthInfo(GetToken());
120             org.uddi.api_v3.FindQualifiers fq = new org.uddi.api_v3.FindQualifiers();
121             fq.getFindQualifier().add(UDDIConstants.CASE_INSENSITIVE_MATCH);
122             fq.getFindQualifier().add(UDDIConstants.APPROXIMATE_MATCH);
123             fq.getFindQualifier().add(UDDIConstants.SORT_BY_NAME_ASC);
124             fb.setFindQualifiers(fq);
125             Name searchname = new Name();
126             searchname.setLang("%");
127             searchname.setValue("%");
128             fb.getName().add(searchname);
129             
130             BusinessList result = clientInquiry.findBusiness(fb);
131             System.out.println(result.getBusinessInfos().getBusinessInfo().size() + " businesses available");
132             uddiClientHttp.stop();
133         }
134 
135         //clients within this process can use invm transport
136         {
137             
138             cfg = new File("uddi-invm.xml");
139             UDDIClient uddiClientHttp = new UDDIClient(cfg.getCanonicalPath());
140             uddiClientHttp.start();
141             Transport transport = uddiClientHttp.getTransport("default");
142             UDDISecurityPortType clientSecurity = transport.getUDDISecurityService();
143             UDDIInquiryPortType clientInquiry = transport.getUDDIInquiryService();
144             
145             System.out.println("started, verifying embedded access");
146             FindBusiness fb = new FindBusiness();
147             fb.setMaxRows(200);
148             fb.setListHead(0);
149             // fb.setAuthInfo(GetToken());
150             org.uddi.api_v3.FindQualifiers fq = new org.uddi.api_v3.FindQualifiers();
151             fq.getFindQualifier().add(UDDIConstants.CASE_INSENSITIVE_MATCH);
152             fq.getFindQualifier().add(UDDIConstants.APPROXIMATE_MATCH);
153             fq.getFindQualifier().add(UDDIConstants.SORT_BY_NAME_ASC);
154             fb.setFindQualifiers(fq);
155             Name searchname = new Name();
156             searchname.setLang("%");
157             searchname.setValue("%");
158             fb.getName().add(searchname);
159             
160             BusinessList result = clientInquiry.findBusiness(fb);
161             System.out.println(result.getBusinessInfos().getBusinessInfo().size() + " businesses available");
162             //uddiClientHttp.stop();
163         }
164         
165         System.out.println("ready, press enter to stop");
166       //  System.console().readLine();
167 
168         //shutdown
169         endpointJuddi.stop();
170         endpointPublish.stop();
171         endpointInquiry.stop();
172         endpointSecurity.stop();
173         endpointSubscription.stop();
174         endpointCustody.stop();
175         endpointCache.stop();
176         endpointValidation.stop();
177         httpServer.stop(0);
178     }
179 }