From 38f720752af4d4aad8c4e467a288d9048659f688 Mon Sep 17 00:00:00 2001 From: Rob Daugherty Date: Wed, 14 Mar 2018 02:07:32 -0400 Subject: AT&T 1712 and 1802 release code This is code from AT&T's 1712 and 1802 releases. Change-Id: Ie1e85851e94bc66c4d9514a0226c221939531a04 Issue-ID: SO-425 Signed-off-by: Rob Daugherty --- .../base/client/CloudifyBaseException.java | 43 +++++ .../mso/cloudify/base/client/CloudifyClient.java | 130 ++++++++++++++ .../base/client/CloudifyClientConnector.java | 28 +++ .../base/client/CloudifyClientTokenProvider.java | 85 ++++++++++ .../base/client/CloudifyConnectException.java | 39 +++++ .../mso/cloudify/base/client/CloudifyRequest.java | 188 +++++++++++++++++++++ .../mso/cloudify/base/client/CloudifyResponse.java | 38 +++++ .../base/client/CloudifyResponseException.java | 61 +++++++ .../base/client/CloudifyResponseStatus.java | 37 ++++ .../base/client/CloudifySimpleTokenProvider.java | 40 +++++ .../base/client/CloudifyTokenProvider.java | 29 ++++ .../openecomp/mso/cloudify/base/client/Entity.java | 71 ++++++++ .../mso/cloudify/base/client/HttpMethod.java | 25 +++ 13 files changed, 814 insertions(+) create mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyBaseException.java create mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyClient.java create mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyClientConnector.java create mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyClientTokenProvider.java create mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyConnectException.java create mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyRequest.java create mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyResponse.java create mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyResponseException.java create mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyResponseStatus.java create mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifySimpleTokenProvider.java create mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyTokenProvider.java create mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/Entity.java create mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/HttpMethod.java (limited to 'cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client') diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyBaseException.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyBaseException.java new file mode 100644 index 0000000000..1fe933b174 --- /dev/null +++ b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyBaseException.java @@ -0,0 +1,43 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 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========================================================= + */ + +package org.openecomp.mso.cloudify.base.client; + +/** + * A common abstract parent of all Openstack Exception types, allowing + * calling classes the choice to catch all error exceptions together. + */ +public abstract class CloudifyBaseException extends RuntimeException +{ + private static final long serialVersionUID = 1L; + + /* + * Implement only the basic constructors + */ + public CloudifyBaseException () {} + + public CloudifyBaseException(String message) { + super(message); + } + + public CloudifyBaseException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyClient.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyClient.java new file mode 100644 index 0000000000..03f5a9907b --- /dev/null +++ b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyClient.java @@ -0,0 +1,130 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 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========================================================= + */ + +package org.openecomp.mso.cloudify.base.client; + +import java.util.Properties; + +import org.openecomp.mso.cloudify.connector.http.HttpClientConnector; + +public class CloudifyClient { + + protected String managerEndpoint; + protected String tenant = "default_tenant"; // Note - only default_tenant supported in community edition + + protected CloudifyTokenProvider tokenProvider; + + protected static int AUTHENTICATION_RETRIES = 1; + + protected CloudifyClientConnector connector; + + protected Properties properties = new Properties(); + + public CloudifyClient(String managerEndpoint) { + this.managerEndpoint = managerEndpoint; + this.connector = new HttpClientConnector(); + } + + public CloudifyClient(String managerEndpoint, String tenant) { + this.managerEndpoint = managerEndpoint; + this.tenant = tenant; + this.connector = new HttpClientConnector(); + } + + public CloudifyClient(String managerEndpoint, CloudifyClientConnector connector) { + this.managerEndpoint = managerEndpoint; + this.connector = connector; + } + + /** + * Execute a Cloudify request by making the REST API call. Return the + * complete CloudifyResponse structure, which includes the complete + * HTTP response. + * @param request a CloudifyRequest object + * @return a CloudifyResponse object + */ + public CloudifyResponse request(CloudifyRequest request) { + CloudifyResponseException authException = null; + + for (int i = 0; i <= AUTHENTICATION_RETRIES; i++) { + request.endpoint(managerEndpoint); + request.header("Tenant", tenant); + if (tokenProvider != null) + request.header("Authentication-Token", tokenProvider.getToken()); + + try { + return connector.request(request); + } catch (CloudifyResponseException e) { + if (e.getStatus() != CloudifyResponseStatus.NOT_AUTHORIZED + || tokenProvider == null) { + throw e; + } + authException = e; + tokenProvider.expireToken(); + } + } + + throw authException; + } + + /** + * Execute a CloudifyRequest by sending the REST API call to the Cloudify + * Manager endpoint. The return type is a JSON POJO object containing the + * response body entity. + * @param request + * @return a JSON POJO object specific to the request type + */ + public T execute(CloudifyRequest request) { + CloudifyResponse response = request(request); + return (request.returnType() != null && request.returnType() != Void.class) ? response.getEntity(request.returnType()) : null; + } + + public void property(String property, String value) { + properties.put(property, value); + } + + /** + * Set a Token Provider. This class should be able to produce an + * authentication token on-demand. + * @param tokenProvider + */ + public void setTokenProvider(CloudifyTokenProvider tokenProvider) { + this.tokenProvider = tokenProvider; + } + + /** + * Manually set the authentication token to use for this client. + * @param token + */ + public void setToken(String token) { + setTokenProvider(new CloudifySimpleTokenProvider(token)); + } + + /** + * Perform a simple GET request with no request message body + * @param path + * @param returnType + * @return An object of Class + */ + public CloudifyRequest get(String path, Class returnType) { + return new CloudifyRequest(this, HttpMethod.GET, path, null, returnType); + } + +} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyClientConnector.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyClientConnector.java new file mode 100644 index 0000000000..12162c3d4f --- /dev/null +++ b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyClientConnector.java @@ -0,0 +1,28 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 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========================================================= + */ + +package org.openecomp.mso.cloudify.base.client; + + +public interface CloudifyClientConnector { + + public CloudifyResponse request(CloudifyRequest request); + +} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyClientTokenProvider.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyClientTokenProvider.java new file mode 100644 index 0000000000..946720bb45 --- /dev/null +++ b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyClientTokenProvider.java @@ -0,0 +1,85 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 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========================================================= + */ + +package org.openecomp.mso.cloudify.base.client; + +import java.util.Date; + +import org.apache.commons.lang.time.DateUtils; + +import org.openecomp.mso.cloudify.v3.client.Cloudify; +import org.openecomp.mso.cloudify.v3.client.TokensResource.GetToken; +import org.openecomp.mso.cloudify.v3.model.Token; + +/** + * Cloudify Token Provider that uses the Cloudify client API itself to obtain a token + * + * @author JC1348 + * + */ +public class CloudifyClientTokenProvider implements CloudifyTokenProvider { + + String user; + String password; + String token; + Date expiration; + Cloudify cloudify = null; + + public CloudifyClientTokenProvider(String cloudifyEndpoint, String user, String password) { + this.user = user; + this.password = password; + + cloudify = new Cloudify (cloudifyEndpoint); + } + + @Override + public String getToken() { + Date now = new Date(); + if (token != null && expiration != null && expiration.after(now)) { + return token; + } + + // Create a "Get Token" request. Force basic authentication to acquire the token itself. + GetToken tokenRequest = cloudify.tokens().token(); + tokenRequest.setBasicAuthentication(user, password); + Token newToken = tokenRequest.execute(); + + token = newToken.getValue(); + + if (expiration == null) { + expiration = new Date(); + } + // TODO: Make this property driven (or see if it comes back somehow in response) + expiration = DateUtils.addMinutes(expiration, 10); + + return token; + } + + @Override + /** + * This doesn't actually expire the token in Cloudify. It just prevents this token provider + * from using it. + */ + public void expireToken() { + expiration = null; + token = null; + } + +} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyConnectException.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyConnectException.java new file mode 100644 index 0000000000..3b28b6e3f9 --- /dev/null +++ b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyConnectException.java @@ -0,0 +1,39 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 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========================================================= + */ + +package org.openecomp.mso.cloudify.base.client; + +/** + * Custom RuntimeException to report connection errors to Openstack endpoints. + * Must be a RuntimeException to conform with OpenstackClient interface, which + * does not declare specific Exceptions. + */ +public class CloudifyConnectException extends CloudifyBaseException { + + private static final long serialVersionUID = 7294957362769575271L; + + public CloudifyConnectException(String message) { + super(message); + } + + public CloudifyConnectException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyRequest.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyRequest.java new file mode 100644 index 0000000000..6b0a4c1d13 --- /dev/null +++ b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyRequest.java @@ -0,0 +1,188 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 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========================================================= + */ + +package org.openecomp.mso.cloudify.base.client; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.ArrayList; +import java.util.Map; + +public class CloudifyRequest { + + private CloudifyClient client; + + public CloudifyRequest() { + + } + + public CloudifyRequest(CloudifyClient client, HttpMethod method, CharSequence path, Entity entity, Class returnType) { + this.client = client; + this.method = method; + this.path = new StringBuilder(path); + this.entity = entity; + this.returnType = returnType; + header("Accept", "application/json"); + } + + private String endpoint; + + private HttpMethod method; + + private StringBuilder path = new StringBuilder(); + + private Map> headers = new HashMap>(); + + private Entity entity; + + private Class returnType; + + private boolean basicAuth = false; + private String user = null; + private String password = null; + + public CloudifyRequest endpoint(String endpoint) { + this.endpoint = endpoint; + return this; + } + + public String endpoint() { + return endpoint; + } + + public CloudifyRequest method(HttpMethod method) { + this.method = method; + return this; + } + + public HttpMethod method() { + return method; + } + + public CloudifyRequest path(String path) { + this.path.append(path); + return this; + } + + public String path() { + return path.toString(); + } + + public CloudifyRequest header(String name, Object value) { + if(value != null) { + headers.put(name, Arrays.asList(value)); + } + return this; + } + + public Map> headers() { + return headers; + } + + public Entity entity(T entity, String contentType) { + return new Entity(entity, contentType); + } + + public Entity entity() { + return entity; + } + + public Entity json(T entity) { + return entity(entity, "application/json"); + } + + public void returnType(Class returnType) { + this.returnType = returnType; + } + + public Class returnType() { + return returnType; + } + + /* + * Use Basic Authentication for this request. If not set, the client will use Token authentication + * if a token provider is defined. Otherwise, no authentication will be applied. + */ + public void setBasicAuthentication (String user, String password) { + this.basicAuth = true; + this.user = user; + this.password= password; + } + + public boolean isBasicAuth () { + return this.basicAuth; + } + + public String getUser() { + return user; + } + + public String getPassword() { + return password; + } + + public R execute() { + return client.execute(this); + } + + public CloudifyResponse request() { + return client.request(this); + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return "CloudifyRequest [endpoint=" + endpoint + ", method=" + method + + ", path=" + path + ", headers=" + headers + ", entity=" + + entity + ", returnType=" + returnType + "]"; + } + + private Map > queryParams = new LinkedHashMap >(); + + public Map > queryParams() { + return queryParams; + } + + public CloudifyRequest queryParam(String key, Object value) { + if (queryParams.containsKey(key)) { + List values = queryParams.get(key); + values.add(value); + } else { + List values = new ArrayList(); + values.add(value); + queryParams.put(key, values); + } + + return this; + } + + protected static String buildPath(String ... elements) { + StringBuilder stringBuilder = new StringBuilder(); + for (String element : elements) { + stringBuilder.append(element); + } + + return stringBuilder.toString(); + } +} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyResponse.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyResponse.java new file mode 100644 index 0000000000..7ddeaa8c4b --- /dev/null +++ b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyResponse.java @@ -0,0 +1,38 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 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========================================================= + */ + +package org.openecomp.mso.cloudify.base.client; + +import java.io.InputStream; +import java.util.Map; + +public interface CloudifyResponse { + + public T getEntity(Class returnType); + + public T getErrorEntity(Class returnType); + + public InputStream getInputStream(); + + public String getHeader(String name); + + public Map headers(); + +} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyResponseException.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyResponseException.java new file mode 100644 index 0000000000..27e61f9581 --- /dev/null +++ b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyResponseException.java @@ -0,0 +1,61 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 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========================================================= + */ + +package org.openecomp.mso.cloudify.base.client; + +import org.openecomp.mso.cloudify.v3.model.CloudifyError; + +public class CloudifyResponseException extends CloudifyBaseException { + + private static final long serialVersionUID = 7294957362769575271L; + + protected String message; + protected int status; + + // Make the response available for exception handling (includes body) + protected CloudifyResponse response; + + public CloudifyResponseException(String message, int status) { + this.message = message; + this.status = status; + this.response = null; + } + + // Include the response message itself. The body is a CloudifyError JSON structure. + public CloudifyResponseException(String message, int status, CloudifyResponse response) { + CloudifyError error = response.getErrorEntity(CloudifyError.class); + this.message = message + ": " + error.getErrorCode(); + this.status = status; + this.response = response; + } + + public String getMessage() { + return message; + } + + public int getStatus() { + return status; + } + + public CloudifyResponse getResponse() { + return response; + } + +} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyResponseStatus.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyResponseStatus.java new file mode 100644 index 0000000000..38079d6f26 --- /dev/null +++ b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyResponseStatus.java @@ -0,0 +1,37 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 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========================================================= + */ + +package org.openecomp.mso.cloudify.base.client; + +public class CloudifyResponseStatus { + + public static final int OK = 200; + + public static final int ACCEPTED = 201; + + public static final int BAD_REQUEST = 400; + + public static final int NOT_AUTHORIZED = 401; + + public static final int NOT_FOUND = 404; + + public static final int CONFLICT = 409; + +} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifySimpleTokenProvider.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifySimpleTokenProvider.java new file mode 100644 index 0000000000..8f37e069d9 --- /dev/null +++ b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifySimpleTokenProvider.java @@ -0,0 +1,40 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 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========================================================= + */ + +package org.openecomp.mso.cloudify.base.client; + +public class CloudifySimpleTokenProvider implements CloudifyTokenProvider { + + String token; + + public CloudifySimpleTokenProvider(String token) { + this.token = token; + } + + @Override + public String getToken() { + return this.token; + } + + @Override + public void expireToken() { + } + +} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyTokenProvider.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyTokenProvider.java new file mode 100644 index 0000000000..ee32f9321d --- /dev/null +++ b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyTokenProvider.java @@ -0,0 +1,29 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 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========================================================= + */ + +package org.openecomp.mso.cloudify.base.client; + +public interface CloudifyTokenProvider { + + String getToken(); + + void expireToken(); + +} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/Entity.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/Entity.java new file mode 100644 index 0000000000..db2587937b --- /dev/null +++ b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/Entity.java @@ -0,0 +1,71 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 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========================================================= + */ + +package org.openecomp.mso.cloudify.base.client; + +public class Entity { + + private T entity; + + private String contentType; + + public static Entity json(T entity) { + return new Entity(entity, "application/json"); + } + + public static Entity stream(T entity) { + return new Entity(entity, "application/octet-stream"); + } + + public Entity(T entity, String contentType) { + super(); + this.entity = entity; + this.contentType = contentType; + } + + /** + * @return the entity + */ + public T getEntity() { + return entity; + } + + /** + * @param entity the entity to set + */ + public void setEntity(T entity) { + this.entity = entity; + } + + /** + * @return the contentType + */ + public String getContentType() { + return contentType; + } + + /** + * @param contentType the contentType to set + */ + public void setContentType(String contentType) { + this.contentType = contentType; + } + +} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/HttpMethod.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/HttpMethod.java new file mode 100644 index 0000000000..a8c0cab2d8 --- /dev/null +++ b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/HttpMethod.java @@ -0,0 +1,25 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 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========================================================= + */ + +package org.openecomp.mso.cloudify.base.client; + +public enum HttpMethod { + HEAD, GET, POST, PUT, PATCH, DELETE, OPTIONS, TRACE +} -- cgit 1.2.3-korg