diff options
18 files changed, 1374 insertions, 0 deletions
diff --git a/activiti-extension/.gitignore b/activiti-extension/.gitignore new file mode 100644 index 0000000..7e2df70 --- /dev/null +++ b/activiti-extension/.gitignore @@ -0,0 +1,37 @@ +### JAVA +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +### MAVEN +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties + +# Avoid ignoring Maven wrapper jar file (.jar files are usually ignored) +!/.mvn/wrapper/maven-wrapper.jar
\ No newline at end of file diff --git a/activiti-extension/pom.xml b/activiti-extension/pom.xml new file mode 100644 index 0000000..d1a518a --- /dev/null +++ b/activiti-extension/pom.xml @@ -0,0 +1,287 @@ +<?xml version="1.0"?>
+<!-- Copyright 2016 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. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <groupId>org.onap.oparent</groupId>
+ <artifactId>oparent</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>activiti-extension</artifactId>
+ <name>workflow/activiti-extension</name>
+ <packaging>jar</packaging>
+
+ <properties>
+ <ant.version>1.9.6</ant.version>
+ <apache-velocity.version>1.6.2</apache-velocity.version>
+ <jgrapht.version>0.9.1</jgrapht.version>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.eclipse.m2e</groupId>
+ <artifactId>lifecycle-mapping</artifactId>
+ <version>1.0.0</version>
+ <configuration>
+ <lifecycleMappingMetadata>
+ <pluginExecutions>
+ <pluginExecution>
+ <pluginExecutionFilter>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <version>2.8</version>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ </pluginExecutionFilter>
+ <action>
+ <ignore />
+ </action>
+ </pluginExecution>
+ </pluginExecutions>
+ </lifecycleMappingMetadata>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>2.6</version>
+ <configuration>
+ <archive>
+ <manifest>
+ <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.5.1</version>
+ <configuration>
+ <source>1.8</source>
+ <target>1.8</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-shade-plugin</artifactId>
+ <version>2.4</version>
+ <configuration>
+ <createDependencyReducedPom>false</createDependencyReducedPom>
+ <filters>
+ <filter>
+ <artifact>*:*</artifact>
+ <excludes>
+ <exclude>META-INF/*.SF</exclude>
+ <exclude>META-INF/*.DSA</exclude>
+ <exclude>META-INF/*.RSA</exclude>
+ </excludes>
+ </filter>
+ </filters>
+ </configuration>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>shade</goal>
+ </goals>
+ <configuration>
+ <transformers>
+ <transformer
+ implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
+ <transformer
+ implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
+ <mainClass>org.onap.workflow.activitiext.activitiExtApp</mainClass>
+ </transformer>
+ </transformers>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <version>2.10</version>
+ <executions>
+ <execution>
+ <id>copy-dependencies</id>
+ <phase>package</phase>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ <configuration>
+ <artifactItems>
+ <artifactItem>
+ <groupId>io.dropwizard</groupId>
+ <artifactId>dropwizard-core</artifactId>
+ <version>0.8.0</version>
+ <overWrite>true</overWrite>
+ </artifactItem>
+ </artifactItems>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ <pluginManagement>
+ <plugins>
+ <!--This plugin's configuration is used to store Eclipse m2e settings
+ only. It has no influence on the Maven build itself. -->
+ <plugin>
+ <groupId>org.eclipse.m2e</groupId>
+ <artifactId>lifecycle-mapping</artifactId>
+ <version>1.0.0</version>
+ <configuration>
+ <lifecycleMappingMetadata>
+ <pluginExecutions>
+ <pluginExecution>
+ <pluginExecutionFilter>
+ <groupId>
+ org.apache.maven.plugins
+ </groupId>
+ <artifactId>
+ maven-checkstyle-plugin
+ </artifactId>
+ <versionRange>
+ [2.17,)
+ </versionRange>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ </pluginExecutionFilter>
+ <action>
+ <ignore></ignore>
+ </action>
+ </pluginExecution>
+ </pluginExecutions>
+ </lifecycleMappingMetadata>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>io.dropwizard</groupId>
+ <artifactId>dropwizard-core</artifactId>
+ <version>0.8.0</version>
+ </dependency>
+ <dependency>
+ <groupId>io.dropwizard</groupId>
+ <artifactId>dropwizard-assets</artifactId>
+ <version>0.8.0</version>
+ </dependency>
+ <dependency>
+ <groupId>io.dropwizard</groupId>
+ <artifactId>dropwizard-hibernate</artifactId>
+ <version>0.8.0</version>
+ </dependency>
+ <dependency>
+ <groupId>io.dropwizard</groupId>
+ <artifactId>dropwizard-migrations</artifactId>
+ <version>0.8.0</version>
+ </dependency>
+ <dependency>
+ <groupId>io.swagger</groupId>
+ <artifactId>swagger-jersey2-jaxrs</artifactId>
+ <version>1.5.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.projectlombok</groupId>
+ <artifactId>lombok</artifactId>
+ <version>1.16.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-server</artifactId>
+ <version>2.16</version>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.media</groupId>
+ <artifactId>jersey-media-multipart</artifactId>
+ <version>2.16</version>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ <version>2.16</version>
+ </dependency>
+ <dependency>
+ <groupId>com.eclipsesource.jaxrs</groupId>
+ <artifactId>consumer</artifactId>
+ <version>5.0</version>
+ <exclusions>
+ <exclusion>
+ <groupId>com.eclipsesource.jaxrs</groupId>
+ <artifactId>jersey-all</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>com.jcraft</groupId>
+ <artifactId>jsch</artifactId>
+ <version>0.1.53</version>
+ </dependency>
+ <dependency>
+ <groupId>io.dropwizard</groupId>
+ <artifactId>dropwizard-jdbi</artifactId>
+ <version>0.8.0</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>2.4</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.12</version>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4</artifactId>
+ <version>1.6.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-api-mockito</artifactId>
+ <version>1.6.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <version>1.9.5</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ant</groupId>
+ <artifactId>ant</artifactId>
+ <version>${ant.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.alibaba</groupId>
+ <artifactId>fastjson</artifactId>
+ <version>1.2.23</version>
+ </dependency>
+ <dependency>
+ <groupId>org.activiti</groupId>
+ <artifactId>activiti-engine</artifactId>
+ <version>5.21.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-httpclient</groupId>
+ <artifactId>commons-httpclient</artifactId>
+ <version>3.1</version>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/activiti-extension/src/main/java/org/onap/workflow/activitiext/ActivitiExtApp.java b/activiti-extension/src/main/java/org/onap/workflow/activitiext/ActivitiExtApp.java new file mode 100644 index 0000000..dd56610 --- /dev/null +++ b/activiti-extension/src/main/java/org/onap/workflow/activitiext/ActivitiExtApp.java @@ -0,0 +1,41 @@ +/** + * 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); + } +} + diff --git a/activiti-extension/src/main/java/org/onap/workflow/activitiext/ActivitiExtAppConfig.java b/activiti-extension/src/main/java/org/onap/workflow/activitiext/ActivitiExtAppConfig.java new file mode 100644 index 0000000..ffe3c9e --- /dev/null +++ b/activiti-extension/src/main/java/org/onap/workflow/activitiext/ActivitiExtAppConfig.java @@ -0,0 +1,43 @@ +/** + * 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; + } +} diff --git a/activiti-extension/src/main/java/org/onap/workflow/activitiext/ActivitiExtAppInit.java b/activiti-extension/src/main/java/org/onap/workflow/activitiext/ActivitiExtAppInit.java new file mode 100644 index 0000000..0291e3b --- /dev/null +++ b/activiti-extension/src/main/java/org/onap/workflow/activitiext/ActivitiExtAppInit.java @@ -0,0 +1,39 @@ +/** + * 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 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); + } +} diff --git a/activiti-extension/src/main/java/org/onap/workflow/activitiext/common/Config.java b/activiti-extension/src/main/java/org/onap/workflow/activitiext/common/Config.java new file mode 100644 index 0000000..62ee72a --- /dev/null +++ b/activiti-extension/src/main/java/org/onap/workflow/activitiext/common/Config.java @@ -0,0 +1,39 @@ +/**
+ * 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;
+
+import org.onap.workflow.activitiext.ActivitiExtAppConfig;
+
+public class Config {
+
+ private static Config instance = new Config();
+
+ private ActivitiExtAppConfig appconfig;
+
+ public static Config getInstance(){
+ return instance;
+ }
+
+ public ActivitiExtAppConfig getAppconfig() {
+ return appconfig;
+ }
+
+ public void setAppconfig(ActivitiExtAppConfig config) {
+ this.appconfig = config;
+ }
+
+}
diff --git a/activiti-extension/src/main/java/org/onap/workflow/activitiext/common/MsbClientConfig.java b/activiti-extension/src/main/java/org/onap/workflow/activitiext/common/MsbClientConfig.java new file mode 100644 index 0000000..338a1ff --- /dev/null +++ b/activiti-extension/src/main/java/org/onap/workflow/activitiext/common/MsbClientConfig.java @@ -0,0 +1,26 @@ +/**
+ * 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;
+
+import lombok.Data;
+
+@Data
+public class MsbClientConfig {
+
+ private String msbSvrIp;
+ private Integer msbSvrPort;
+}
diff --git a/activiti-extension/src/main/java/org/onap/workflow/activitiext/restservicetask/ConstString.java b/activiti-extension/src/main/java/org/onap/workflow/activitiext/restservicetask/ConstString.java new file mode 100644 index 0000000..371d8d7 --- /dev/null +++ b/activiti-extension/src/main/java/org/onap/workflow/activitiext/restservicetask/ConstString.java @@ -0,0 +1,70 @@ +/**
+ * Copyright 2016-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;
+
+/**
+ *
+ * @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_TYPE_STRING = "string";
+
+ /**
+ * parameter type : acitviti expression
+ */
+ public static final String PARAMETER_TYPE_EXPRESSION = "expression";
+
+}
diff --git a/activiti-extension/src/main/java/org/onap/workflow/activitiext/restservicetask/DeployBpmnFileResponse.java b/activiti-extension/src/main/java/org/onap/workflow/activitiext/restservicetask/DeployBpmnFileResponse.java new file mode 100644 index 0000000..83b8514 --- /dev/null +++ b/activiti-extension/src/main/java/org/onap/workflow/activitiext/restservicetask/DeployBpmnFileResponse.java @@ -0,0 +1,31 @@ +/** + * 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 lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class DeployBpmnFileResponse { + private int status; + private String message; + private String deployedId; + private String processId; +} diff --git a/activiti-extension/src/main/java/org/onap/workflow/activitiext/restservicetask/HighLevelRestApi.java b/activiti-extension/src/main/java/org/onap/workflow/activitiext/restservicetask/HighLevelRestApi.java new file mode 100644 index 0000000..31001b7 --- /dev/null +++ b/activiti-extension/src/main/java/org/onap/workflow/activitiext/restservicetask/HighLevelRestApi.java @@ -0,0 +1,210 @@ +/** + * Copyright 2016-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.activiti.engine.ActivitiException; +import org.apache.commons.httpclient.HttpMethodBase; +import org.apache.commons.httpclient.NameValuePair; +import org.apache.commons.httpclient.methods.DeleteMethod; +import org.apache.commons.httpclient.methods.GetMethod; +import org.apache.commons.httpclient.methods.PostMethod; +import org.apache.commons.httpclient.methods.PutMethod; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author 10222158 + * + */ +public class HighLevelRestApi { + + private static final Logger logger = LoggerFactory.getLogger(HighLevelRestApi.class); + + /** + * invoke http service + * + * @param methodValue + * @param uri + * @param requestPayload + * @param acceptValue + * @param contentTypeValue + * @return + */ + public static HttpResponseMessage invoke(String methodValue, String uri, String requestPayload, String acceptValue, + String contentTypeValue) throws ActivitiException { + + // 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); + + HttpResponseMessage msg = new HttpResponseMessage(); + switch (methodValue.toUpperCase()) { + case ConstString.HTTP_GET: + msg = HighLevelRestApi.Get(uri, acceptValue, contentTypeValue); + break; + case ConstString.HTTP_POST: + msg = HighLevelRestApi.Post(uri, requestPayload, acceptValue, contentTypeValue); + break; + case ConstString.HTTP_DELETE: + msg = HighLevelRestApi.Delete(uri, acceptValue, contentTypeValue); + break; + case ConstString.HTTP_PUT: + msg = HighLevelRestApi.Put(uri, requestPayload, acceptValue, contentTypeValue); + break; + default: + throw new ActivitiException("can not find the http method type '" + methodValue + "'!"); + } + return msg; + } + + /** + * This method implements the HTTP Put Method + * + * @param uri + * Resource URI + * @param requestPayload + * 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) { + + PutMethod method = new PutMethod(uri); + + HighLevelRestApi.setAcceptHeader(method, acceptValue); + HighLevelRestApi.setContentTypeHeader(method, contentTypeValue); + method.setRequestBody(requestPayload); + + HttpResponseMessage responseMessage = LowLevelRestApi.executeHttpMethod(method); + + return responseMessage; + } + + /** + * This method implements the HTTP Post Method + * + * @param uri + * Resource URI + * @param requestPayload + * 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) { + + PostMethod method = null; + if (uri.contains("?")) { + String[] split = uri.split("\\?"); + method = new PostMethod(split[0]); + method.setQueryString(HighLevelRestApi.createNameValuePairArrayFromQuery(split[1])); + } else { + method = new PostMethod(uri); + } + method.setRequestBody(requestPayload); + HighLevelRestApi.setAcceptHeader(method, acceptValue); + HighLevelRestApi.setContentTypeHeader(method, contentTypeValue); + HttpResponseMessage responseMessage = LowLevelRestApi.executeHttpMethod(method); + return responseMessage; + } + + /** + * This method implements the HTTP Get Method + * + * @param uri + * Resource URI + * @return Content represented by the Resource URI + */ + public static HttpResponseMessage Get(String uri, String acceptValue, String contentTypeValue) { + GetMethod method = null; + if (uri.contains("?")) { + String[] split = uri.split("\\?"); + method = new GetMethod(split[0]); + method.setQueryString(HighLevelRestApi.createNameValuePairArrayFromQuery(split[1])); + } else { + method = new GetMethod(uri); + } + + HighLevelRestApi.setAcceptHeader(method, acceptValue); + HighLevelRestApi.setContentTypeHeader(method, contentTypeValue); + HttpResponseMessage responseMessage = LowLevelRestApi.executeHttpMethod(method); + return responseMessage; + } + + private static NameValuePair[] createNameValuePairArrayFromQuery(String query) { + String[] pairs = query.trim().split("&"); + NameValuePair[] nameValuePairArray = new NameValuePair[pairs.length]; + int count = 0; + for (String pair : pairs) { + String[] keyValue = pair.split("="); + NameValuePair nameValuePair = new NameValuePair(); + nameValuePair.setName(keyValue[0]); + nameValuePair.setValue(keyValue[1]); + nameValuePairArray[count] = nameValuePair; + count++; + } + return nameValuePairArray; + } + + /** + * This method implements the HTTP Delete Method + * + * @param uri + * Resource URI + * @return ResponseCode of HTTP Interaction + */ + public static HttpResponseMessage Delete(String uri, String acceptValue, String contentTypeValue) { + + DeleteMethod method = new DeleteMethod(uri); + HighLevelRestApi.setAcceptHeader(method, acceptValue); + HighLevelRestApi.setContentTypeHeader(method, contentTypeValue); + HttpResponseMessage responseMessage = LowLevelRestApi.executeHttpMethod(method); + return responseMessage; + } + + private static void setAcceptHeader(HttpMethodBase method, String value) { + if (!StringUtils.isEmpty(value)) { + method.setRequestHeader("Accept", value); + } else { + method.setRequestHeader("Accept", "application/xml"); + } + } + + private static void setContentTypeHeader(HttpMethodBase method, String value) { + if (!StringUtils.isEmpty(value)) { + 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; + } +} diff --git a/activiti-extension/src/main/java/org/onap/workflow/activitiext/restservicetask/HttpResponseMessage.java b/activiti-extension/src/main/java/org/onap/workflow/activitiext/restservicetask/HttpResponseMessage.java new file mode 100644 index 0000000..2128c18 --- /dev/null +++ b/activiti-extension/src/main/java/org/onap/workflow/activitiext/restservicetask/HttpResponseMessage.java @@ -0,0 +1,56 @@ +/** + * 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.io.Serializable; + +/** + */ +public class HttpResponseMessage implements Serializable { + + private int statusCode; + private String responseBody; + + + /** + * @return the statusCode + */ + public int getStatusCode() { + return this.statusCode; + } + + /** + * @param statusCode the statusCode to set + */ + protected void setStatusCode(int statusCode) { + this.statusCode = statusCode; + } + + /** + * @return the responseBody + */ + public String getResponseBody() { + return this.responseBody; + } + + /** + * @param responseBody the responseBody to set + */ + protected void setResponseBody(String responseBody) { + this.responseBody = responseBody; + } + +} diff --git a/activiti-extension/src/main/java/org/onap/workflow/activitiext/restservicetask/HttpUtil.java b/activiti-extension/src/main/java/org/onap/workflow/activitiext/restservicetask/HttpUtil.java new file mode 100644 index 0000000..75a6b2f --- /dev/null +++ b/activiti-extension/src/main/java/org/onap/workflow/activitiext/restservicetask/HttpUtil.java @@ -0,0 +1,176 @@ +/**
+ * Copyright 2016-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.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.activiti.engine.ActivitiException;
+import org.activiti.engine.delegate.BpmnError;
+import org.activiti.engine.delegate.DelegateExecution;
+import org.activiti.engine.delegate.Expression;
+import org.activiti.engine.delegate.JavaDelegate;
+import org.activiti.engine.impl.context.Context;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+
+/**
+ * rest service
+ *
+ * @author 10222158
+ *
+ */
+public class HttpUtil implements JavaDelegate {
+
+ private static final Logger logger = LoggerFactory.getLogger(HttpUtil.class);
+
+ private Expression uri;
+ private Expression method;
+ private Expression accept;
+ private Expression contentType;
+ private Expression parameters;
+
+ @Override
+ public void execute(DelegateExecution execution) throws ActivitiException {
+
+ try {
+ this.executeMethod(execution);
+ } catch (Exception e) {
+
+ logger.error("Invoke rest service failed!", e);
+ throw new BpmnError(e.getMessage());
+ }
+ }
+
+ /**
+ * invoke rest service
+ *
+ * @param execution
+ */
+ public boolean executeMethod(DelegateExecution execution) throws Exception {
+
+ String uriValue = getValue(uri, execution);
+ String methodValue = getValue(method, execution);
+ String acceptValue = getValue(accept, execution);
+ String contentTypeValue = getValue(contentType, execution);
+ String parametersValue = getValue(parameters, execution);
+
+ Map<String, String> requestBody = new HashMap<String, String>();
+
+ if (!StringUtils.isEmpty(parametersValue)) {
+
+ // Parse the parameter into Object List
+ List<Parameter> parameters = JSONArray.parseArray(parametersValue, Parameter.class);
+
+ for (Parameter param : parameters) {
+
+ handleParam(execution, param, requestBody, uriValue);
+ }
+ }
+
+ String requestPayload = JSON.toJSONString(requestBody);
+
+ // invoke http service
+ HttpResponseMessage msg = HighLevelRestApi.invoke(methodValue, uriValue, requestPayload, acceptValue,
+ contentTypeValue);
+
+ // inject the result to variable
+ execution.setVariable(execution.getCurrentActivityId(), msg);
+
+ logger.info("statusCode: " + msg.getStatusCode());
+ logger.info("responseBody: " + msg.getResponseBody());
+
+ return true;
+ }
+
+ /**
+ *
+ * @param execution
+ * @param param
+ * @param requestBody
+ * @param uriValue
+ */
+ public void handleParam(DelegateExecution execution, Parameter param, Map<String, String> requestBody,
+ String uriValue) throws ActivitiException {
+
+ if (ConstString.PARAMETER_TYPE_EXPRESSION.equals(param.getType())) {
+ handleExpression(execution, param);
+ }
+
+ switch (param.getPosition()) {
+ case ConstString.PARAMETER_POSITION_PATH:
+
+ // replace the path parameter
+ uriValue = uriValue.replaceAll("\\{+" + param.getName() + "+\\}", param.getValue());
+ break;
+ case ConstString.PARAMETER_POSITION_QUERY:
+
+ // add the query parameter
+ if (!uriValue.contains("?")) {
+ uriValue = uriValue + "?" + param.getName() + "=" + param.getValue();
+ } else {
+ uriValue = uriValue + "&" + param.getName() + "=" + param.getValue();
+ }
+ break;
+ case ConstString.PARAMETER_POSITION_BODY:
+
+ // add parameter to request body
+ requestBody.put(param.getName(), param.getValue());
+ break;
+ default:
+ throw new ActivitiException(
+ "The position '" + param.getPosition() + "' is illegal, please check your input!");
+ }
+ }
+
+ /**
+ * get value from VariableScope
+ *
+ * @param expression
+ * @param execution
+ * @return
+ */
+ public String getValue(Expression expression, DelegateExecution execution) {
+
+ String value = new String();
+ if (expression != null) {
+ value = (String) expression.getValue(execution);
+ }
+
+ return value;
+ }
+
+ /**
+ * parse expression in the parameter
+ *
+ * @param execution
+ * @param param
+ */
+ public void handleExpression(DelegateExecution execution, Parameter param) {
+
+ Expression expression = Context.getProcessEngineConfiguration().getExpressionManager()
+ .createExpression(param.getValue());
+
+ String value = String.valueOf(expression.getValue(execution));
+
+ param.setValue(value);
+ }
+}
\ No newline at end of file diff --git a/activiti-extension/src/main/java/org/onap/workflow/activitiext/restservicetask/LowLevelRestApi.java b/activiti-extension/src/main/java/org/onap/workflow/activitiext/restservicetask/LowLevelRestApi.java new file mode 100644 index 0000000..9171c31 --- /dev/null +++ b/activiti-extension/src/main/java/org/onap/workflow/activitiext/restservicetask/LowLevelRestApi.java @@ -0,0 +1,79 @@ +/** + * 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.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.HttpMethod; + +/** + * 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) { + + HttpResponseMessage responseMessage = null; + + try { + + // Execute Request + LowLevelRestApi.httpClient.executeMethod(method); + responseMessage = LowLevelRestApi.extractResponseInformation(method); + + } catch (Exception e) { + e.printStackTrace(); + } finally { + + // Release Connection anyway + method.releaseConnection(); + } + + // 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 { + responseMessage.setResponseBody(method.getResponseBodyAsString()); + } catch (Exception e) { + e.printStackTrace(); + } + return responseMessage; + + } + +} diff --git a/activiti-extension/src/main/java/org/onap/workflow/activitiext/restservicetask/Parameter.java b/activiti-extension/src/main/java/org/onap/workflow/activitiext/restservicetask/Parameter.java new file mode 100644 index 0000000..9397d33 --- /dev/null +++ b/activiti-extension/src/main/java/org/onap/workflow/activitiext/restservicetask/Parameter.java @@ -0,0 +1,56 @@ +/**
+ * 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;
+
+public class Parameter {
+
+ private String position;
+ private String type;
+ private String name;
+ private String value;
+
+ public String getPosition() {
+ return position;
+ }
+
+ public void setPosition(String position) {
+ this.position = position;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+}
diff --git a/activiti-extension/src/main/java/org/onap/workflow/activitiext/restservicetask/PropertyUtil.java b/activiti-extension/src/main/java/org/onap/workflow/activitiext/restservicetask/PropertyUtil.java new file mode 100644 index 0000000..5391757 --- /dev/null +++ b/activiti-extension/src/main/java/org/onap/workflow/activitiext/restservicetask/PropertyUtil.java @@ -0,0 +1,46 @@ +/**
+ * 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.ResourceBundle;
+
+public class PropertyUtil {
+
+ public static final String REST_PROPERTY_LOCATION = "config";
+
+ public static final String BASE_URL = "baseurl";
+
+ private static ResourceBundle resource;
+
+ static{
+ resource = ResourceBundle.getBundle(REST_PROPERTY_LOCATION);
+ }
+
+ public static String findByKey(String key){
+
+ String value = resource.getString(key);
+
+ return value;
+ }
+
+ public static String getBasePath(){
+
+ String basepath = findByKey(BASE_URL);
+
+ return basepath;
+ }
+}
diff --git a/activiti-extension/src/main/java/org/onap/workflow/activitiext/restservicetask/StartProcessRequest.java b/activiti-extension/src/main/java/org/onap/workflow/activitiext/restservicetask/StartProcessRequest.java new file mode 100644 index 0000000..9d712f2 --- /dev/null +++ b/activiti-extension/src/main/java/org/onap/workflow/activitiext/restservicetask/StartProcessRequest.java @@ -0,0 +1,33 @@ +/** + * 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; + +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; +} diff --git a/activiti-extension/src/main/resources/api-doc/index.html b/activiti-extension/src/main/resources/api-doc/index.html new file mode 100644 index 0000000..fb25d00 --- /dev/null +++ b/activiti-extension/src/main/resources/api-doc/index.html @@ -0,0 +1,99 @@ +<!DOCTYPE html> +<html> +<head> + <title>Swagger UI</title> + <link href='css/typography.css' media='screen' rel='stylesheet' type='text/css'/> + <link href='css/reset.css' media='screen' rel='stylesheet' type='text/css'/> + <link href='css/screen.css' media='screen' rel='stylesheet' type='text/css'/> + <link href='css/reset.css' media='print' rel='stylesheet' type='text/css'/> + <link href='css/screen.css' media='print' rel='stylesheet' type='text/css'/> + <script type="text/javascript" src="lib/shred.bundle.js"></script> + <script src='lib/jquery-1.8.0.min.js' type='text/javascript'></script> + <script src='lib/jquery.slideto.min.js' type='text/javascript'></script> + <script src='lib/jquery.wiggle.min.js' type='text/javascript'></script> + <script src='lib/jquery.ba-bbq.min.js' type='text/javascript'></script> + <script src='lib/handlebars-2.0.0.js' type='text/javascript'></script> + <script src='lib/underscore-min.js' type='text/javascript'></script> + <script src='lib/backbone-min.js' type='text/javascript'></script> + <script src='lib/swagger-client.js' type='text/javascript'></script> + <script src='swagger-ui.js' type='text/javascript'></script> + <script src='lib/highlight.7.3.pack.js' type='text/javascript'></script> + <script src='lib/marked.js' type='text/javascript'></script> + + <!-- enabling this will enable oauth2 implicit scope support --> + <script src='lib/swagger-oauth.js' type='text/javascript'></script> + <script type="text/javascript"> + $(function () { + var url = window.location.search.match(/url=([^&]+)/); + if (url && url.length > 1) { + url = decodeURIComponent(url[1]); + } else { + url = "/api/activitiext/v1/swagger.json"; + } + window.swaggerUi = new SwaggerUi({ + url: url, + dom_id: "swagger-ui-container", + supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'], + onComplete: function(swaggerApi, swaggerUi){ + + if(typeof initOAuth == "function") { + /* + initOAuth({ + clientId: "your-client-id", + realm: "your-realms", + appName: "your-app-name" + }); + */ + } + $('pre code').each(function(i, e) { + hljs.highlightBlock(e) + }); + }, + onFailure: function(data) { + log("Unable to Load SwaggerUI"); + }, + docExpansion: "none", + sorter : "alpha" + }); + + function addApiKeyAuthorization() { + var key = $('#input_apiKey')[0].value; + log("key: " + key); + if(key && key.trim() != "") { + log("added key " + key); + window.authorizations.add("api_key", new ApiKeyAuthorization("api_key", key, "query")); + } + } + + $('#input_apiKey').change(function() { + addApiKeyAuthorization(); + }); + + // if you have an apiKey you would like to pre-populate on the page for demonstration purposes... + /* + var apiKey = "myApiKeyXXXX123456789"; + $('#input_apiKey').val(apiKey); + addApiKeyAuthorization(); + */ + + window.swaggerUi.load(); + }); + </script> +</head> + +<body class="swagger-section"> +<div id='header' style="display:none"> + <div class="swagger-ui-wrap" > + <a id="logo" >zte conductor</a> + <form id='api_selector'> + <div class='input'><input placeholder="http://example.com/api" id="input_baseUrl" name="baseUrl" type="text"/></div> + <div class='input'><input placeholder="api_key" id="input_apiKey" name="apiKey" type="text"/></div> + <div class='input'><a id="explore" href="#">Explore</a></div> + </form> + </div> +</div> + +<div id="message-bar" class="swagger-ui-wrap"> </div> +<div id="swagger-ui-container" class="swagger-ui-wrap"></div> +</body> +</html> diff --git a/activiti-extension/src/main/resources/banner.txt b/activiti-extension/src/main/resources/banner.txt new file mode 100644 index 0000000..ec90bd7 --- /dev/null +++ b/activiti-extension/src/main/resources/banner.txt @@ -0,0 +1,6 @@ + _ ____ _____ ___ __ __ ___ _____ ___ _____ __ __ _____
+ / \ / ___| |_ _| |_ _| \ \ / / |_ _| |_ _| |_ _| | ____| \ \/ / |_ _|
+ / _ \ | | | | | | \ \ / / | | | | | | _____ | _| \ / | |
+ / ___ \ | |___ | | | | \ V / | | | | | | |_____| | |___ / \ | |
+ /_/ \_\ \____| |_| |___| \_/ |___| |_| |___| |_____| /_/\_\ |_|
+
\ No newline at end of file |