1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * ===========================================================================
\r
7 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * * you may not use this file except in compliance with the License.
\r
9 * * You may obtain a copy of the License at
\r
11 * * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * * Unless required by applicable law or agreed to in writing, software
\r
14 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * * See the License for the specific language governing permissions and
\r
17 * * limitations under the License.
\r
18 * * ============LICENSE_END====================================================
\r
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
23 package org.onap.aaf.cadi.dme2;
\r
25 import java.net.MalformedURLException;
\r
26 import java.net.URI;
\r
27 import java.net.URISyntaxException;
\r
28 import java.util.ArrayList;
\r
29 import java.util.List;
\r
31 import org.onap.aaf.cadi.CadiException;
\r
32 import org.onap.aaf.cadi.SecuritySetter;
\r
33 import org.onap.aaf.cadi.client.EClient;
\r
34 import org.onap.aaf.cadi.client.Rcli;
\r
36 import com.att.aft.dme2.api.DME2Client;
\r
37 import com.att.aft.dme2.api.DME2Exception;
\r
38 import com.att.aft.dme2.api.DME2Manager;
\r
39 import com.att.aft.dme2.manager.registry.DME2Endpoint;
\r
40 import com.att.aft.dme2.request.DmeUniformResource;
\r
41 import org.onap.aaf.inno.env.APIException;
\r
42 import org.onap.aaf.inno.env.Data.TYPE;
\r
45 * DME2 Rosetta Client
\r
47 * JAXB defined JSON or XML over DME2 middleware
\r
52 public class DRcli extends Rcli<DME2Client> {
\r
53 // Can be more efficient if tied to manager, apparently. Can pass in null.
\r
54 DME2Manager manager=null;
\r
55 private SecuritySetter<DME2Client> ss;
\r
56 private boolean isProxy;
\r
58 public DRcli(URI uri, SecuritySetter<DME2Client> secSet) {
\r
66 protected DRcli clone(URI uri, SecuritySetter<DME2Client> ss) {
\r
67 return new DRcli(uri,ss);
\r
73 * Note from Thaniga on 11/5. DME2Client is not expected to be reused... need a fresh one
\r
74 * on each transaction, which is expected to cover the Async aspects.
\r
77 * @throws APIException
\r
78 * @throws DME2Exception
\r
80 protected EClient<DME2Client> client() throws CadiException {
\r
82 DEClient dc = new DEClient(manager,getSecuritySetter(),uri,readTimeout);
\r
83 dc.setProxy(isProxy);
\r
85 } catch (DME2Exception e) {
\r
86 throw new CadiException(e);
\r
90 public DRcli setManager(DME2Manager dme2Manager) {
\r
91 manager = dme2Manager;
\r
95 public List<DRcli> all() throws DME2Exception, APIException {
\r
96 ArrayList<DRcli> al = new ArrayList<DRcli>();
\r
98 if(manager == null) {
\r
99 manager = DME2Manager.getDefaultInstance();
\r
102 DME2Endpoint[] endp = manager.getEndpoints(new DmeUniformResource(manager.getConfig(),uri));
\r
103 // Convert Searchable Endpoints to Direct Endpoints
\r
104 for(DME2Endpoint de : endp) {
\r
106 new URI(uri.getScheme(),null,de.getHost(),de.getPort(),null,null,null),ss)
\r
107 // new URI(uri.getScheme(),null,de.getHost(),de.getPort(),uri.getPath(),null,null),ss)
\r
108 .setManager(manager)
\r
111 } catch (MalformedURLException e) {
\r
112 throw new APIException("Invalid URL",e);
\r
113 } catch (URISyntaxException e) {
\r
114 throw new APIException("Invalid URI",e);
\r
120 public void invalidate() throws CadiException {
\r
123 } catch (Exception e) {
\r
124 throw new CadiException(e);
\r
129 public void setSecuritySetter(SecuritySetter<DME2Client> ss) {
\r
134 public SecuritySetter<DME2Client> getSecuritySetter() {
\r
138 public void setProxy(boolean isProxy) {
\r
139 this.isProxy = isProxy;
\r