summaryrefslogtreecommitdiffstats
path: root/client/src/main/java/org/onap/aaf/cadi/client
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/main/java/org/onap/aaf/cadi/client')
-rw-r--r--client/src/main/java/org/onap/aaf/cadi/client/AAFClient.java199
-rw-r--r--client/src/main/java/org/onap/aaf/cadi/client/AbsBasicAuth.java93
-rw-r--r--client/src/main/java/org/onap/aaf/cadi/client/AbsTransferSS.java73
-rw-r--r--client/src/main/java/org/onap/aaf/cadi/client/Delete.java71
-rw-r--r--client/src/main/java/org/onap/aaf/cadi/client/EClient.java52
-rw-r--r--client/src/main/java/org/onap/aaf/cadi/client/EnvAccess.java169
-rw-r--r--client/src/main/java/org/onap/aaf/cadi/client/Future.java34
-rw-r--r--client/src/main/java/org/onap/aaf/cadi/client/Get.java49
-rw-r--r--client/src/main/java/org/onap/aaf/cadi/client/Holder.java44
-rw-r--r--client/src/main/java/org/onap/aaf/cadi/client/Post.java50
-rw-r--r--client/src/main/java/org/onap/aaf/cadi/client/PropertyLocator.java143
-rw-r--r--client/src/main/java/org/onap/aaf/cadi/client/Put.java65
-rw-r--r--client/src/main/java/org/onap/aaf/cadi/client/RawClient.java159
-rw-r--r--client/src/main/java/org/onap/aaf/cadi/client/Rcli.java697
-rw-r--r--client/src/main/java/org/onap/aaf/cadi/client/Result.java57
-rw-r--r--client/src/main/java/org/onap/aaf/cadi/client/Retryable.java72
16 files changed, 0 insertions, 2027 deletions
diff --git a/client/src/main/java/org/onap/aaf/cadi/client/AAFClient.java b/client/src/main/java/org/onap/aaf/cadi/client/AAFClient.java
deleted file mode 100644
index cb6299b..0000000
--- a/client/src/main/java/org/onap/aaf/cadi/client/AAFClient.java
+++ /dev/null
@@ -1,199 +0,0 @@
-/*******************************************************************************
- * ============LICENSE_START====================================================
- * * org.onap.aaf
- * * ===========================================================================
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * * ===========================================================================
- * * Licensed under the Apache License, Version 2.0 (the "License");
- * * you may not use this file except in compliance with the License.
- * * You may obtain a copy of the License at
- * *
- * * http://www.apache.org/licenses/LICENSE-2.0
- * *
- * * Unless required by applicable law or agreed to in writing, software
- * * distributed under the License is distributed on an "AS IS" BASIS,
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * * See the License for the specific language governing permissions and
- * * limitations under the License.
- * * ============LICENSE_END====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.client;
-
-import java.net.HttpURLConnection;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.onap.aaf.cadi.Access;
-import org.onap.aaf.cadi.config.Config;
-import org.onap.aaf.cadi.config.SecurityInfoC;
-import org.onap.aaf.cadi.http.HBasicAuthSS;
-import org.onap.aaf.cadi.http.HMangr;
-import org.onap.aaf.cadi.locator.DME2Locator;
-
-import com.att.aft.dme2.api.DME2Manager;
-import org.onap.aaf.inno.env.APIException;
-import org.onap.aaf.rosetta.env.RosettaDF;
-import org.onap.aaf.rosetta.env.RosettaEnv;
-
-public class AAFClient {
- private RosettaEnv env;
- private Map<Class<?>,RosettaDF<?>> map = new HashMap<Class<?>,RosettaDF<?>>();
- HMangr hman;
- HBasicAuthSS ss;
-
- public AAFClient(RosettaEnv env) throws Exception {
- this.env = env;
- Access access = new EnvAccess(env);
- String user = access.getProperty(Config.AAF_MECHID,null);
- String password = access.decrypt(access.getProperty(Config.AAF_MECHPASS,null), true);
-
- SecurityInfoC<HttpURLConnection> si = new SecurityInfoC<HttpURLConnection>(access);
- DME2Manager dm = new DME2Manager("APIclient DME2Manager", System.getProperties());
- DME2Locator loc = new DME2Locator(access, dm, access.getProperty(Config.AAF_URL,null));
-
- int TIMEOUT = Integer.parseInt(access.getProperty(Config.AAF_CONN_TIMEOUT, "30000"));
-
- hman = new HMangr(access, loc).readTimeout(TIMEOUT).apiVersion("2.0");
- ss = new HBasicAuthSS(user, password, si);
- }
-
- public AAFClient(RosettaEnv env, DME2Manager dm) throws Exception {
- this.env = env;
- Access access = new EnvAccess(env);
- String user = access.getProperty(Config.AAF_MECHID,null);
- String password = access.decrypt(access.getProperty(Config.AAF_MECHPASS,null), true);
-
- SecurityInfoC<HttpURLConnection> si = new SecurityInfoC<HttpURLConnection>(access);
- DME2Locator loc = new DME2Locator(access, dm, access.getProperty(Config.AAF_URL,null));
-
- int TIMEOUT = Integer.parseInt(access.getProperty(Config.AAF_CONN_TIMEOUT, "30000"));
-
- hman = new HMangr(access, loc).readTimeout(TIMEOUT).apiVersion("2.0");
- ss = new HBasicAuthSS(user, password, si);
- }
-
- @SuppressWarnings("unchecked")
- private synchronized<T> RosettaDF<T> getDF(Class<T> cls) throws APIException {
- RosettaDF<?> rdf;
- synchronized (env) {
- rdf = map.get(cls);
- if(rdf==null) {
- rdf = env.newDataFactory(cls);
- map.put(cls, rdf);
- }
- }
- return (RosettaDF<T>)rdf;
- }
-
- // Package on purpose
- static class Call<T> {
- protected final static String VOID_CONTENT_TYPE="application/Void+json;version=2.0";
-
- protected RosettaDF<T> df;
- protected AAFClient client;
-
- public Call(AAFClient ac, RosettaDF<T> df) {
- this.client = ac;
- this.df = df;
- }
- }
-
-
- /////////// Calls /////////////////
- /**
- * Returns a Get Object... same as "get"
- *
- * @param cls
- * @return
- * @throws APIException
- */
- public<T> Get<T> read(Class<T> cls) throws APIException {
- return new Get<T>(this,getDF(cls));
- }
-
- /**
- * Returns a Get Object... same as "read"
- *
- * @param cls
- * @return
- * @throws APIException
- */
- public<T> Get<T> get(Class<T> cls) throws APIException {
- return new Get<T>(this,getDF(cls));
- }
-
- /**
- * Returns a Post Object... same as "create"
- *
- * @param cls
- * @return
- * @throws APIException
- */
- public<T> Post<T> post(Class<T> cls) throws APIException {
- return new Post<T>(this,getDF(cls));
- }
-
- /**
- * Returns a Post Object... same as "post"
- *
- * @param cls
- * @return
- * @throws APIException
- */
- public<T> Post<T> create(Class<T> cls) throws APIException {
- return new Post<T>(this,getDF(cls));
- }
-
- /**
- * Returns a Put Object... same as "update"
- *
- * @param cls
- * @return
- * @throws APIException
- */
- public<T> Put<T> put(Class<T> cls) throws APIException {
- return new Put<T>(this,getDF(cls));
- }
-
- /**
- * Returns a Put Object... same as "put"
- *
- * @param cls
- * @return
- * @throws APIException
- */
- public<T> Put<T> update(Class<T> cls) throws APIException {
- return new Put<T>(this,getDF(cls));
- }
-
- /**
- * Returns a Delete Object
- *
- * @param cls
- * @return
- * @throws APIException
- */
- public<T> Delete<T> delete(Class<T> cls) throws APIException {
- return new Delete<T>(this,getDF(cls));
- }
-
- /**
- * Returns a Delete Object
- *
- * @param cls
- * @return
- * @throws APIException
- */
- public Delete<Void> delete() throws APIException {
- return new Delete<Void>(this,null);
- }
-
- public Put<Void> put() {
- return new Put<Void>(this,null);
- }
-
-
-}
diff --git a/client/src/main/java/org/onap/aaf/cadi/client/AbsBasicAuth.java b/client/src/main/java/org/onap/aaf/cadi/client/AbsBasicAuth.java
deleted file mode 100644
index e714e3a..0000000
--- a/client/src/main/java/org/onap/aaf/cadi/client/AbsBasicAuth.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*******************************************************************************
- * ============LICENSE_START====================================================
- * * org.onap.aaf
- * * ===========================================================================
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * * ===========================================================================
- * * Licensed under the Apache License, Version 2.0 (the "License");
- * * you may not use this file except in compliance with the License.
- * * You may obtain a copy of the License at
- * *
- * * http://www.apache.org/licenses/LICENSE-2.0
- * *
- * * Unless required by applicable law or agreed to in writing, software
- * * distributed under the License is distributed on an "AS IS" BASIS,
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * * See the License for the specific language governing permissions and
- * * limitations under the License.
- * * ============LICENSE_END====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.client;
-
-import java.io.IOException;
-
-import org.onap.aaf.cadi.SecuritySetter;
-import org.onap.aaf.cadi.Symm;
-import org.onap.aaf.cadi.config.SecurityInfoC;
-
-public abstract class AbsBasicAuth<CLIENT> implements SecuritySetter<CLIENT> {
- protected static final String REPEAT_OFFENDER="This call is aborted because of repeated usage of invalid Passwords";
- private static final int MAX_TEMP_COUNT = 10;
- private static final int MAX_SPAM_COUNT = 10000;
- private static final long WAIT_TIME = 1000*60*4;
-
- protected final String headValue;
- protected SecurityInfoC<CLIENT> securityInfo;
- protected String user;
- private long lastMiss;
- private int count;
-
- public AbsBasicAuth(String user, String pass, SecurityInfoC<CLIENT> si) throws IOException {
- this.user = user;
- headValue = "Basic " + Symm.base64.encode(user + ':' + pass);
- securityInfo = si;
- lastMiss=0L;
- count=0;
- }
-
- /* (non-Javadoc)
- * @see com.att.cadi.SecuritySetter#getID()
- */
- @Override
- public String getID() {
- return user;
- }
-
- public boolean isDenied() {
- if(lastMiss>0 && lastMiss>System.currentTimeMillis()) {
- return true;
- } else {
- lastMiss=0L;
- return false;
- }
- }
-
- public synchronized int setLastResponse(int httpcode) {
- if(httpcode == 401) {
- ++count;
- if(lastMiss==0L && count>MAX_TEMP_COUNT) {
- lastMiss=System.currentTimeMillis()+WAIT_TIME;
- }
-// if(count>MAX_SPAM_COUNT) {
-// System.err.printf("Your service has %d consecutive bad service logins to AAF. \nIt will now exit\n",
-// count);
-// System.exit(401);
-// }
- if(count%1000==0) {
- System.err.printf("Your service has %d consecutive bad service logins to AAF. AAF Access will be disabled after %d\n",
- count,MAX_SPAM_COUNT);
- }
-
- } else {
- lastMiss=0;
- }
- return count;
- }
-
- public int count() {
- return count;
- }
-}
diff --git a/client/src/main/java/org/onap/aaf/cadi/client/AbsTransferSS.java b/client/src/main/java/org/onap/aaf/cadi/client/AbsTransferSS.java
deleted file mode 100644
index e731f09..0000000
--- a/client/src/main/java/org/onap/aaf/cadi/client/AbsTransferSS.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*******************************************************************************
- * ============LICENSE_START====================================================
- * * org.onap.aaf
- * * ===========================================================================
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * * ===========================================================================
- * * Licensed under the Apache License, Version 2.0 (the "License");
- * * you may not use this file except in compliance with the License.
- * * You may obtain a copy of the License at
- * *
- * * http://www.apache.org/licenses/LICENSE-2.0
- * *
- * * Unless required by applicable law or agreed to in writing, software
- * * distributed under the License is distributed on an "AS IS" BASIS,
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * * See the License for the specific language governing permissions and
- * * limitations under the License.
- * * ============LICENSE_END====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.client;
-
-import java.security.Principal;
-
-import org.onap.aaf.cadi.SecuritySetter;
-import org.onap.aaf.cadi.config.SecurityInfoC;
-import org.onap.aaf.cadi.principal.BasicPrincipal;
-import org.onap.aaf.cadi.principal.TGuardPrincipal;
-import org.onap.aaf.cadi.principal.TrustPrincipal;
-
-public abstract class AbsTransferSS<CLIENT> implements SecuritySetter<CLIENT> {
- protected String value;
- protected SecurityInfoC<CLIENT> securityInfo;
- protected SecuritySetter<CLIENT> defSS;
- private Principal principal;
-
- //Format:<ID>:<APP>:<protocol>[:AS][,<ID>:<APP>:<protocol>]*
- public AbsTransferSS(Principal principal, String app) {
- init(principal, app);
- }
-
- public AbsTransferSS(Principal principal, String app, SecurityInfoC<CLIENT> si) {
- init(principal,app);
- securityInfo = si;
- this.defSS = si.defSS;
- }
-
- private void init(Principal principal, String app) {
- this.principal=principal;
- if(principal==null) {
- return;
- } else if(principal instanceof BasicPrincipal) {
- value = principal.getName() + ':' + app + ":BasicAuth:AS";
- } else if(principal instanceof TrustPrincipal) {
- TrustPrincipal tp = (TrustPrincipal)principal;
- // recursive
- init(tp.original(),app);
- value += principal.getName() + ':' + app + ":Trust:AS" + ',' + tp.userChain();
- } else if(principal instanceof TGuardPrincipal) {
- value = principal.getName() + ':' + app + ":TGUARD:AS";
- }
- }
-
- /* (non-Javadoc)
- * @see com.att.cadi.SecuritySetter#getID()
- */
- @Override
- public String getID() {
- return principal==null?"":principal.getName();
- }
-}
diff --git a/client/src/main/java/org/onap/aaf/cadi/client/Delete.java b/client/src/main/java/org/onap/aaf/cadi/client/Delete.java
deleted file mode 100644
index 9f03aab..0000000
--- a/client/src/main/java/org/onap/aaf/cadi/client/Delete.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*******************************************************************************
- * ============LICENSE_START====================================================
- * * org.onap.aaf
- * * ===========================================================================
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * * ===========================================================================
- * * Licensed under the Apache License, Version 2.0 (the "License");
- * * you may not use this file except in compliance with the License.
- * * You may obtain a copy of the License at
- * *
- * * http://www.apache.org/licenses/LICENSE-2.0
- * *
- * * Unless required by applicable law or agreed to in writing, software
- * * distributed under the License is distributed on an "AS IS" BASIS,
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * * See the License for the specific language governing permissions and
- * * limitations under the License.
- * * ============LICENSE_END====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.client;
-
-import org.onap.aaf.cadi.CadiException;
-
-import org.onap.aaf.inno.env.APIException;
-import org.onap.aaf.rosetta.env.RosettaDF;
-
-public class Delete<T> extends AAFClient.Call<T> {
- public Delete(AAFClient ac, RosettaDF<T> df) {
- super(ac,df);
- }
-
- @SuppressWarnings("unchecked")
- public Result<T> delete(final String pathInfo, final T t) throws Exception {
- if(t==null) {
- return (Result<T>)delete(pathInfo);
- }
- return client.hman.best(client.ss,
- new Retryable<Result<T>>() {
- @Override
- public Result<T> code(Rcli<?> client) throws APIException, CadiException {
- Future<T> ft = client.delete(pathInfo,df,t);
- if(ft.get(client.readTimeout)) {
- return Result.ok(ft.code(),ft.value);
- } else {
- return Result.err(ft.code(),ft.body());
- }
- }
- });
- }
-
- public Result<Void> delete(final String pathInfo) throws Exception {
- return client.hman.best(client.ss,
- new Retryable<Result<Void>>() {
- @Override
- public Result<Void> code(Rcli<?> client) throws APIException, CadiException {
- Future<Void> ft = client.delete(pathInfo,VOID_CONTENT_TYPE);
- if(ft.get(client.readTimeout)) {
- return Result.ok(ft.code(),ft.value);
- } else {
- return Result.err(ft.code(),ft.body());
- }
- }
- });
- }
-
-
-
-}
diff --git a/client/src/main/java/org/onap/aaf/cadi/client/EClient.java b/client/src/main/java/org/onap/aaf/cadi/client/EClient.java
deleted file mode 100644
index a880331..0000000
--- a/client/src/main/java/org/onap/aaf/cadi/client/EClient.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*******************************************************************************
- * ============LICENSE_START====================================================
- * * org.onap.aaf
- * * ===========================================================================
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * * ===========================================================================
- * * Licensed under the Apache License, Version 2.0 (the "License");
- * * you may not use this file except in compliance with the License.
- * * You may obtain a copy of the License at
- * *
- * * http://www.apache.org/licenses/LICENSE-2.0
- * *
- * * Unless required by applicable law or agreed to in writing, software
- * * distributed under the License is distributed on an "AS IS" BASIS,
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * * See the License for the specific language governing permissions and
- * * limitations under the License.
- * * ============LICENSE_END====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.client;
-
-import java.io.IOException;
-import java.io.OutputStream;
-
-import javax.servlet.http.HttpServletResponse;
-
-import org.onap.aaf.inno.env.APIException;
-import org.onap.aaf.inno.env.Data;
-import org.onap.aaf.rosetta.env.RosettaDF;
-
-
-public interface EClient<CT> {
- public void setMethod(String meth);
- public void setPathInfo(String pathinfo);
- public void setPayload(Transfer transfer);
- public void addHeader(String tag, String value);
- public void setQueryParams(String q);
- public void setFragment(String f);
- public void send() throws APIException;
- public<T> Future<T> futureCreate(Class<T> t);
- public Future<String> futureReadString();
- public<T> Future<T> futureRead(RosettaDF<T> df,Data.TYPE type);
- public<T> Future<T> future(T t);
- public Future<Void> future(HttpServletResponse resp, int expected) throws APIException;
-
- public interface Transfer {
- public void transfer(OutputStream os) throws IOException, APIException;
- }
-}
diff --git a/client/src/main/java/org/onap/aaf/cadi/client/EnvAccess.java b/client/src/main/java/org/onap/aaf/cadi/client/EnvAccess.java
deleted file mode 100644
index bcf41f8..0000000
--- a/client/src/main/java/org/onap/aaf/cadi/client/EnvAccess.java
+++ /dev/null
@@ -1,169 +0,0 @@
-/*******************************************************************************
- * ============LICENSE_START====================================================
- * * org.onap.aaf
- * * ===========================================================================
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * * ===========================================================================
- * * Licensed under the Apache License, Version 2.0 (the "License");
- * * you may not use this file except in compliance with the License.
- * * You may obtain a copy of the License at
- * *
- * * http://www.apache.org/licenses/LICENSE-2.0
- * *
- * * Unless required by applicable law or agreed to in writing, software
- * * distributed under the License is distributed on an "AS IS" BASIS,
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * * See the License for the specific language governing permissions and
- * * limitations under the License.
- * * ============LICENSE_END====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.client;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Map.Entry;
-
-import org.onap.aaf.cadi.Access;
-import org.onap.aaf.cadi.Symm;
-
-import java.util.Properties;
-
-import org.onap.aaf.inno.env.Decryptor;
-import org.onap.aaf.inno.env.Env;
-import org.onap.aaf.inno.env.impl.BasicEnv;
-
-public class EnvAccess implements Access {
- private Env env;
-
- /**
- * String Property tag for files/resources that may contain properties. Can be null.
- * Resources of ClassLoader will be checked first, if exist. Can be null.
- * @param env
- * @param tag
- * @param cl
- * @throws IOException
- */
- public EnvAccess(BasicEnv env, ClassLoader cl) throws IOException {
- this.env = env;
- final Symm s = Symm.obtain(this);
- env.set(new Decryptor() {
- private Symm symm = s;
- @Override
- public String decrypt(String encrypted) {
- try {
- return (encrypted!=null && (encrypted.startsWith(Symm.ENC)))
- ? symm.depass(encrypted)
- : encrypted;
- } catch (IOException e) {
- return "";
- }
- }
- }
- );
- }
-
-
- /**
- * Construct with the Classloader of Env and CADI_PROP_FILES, if possible
- *
- * @param env
- * @throws IOException
- */
- public EnvAccess(BasicEnv env) throws IOException {
- this(env, env.getClass().getClassLoader());
- }
-
- @Override
- public void log(Level level, Object... elements) {
- switch(level) {
- case AUDIT:
- env.audit().log(elements);
- break;
- case DEBUG:
- env.debug().log(elements);
- break;
- case ERROR:
- env.error().log(elements);
- break;
- case INFO:
- env.info().log(elements);
- break;
- case INIT:
- env.init().log(elements);
- break;
- case WARN:
- env.warn().log(elements);
- break;
- default:
- break;
- }
-
- }
-
- @Override
- public void log(Exception e, Object... elements) {
- env.error().log(e,elements);
- }
-
- @Override
- public void printf(Level level, String fmt, Object... elements) {
- if(willLog(level)) {
- log(level,String.format(fmt, elements));
- }
- }
-
-
- @Override
- public boolean willLog(Level level) {
- switch(level) {
- case AUDIT:
- return env.audit().isLoggable();
- case DEBUG:
- return env.debug().isLoggable();
- case ERROR:
- return env.error().isLoggable();
- case INFO:
- return env.info().isLoggable();
- case INIT:
- return env.init().isLoggable();
- case WARN:
- return env.warn().isLoggable();
- default:
- return false;
- }
- }
-
-
- @Override
- public void setLogLevel(Level level) {
- // unused
- }
-
- @Override
- public ClassLoader classLoader() {
- return env.getClass().getClassLoader();
- }
-
- @Override
- public String getProperty(String string, String def) {
- return env.getProperty(string, def);
- }
-
- @Override
- public void load(InputStream is) throws IOException {
- Properties props = new Properties();
- props.load(is);
- for(Entry<Object, Object> es :props.entrySet()) {
- env.setProperty(es.getKey().toString(), es.getValue().toString());
- }
- }
-
- @Override
- public String decrypt(String encrypted, boolean anytext) throws IOException {
- return env.decryptor().decrypt(encrypted);
- }
-
-}
diff --git a/client/src/main/java/org/onap/aaf/cadi/client/Future.java b/client/src/main/java/org/onap/aaf/cadi/client/Future.java
deleted file mode 100644
index 01a85b8..0000000
--- a/client/src/main/java/org/onap/aaf/cadi/client/Future.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*******************************************************************************
- * ============LICENSE_START====================================================
- * * org.onap.aaf
- * * ===========================================================================
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * * ===========================================================================
- * * Licensed under the Apache License, Version 2.0 (the "License");
- * * you may not use this file except in compliance with the License.
- * * You may obtain a copy of the License at
- * *
- * * http://www.apache.org/licenses/LICENSE-2.0
- * *
- * * Unless required by applicable law or agreed to in writing, software
- * * distributed under the License is distributed on an "AS IS" BASIS,
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * * See the License for the specific language governing permissions and
- * * limitations under the License.
- * * ============LICENSE_END====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.client;
-
-import org.onap.aaf.cadi.CadiException;
-
-public abstract class Future<T> {
- public T value;
- public abstract boolean get(int timeout) throws CadiException;
-
- public abstract int code();
- public abstract String body();
- public abstract String header(String tag);
-}
diff --git a/client/src/main/java/org/onap/aaf/cadi/client/Get.java b/client/src/main/java/org/onap/aaf/cadi/client/Get.java
deleted file mode 100644
index 920b476..0000000
--- a/client/src/main/java/org/onap/aaf/cadi/client/Get.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*******************************************************************************
- * ============LICENSE_START====================================================
- * * org.onap.aaf
- * * ===========================================================================
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * * ===========================================================================
- * * Licensed under the Apache License, Version 2.0 (the "License");
- * * you may not use this file except in compliance with the License.
- * * You may obtain a copy of the License at
- * *
- * * http://www.apache.org/licenses/LICENSE-2.0
- * *
- * * Unless required by applicable law or agreed to in writing, software
- * * distributed under the License is distributed on an "AS IS" BASIS,
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * * See the License for the specific language governing permissions and
- * * limitations under the License.
- * * ============LICENSE_END====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.client;
-
-import org.onap.aaf.cadi.CadiException;
-
-import org.onap.aaf.inno.env.APIException;
-import org.onap.aaf.rosetta.env.RosettaDF;
-
-public class Get<T> extends AAFClient.Call<T> {
- public Get(AAFClient ac, RosettaDF<T> df) {
- super(ac,df);
- }
-
- public Result<T> read(final String pathInfo) throws Exception {
- return client.hman.best(client.ss,
- new Retryable<Result<T>>() {
- @Override
- public Result<T> code(Rcli<?> client) throws APIException, CadiException {
- Future<T> ft = client.read(pathInfo,df);
- if(ft.get(client.readTimeout)) {
- return Result.ok(ft.code(),ft.value);
- } else {
- return Result.err(ft.code(),ft.body());
- }
- }
- });
- }
-}
diff --git a/client/src/main/java/org/onap/aaf/cadi/client/Holder.java b/client/src/main/java/org/onap/aaf/cadi/client/Holder.java
deleted file mode 100644
index 577fa5f..0000000
--- a/client/src/main/java/org/onap/aaf/cadi/client/Holder.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*******************************************************************************
- * ============LICENSE_START====================================================
- * * org.onap.aaf
- * * ===========================================================================
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * * ===========================================================================
- * * Licensed under the Apache License, Version 2.0 (the "License");
- * * you may not use this file except in compliance with the License.
- * * You may obtain a copy of the License at
- * *
- * * http://www.apache.org/licenses/LICENSE-2.0
- * *
- * * Unless required by applicable law or agreed to in writing, software
- * * distributed under the License is distributed on an "AS IS" BASIS,
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * * See the License for the specific language governing permissions and
- * * limitations under the License.
- * * ============LICENSE_END====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.client;
-
-/**
- * Use to set Variables outside of Anonymous classes.
- *
- *
- * @param <T>
- */
-public class Holder<T> {
- private T value;
- public Holder(T t) {
- value = t;
- }
- public void set(T t) {
- value = t;
- }
-
- public T get() {
- return value;
- }
-
-}
diff --git a/client/src/main/java/org/onap/aaf/cadi/client/Post.java b/client/src/main/java/org/onap/aaf/cadi/client/Post.java
deleted file mode 100644
index 5c9bde2..0000000
--- a/client/src/main/java/org/onap/aaf/cadi/client/Post.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*******************************************************************************
- * ============LICENSE_START====================================================
- * * org.onap.aaf
- * * ===========================================================================
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * * ===========================================================================
- * * Licensed under the Apache License, Version 2.0 (the "License");
- * * you may not use this file except in compliance with the License.
- * * You may obtain a copy of the License at
- * *
- * * http://www.apache.org/licenses/LICENSE-2.0
- * *
- * * Unless required by applicable law or agreed to in writing, software
- * * distributed under the License is distributed on an "AS IS" BASIS,
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * * See the License for the specific language governing permissions and
- * * limitations under the License.
- * * ============LICENSE_END====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.client;
-
-import org.onap.aaf.cadi.CadiException;
-import org.onap.aaf.cadi.LocatorException;
-
-import org.onap.aaf.inno.env.APIException;
-import org.onap.aaf.rosetta.env.RosettaDF;
-
-public class Post<T> extends AAFClient.Call<T> {
- public Post(AAFClient ac, RosettaDF<T> df) {
- super(ac,df);
- }
-
- public Result<T> create(final String pathInfo, final T t) throws APIException, CadiException, LocatorException {
- return client.hman.best(client.ss,
- new Retryable<Result<T>>() {
- @Override
- public Result<T> code(Rcli<?> client) throws APIException, CadiException {
- Future<T> ft = client.create(pathInfo,df,t);
- if(ft.get(client.readTimeout)) {
- return Result.ok(ft.code(),ft.value);
- } else {
- return Result.err(ft.code(),ft.body());
- }
- }
- });
- }
-}
diff --git a/client/src/main/java/org/onap/aaf/cadi/client/PropertyLocator.java b/client/src/main/java/org/onap/aaf/cadi/client/PropertyLocator.java
deleted file mode 100644
index 15705ab..0000000
--- a/client/src/main/java/org/onap/aaf/cadi/client/PropertyLocator.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*******************************************************************************
- * ============LICENSE_START====================================================
- * * org.onap.aaf
- * * ===========================================================================
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * * ===========================================================================
- * * Licensed under the Apache License, Version 2.0 (the "License");
- * * you may not use this file except in compliance with the License.
- * * You may obtain a copy of the License at
- * *
- * * http://www.apache.org/licenses/LICENSE-2.0
- * *
- * * Unless required by applicable law or agreed to in writing, software
- * * distributed under the License is distributed on an "AS IS" BASIS,
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * * See the License for the specific language governing permissions and
- * * limitations under the License.
- * * ============LICENSE_END====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.client;
-
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Random;
-
-import org.onap.aaf.cadi.Locator;
-import org.onap.aaf.cadi.LocatorException;
-
-public class PropertyLocator implements Locator {
- private final URI [] orig;
- private PLItem[] current;
- private int end;
- private final Random random;
-
- /**
- * comma delimited root url list
- *
- * @param locList
- * @throws LocatorException
- */
- public PropertyLocator(String locList) throws LocatorException {
- if(locList==null)throw new LocatorException("No Location List given for PropertyLocator");
- String[] locarray = locList.split("\\s*,\\s*");
- orig = new URI[locarray.length];
-
- random = new Random();
-
- for(int i=0;i<locarray.length;++i) {
- try {
- orig[i] = new URI(locarray[i]);
- } catch (URISyntaxException e) {
- throw new LocatorException(e);
- }
- }
-
- current = new PLItem[orig.length];
- refresh();
- }
-
- @Override
- public URI get(Item item) throws LocatorException {
- return orig[((PLItem)item).idx];
- }
-
- @Override
- public Item first() throws LocatorException {
- return end>0?current[0]:null;
- }
-
- @Override
- public boolean hasItems() {
- return end>0;
- }
-
- @Override
- public Item next(Item item) throws LocatorException {
- int spot;
- if((spot=(((PLItem)item).order+1))>=end)return null;
- return current[spot];
- }
-
- @Override
- public synchronized void invalidate(Item item) throws LocatorException {
- if(--end<=0)return;
- PLItem pli = (PLItem)item;
- int i,order;
- for(i=0;i<end;++i) {
- if(pli==current[i])break;
- }
- order = current[i].order;
- for(;i<end;++i) {
- current[i]=current[i+1];
- current[i].order=order++;
- }
- current[end]=pli;
- }
-
- @Override
- public Item best() throws LocatorException {
- switch(current.length) {
- case 0:
- return null;
- case 1:
- return current[0];
- default:
- return current[Math.abs(random.nextInt())%end];
- }
- }
-
- @Override
- public synchronized boolean refresh() {
- end = orig.length;
-
- // Build up list
- for(int i = 0; i < end ; ++i) {
- if(current[i]==null)current[i]=new PLItem(i);
- else current[i].idx=current[i].order=i;
- }
- return true;
- }
-
- private class PLItem implements Item {
- public int idx,order;
-
- public PLItem(int i) {
- idx = order =i;
- }
-
- public String toString() {
- return "Item: " + idx + " order: " + order;
- }
- }
-
- @Override
- public void destroy() {
- // TODO Auto-generated method stub
-
- }
-
-}
diff --git a/client/src/main/java/org/onap/aaf/cadi/client/Put.java b/client/src/main/java/org/onap/aaf/cadi/client/Put.java
deleted file mode 100644
index ebd6e0d..0000000
--- a/client/src/main/java/org/onap/aaf/cadi/client/Put.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*******************************************************************************
- * ============LICENSE_START====================================================
- * * org.onap.aaf
- * * ===========================================================================
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * * ===========================================================================
- * * Licensed under the Apache License, Version 2.0 (the "License");
- * * you may not use this file except in compliance with the License.
- * * You may obtain a copy of the License at
- * *
- * * http://www.apache.org/licenses/LICENSE-2.0
- * *
- * * Unless required by applicable law or agreed to in writing, software
- * * distributed under the License is distributed on an "AS IS" BASIS,
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * * See the License for the specific language governing permissions and
- * * limitations under the License.
- * * ============LICENSE_END====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.client;
-
-import org.onap.aaf.cadi.CadiException;
-
-import org.onap.aaf.inno.env.APIException;
-import org.onap.aaf.rosetta.env.RosettaDF;
-
-public class Put<T> extends AAFClient.Call<T> {
- public Put(AAFClient ac, RosettaDF<T> df) {
- super(ac,df);
- }
-
- public Result<T> update(final String pathInfo, final T t) throws Exception {
- return client.hman.best(client.ss,
- new Retryable<Result<T>>() {
- @Override
- public Result<T> code(Rcli<?> client) throws APIException, CadiException {
- Future<T> ft = client.update(pathInfo,df,t);
- if(ft.get(client.readTimeout)) {
- return Result.ok(ft.code(),ft.value);
- } else {
- return Result.err(ft.code(),ft.body());
- }
- }
- });
- }
-
- public Result<Void> update(final String pathInfo) throws Exception {
- return client.hman.best(client.ss,
- new Retryable<Result<Void>>() {
- @Override
- public Result<Void> code(Rcli<?> client) throws APIException, CadiException {
- Future<Void> ft = client.update(pathInfo);
- if(ft.get(client.readTimeout)) {
- return Result.ok(ft.code(),ft.value);
- } else {
- return Result.err(ft.code(),ft.body());
- }
- }
- });
- }
-
-}
diff --git a/client/src/main/java/org/onap/aaf/cadi/client/RawClient.java b/client/src/main/java/org/onap/aaf/cadi/client/RawClient.java
deleted file mode 100644
index 0386383..0000000
--- a/client/src/main/java/org/onap/aaf/cadi/client/RawClient.java
+++ /dev/null
@@ -1,159 +0,0 @@
-/*******************************************************************************
- * ============LICENSE_START====================================================
- * * org.onap.aaf
- * * ===========================================================================
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * * ===========================================================================
- * * Licensed under the Apache License, Version 2.0 (the "License");
- * * you may not use this file except in compliance with the License.
- * * You may obtain a copy of the License at
- * *
- * * http://www.apache.org/licenses/LICENSE-2.0
- * *
- * * Unless required by applicable law or agreed to in writing, software
- * * distributed under the License is distributed on an "AS IS" BASIS,
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * * See the License for the specific language governing permissions and
- * * limitations under the License.
- * * ============LICENSE_END====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.client;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.PrintStream;
-import java.net.URI;
-
-import org.onap.aaf.cadi.Symm;
-import org.onap.aaf.cadi.config.Config;
-
-import com.att.aft.dme2.api.DME2Client;
-
-public abstract class RawClient {
- protected static String aafid, aafpass, aafurl;
- protected static Symm symm;
-
- protected static boolean init(PrintStream out) {
- try {
- String propfile = System.getProperty(Config.CADI_PROP_FILES);
- if(propfile==null) {
- propfile = "raw.props";
- }
- File pfile = new File(propfile);
- if(!pfile.exists()) {
- if(propfile.equals("raw.props")) {
- out.println("Creating 'raw.props'. Edit for proper values, then run again. Alternatively, set "
- + Config.CADI_PROP_FILES+" to a cadi properties file");
- FileOutputStream fos = new FileOutputStream(pfile);
- PrintStream ps = new PrintStream(fos);
- try {
- ps.println("# Use http://www.bing.com/maps to figure out LAT/LONG of an Address");
- ps.println("AFT_LATITUDE=38.432930");
- ps.println("AFT_LONGITUDE=-90.432480");
- ps.println("AFT_ENVIRONMENT=AFTUAT");
- ps.print(Config.AAF_URL);
- ps.println("=aaf_url=https://DME2RESOLVE/service=com.att.authz.AuthorizationService/version=2.0/envContext=DEV/routeOffer=BAU_SE");
- ps.print(Config.CADI_KEYFILE);
- ps.println("=<keyfile. use java -jar cadi-core*.jar in lib dir>");
- ps.println(Config.AAF_MECHID);
- ps.print("=<your id>");
- ps.println(Config.AAF_MECHPASS);
- ps.print("=<your encrypted password. use java -jar cadi-core*.jar in lib dir>");
- } finally {
- ps.close();
- }
- }
- } else {
- FileInputStream fis = new FileInputStream(propfile);
- try {
- System.getProperties().load(fis);
- } finally {
- fis.close();
- }
-
- String cadiKeyFile = System.getProperty(Config.CADI_KEYFILE);
- aafid = System.getProperty(Config.AAF_MECHID);
- aafpass = System.getProperty(Config.AAF_MECHPASS);
- aafurl = System.getProperty(Config.AAF_URL);
- out.println("Contacting: " + aafurl);
-
- if(cadiKeyFile==null || aafid==null || aafpass==null || aafurl==null ) {
- out.print(Config.CADI_KEYFILE);
- out.print(", ");
- out.print(Config.CADI_KEYFILE);
- out.print(", ");
- out.print(Config.CADI_KEYFILE);
- out.print(", ");
- out.print(Config.CADI_KEYFILE);
- out.print(" need to be set in ");
- out.println(propfile);
- } else {
- fis = new FileInputStream(cadiKeyFile);
- try {
- symm = Symm.obtain(fis);
- } finally {
- fis.close();
- }
- }
- return true;
- }
- } catch (Exception e) {
- e.printStackTrace(out);
- }
- return false;
-
- }
-
- public abstract String call(final PrintStream out, final String meth, final String path) throws Exception;
-
- public static void main(String[] args) {
- // Sonar idiocy
- PrintStream out = System.out;
-
- try {
- if(init(out)) {
- if(args.length<2) {
- System.out.println("Parameters: <Method> <path>");
- } else {
- RawClient client = new DME2();
- out.println(client.call(out,args[0],args[1]));
- }
- }
- } catch (Exception e) {
- e.printStackTrace(out);
- }
- }
-
- protected static class DME2 extends RawClient {
-
- public String call(final PrintStream out, final String meth, final String path) {
- try {
- DME2Client client = new DME2Client(new URI(aafurl),10000);
- client.setCredentials(aafid, symm.depass(aafpass));
- client.setMethod(meth);
- client.setContext(path);
-
- if("GET".equalsIgnoreCase(meth) ||
- "DELETE".equalsIgnoreCase(meth)) {
- client.setPayload("");
- } else if("POST".equalsIgnoreCase(meth) ||
- "PUT".equalsIgnoreCase(meth)) {
- int c;
- StringBuilder sb = new StringBuilder();
- while((c=System.in.read()) >=0) {
- sb.append((char)c);
- }
- client.setPayload(sb.toString());
- }
- return client.sendAndWait(10000);
- } catch (Exception e) {
- e.printStackTrace(out);
- return "";
- }
- }
- }
-}
diff --git a/client/src/main/java/org/onap/aaf/cadi/client/Rcli.java b/client/src/main/java/org/onap/aaf/cadi/client/Rcli.java
deleted file mode 100644
index 23158ef..0000000
--- a/client/src/main/java/org/onap/aaf/cadi/client/Rcli.java
+++ /dev/null
@@ -1,697 +0,0 @@
-/*******************************************************************************
- * ============LICENSE_START====================================================
- * * org.onap.aaf
- * * ===========================================================================
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * * ===========================================================================
- * * Licensed under the Apache License, Version 2.0 (the "License");
- * * you may not use this file except in compliance with the License.
- * * You may obtain a copy of the License at
- * *
- * * http://www.apache.org/licenses/LICENSE-2.0
- * *
- * * Unless required by applicable law or agreed to in writing, software
- * * distributed under the License is distributed on an "AS IS" BASIS,
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * * See the License for the specific language governing permissions and
- * * limitations under the License.
- * * ============LICENSE_END====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.client;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.net.URI;
-import java.util.Enumeration;
-
-import javax.servlet.ServletInputStream;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.onap.aaf.cadi.CadiException;
-import org.onap.aaf.cadi.SecuritySetter;
-
-import org.onap.aaf.inno.env.APIException;
-import org.onap.aaf.inno.env.Data.TYPE;
-import org.onap.aaf.inno.env.util.Pool;
-import org.onap.aaf.inno.env.util.Pool.Pooled;
-import org.onap.aaf.rosetta.env.RosettaDF;
-
-public abstract class Rcli<CT> {
- public static final String BLANK = "";
- public static final String CONTENT_TYPE = "Content-Type";
- public static final String ACCEPT = "Accept";
-
- protected static final String POST = "POST";
- protected static final String GET = "GET";
- protected static final String PUT = "PUT";
- protected static final String DELETE = "DELETE";
- protected TYPE type;
- protected String apiVersion;
- protected int readTimeout = 5000;
- protected int connectionTimeout = 3000;
- protected URI uri;
- private String queryParams, fragment;
- public static Pool<byte[]> buffPool = new Pool<byte[]>(new Pool.Creator<byte[]>() {
- @Override
- public byte[] create() throws APIException {
- return new byte[1024];
- }
-
- @Override
- public void destroy(byte[] t) {
- }
-
- @Override
- public boolean isValid(byte[] t) {
- return true;
- }
-
- @Override
- public void reuse(byte[] t) {
- }
- });
-
-
- public Rcli() {
- super();
- }
-
- public abstract void setSecuritySetter(SecuritySetter<CT> ss);
- public abstract SecuritySetter<CT> getSecuritySetter();
-
-
- public Rcli<CT> forUser(SecuritySetter<CT> ss) {
- Rcli<CT> rv = clone(uri==null?this.uri:uri,ss);
- setSecuritySetter(ss);
- rv.type = type;
- rv.apiVersion = apiVersion;
- return rv;
- }
-
- protected abstract Rcli<CT> clone(URI uri, SecuritySetter<CT> ss);
-
- public abstract void invalidate() throws CadiException;
-
- public Rcli<CT> readTimeout(int millis) {
- readTimeout = millis;
- return this;
- }
-
- public Rcli<CT> connectionTimeout(int millis) {
- connectionTimeout = millis;
- return this;
- }
-
- public Rcli<CT> type(TYPE type) {
- this.type=type;
- return this;
- }
-
- public Rcli<CT> apiVersion(String apiVersion) {
- this.apiVersion = apiVersion;
- return this;
- }
-
- public boolean isApiVersion(String prospective) {
- return apiVersion.equals(prospective);
- }
-
-
- public String typeString(Class<?> cls) {
- return "application/"+cls.getSimpleName()+"+"+type.name().toLowerCase()+
- (apiVersion==null?BLANK:";version="+apiVersion);
- }
-
- protected abstract EClient<CT> client() throws CadiException;
-
-
- public<T> Future<T> create(String pathinfo, String contentType, final RosettaDF<T> df, final T t) throws APIException, CadiException {
- final int idx = pathinfo.indexOf('?');
- final String qp;
- if(idx>=0) {
- qp=pathinfo.substring(idx+1);
- pathinfo=pathinfo.substring(0,idx);
- } else {
- qp=queryParams;
- }
- EClient<CT> client = client();
- client.setMethod(POST);
- client.addHeader(CONTENT_TYPE,contentType);
- client.setPathInfo(pathinfo);
- client.setQueryParams(qp);
- client.setFragment(fragment);
- client.setPayload(new EClient.Transfer() {
- @Override
- public void transfer(OutputStream os) throws IOException, APIException {
- df.newData().out(type).direct(t,os);
- }
- });
- client.send();
- queryParams = fragment = null;
- return client.futureCreate(df.getTypeClass());
- }
-
- public<T> Future<T> create(String pathinfo, final RosettaDF<T> df, final T t) throws APIException, CadiException {
- final int idx = pathinfo.indexOf('?');
- final String qp;
- if(idx>=0) {
- qp=pathinfo.substring(idx+1);
- pathinfo=pathinfo.substring(0,idx);
- } else {
- qp=queryParams;
- }
- EClient<CT> client = client();
- client.setMethod(POST);
- client.addHeader(CONTENT_TYPE,typeString(df.getTypeClass()));
- client.setPathInfo(pathinfo);
- client.setQueryParams(qp);
- client.setFragment(fragment);
- client.setPayload(new EClient.Transfer() {
- @Override
- public void transfer(OutputStream os) throws IOException, APIException {
- df.newData().out(type).direct(t,os);
- }
- });
- client.send();
- queryParams = fragment = null;
- return client.futureCreate(df.getTypeClass());
- }
-
- public<T> Future<T> create(String pathinfo, Class<?> cls, final RosettaDF<T> df, final T t) throws APIException, CadiException {
- final int idx = pathinfo.indexOf('?');
- final String qp;
- if(idx>=0) {
- qp=pathinfo.substring(idx+1);
- pathinfo=pathinfo.substring(0,idx);
- } else {
- qp=queryParams;
- }
-
- EClient<CT> client = client();
- client.setMethod(POST);
- client.addHeader(CONTENT_TYPE,typeString(cls));
- client.setPathInfo(pathinfo);
- client.setQueryParams(qp);
- client.setFragment(fragment);
- client.setPayload(new EClient.Transfer() {
- @Override
- public void transfer(OutputStream os) throws IOException, APIException {
- df.newData().out(type).direct(t,os);
- }
- });
- client.send();
- queryParams = fragment = null;
- return client.futureCreate(df.getTypeClass());
- }
-
- public<T> Future<T> create(String pathinfo, Class<T> cls) throws APIException, CadiException {
- final int idx = pathinfo.indexOf('?');
- final String qp;
- if(idx>=0) {
- qp=pathinfo.substring(idx+1);
- pathinfo=pathinfo.substring(0,idx);
- } else {
- qp=queryParams;
- }
-
- EClient<CT> client = client();
- client.setMethod(POST);
- client.addHeader(CONTENT_TYPE,typeString(cls));
- client.setPathInfo(pathinfo);
- client.setQueryParams(qp);
- client.setFragment(fragment);
- client.setPayload(null);
- client.send();
- queryParams = fragment = null;
- return client.futureCreate(cls);
- }
-
- public Future<Void> create(String pathinfo, String contentType) throws APIException, CadiException {
- final int idx = pathinfo.indexOf('?');
- final String qp;
- if(idx>=0) {
- qp=pathinfo.substring(idx+1);
- pathinfo=pathinfo.substring(0,idx);
- } else {
- qp=queryParams;
- }
-
- EClient<CT> client = client();
- client.setMethod(POST);
- client.addHeader(CONTENT_TYPE,contentType);
- client.setPathInfo(pathinfo);
- client.setQueryParams(qp);
- client.setFragment(fragment);
- client.setPayload(null);
- client.send();
- queryParams = fragment = null;
- return client.futureCreate(Void.class);
- }
-
-
- public Future<String> read(String pathinfo, String accept, String ... headers) throws APIException, CadiException {
- final int idx = pathinfo.indexOf('?');
- final String qp;
- if(idx>=0) {
- qp=pathinfo.substring(idx+1);
- pathinfo=pathinfo.substring(0,idx);
- } else {
- qp=queryParams;
- }
-
- EClient<CT> client = client();
- client.setMethod(GET);
- client.addHeader(ACCEPT, accept);
-
- for(int i=1;i<headers.length;i=i+2) {
- client.addHeader(headers[i-1],headers[i]);
- }
- client.setQueryParams(qp);
- client.setFragment(fragment);
-
- client.setPathInfo(pathinfo);
-
- client.setPayload(null);
- client.send();
- queryParams = fragment = null;
- return client.futureReadString();
- }
-
- public<T> Future<T> read(String pathinfo, String accept, RosettaDF<T> df, String ... headers) throws APIException, CadiException {
- final int idx = pathinfo.indexOf('?');
- final String qp;
- if(idx>=0) {
- qp=pathinfo.substring(idx+1);
- pathinfo=pathinfo.substring(0,idx);
- } else {
- qp=queryParams;
- }
-
- EClient<CT> client = client();
- client.setMethod(GET);
- client.addHeader(ACCEPT, accept);
- for(int i=1;i<headers.length;i=i+2) {
- client.addHeader(headers[i-1],headers[i]);
- }
- client.setQueryParams(qp);
- client.setFragment(fragment);
- client.setPathInfo(pathinfo);
-
- client.setPayload(null);
- client.send();
- queryParams = fragment = null;
- return client.futureRead(df,type);
- }
-
- public<T> Future<T> read(String pathinfo, RosettaDF<T> df,String ... headers) throws APIException, CadiException {
- final int idx = pathinfo.indexOf('?');
- final String qp;
- if(idx>=0) {
- qp=pathinfo.substring(idx+1);
- pathinfo=pathinfo.substring(0,idx);
- } else {
- qp=queryParams;
- }
-
- EClient<CT> client = client();
- client.setMethod(GET);
- client.addHeader(ACCEPT, typeString(df.getTypeClass()));
- for(int i=1;i<headers.length;i=i+2) {
- client.addHeader(headers[i-1],headers[i]);
- }
- client.setQueryParams(qp);
- client.setFragment(fragment);
- client.setPathInfo(pathinfo);
-
- client.setPayload(null);
- client.send();
- queryParams = fragment = null;
- return client.futureRead(df,type);
- }
-
- public<T> Future<T> read(String pathinfo, Class<?> cls, RosettaDF<T> df) throws APIException, CadiException {
- final int idx = pathinfo.indexOf('?');
- final String qp;
- if(idx>=0) {
- qp=pathinfo.substring(idx+1);
- pathinfo=pathinfo.substring(0,idx);
- } else {
- qp=queryParams;
- }
-
- EClient<CT> client = client();
- client.setMethod(GET);
- client.addHeader(ACCEPT, typeString(cls));
- client.setQueryParams(qp);
- client.setFragment(fragment);
- client.setPathInfo(pathinfo);
-
- client.setPayload(null);
- client.send();
- queryParams = fragment = null;
- return client.futureRead(df,type);
- }
-
- public<T> Future<T> update(String pathinfo, String contentType, final RosettaDF<T> df, final T t) throws APIException, CadiException {
- final int idx = pathinfo.indexOf('?');
- final String qp;
- if(idx>=0) {
- qp=pathinfo.substring(idx+1);
- pathinfo=pathinfo.substring(0,idx);
- } else {
- qp=queryParams;
- }
-
- EClient<CT> client = client();
- client.setMethod(PUT);
- client.addHeader(CONTENT_TYPE,contentType);
- client.setQueryParams(qp);
- client.setFragment(fragment);
- client.setPathInfo(pathinfo);
- client.setPayload(new EClient.Transfer() {
- @Override
- public void transfer(OutputStream os) throws IOException, APIException {
- df.newData().out(type).direct(t,os);
- }
- });
- client.send();
- queryParams = fragment = null;
- return client.future(t);
- }
-
- public<T> Future<String> updateRespondString(String pathinfo, final RosettaDF<T> df, final T t) throws APIException, CadiException {
- final int idx = pathinfo.indexOf('?');
- final String qp;
- if(idx>=0) {
- qp=pathinfo.substring(idx+1);
- pathinfo=pathinfo.substring(0,idx);
- } else {
- qp=queryParams;
- }
-
- EClient<CT> client = client();
- client.setMethod(PUT);
- client.addHeader(CONTENT_TYPE, typeString(df.getTypeClass()));
- client.setQueryParams(qp);
- client.setFragment(fragment);
- client.setPathInfo(pathinfo);
- client.setPayload(new EClient.Transfer() {
- @Override
- public void transfer(OutputStream os) throws IOException, APIException {
- df.newData().out(type).direct(t,os);
- }
- });
- client.send();
- queryParams = fragment = null;
- return client.futureReadString();
- }
-
-
- public<T> Future<T> update(String pathinfo, final RosettaDF<T> df, final T t) throws APIException, CadiException {
- final int idx = pathinfo.indexOf('?');
- final String qp;
- if(idx>=0) {
- qp=pathinfo.substring(idx+1);
- pathinfo=pathinfo.substring(0,idx);
- } else {
- qp=queryParams;
- }
-
- EClient<CT> client = client();
- client.setMethod(PUT);
- client.addHeader(CONTENT_TYPE, typeString(df.getTypeClass()));
- client.setQueryParams(qp);
- client.setFragment(fragment);
- client.setPathInfo(pathinfo);
- client.setPayload(new EClient.Transfer() {
- @Override
- public void transfer(OutputStream os) throws IOException, APIException {
- df.newData().out(type).direct(t,os);
- }
- });
- client.send();
- queryParams = fragment = null;
- return client.future(t);
- }
-
- public<T> Future<T> update(String pathinfo, Class<?> cls, final RosettaDF<T> df, final T t) throws APIException, CadiException {
- final int idx = pathinfo.indexOf('?');
- final String qp;
- if(idx>=0) {
- qp=pathinfo.substring(idx+1);
- pathinfo=pathinfo.substring(0,idx);
- } else {
- qp=queryParams;
- }
-
- EClient<CT> client = client();
- client.setMethod(PUT);
- client.addHeader(CONTENT_TYPE, typeString(cls));
- client.setQueryParams(qp);
- client.setFragment(fragment);
- client.setPathInfo(pathinfo);
- client.setPayload(new EClient.Transfer() {
- @Override
- public void transfer(OutputStream os) throws IOException, APIException {
- df.newData().out(type).direct(t,os);
- }
- });
- client.send();
- queryParams = fragment = null;
- return client.future(t);
- }
-
- /**
- * A method to update with a VOID
- * @param pathinfo
- * @param resp
- * @param expected
- * @return
- * @throws APIException
- * @throws CadiException
- */
- public<T> Future<Void> update(String pathinfo) throws APIException, CadiException {
- final int idx = pathinfo.indexOf('?');
- final String qp;
- if(idx>=0) {
- qp=pathinfo.substring(idx+1);
- pathinfo=pathinfo.substring(0,idx);
- } else {
- qp=queryParams;
- }
-
- EClient<CT> client = client();
- client.setMethod(PUT);
- client.addHeader(CONTENT_TYPE, typeString(Void.class));
- client.setQueryParams(qp);
- client.setFragment(fragment);
- client.setPathInfo(pathinfo);
-// client.setPayload(new EClient.Transfer() {
-// @Override
-// public void transfer(OutputStream os) throws IOException, APIException {
-// }
-// });
- client.send();
- queryParams = fragment = null;
- return client.future(null);
- }
-
- public<T> Future<T> delete(String pathinfo, String contentType, final RosettaDF<T> df, final T t) throws APIException, CadiException {
- final int idx = pathinfo.indexOf('?');
- final String qp;
- if(idx>=0) {
- qp=pathinfo.substring(idx+1);
- pathinfo=pathinfo.substring(0,idx);
- } else {
- qp=queryParams;
- }
-
- EClient<CT> client = client();
- client.setMethod(DELETE);
- client.addHeader(CONTENT_TYPE, contentType);
- client.setQueryParams(qp);
- client.setFragment(fragment);
- client.setPathInfo(pathinfo);
- client.setPayload(new EClient.Transfer() {
- @Override
- public void transfer(OutputStream os) throws IOException, APIException {
- df.newData().out(type).direct(t,os);
- }
- });
- client.send();
- queryParams = fragment = null;
- return client.future(t);
- }
-
- public<T> Future<T> delete(String pathinfo, Class<?> cls, final RosettaDF<T> df, final T t) throws APIException, CadiException {
- final int idx = pathinfo.indexOf('?');
- final String qp;
- if(idx>=0) {
- qp=pathinfo.substring(idx+1);
- pathinfo=pathinfo.substring(0,idx);
- } else {
- qp=queryParams;
- }
-
- EClient<CT> client = client();
- client.setMethod(DELETE);
- client.addHeader(CONTENT_TYPE, typeString(cls));
- client.setQueryParams(qp);
- client.setFragment(fragment);
- client.setPathInfo(pathinfo);
- client.setPayload(new EClient.Transfer() {
- @Override
- public void transfer(OutputStream os) throws IOException, APIException {
- df.newData().out(type).direct(t,os);
- }
- });
- client.send();
- queryParams = fragment = null;
- return client.future(t);
- }
-
- public<T> Future<T> delete(String pathinfo, final RosettaDF<T> df, final T t) throws APIException, CadiException {
- final int idx = pathinfo.indexOf('?');
- final String qp;
- if(idx>=0) {
- qp=pathinfo.substring(idx+1);
- pathinfo=pathinfo.substring(0,idx);
- } else {
- qp=queryParams;
- }
-
- EClient<CT> client = client();
- client.setMethod(DELETE);
- client.addHeader(CONTENT_TYPE, typeString(df.getTypeClass()));
- client.setQueryParams(qp);
- client.setFragment(fragment);
- client.setPathInfo(pathinfo);
- client.setPayload(new EClient.Transfer() {
- @Override
- public void transfer(OutputStream os) throws IOException, APIException {
- df.newData().out(type).direct(t,os);
- }
- });
-
- client.send();
- queryParams = fragment = null;
- return client.future(t);
- }
-
-
- public<T> Future<T> delete(String pathinfo, Class<T> cls) throws APIException, CadiException {
- final int idx = pathinfo.indexOf('?');
- final String qp;
- if(idx>=0) {
- qp=pathinfo.substring(idx+1);
- pathinfo=pathinfo.substring(0,idx);
- } else {
- qp=queryParams;
- }
-
- EClient<CT> client = client();
- client.setMethod(DELETE);
- client.addHeader(CONTENT_TYPE, typeString(cls));
- client.setQueryParams(qp);
- client.setFragment(fragment);
- client.setPathInfo(pathinfo);
- client.setPayload(null);
- client.send();
- queryParams = fragment = null;
- return client.future((T)null);
- }
-
- public Future<Void> delete(String pathinfo, String contentType) throws APIException, CadiException {
- final int idx = pathinfo.indexOf('?');
- final String qp;
- if(idx>=0) {
- qp=pathinfo.substring(idx+1);
- pathinfo=pathinfo.substring(0,idx);
- } else {
- qp=queryParams;
- }
-
- EClient<CT> client = client();
- client.setMethod(DELETE);
- client.addHeader(CONTENT_TYPE, contentType);
- client.setQueryParams(qp);
- client.setFragment(fragment);
- client.setPathInfo(pathinfo);
- client.setPayload(null);
- client.send();
- queryParams = fragment = null;
- return client.future(null);
- }
-
- public Future<Void> transfer(final HttpServletRequest req, final HttpServletResponse resp, final String pathParam, final int expected) throws CadiException, APIException {
- EClient<CT> client = client();
- URI uri;
- try {
- uri = new URI(req.getRequestURI());
- } catch (Exception e) {
- throw new CadiException("Invalid incoming URI",e);
- }
- String name;
- for(Enumeration<String> en = req.getHeaderNames();en.hasMoreElements();) {
- name = en.nextElement();
- client.addHeader(name,req.getHeader(name));
- }
- client.setQueryParams(req.getQueryString());
- client.setFragment(uri.getFragment());
- client.setPathInfo(pathParam);
- String meth = req.getMethod();
- client.setMethod(meth);
- if(!"GET".equals(meth)) {
- client.setPayload(new EClient.Transfer() {
- @Override
- public void transfer(OutputStream os) throws IOException, APIException {
- final ServletInputStream is = req.getInputStream();
- int read;
- // reuse Buffers
- Pooled<byte[]> pbuff = buffPool.get();
- try {
- while((read=is.read(pbuff.content))>=0) {
- os.write(pbuff.content,0,read);
- }
- } finally {
- pbuff.done();
- }
- }
- });
- }
- client.send();
- return client.future(resp, expected);
- }
-
- public String toString() {
- return uri.toString();
- }
-
- /**
- * @param queryParams the queryParams to set
- * @return
- */
- public Rcli<CT> setQueryParams(String queryParams) {
- this.queryParams = queryParams;
- return this;
- }
-
-
- /**
- * @param fragment the fragment to set
- * @return
- */
- public Rcli<CT> setFragment(String fragment) {
- this.fragment = fragment;
- return this;
- }
-
- public URI getURI() {
- return uri;
- }
-
-}
diff --git a/client/src/main/java/org/onap/aaf/cadi/client/Result.java b/client/src/main/java/org/onap/aaf/cadi/client/Result.java
deleted file mode 100644
index 5b3d8fd..0000000
--- a/client/src/main/java/org/onap/aaf/cadi/client/Result.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*******************************************************************************
- * ============LICENSE_START====================================================
- * * org.onap.aaf
- * * ===========================================================================
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * * ===========================================================================
- * * Licensed under the Apache License, Version 2.0 (the "License");
- * * you may not use this file except in compliance with the License.
- * * You may obtain a copy of the License at
- * *
- * * http://www.apache.org/licenses/LICENSE-2.0
- * *
- * * Unless required by applicable law or agreed to in writing, software
- * * distributed under the License is distributed on an "AS IS" BASIS,
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * * See the License for the specific language governing permissions and
- * * limitations under the License.
- * * ============LICENSE_END====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.client;
-
-public class Result<T> {
- public final int code;
- public final T value;
- public final String error;
-
- private Result(int code, T value, String error) {
- this.code = code;
- this.value = value;
- this.error = error;
- }
-
- public static<T> Result<T> ok(int code,T t) {
- return new Result<T>(code,t,null);
- }
-
- public static<T> Result<T> err(int code,String body) {
- return new Result<T>(code,null,body);
- }
-
- public boolean isOK() {
- return error==null;
- }
-
- public String toString() {
- StringBuilder sb = new StringBuilder("Code: ");
- sb.append(code);
- if(error!=null) {
- sb.append(" = ");
- sb.append(error);
- }
- return sb.toString();
- }
-}
diff --git a/client/src/main/java/org/onap/aaf/cadi/client/Retryable.java b/client/src/main/java/org/onap/aaf/cadi/client/Retryable.java
deleted file mode 100644
index 9c701ef..0000000
--- a/client/src/main/java/org/onap/aaf/cadi/client/Retryable.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*******************************************************************************
- * ============LICENSE_START====================================================
- * * org.onap.aaf
- * * ===========================================================================
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * * ===========================================================================
- * * Licensed under the Apache License, Version 2.0 (the "License");
- * * you may not use this file except in compliance with the License.
- * * You may obtain a copy of the License at
- * *
- * * http://www.apache.org/licenses/LICENSE-2.0
- * *
- * * Unless required by applicable law or agreed to in writing, software
- * * distributed under the License is distributed on an "AS IS" BASIS,
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * * See the License for the specific language governing permissions and
- * * limitations under the License.
- * * ============LICENSE_END====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.client;
-
-import java.net.ConnectException;
-
-import org.onap.aaf.cadi.CadiException;
-import org.onap.aaf.cadi.Locator;
-
-import org.onap.aaf.inno.env.APIException;
-
-/**
- *
- *
- * @param <RT>
- * @param <RET>
- */
-public abstract class Retryable<RET> {
- // be able to hold state for consistent Connections. Not required for all connection types.
- public Rcli<?> lastClient;
- private Locator.Item item;
-
- public Retryable() {
- lastClient = null;
- item = null;
- }
-
- public Retryable(Retryable<?> ret) {
- lastClient = ret.lastClient;
- item = ret.item;
- }
-
- public Locator.Item item(Locator.Item item) {
- lastClient = null;
- this.item = item;
- return item;
- }
- public Locator.Item item() {
- return item;
- }
-
- public abstract RET code(Rcli<?> client) throws CadiException, ConnectException, APIException;
-
- /**
- * Note, Retryable is tightly coupled to the Client Utilizing. It will not be the wrong type.
- * @return
- */
- @SuppressWarnings("unchecked")
- public <CLIENT> Rcli<CLIENT> lastClient() {
- return (Rcli<CLIENT>)lastClient;
- }
-}