<artifactId>commons-httpclient</artifactId>\r
<version>3.1</version>\r
</dependency>\r
+ <dependency>\r
+ <groupId>com.google.code.gson</groupId>\r
+ <artifactId>gson</artifactId>\r
+ <version>2.7</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.springframework</groupId>\r
+ <artifactId>spring-context</artifactId>\r
+ <version>3.2.3.RELEASE</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.onap.msb.java-sdk</groupId>\r
+ <artifactId>msb-java-sdk</artifactId>\r
+ <version>1.0.0-SNAPSHOT</version>\r
+ </dependency> \r
</dependencies>\r
</project>\r
--- /dev/null
+/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * 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.
+ */
+package org.activiti.engine.impl.pvm.runtime;
+
+import java.util.List;
+import java.util.Map;
+
+import org.activiti.engine.delegate.event.ActivitiEventType;
+import org.activiti.engine.delegate.event.impl.ActivitiEventBuilder;
+import org.activiti.engine.impl.context.Context;
+import org.activiti.engine.impl.pvm.process.ActivityImpl;
+import org.activiti.engine.impl.pvm.process.ProcessDefinitionImpl;
+import org.activiti.engine.impl.pvm.process.ScopeImpl;
+
+public class AtomicOperationProcessStart extends AbstractEventAtomicOperation {
+ @Override
+ public boolean isAsync(InterpretableExecution execution) {
+ return true;
+ }
+
+ protected ScopeImpl getScope(InterpretableExecution execution) {
+ return execution.getProcessDefinition();
+ }
+
+ protected String getEventName() {
+ return "start";
+ }
+
+ protected void eventNotificationsCompleted(InterpretableExecution execution) {
+ if ((Context.getProcessEngineConfiguration() != null)
+ && (Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled())) {
+ Map variablesMap = null;
+ try {
+ variablesMap = execution.getVariables();
+ } catch (Throwable localThrowable) {
+ }
+ Context
+ .getProcessEngineConfiguration()
+ .getEventDispatcher()
+ .dispatchEvent(
+ ActivitiEventBuilder.createEntityWithVariablesEvent(
+ ActivitiEventType.ENTITY_INITIALIZED, execution, variablesMap, false));
+
+ Context
+ .getProcessEngineConfiguration()
+ .getEventDispatcher()
+ .dispatchEvent(
+ ActivitiEventBuilder.createProcessStartedEvent(execution, variablesMap, false));
+ }
+
+ ProcessDefinitionImpl processDefinition = execution.getProcessDefinition();
+ StartingExecution startingExecution = execution.getStartingExecution();
+ List initialActivityStack =
+ processDefinition.getInitialActivityStack(startingExecution.getInitial());
+ execution.setActivity((ActivityImpl) initialActivityStack.get(0));
+ execution.performOperation(PROCESS_START_INITIAL);
+ }
+}
--- /dev/null
+/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * 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.
+ */
+package org.activiti.rest.conf.init;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.util.List;
+
+import javax.annotation.PostConstruct;
+
+import org.activiti.engine.RepositoryService;
+import org.activiti.engine.repository.DeploymentBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.env.Environment;
+
+@Configuration
+public class InitBaseProcessDefinition {
+
+ protected static final Logger LOGGER = LoggerFactory.getLogger(InitBaseProcessDefinition.class);
+
+ @Autowired
+ protected RepositoryService repositoryService;
+
+ @Autowired
+ protected Environment environment;
+
+ @PostConstruct
+ public void init() {
+
+ if (Boolean.valueOf(this.environment.getProperty("init.process.definitions", "true"))
+ .booleanValue()) {
+ LOGGER.info("Initializing base process definitions");
+ initBaseProcessDefinitions();
+ }
+ }
+
+ protected void initBaseProcessDefinitions() {
+ String deploymentName = "base definitions";
+ List deploymentList =
+ this.repositoryService.createDeploymentQuery().deploymentName(deploymentName).list();
+
+ if ((deploymentList == null) || (deploymentList.isEmpty())) {
+
+ String classPath = this.getClass().getClassLoader().getResource("/").getPath();
+ classPath = classPath.replaceAll("WEB-INF/classes", "baseProccessDefinition");
+
+ File files = new File(classPath);
+ DeploymentBuilder builder = this.repositoryService.createDeployment().name(deploymentName);
+ File flist[] = files.listFiles();
+ if (flist != null && flist.length != 0) {
+ for (File f : flist) {
+
+ String fileName = f.getName();
+ if (fileName != null && fileName.endsWith("bpmn20.xml")) {
+ try {
+ builder.addInputStream(fileName, new FileInputStream(f));
+ LOGGER.info("deploy success: {}", fileName);
+ } catch (FileNotFoundException e) {
+ LOGGER.info("deploy failed: {}", fileName);
+ }
+ }
+ }
+ builder.deploy();
+ }
+ }
+ }
+}
+++ /dev/null
-/**
- * Copyright 2017 ZTE Corporation.
- *
- * 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.
- */
-
-package org.onap.workflow.activitiext;
-
-import org.glassfish.jersey.media.multipart.MultiPartFeature;
-
-import io.dropwizard.Application;
-import io.dropwizard.setup.Environment;
-
-public class ActivitiExtApp extends Application<ActivitiExtAppConfig> {
-
- public static void main(String[] args) throws Exception {
- new ActivitiExtApp().run(args);
- }
-
- @Override
- public String getName() {
- return " Activiti Ext APP ";
- }
-
- @Override
- public void run(ActivitiExtAppConfig configuration, Environment environment) throws Exception {
-
- environment.jersey().register(MultiPartFeature.class);
- }
-}
-
+++ /dev/null
-/**
- * Copyright 2017 ZTE Corporation.
- *
- * 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.
- */
-
-package org.onap.workflow.activitiext;
-
-import io.dropwizard.Configuration;
-
-import javax.validation.Valid;
-
-import org.hibernate.validator.constraints.NotEmpty;
-import org.onap.workflow.activitiext.common.MsbClientConfig;
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-public class ActivitiExtAppConfig extends Configuration {
-
- @NotEmpty
- private String defaultName = "WORKFLOW-ACTIVITI-EXT";
- @NotEmpty
- @JsonProperty
- private String apidescription = "ZTE workflow-activiti-ext rest API";
-
- @JsonProperty
- @Valid
- private MsbClientConfig msbClientConfig;
-
- public MsbClientConfig getMsbClientConfig() {
- return msbClientConfig;
- }
-}
+++ /dev/null
-/**\r
- * Copyright 2017 ZTE Corporation.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.onap.workflow.activitiext.common;\r
-\r
-import org.onap.workflow.activitiext.ActivitiExtAppConfig;\r
-\r
-public class Config {\r
-\r
- private static Config instance = new Config();\r
- \r
- private ActivitiExtAppConfig appconfig;\r
-\r
- public static Config getInstance(){\r
- return instance;\r
- }\r
- \r
- public ActivitiExtAppConfig getAppconfig() {\r
- return appconfig;\r
- }\r
-\r
- public void setAppconfig(ActivitiExtAppConfig config) {\r
- this.appconfig = config;\r
- }\r
- \r
-}\r
-/**\r
- * Copyright 2016-2017 ZTE Corporation.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.onap.workflow.activitiext.restservicetask;\r
-\r
-/**\r
- * \r
- * @author 10222158\r
- *\r
- */\r
-public class ConstString {\r
-\r
- /**\r
- * http method type : get\r
- */\r
- public static final String HTTP_GET = "GET";\r
- \r
- /**\r
- * http method type : post\r
- */\r
- public static final String HTTP_POST = "POST";\r
- \r
- /**\r
- * http method type : delete\r
- */\r
- public static final String HTTP_DELETE = "DELETE";\r
- \r
- /**\r
- * http method type : put\r
- */\r
- public static final String HTTP_PUT = "PUT";\r
- \r
- /**\r
- * parameter position : in the uri path\r
- */\r
- public static final String PARAMETER_POSITION_PATH = "path";\r
- \r
- /**\r
- * parameter positoin : after the uri\r
- */\r
- public static final String PARAMETER_POSITION_QUERY = "query";\r
- \r
- /**\r
- * parameter positoin : in the request body\r
- */\r
- public static final String PARAMETER_POSITION_BODY = "body";\r
- \r
- /**\r
- * parameter type : string\r
- */\r
- public static final String PARAMETER_TYPE_STRING = "string";\r
- \r
- /**\r
- * parameter type : acitviti expression\r
- */\r
- public static final String PARAMETER_TYPE_EXPRESSION = "expression";\r
- \r
-}\r
+/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * 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.
+ */
+package org.onap.workflow.activitiext.common;
+
+/**
+ *
+ * @author 10222158
+ *
+ */
+public class ConstString {
+
+ /**
+ * http method type : get
+ */
+ public static final String HTTP_GET = "GET";
+
+ /**
+ * http method type : post
+ */
+ public static final String HTTP_POST = "POST";
+
+ /**
+ * http method type : delete
+ */
+ public static final String HTTP_DELETE = "DELETE";
+
+ /**
+ * http method type : put
+ */
+ public static final String HTTP_PUT = "PUT";
+
+ /**
+ * parameter position : in the uri path
+ */
+ public static final String PARAMETER_POSITION_PATH = "path";
+
+ /**
+ * parameter positoin : after the uri
+ */
+ public static final String PARAMETER_POSITION_QUERY = "query";
+
+ /**
+ * parameter positoin : in the request body
+ */
+ public static final String PARAMETER_POSITION_BODY = "body";
+
+ /**
+ * parameter type : string
+ */
+ public static final String PARAMETER_VALUE_SOURCE_STRING = "String";
+
+ /**
+ * parameter type : plan
+ */
+ public static final String PARAMETER_VALUE_SOURCE_PLAN = "Plan";
+
+ /**
+ * parameter type : Topology
+ */
+ public static final String PARAMETER_VALUE_SOURCE_TOPOLOGY = "Topology";
+
+ /**
+ * parameter type : Variable
+ */
+ public static final String PARAMETER_VALUE_SOURCE_VARIABLE = "Variable";
+
+ /**
+ * parameter type : Definition
+ */
+ public static final String PARAMETER_VALUE_SOURCE_DEFINITION = "Definition";
+
+ /**
+ *
+ */
+ public static final String PARAMETER_VALUE = "value";
+
+ /**
+ *
+ */
+ public static final String PARAMETER_VALUESOURCE = "valueSource";
+
+ /**
+ *
+ */
+ public static final String CSARID_EXPRESSION = "csarId";
+}
--- /dev/null
+/**
+ * Copyright 2017 [ZTE] and others.
+ *
+ * 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.
+ */
+package org.onap.workflow.activitiext.common;
+
+import org.apache.commons.lang3.StringUtils;
+import org.onap.workflow.activitiext.restservicetask.PropertyUtil;
+import org.onap.workflow.utils.MsbUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ */
+public class EnumModuleUrl {
+
+ private static final Logger logger = LoggerFactory.getLogger(EnumModuleUrl.class);
+
+ public static String getApiRootDomain() {
+ return "/openoapi/catalog/v1";
+ }
+
+ public static String getBaseUrl(ServiceType type) {
+ String baseUrl = "";
+ String publishUrl ="";
+ try {
+ publishUrl = MsbUtils.getServiceAddress("catalog", "v1");
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ if(StringUtils.isNotEmpty(publishUrl))
+ {
+ baseUrl = publishUrl;
+ }else{
+
+ baseUrl = PropertyUtil.getBasePath() + getApiRootDomain();
+ }
+ logger.info("baseUrl is" + baseUrl);
+
+ return baseUrl;
+ }
+}
--- /dev/null
+/**
+ * Copyright 2017 [ZTE] and others.
+ *
+ * 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.
+ */
+package org.onap.workflow.activitiext.common;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class Parameter {
+
+ private String position;
+ private String type;
+ private String name;
+ private String value;
+ private String valueSource;
+}
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.onap.workflow.activitiext.restservicetask;
+package org.onap.workflow.activitiext.common;
-import java.util.Map;
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-
@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
-public class StartProcessRequest {
- private String processId;
- private Map<String, String> params;
+public class RestInfo {
+
+ private String name;
+ private String version;
+ private String url;
+ private String path;
+ private String method;
+ private String accept;
+ private String contentType;
+ private String requestBody;
+ private String realUri;
+
}
-/**\r
- * Copyright 2017 ZTE Corporation.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.onap.workflow.activitiext.common;\r
-\r
-import lombok.Data;\r
-\r
-@Data\r
-public class MsbClientConfig {\r
-\r
- private String msbSvrIp;\r
- private Integer msbSvrPort;\r
-}\r
+/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * 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.
+ */
+package org.onap.workflow.activitiext.common;
+
+/**
+ * @author 10175158
+ *
+ */
+public enum ServiceType {
+ catalog
+}
--- /dev/null
+/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * 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.
+ */
+package org.onap.workflow.activitiext.restservicetask;
+
+import org.glassfish.jersey.client.ClientConfig;
+import org.onap.workflow.activitiext.common.EnumModuleUrl;
+import org.onap.workflow.activitiext.common.ServiceType;
+
+import com.eclipsesource.jaxrs.consumer.ConsumerFactory;
+
+/**
+ *
+ * @author 10090474
+ *
+ */
+public class CatalogServiceConsumer {
+
+ private static ICatalogService activitiServiceProxy = null;
+
+ private static ICatalogService getCatalogService() {
+ if (activitiServiceProxy == null) {
+ ClientConfig config = new ClientConfig();
+ activitiServiceProxy = ConsumerFactory.createConsumer(
+ EnumModuleUrl.getBaseUrl(ServiceType.catalog), config, ICatalogService.class);
+
+ }
+ return activitiServiceProxy;
+ }
+
+ public static String getTopologyJson(String csarId, String nodeName) {
+
+ getCatalogService();
+ String result = activitiServiceProxy.getTopologyJson(csarId, nodeName);
+
+ return result;
+ }
+}
--- /dev/null
+/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * 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.
+ */
+package org.onap.workflow.activitiext.restservicetask;
+
+import java.util.Map.Entry;
+
+import org.activiti.engine.delegate.DelegateExecution;
+import org.onap.workflow.activitiext.common.ConstString;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonPrimitive;
+
+public class GsonUtil {
+
+ private static final Logger logger = LoggerFactory.getLogger(GsonUtil.class);
+
+ public static JsonObject formatJsonObject(String key, JsonObject obj, DelegateExecution execution) {
+
+ JsonObject res = new JsonObject();
+
+ for (Entry<String, JsonElement> entry : obj.entrySet()) {
+
+ if (entry.getValue() instanceof JsonObject) {
+
+ JsonObject tempObj = (JsonObject) entry.getValue();
+ JsonElement valueSource = tempObj.get(ConstString.PARAMETER_VALUESOURCE);
+ if(valueSource == null || valueSource.getAsString().equals(ConstString.PARAMETER_VALUE_SOURCE_DEFINITION))
+ {
+ res.add(entry.getKey(), formatJsonObject(entry.getKey(), entry.getValue().getAsJsonObject(), execution));
+ }else{
+ res.addProperty(entry.getKey(), getValue(tempObj, execution));
+ }
+
+ } else if (entry.getValue() instanceof JsonArray) {
+
+ JsonArray objArray = entry.getValue().getAsJsonArray();
+ JsonArray resArray = formatJsonArray(objArray, execution);
+ res.add(entry.getKey(), resArray);
+ }
+ }
+
+ return res;
+ }
+
+ public static JsonArray formatJsonArray(JsonArray objArray, DelegateExecution execution) {
+
+ JsonArray array = new JsonArray();
+
+ for (JsonElement element : objArray) {
+
+ if (element.isJsonObject()) {
+
+ JsonObject tempObj = (JsonObject) element;
+ JsonElement valueSource = tempObj.get(ConstString.PARAMETER_VALUESOURCE);
+ if(valueSource == null || valueSource.getAsString().equals(ConstString.PARAMETER_VALUE_SOURCE_DEFINITION))
+ {
+ array.add(formatJsonObject(null, element.getAsJsonObject(), execution));
+ }else{
+ array.add(new JsonPrimitive(getValue(tempObj, execution)));
+ }
+
+ } else if (element.isJsonArray()) {
+
+ array = formatJsonArray(element.getAsJsonArray(), execution);
+ }
+ }
+
+ return array;
+ }
+
+ /**
+ * obtain jsonObject value
+ * @param obj
+ * @param execution
+ * @return
+ */
+ public static String getValue(JsonObject obj, DelegateExecution execution)
+ {
+ String result = new String();
+ try {
+ String valueSource = obj.get(ConstString.PARAMETER_VALUESOURCE).getAsString();
+ String value = obj.get(ConstString.PARAMETER_VALUE).getAsString();
+ if(ConstString.PARAMETER_VALUE_SOURCE_STRING.equals(valueSource))
+ {
+ result = value;
+ }else if(ConstString.PARAMETER_VALUE_SOURCE_PLAN.equals(valueSource))
+ {
+ result = HttpUtil.parsePlanExpression(value, execution);
+ }else if(ConstString.PARAMETER_VALUE_SOURCE_TOPOLOGY.equals(valueSource))
+ {
+ result = HttpUtil.parseTopologyExpression(value, execution);
+ }
+ } catch (Exception e) {
+ logger.error("jsonObject {} is illegal!", obj.toString(), e);
+ throw e;
+ }
+
+ return result;
+ }
+}
/**
- * Copyright 2016-2017 ZTE Corporation.
+ * Copyright 2017 ZTE Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.PutMethod;
import org.apache.commons.lang3.StringUtils;
+import org.onap.workflow.activitiext.common.ConstString;
+import org.onap.workflow.activitiext.common.RestInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* invoke http service
*
- * @param methodValue
+ * @param method
* @param uri
- * @param requestPayload
- * @param acceptValue
- * @param contentTypeValue
+ * @param requestBody
+ * @param accept
+ * @param contentType
* @return
*/
- public static HttpResponseMessage invoke(String methodValue, String uri, String requestPayload, String acceptValue,
- String contentTypeValue) throws Exception {
-
- // complete uri
- uri = completeUri(uri);
-
- logger.info("uri: " + uri);
- logger.info("method: " + methodValue);
- logger.info("requestbody: " + requestPayload);
- logger.info("accept: " + acceptValue);
- logger.info("content-type: " + contentTypeValue);
-
+ public static HttpResponseMessage invoke(RestInfo restInfo) throws Exception {
+
+ String realUri = restInfo.getRealUri();
+ String method = restInfo.getMethod();
+ String requestBody = restInfo.getRequestBody();
+ String accept = restInfo.getAccept();
+ String contentType = restInfo.getContentType();
+
+ logger.info("uri: " + realUri);
+ logger.info("method: " + method);
+ logger.info("requestbody: " + requestBody);
+ logger.info("accept: " + accept);
+ logger.info("content-type: " + contentType);
+
HttpResponseMessage msg = new HttpResponseMessage();
- switch (methodValue.toUpperCase()) {
+ switch (method.toUpperCase()) {
case ConstString.HTTP_GET:
- msg = HighLevelRestApi.Get(uri, acceptValue, contentTypeValue);
+ msg = HighLevelRestApi.Get(realUri, accept, contentType);
break;
case ConstString.HTTP_POST:
- msg = HighLevelRestApi.Post(uri, requestPayload, acceptValue, contentTypeValue);
+ msg = HighLevelRestApi.Post(realUri, requestBody, accept, contentType);
break;
case ConstString.HTTP_DELETE:
- msg = HighLevelRestApi.Delete(uri, acceptValue, contentTypeValue);
+ msg = HighLevelRestApi.Delete(realUri, accept, contentType);
break;
case ConstString.HTTP_PUT:
- msg = HighLevelRestApi.Put(uri, requestPayload, acceptValue, contentTypeValue);
+ msg = HighLevelRestApi.Put(realUri, requestBody, accept, contentType);
break;
default:
- throw new ActivitiException("can not find the http method type '" + methodValue + "'!");
+ throw new ActivitiException("can not find the http method type '" + method + "'!");
}
return msg;
}
*
* @param uri
* Resource URI
- * @param requestPayload
+ * @param requestBody
* Content which has to be put into the Resource
* @return ResponseCode of HTTP Interaction
*/
@SuppressWarnings("deprecation")
- public static HttpResponseMessage Put(String uri, String requestPayload, String acceptValue,
- String contentTypeValue) {
+ public static HttpResponseMessage Put(String uri, String requestBody, String accept,
+ String contentType) throws Exception {
PutMethod method = new PutMethod(uri);
- HighLevelRestApi.setAcceptHeader(method, acceptValue);
- HighLevelRestApi.setContentTypeHeader(method, contentTypeValue);
- method.setRequestBody(requestPayload);
+ HighLevelRestApi.setAcceptHeader(method, accept);
+ HighLevelRestApi.setContentTypeHeader(method, contentType);
+ method.setRequestBody(requestBody);
HttpResponseMessage responseMessage = LowLevelRestApi.executeHttpMethod(method);
*
* @param uri
* Resource URI
- * @param requestPayload
+ * @param requestBody
* Content which has to be posted into the Resource
* @return ResponseCode of HTTP Interaction
*/
@SuppressWarnings("deprecation")
- public static HttpResponseMessage Post(String uri, String requestPayload, String acceptValue,
- String contentTypeValue) {
+ public static HttpResponseMessage Post(String uri, String requestBody, String accept,
+ String contentType) throws Exception {
PostMethod method = null;
if (uri.contains("?")) {
} else {
method = new PostMethod(uri);
}
- method.setRequestBody(requestPayload);
- HighLevelRestApi.setAcceptHeader(method, acceptValue);
- HighLevelRestApi.setContentTypeHeader(method, contentTypeValue);
+ method.setRequestBody(requestBody);
+ HighLevelRestApi.setAcceptHeader(method, accept);
+ HighLevelRestApi.setContentTypeHeader(method, contentType);
HttpResponseMessage responseMessage = LowLevelRestApi.executeHttpMethod(method);
return responseMessage;
}
* Resource URI
* @return Content represented by the Resource URI
*/
- public static HttpResponseMessage Get(String uri, String acceptValue, String contentTypeValue) {
+ public static HttpResponseMessage Get(String uri, String accept, String contentType) throws Exception {
GetMethod method = null;
if (uri.contains("?")) {
String[] split = uri.split("\\?");
method = new GetMethod(uri);
}
- HighLevelRestApi.setAcceptHeader(method, acceptValue);
- HighLevelRestApi.setContentTypeHeader(method, contentTypeValue);
+ HighLevelRestApi.setAcceptHeader(method, accept);
+ HighLevelRestApi.setContentTypeHeader(method, contentType);
HttpResponseMessage responseMessage = LowLevelRestApi.executeHttpMethod(method);
return responseMessage;
}
- private static NameValuePair[] createNameValuePairArrayFromQuery(String query) {
+ static NameValuePair[] createNameValuePairArrayFromQuery(String query) {
String[] pairs = query.trim().split("&");
NameValuePair[] nameValuePairArray = new NameValuePair[pairs.length];
int count = 0;
* Resource URI
* @return ResponseCode of HTTP Interaction
*/
- public static HttpResponseMessage Delete(String uri, String acceptValue, String contentTypeValue) {
+ public static HttpResponseMessage Delete(String uri, String accept, String contentType) throws Exception {
DeleteMethod method = new DeleteMethod(uri);
- HighLevelRestApi.setAcceptHeader(method, acceptValue);
- HighLevelRestApi.setContentTypeHeader(method, contentTypeValue);
+ HighLevelRestApi.setAcceptHeader(method, accept);
+ HighLevelRestApi.setContentTypeHeader(method, contentType);
HttpResponseMessage responseMessage = LowLevelRestApi.executeHttpMethod(method);
return responseMessage;
}
private static void setAcceptHeader(HttpMethodBase method, String value) {
- if (!StringUtils.isEmpty(value)) {
+ if (StringUtils.isNotEmpty(value)) {
+ if(value.startsWith("[")&&value.endsWith("]")){
+ value = value.substring(1, value.length()-1);
+ }
+
method.setRequestHeader("Accept", value);
- } else {
- method.setRequestHeader("Accept", "application/xml");
}
}
private static void setContentTypeHeader(HttpMethodBase method, String value) {
- if (!StringUtils.isEmpty(value)) {
+ if (StringUtils.isNotEmpty(value)) {
+ if(value.startsWith("[")&&value.endsWith("]")){
+ value = value.substring(1, value.length()-1);
+ }
+
method.setRequestHeader("content-type", value);
- } else {
- method.setRequestHeader("content-type", "application/json");
}
}
-
- private static String completeUri(String uri) {
-
- String urlReg = "^http[\\s\\S]*";
- if (uri != null && !uri.matches(urlReg)) {
- uri = PropertyUtil.getBasePath() + uri;
- }
-
- return uri;
- }
}
/**
- * Copyright 2017 ZTE Corporation.
+ * Copyright 2017 [ZTE] and others.
*
- * 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
+ * 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
+ * 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.
+ * 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.
*/
package org.onap.workflow.activitiext.restservicetask;
import java.io.Serializable;
+import com.alibaba.fastjson.JSON;
+
/**
*/
public class HttpResponseMessage implements Serializable {
private int statusCode;
- private String responseBody;
+ private JSON responseBody;
/**
/**
* @return the responseBody
*/
- public String getResponseBody() {
+ public JSON getResponseBody() {
return this.responseBody;
}
/**
* @param responseBody the responseBody to set
*/
- protected void setResponseBody(String responseBody) {
+ protected void setResponseBody(JSON responseBody) {
this.responseBody = responseBody;
}
+
+ @Override
+ public String toString() {
+ return "{statusCode=" + statusCode + ", responseBody=" + responseBody.toJSONString() + "}";
+ }
}
/**\r
- * Copyright 2016-2017 ZTE Corporation.\r
+ * Copyright 2017 ZTE Corporation.\r
*\r
* Licensed under the Apache License, Version 2.0 (the "License");\r
* you may not use this file except in compliance with the License.\r
*/\r
package org.onap.workflow.activitiext.restservicetask;\r
\r
-import java.util.HashMap;\r
+import java.util.LinkedList;\r
import java.util.List;\r
-import java.util.Map;\r
+import java.util.Queue;\r
+import java.util.regex.Matcher;\r
+import java.util.regex.Pattern;\r
\r
import org.activiti.engine.ActivitiException;\r
import org.activiti.engine.delegate.BpmnError;\r
import org.activiti.engine.delegate.JavaDelegate;\r
import org.activiti.engine.impl.context.Context;\r
import org.apache.commons.lang3.StringUtils;\r
+import org.onap.workflow.activitiext.common.ConstString;\r
+import org.onap.workflow.activitiext.common.Parameter;\r
+import org.onap.workflow.activitiext.common.RestInfo;\r
+import org.onap.workflow.utils.MsbUtils;\r
import org.slf4j.Logger;\r
import org.slf4j.LoggerFactory;\r
\r
-import com.alibaba.fastjson.JSON;\r
import com.alibaba.fastjson.JSONArray;\r
+import com.google.gson.JsonArray;\r
+import com.google.gson.JsonObject;\r
+import com.google.gson.JsonParser;\r
+import com.google.gson.JsonPrimitive;\r
\r
/**\r
* rest service\r
\r
private static final Logger logger = LoggerFactory.getLogger(HttpUtil.class);\r
\r
- private Expression uri;\r
+ private Expression name;\r
+ private Expression version;\r
+ private Expression url;\r
+ private Expression path;\r
private Expression method;\r
private Expression accept;\r
private Expression contentType;\r
try {\r
this.executeMethod(execution);\r
} catch (Exception e) {\r
-\r
logger.error("Invoke rest service failed!", e);\r
throw new BpmnError(e.getMessage());\r
}\r
* \r
* @param execution\r
*/\r
- public boolean executeMethod(DelegateExecution execution) throws Exception {\r
+ public void executeMethod(DelegateExecution execution) throws Exception {\r
+\r
+ // get rest task information\r
+ RestInfo restInfo = new RestInfo();\r
+ restInfo.setName(getValue(name, execution));\r
+ restInfo.setVersion(getValue(version, execution));\r
+ restInfo.setUrl(getValue(url, execution));\r
+ restInfo.setPath(getValue(path, execution));\r
+ restInfo.setMethod(getValue(method, execution));\r
+ restInfo.setAccept(getValue(accept, execution));\r
+ restInfo.setContentType(getValue(contentType, execution));\r
\r
- String uriValue = getValue(uri, execution);\r
- String methodValue = getValue(method, execution);\r
- String acceptValue = getValue(accept, execution);\r
- String contentTypeValue = getValue(contentType, execution);\r
String parametersValue = getValue(parameters, execution);\r
\r
- Map<String, String> requestBody = new HashMap<String, String>();\r
+ // real uri\r
+ compeleteUri(restInfo);\r
\r
if (!StringUtils.isEmpty(parametersValue)) {\r
-\r
// Parse the parameter into Object List\r
List<Parameter> parameters = JSONArray.parseArray(parametersValue, Parameter.class);\r
\r
for (Parameter param : parameters) {\r
\r
- handleParam(execution, param, requestBody, uriValue);\r
+ restInfo = handleParam(execution, param, restInfo);\r
}\r
}\r
\r
- String requestPayload = JSON.toJSONString(requestBody);\r
-\r
// invoke http service\r
- HttpResponseMessage msg = HighLevelRestApi.invoke(methodValue, uriValue, requestPayload, acceptValue,\r
- contentTypeValue);\r
+ HttpResponseMessage msg = HighLevelRestApi.invoke(restInfo);\r
\r
// inject the result to variable\r
execution.setVariable(execution.getCurrentActivityId(), msg);\r
-\r
- logger.info("statusCode: " + msg.getStatusCode());\r
- logger.info("responseBody: " + msg.getResponseBody());\r
- \r
- return true;\r
}\r
\r
/**\r
* @param requestBody\r
* @param uriValue\r
*/\r
- public void handleParam(DelegateExecution execution, Parameter param, Map<String, String> requestBody,\r
- String uriValue) throws ActivitiException {\r
+ public RestInfo handleParam(DelegateExecution execution, Parameter param, RestInfo restInfo)\r
+ throws ActivitiException {\r
\r
- if (ConstString.PARAMETER_TYPE_EXPRESSION.equals(param.getType())) {\r
- handleExpression(execution, param);\r
+ String realUri = restInfo.getRealUri();\r
+\r
+ if (ConstString.PARAMETER_VALUE_SOURCE_PLAN.equals(param.getValueSource())) {\r
+\r
+ String planValue = parsePlanExpression(param.getValue(), execution);\r
+ param.setValue(planValue);\r
+ } else if (ConstString.PARAMETER_VALUE_SOURCE_TOPOLOGY.equals(param.getValueSource())) {\r
+\r
+ String topValue = parseTopologyExpression(param.getValue(), execution);\r
+ param.setValue(topValue);\r
+ }else if(ConstString.PARAMETER_VALUE_SOURCE_VARIABLE.equals(param.getValueSource())) {\r
+\r
+ String varValue = parseVariableExpression(param.getValue(), execution);\r
+ param.setValue(varValue);\r
}\r
\r
switch (param.getPosition()) {\r
case ConstString.PARAMETER_POSITION_PATH:\r
\r
// replace the path parameter\r
- uriValue = uriValue.replaceAll("\\{+" + param.getName() + "+\\}", param.getValue());\r
+ realUri = realUri.replaceAll("\\{+" + param.getName() + "+\\}", param.getValue());\r
+ restInfo.setRealUri(realUri);\r
break;\r
case ConstString.PARAMETER_POSITION_QUERY:\r
\r
// add the query parameter\r
- if (!uriValue.contains("?")) {\r
- uriValue = uriValue + "?" + param.getName() + "=" + param.getValue();\r
+ if (!realUri.contains("?")) {\r
+ realUri = realUri + "?" + param.getName() + "=" + param.getValue();\r
} else {\r
- uriValue = uriValue + "&" + param.getName() + "=" + param.getValue();\r
+ realUri = realUri + "&" + param.getName() + "=" + param.getValue();\r
}\r
+ restInfo.setRealUri(realUri);\r
break;\r
case ConstString.PARAMETER_POSITION_BODY:\r
\r
// add parameter to request body\r
- requestBody.put(param.getName(), param.getValue());\r
+ String value = param.getValue();\r
+\r
+ JsonObject obj = new JsonParser().parse(value).getAsJsonObject();\r
+\r
+ JsonObject res = GsonUtil.formatJsonObject(null, obj, execution);\r
+\r
+ restInfo.setRequestBody(res.toString());\r
break;\r
default:\r
- throw new ActivitiException(\r
- "The position '" + param.getPosition() + "' is illegal, please check your input!");\r
+ logger.info("The position {} is illegal, please check your input!",param.getPosition());\r
}\r
+\r
+ return restInfo;\r
}\r
\r
/**\r
*/\r
public String getValue(Expression expression, DelegateExecution execution) {\r
\r
- String value = new String();\r
+ String result = new String();\r
if (expression != null) {\r
- value = (String) expression.getValue(execution);\r
+ result = (String) expression.getValue(execution);\r
}\r
\r
- return value;\r
+ return result;\r
}\r
\r
/**\r
- * parse expression in the parameter\r
+ * parse plan expression\r
* \r
* @param execution\r
- * @param param\r
+ * @param expStr\r
+ * @return\r
*/\r
- public void handleExpression(DelegateExecution execution, Parameter param) {\r
+ public static String parsePlanExpression(String expStr, DelegateExecution execution) {\r
\r
- Expression expression = Context.getProcessEngineConfiguration().getExpressionManager()\r
- .createExpression(param.getValue());\r
+ String result = "";\r
+ String key = "";\r
+ try {\r
\r
- String value = String.valueOf(expression.getValue(execution));\r
+ Queue<String> planQueue = parseExpressionToQueue(expStr);\r
+ Object planObj = execution.getVariable(planQueue.poll());\r
+ \r
+ if (planQueue.isEmpty()) {\r
+ result = String.valueOf(planObj);\r
+ } else if(planObj instanceof HttpResponseMessage) {\r
+ \r
+ JsonObject jsonObj = new JsonParser().parse(planObj.toString()).getAsJsonObject();\r
+ while (!planQueue.isEmpty()) {\r
+ \r
+ key = planQueue.poll();\r
+ Object obj = jsonObj.get(key);\r
+ if (obj instanceof JsonArray) {\r
+ \r
+ break;\r
+ }else if(obj instanceof JsonObject){\r
+ \r
+ jsonObj = (JsonObject) obj;\r
+ }else if(obj instanceof JsonPrimitive){\r
+ \r
+ JsonPrimitive jsonPri = (JsonPrimitive)obj;\r
+ result = jsonPri.getAsString();\r
+ }\r
+ }\r
+ }\r
+ } catch (Exception e) {\r
+ logger.error("expression {} is illegal, parse key {} failed!", expStr, key, e);\r
+ throw e;\r
+ }\r
\r
- param.setValue(value);\r
+ return result;\r
}\r
-}
\ No newline at end of file
+\r
+ /**\r
+ * parse topology expression\r
+ * \r
+ * @param expStr\r
+ * @param csarId\r
+ * @return\r
+ */\r
+ public static String parseTopologyExpression(String expStr, DelegateExecution execution) {\r
+\r
+ String csarId = getCsarId(execution);\r
+ Queue<String> topQueue = parseExpressionToQueue(expStr);\r
+\r
+ // parse topology expression\r
+ if (topQueue.size() != 2) {\r
+ logger.error("topology data {} is illegal!", expStr);\r
+ return new String();\r
+ }\r
+\r
+ // obtain topology json data\r
+ String topJsonStr = CatalogServiceConsumer.getTopologyJson(csarId, topQueue.poll());\r
+ JsonObject topJsonObj = new JsonParser().parse(topJsonStr).getAsJsonObject();\r
+\r
+ // obtain topology value\r
+ String topValue = topJsonObj.get(topQueue.poll()).getAsString();\r
+\r
+ logger.info("topology expression {} : {}", expStr, topValue);\r
+\r
+ return topValue;\r
+ }\r
+ \r
+ /**\r
+ * parse variable expression\r
+ * \r
+ * @param execution\r
+ * @param expStr\r
+ * @return\r
+ */\r
+ public static String parseVariableExpression(String expStr, DelegateExecution execution) {\r
+\r
+ String result = "";\r
+ \r
+ try {\r
+ Expression expression = Context.getProcessEngineConfiguration().getExpressionManager()\r
+ .createExpression(expStr);\r
+ \r
+ result = String.valueOf(expression.getValue(execution));\r
+ } catch (Exception e) {\r
+ logger.error("variable expression illegal!",e);\r
+ }\r
+\r
+ return result;\r
+ }\r
+ \r
+ /**\r
+ * obtain csar id\r
+ * \r
+ * @param execution\r
+ */\r
+ private static String getCsarId(DelegateExecution execution) {\r
+\r
+ String csarId = "";\r
+ csarId = String.valueOf(execution.getVariable(ConstString.CSARID_EXPRESSION));\r
+\r
+ return csarId;\r
+ }\r
+\r
+ /**\r
+ * compelete uri\r
+ * \r
+ * @param restInfo\r
+ * @return\r
+ */\r
+ private static String compeleteUri(RestInfo restInfo) {\r
+\r
+ String publishUrl = "";\r
+ try {\r
+ publishUrl = new MsbUtils().getServiceAddress(restInfo.getName(), restInfo.getVersion());\r
+ } catch (Exception e) {\r
+ logger.error("get service publish address error!", e);\r
+ }\r
+ String realUri = null;\r
+ if (StringUtils.isNotEmpty(publishUrl)) {\r
+ realUri = publishUrl + restInfo.getPath();\r
+ } else {\r
+ realUri = PropertyUtil.getBasePath() + restInfo.getUrl() + restInfo.getPath();\r
+ }\r
+\r
+ logger.info("realUri is " + realUri);\r
+ restInfo.setRealUri(realUri);\r
+\r
+ return realUri;\r
+ }\r
+\r
+ /**\r
+ * prase expression as a queue\r
+ * \r
+ * @param expStr\r
+ * @return\r
+ */\r
+ private static Queue<String> parseExpressionToQueue(String expStr) {\r
+\r
+ Queue<String> queue = new LinkedList<String>();\r
+\r
+ if (StringUtils.isNotEmpty(expStr) && expStr.startsWith("[")) {\r
+\r
+ Pattern p = Pattern.compile("[\\[]+[^]]+[\\]]");\r
+ Matcher m = p.matcher(expStr);\r
+ String key = "";\r
+ while (m.find()) {\r
+ key = m.group();\r
+ key = key.substring(1, key.length() - 1);\r
+ queue.offer(key);\r
+ }\r
+ }\r
+\r
+ return queue;\r
+ }\r
+\r
+}\r
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+package org.onap.workflow.activitiext.restservicetask;
-package org.onap.workflow.activitiext;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
-import javax.annotation.PostConstruct;
-import javax.inject.Inject;
-
-import org.jvnet.hk2.annotations.Service;
-import org.onap.workflow.activitiext.common.Config;
-
-
-@Service
-public class ActivitiExtAppInit {
- @Inject
- private ActivitiExtAppConfig appconfig;
-
- @PostConstruct
- private void run() {
- runConfigComponent();
- }
-
- private void runConfigComponent() {
- Config.getInstance().setAppconfig(appconfig);
- }
+@Path("/")
+public interface ICatalogService {
+
+ @Path("csars/{csarId}/tosca/nodes/{nodeName}/properties")
+ @GET
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ String getTopologyJson(@PathParam("csarId") String csarId, @PathParam("nodeName") String nodeName);
}
/**
- * Copyright 2017 ZTE Corporation.
+ * Copyright 2017 [ZTE] and others.
*
- * 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
+ * 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
+ * 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.
+ * 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.
*/
package org.onap.workflow.activitiext.restservicetask;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.alibaba.fastjson.JSON;
/**
- * This static-class eases HTTP-method execution by self-managed fault-handling and automated
- * Response-information processing
+ * This static-class eases HTTP-method execution by self-managed fault-handling
+ * and automated Response-information processing
*/
public class LowLevelRestApi {
- // Local HttpClient used for every communication (Singleton implementation)
- private static HttpClient httpClient = new HttpClient();
-
-
- /**
- * Executes a passed HttpMethod (Method type is either PUT, POST, GET or DELETE) and returns a
- * HttpResponseMessage
- *
- * @param method Method to execute
- * @return HttpResponseMessage which contains all information about the execution
- */
- public static HttpResponseMessage executeHttpMethod(HttpMethod method) {
+ private static final Logger logger = LoggerFactory.getLogger(LowLevelRestApi.class);
- HttpResponseMessage responseMessage = null;
+ // Local HttpClient used for every communication (Singleton implementation)
+ private static HttpClient httpClient = new HttpClient();
- try {
+ /**
+ * Executes a passed HttpMethod (Method type is either PUT, POST, GET or
+ * DELETE) and returns a HttpResponseMessage
+ *
+ * @param method
+ * Method to execute
+ * @return HttpResponseMessage which contains all information about the
+ * execution
+ */
+ public static HttpResponseMessage executeHttpMethod(HttpMethod method) throws Exception {
- // Execute Request
- LowLevelRestApi.httpClient.executeMethod(method);
- responseMessage = LowLevelRestApi.extractResponseInformation(method);
+ HttpResponseMessage responseMessage = null;
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
+ try {
- // Release Connection anyway
- method.releaseConnection();
- }
+ // Execute Request
+ LowLevelRestApi.httpClient.executeMethod(method);
+ responseMessage = LowLevelRestApi.extractResponseInformation(method);
+
+ logger.info("statusCode: {}", method.getStatusCode());
+ logger.info("responseBody: {}", method.getResponseBodyAsString());
+ } catch (Exception e) {
+ logger.error("visit interface failed!", e);
+ throw e;
+ } finally {
- // Extract response information and return
- return responseMessage;
- }
+ // Release Connection anyway
+ method.releaseConnection();
+ }
- /**
- * Extracts the response information from an executed HttpMethod
- *
- * @param method Executed Method
- * @return Packaged response information
- */
- private static HttpResponseMessage extractResponseInformation(HttpMethod method) {
- // Create and return HttpResponseMethod
- HttpResponseMessage responseMessage = new HttpResponseMessage();
- responseMessage.setStatusCode(method.getStatusCode());
- try {
- responseMessage.setResponseBody(method.getResponseBodyAsString());
- } catch (Exception e) {
- e.printStackTrace();
- }
- return responseMessage;
+ // Extract response information and return
+ return responseMessage;
+ }
- }
+ /**
+ * Extracts the response information from an executed HttpMethod
+ *
+ * @param method
+ * Executed Method
+ * @return Packaged response information
+ */
+ private static HttpResponseMessage extractResponseInformation(HttpMethod method) {
+ // Create and return HttpResponseMethod
+ HttpResponseMessage responseMessage = new HttpResponseMessage();
+ responseMessage.setStatusCode(method.getStatusCode());
+ try {
+ JSON json = (JSON) JSON.parse(method.getResponseBodyAsString());
+ responseMessage.setResponseBody(json);
+ json.toJSONString();
+ } catch (Exception e) {
+ logger.info("response is not a json!");
+ }
+ return responseMessage;
+ }
}
+++ /dev/null
-/**\r
- * Copyright 2017 ZTE Corporation.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.onap.workflow.activitiext.restservicetask;\r
-\r
-public class Parameter {\r
-\r
- private String position;\r
- private String type;\r
- private String name;\r
- private String value;\r
-\r
- public String getPosition() {\r
- return position;\r
- }\r
-\r
- public void setPosition(String position) {\r
- this.position = position;\r
- }\r
-\r
- public String getType() {\r
- return type;\r
- }\r
-\r
- public void setType(String type) {\r
- this.type = type;\r
- }\r
-\r
- public String getName() {\r
- return name;\r
- }\r
-\r
- public void setName(String name) {\r
- this.name = name;\r
- }\r
-\r
- public String getValue() {\r
- return value;\r
- }\r
-\r
- public void setValue(String value) {\r
- this.value = value;\r
- }\r
-}\r
/**\r
- * Copyright 2017 ZTE Corporation.\r
+ * Copyright 2017 [ZTE] and others.\r
*\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except\r
+ * in compliance with the License. You may obtain a copy of the License at\r
*\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
*\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
+ * Unless required by applicable law or agreed to in writing, software distributed under the License\r
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express\r
+ * or implied. See the License for the specific language governing permissions and limitations under\r
+ * the License.\r
*/\r
-\r
package org.onap.workflow.activitiext.restservicetask;\r
\r
import java.util.ResourceBundle;\r
\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
public class PropertyUtil {\r
\r
+ private static final Logger logger = LoggerFactory.getLogger(PropertyUtil.class);\r
+ \r
public static final String REST_PROPERTY_LOCATION = "config";\r
\r
public static final String BASE_URL = "baseurl";\r
\r
- private static ResourceBundle resource;\r
- \r
- static{\r
- resource = ResourceBundle.getBundle(REST_PROPERTY_LOCATION);\r
- }\r
-\r
public static String findByKey(String key){\r
\r
- String value = resource.getString(key);\r
- \r
- return value;\r
+ try {\r
+ ResourceBundle resource = ResourceBundle.getBundle(REST_PROPERTY_LOCATION);\r
+ \r
+ String value = resource.getString(key);\r
+ \r
+ return value;\r
+ } catch (Exception e) {\r
+ logger.error("read resource failed!", e);\r
+ throw e;\r
+ }\r
}\r
\r
public static String getBasePath(){\r
\r
- String basepath = findByKey(BASE_URL);\r
- \r
- return basepath;\r
+ return findByKey(BASE_URL);\r
}\r
}\r
--- /dev/null
+/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * 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.
+ */
+package org.onap.workflow.utils;
+
+import org.apache.commons.lang3.StringUtils;
+import org.jvnet.hk2.annotations.Service;
+import org.onap.msb.sdk.discovery.MSBService;
+import org.onap.msb.sdk.discovery.common.RouteException;
+import org.onap.msb.sdk.discovery.entity.MicroServiceFullInfo;
+import org.onap.workflow.activitiext.restservicetask.PropertyUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Service
+public class MsbUtils {
+
+ private static final Logger LOG = LoggerFactory.getLogger(MsbUtils.class);
+
+ public static String getServiceAddress(String serviceName, String version) throws RouteException {
+
+ String baseUrl = "";
+ String msbIp = System.getenv("OPENPALETTE_MSB_IP");
+ String msbPort = System.getenv("OPENPALETTE_MSB_PORT");
+
+ if(StringUtils.isNotEmpty(msbIp) && StringUtils.isNotEmpty(msbPort))
+ {
+ baseUrl = "http://" + msbIp + ":" + msbPort;
+ }else{
+ baseUrl = PropertyUtil.getBasePath();
+ }
+
+ MicroServiceFullInfo msbInfo = new MSBService().queryMicroServiceInfo(baseUrl, serviceName, version);
+
+ LOG.info("publishUrl: {}", msbInfo.getUrl());
+
+ return msbInfo.getUrl();
+ }
+}
--- /dev/null
+/**
+ * Copyright 2017 [ZTE] and others.
+ *
+ * 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.
+ */
+package org.onap.workflow.activitiext.common;
+
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.msb.sdk.discovery.common.RouteException;
+import org.onap.workflow.utils.MsbUtils;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+/**
+ *
+ */
+@PrepareForTest({MsbUtils.class})
+@RunWith(PowerMockRunner.class)
+public class EnumModuleUrlTest {
+ @Test
+ public void testGetBaseUrl() {
+ try {
+ String baseUrl = "http://127.0.0.1:80";
+ PowerMockito.mockStatic(MsbUtils.class);
+ PowerMockito.when(MsbUtils.getServiceAddress("catalog", "v1")).thenReturn(baseUrl);
+ Assert.assertEquals(baseUrl, EnumModuleUrl.getBaseUrl(ServiceType.catalog));
+ } catch (RouteException e) {
+ assert (false);
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright 2017 ZTE Corporation.
+ *
+ * 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.
+ */
+package org.onap.workflow.activitiext.restservicetask;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import org.apache.commons.httpclient.NameValuePair;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@PrepareForTest({HighLevelRestApi.class,LowLevelRestApi.class})
+@RunWith(PowerMockRunner.class)
+public class HighLevelRestApiTest {
+
+ private HighLevelRestApi highLevelRestApi;
+
+ @Before
+ public void setUp() {
+ highLevelRestApi = new HighLevelRestApi();
+ }
+
+ @Test
+ public void testGet() {
+
+ try {
+ HttpResponseMessage msg = new HttpResponseMessage();
+ msg.setStatusCode(200);
+ msg.setResponseBody(null);
+ PowerMockito.mockStatic(LowLevelRestApi.class);
+ PowerMockito.when(LowLevelRestApi.executeHttpMethod(Mockito.anyObject())).thenReturn(msg);
+
+ String uri = "10.74.148.107/openoapi/catalog/v1/csars";
+ String acceptValue = "application/json";
+ String contentTypeValue = "application/json";
+
+ HighLevelRestApi.Get(uri, acceptValue, contentTypeValue);
+ assertThat(HighLevelRestApi.Get(uri, acceptValue, contentTypeValue), is(msg));
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void testPost() {
+
+ try {
+ HttpResponseMessage msg = new HttpResponseMessage();
+ msg.setStatusCode(200);
+ msg.setResponseBody(null);
+ PowerMockito.mockStatic(LowLevelRestApi.class);
+ PowerMockito.when(LowLevelRestApi.executeHttpMethod(Mockito.anyObject())).thenReturn(msg);
+
+ String uri = "10.74.148.107/openoapi/catalog/v1/csars";
+ String requestBody = "{'type':'NFAR'}";
+ String acceptValue = "application/json";
+ String contentTypeValue = "application/json";
+
+ assertThat(HighLevelRestApi.Post(uri, requestBody, acceptValue, contentTypeValue), is(msg));
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void testDelete() {
+
+ try {
+ HttpResponseMessage msg = new HttpResponseMessage();
+ msg.setStatusCode(200);
+ msg.setResponseBody(null);
+ PowerMockito.mockStatic(LowLevelRestApi.class);
+ PowerMockito.when(LowLevelRestApi.executeHttpMethod(Mockito.anyObject())).thenReturn(msg);
+
+ String uri = "10.74.148.107/openoapi/catalog/v1/csars/aa1bc611c9fbc08247d5ea71fd67ec3f";
+ String acceptValue = "application/json";
+ String contentTypeValue = "application/json";
+
+ assertThat(HighLevelRestApi.Delete(uri, acceptValue, contentTypeValue), is(msg));
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void testPut() {
+
+ try {
+ HttpResponseMessage msg = new HttpResponseMessage();
+ msg.setStatusCode(200);
+ msg.setResponseBody(null);
+ PowerMockito.mockStatic(LowLevelRestApi.class);
+ PowerMockito.when(LowLevelRestApi.executeHttpMethod(Mockito.anyObject())).thenReturn(msg);
+
+ String uri = "10.74.148.107/openoapi/catalog/v1/csars";
+ String requestBody = "{'type':'NFAR'}";
+ String acceptValue = "application/json";
+ String contentTypeValue = "application/json";
+
+ assertThat(HighLevelRestApi.Put(uri, requestBody, acceptValue, contentTypeValue), is(msg));
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void testCreateNameValuePairArrayFromQuery() {
+ NameValuePair[] pair = new NameValuePair[2];
+ NameValuePair p1 = new NameValuePair();
+ p1.setName("name");
+ p1.setValue("liuyao");
+ NameValuePair p2 = new NameValuePair();
+ p2.setName("pwd");
+ p2.setValue("zte");
+
+ pair[0] = p1;
+ pair[1] = p2;
+
+ String query = "name=liuyao&pwd=zte";
+
+ assertThat(highLevelRestApi.createNameValuePairArrayFromQuery(query), is(pair));
+ }
+
+}
*/
package org.onap.workflow.activitiext.restservicetask;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
import static org.powermock.api.mockito.PowerMockito.mock;
-import java.util.ArrayList;
-
+import org.activiti.engine.ActivitiException;
import org.activiti.engine.delegate.DelegateExecution;
-import org.activiti.engine.impl.context.Context;
import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
+import org.onap.workflow.activitiext.common.Parameter;
+import org.onap.workflow.activitiext.common.RestInfo;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
public void setUp() {
httpUtil = new HttpUtil();
}
-
+
@Test
- public void testExecute() {
+ public void testExecute(){
+
+ DelegateExecution executionEntity = mock(ExecutionEntity.class);
+
+ HttpUtil httpUtil1 = mock(HttpUtil.class);;
try {
+ httpUtil1.execute(executionEntity);
- DelegateExecution executionEntity = mock(ExecutionEntity.class);
+ Assert.assertTrue(true);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ Assert.assertTrue(false);
+ }
+ }
+
+ @Test
+ public void testExecuteMethod() {
+
+ DelegateExecution executionEntity = mock(ExecutionEntity.class);
+ HttpUtil httpUtil1 = mock(HttpUtil.class);;
+ try {
PowerMockito.when(executionEntity.getCurrentActivityId()).thenReturn("1111");
HttpResponseMessage msg = new HttpResponseMessage();
msg.setStatusCode(200);
- msg.setResponseBody("success");
+ msg.setResponseBody(null);
PowerMockito.mockStatic(HighLevelRestApi.class);
- PowerMockito.when(HighLevelRestApi.invoke(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenReturn(msg);
+ PowerMockito.when(HighLevelRestApi.invoke(Mockito.anyObject())).thenReturn(msg);
- assertThat(httpUtil.executeMethod(executionEntity), is(true));
+ httpUtil1.executeMethod(executionEntity);
+ Assert.assertTrue(true);
} catch (Exception e) {
e.printStackTrace();
+ Assert.assertTrue(false);
+ }
+ }
+
+ @Test
+ public void testHandleParam(){
+
+ try {
+ DelegateExecution executionEntity = mock(ExecutionEntity.class);
+ Parameter param = new Parameter();
+ param.setName("id");
+ param.setPosition("path");
+ param.setType("");
+ param.setValue("abc");
+
+ RestInfo info = new RestInfo();
+ info.setMethod("GET");
+ info.setName("name");
+ info.setPath("/catalog/v1");
+ info.setRealUri("");
+ info.setUrl("csars");
+ info.setVersion("v1");
+
+ httpUtil.handleParam(executionEntity, param, info);
+ Assert.assertTrue(true);
+ } catch (ActivitiException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ Assert.assertTrue(true);
}
+
}
}