aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--openo-portal/pom.xml65
-rw-r--r--openo-portal/portal-common/pom.xml74
-rw-r--r--openo-portal/portal-common/src/main/webapp/WEB-INF/web.xml21
-rw-r--r--openo-portal/portal-extsys/pom.xml64
-rw-r--r--openo-portal/portal-lifecyclemgr/pom.xml62
-rw-r--r--openo-portal/portal-package/pom.xml58
-rw-r--r--openo-portal/portal-package/src/main/webapp/WEB-INF/web.xml21
-rw-r--r--pom.xml70
-rw-r--r--servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/activator/Activator.java169
-rw-r--r--servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/constant/Constant.java304
-rw-r--r--servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/exception/ErrorCode.java135
-rw-r--r--servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/roa/impl/ServiceGatewayRoaModuleImpl.java199
-rw-r--r--servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/service/impl/ServiceGatewayImpl.java204
-rw-r--r--servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/service/inf/IServiceGateway.java110
-rw-r--r--servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/util/http/ResponseUtils.java333
-rw-r--r--servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/util/register/RegisterUtil.java161
-rw-r--r--servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/util/validate/ValidateUtil.java83
-rw-r--r--servicegateway/service/src/test/java/org/openo/gso/gui/servicegateway/roa/impl/ServiceGatewayRoaModuleImplTest.java292
-rw-r--r--servicegateway/service/src/test/java/org/openo/gso/gui/servicegateway/service/impl/ServiceGatewayImplTest.java145
-rw-r--r--servicegateway/service/src/test/resources/json/createServiceInstance.json12
20 files changed, 1582 insertions, 1000 deletions
diff --git a/openo-portal/pom.xml b/openo-portal/pom.xml
index 1152b1d4..e6dbf7b3 100644
--- a/openo-portal/pom.xml
+++ b/openo-portal/pom.xml
@@ -1,30 +1,35 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- Copyright (C) 2015 ZTE, Inc. and others. All rights reserved. (ZTE)
-
- 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.openo.gso.gui</groupId>
- <artifactId>gso-gui</artifactId>
- <version>1.0.0-SNAPSHOT</version>
- <relativePath>..</relativePath>
- </parent>
- <modelVersion>4.0.0</modelVersion>
- <artifactId>openo-portal</artifactId>
- <packaging>pom</packaging>
- <name>portal</name>
-</project>
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (C) 2015 ZTE, Inc. and others. All rights reserved. (ZTE)
+
+ 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.openo.gso.gui</groupId>
+ <artifactId>gso-gui</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>openo-portal</artifactId>
+ <packaging>pom</packaging>
+ <name>portal</name>
+
+ <modules>
+ <module>portal-package</module>
+ <module>portal-common</module>
+ </modules>
+</project>
diff --git a/openo-portal/portal-common/pom.xml b/openo-portal/portal-common/pom.xml
index 5be89d20..ba32aaad 100644
--- a/openo-portal/portal-common/pom.xml
+++ b/openo-portal/portal-common/pom.xml
@@ -1,31 +1,43 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- Copyright (C) 2015 ZTE, Inc. and others. All rights reserved. (ZTE)
-
- 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">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.openo.gso.gui</groupId>
- <artifactId>openo-portal</artifactId>
- <version>1.0.0-SNAPSHOT</version>
- <relativePath/>
- </parent>
-
- <artifactId>common</artifactId>
- <version>1.0.0-SNAPSHOT</version>
- <packaging>pom</packaging>
-</project>
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (C) 2015 ZTE, Inc. and others. All rights reserved. (ZTE)
+
+ 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.openo.gso.gui</groupId>
+ <artifactId>openo-portal</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath></relativePath>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>portal-common</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <packaging>war</packaging>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-war-plugin</artifactId>
+ <configuration>
+ <failOnMissingWebXml>false</failOnMissingWebXml>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/openo-portal/portal-common/src/main/webapp/WEB-INF/web.xml b/openo-portal/portal-common/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 00000000..7c099597
--- /dev/null
+++ b/openo-portal/portal-common/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (C) 2015 CMCC, Inc. and others. All rights reserved. (CMCC)
+
+ 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.
+
+-->
+<web-app>
+ <display-name>OPEN-O Web Common Module</display-name>
+</web-app>
diff --git a/openo-portal/portal-extsys/pom.xml b/openo-portal/portal-extsys/pom.xml
index 703434d2..ded01b8d 100644
--- a/openo-portal/portal-extsys/pom.xml
+++ b/openo-portal/portal-extsys/pom.xml
@@ -1,32 +1,32 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- Copyright (C) 2015 ZTE, Inc. and others. All rights reserved. (ZTE)
-
- 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">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>openo-portal</groupId>
- <artifactId>openo-portal</artifactId>
- <version>1.0.0-SNAPSHOT</version>
- <relativePath/>
- </parent>
-
- <groupId>openo-portal.module.extsys</groupId>
- <artifactId>module-extsys</artifactId>
- <version>1.0.0-SNAPSHOT</version>
- <packaging>pom</packaging>
-</project>
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (C) 2015 ZTE, Inc. and others. All rights reserved. (ZTE)
+
+ 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">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>openo-portal</groupId>
+ <artifactId>openo-portal</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath/>
+ </parent>
+
+ <groupId>openo-portal.module.extsys</groupId>
+ <artifactId>module-extsys</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+</project>
diff --git a/openo-portal/portal-lifecyclemgr/pom.xml b/openo-portal/portal-lifecyclemgr/pom.xml
index 5fe24ac7..634020f3 100644
--- a/openo-portal/portal-lifecyclemgr/pom.xml
+++ b/openo-portal/portal-lifecyclemgr/pom.xml
@@ -1,31 +1,31 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- Copyright 2016, Huawei Technologies Co., Ltd.
-
- 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">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.openo.gso.gui</groupId>
- <artifactId>openo-portal</artifactId>
- <version>1.0.0-SNAPSHOT</version>
- <relativePath/>
- </parent>
-
- <artifactId>module-lifecyclemgr</artifactId>
- <version>1.0.0-SNAPSHOT</version>
- <packaging>pom</packaging>
-</project>
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright 2016, Huawei Technologies Co., Ltd.
+
+ 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">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.openo.gso.gui</groupId>
+ <artifactId>openo-portal</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath/>
+ </parent>
+
+ <artifactId>module-lifecyclemgr</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+</project>
diff --git a/openo-portal/portal-package/pom.xml b/openo-portal/portal-package/pom.xml
new file mode 100644
index 00000000..125380e8
--- /dev/null
+++ b/openo-portal/portal-package/pom.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (C) 2015 ZTE, Inc. and others. All rights reserved. (ZTE)
+
+ 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/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.openo.gso.gui</groupId>
+ <artifactId>openo-portal</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>portal-package</artifactId>
+ <packaging>war</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.openo.gso.gui</groupId>
+ <artifactId>portal-common</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <type>war</type>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <finalName>open-portal</finalName>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-war-plugin</artifactId>
+ <configuration>
+ <packagingExcludes>WEB-INF/web.xml</packagingExcludes>
+ <overlays>
+ <overlay>
+ <groupId>org.openo.gso.gui</groupId>
+ <artifactId>portal-common</artifactId>
+ </overlay>
+ </overlays>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/openo-portal/portal-package/src/main/webapp/WEB-INF/web.xml b/openo-portal/portal-package/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 00000000..e7cd792c
--- /dev/null
+++ b/openo-portal/portal-package/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (C) 2015 CMCC, Inc. and others. All rights reserved. (CMCC)
+
+ 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.
+
+-->
+<web-app>
+ <display-name>OPEN-O Web Application</display-name>
+</web-app>
diff --git a/pom.xml b/pom.xml
index f25e9f02..2564c672 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,35 +1,35 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- Copyright (C) 2015 ZTE, Inc. and others. All rights reserved. (ZTE)
-
- 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.openo.oparent</groupId>
- <artifactId>oparent</artifactId>
- <version>1.0.0-SNAPSHOT</version>
- <relativePath>../oparent</relativePath>
- </parent>
- <modelVersion>4.0.0</modelVersion>
- <groupId>org.openo.gso.gui</groupId>
- <artifactId>gso-gui</artifactId>
- <packaging>pom</packaging>
- <name>gui</name>
- <modules>
- <module>openo-portal</module>
- <module>servicegateway</module>
- </modules>
-</project>
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (C) 2015 ZTE, Inc. and others. All rights reserved. (ZTE)
+
+ 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.openo.oparent</groupId>
+ <artifactId>oparent</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>../oparent</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.openo.gso.gui</groupId>
+ <artifactId>gso-gui</artifactId>
+ <packaging>pom</packaging>
+ <name>gui</name>
+ <modules>
+ <module>openo-portal</module>
+ <module>servicegateway</module>
+ </modules>
+</project>
diff --git a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/activator/Activator.java b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/activator/Activator.java
index befe9328..0055931d 100644
--- a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/activator/Activator.java
+++ b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/activator/Activator.java
@@ -1,83 +1,86 @@
-/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
- *
- * 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.openo.gso.gui.servicegateway.activator;
-
-import java.io.File;
-
-import org.apache.commons.lang3.StringUtils;
-import org.openo.baseservice.util.impl.SystemEnvVariablesFactory;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Service Start <br/>
- *
- * @author
- * @since GSO 0.5, 2016-8-10
- */
-public class Activator {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(Activator.class);
-
- /**
- * start operation by spring <br/>
- *
- * @param context
- * service context
- * @author
- * @since GSO 0.5, 2016-8-10
- */
- public void start() {
- // register restful to M-Bus when starting service
- registerService();
- }
-
- /**
- * register the service to M-Bus<br/>
- *
- * @author
- * @since GSO 0.5, 2016-8-10
- */
- private void registerService() {
- // get the jsonString form the service file
- String root = SystemEnvVariablesFactory.getInstance().getAppRoot();
-// String serviceFilePath = root + File.separator + Constant.FILE_PATH_ETC + File.separator
-// + Constant.FILE_PATH_REGISTER + File.separator + Constant.FILE_PATH_JSON;
-// String jsonInfo = RegisterUtil.readFile(serviceFilePath);
-//
-// // check the jsonInfo
-// if(StringUtils.isEmpty(jsonInfo)) {
-// LOGGER.error("GSO ReadFile fail: jsonInfo is null. the serviceFilePath=" + serviceFilePath);
-// return;
-// }
-
- // register service by the jsonInfo
-// RegisterUtil.registerService(jsonInfo);
- }
-
- /**
- * stop operation by spring <br/>
- *
- * @param context
- * service context
- * @author
- * @since GSO 0.5, 2016-8-10
- */
- public void stop() {
- // no operation
- }
-}
+/*
+ * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ *
+ * 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.openo.gso.gui.servicegateway.activator;
+
+import java.io.File;
+
+import org.apache.commons.lang3.StringUtils;
+import org.openo.baseservice.util.impl.SystemEnvVariablesFactory;
+import org.openo.gso.gui.servicegateway.constant.Constant;
+import org.openo.gso.gui.servicegateway.util.register.RegisterUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Service Start <br/>
+ *
+ * @author
+ * @since GSO 0.5, 2016-8-10
+ */
+public class Activator {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(Activator.class);
+
+
+ /**
+ * start operation by spring <br/>
+ *
+ * @param context
+ * service context
+ * @author
+ * @since GSO 0.5, 2016-8-10
+ */
+ public void start() {
+ // register restful to M-Bus when starting service
+ registerService();
+ }
+
+ /**
+ * register the service to M-Bus<br/>
+ *
+ * @author
+ * @since GSO 0.5, 2016-8-10
+ */
+ private void registerService() {
+ // get the jsonString form the service file
+ String root = SystemEnvVariablesFactory.getInstance().getAppRoot();
+ String serviceFilePath = root + File.separator + Constant.FILE_PATH_ETC + File.separator
+ + Constant.FILE_PATH_REGISTER + File.separator + Constant.FILE_PATH_JSON;
+ String jsonInfo = RegisterUtil.readFile(serviceFilePath);
+
+ // check the jsonInfo
+ if(StringUtils.isEmpty(jsonInfo)) {
+ LOGGER.error("ServiceGateway ReadFile fail: jsonInfo is null. the serviceFilePath=" + serviceFilePath);
+ return;
+ }
+
+ // register service by the jsonInfo
+ RegisterUtil.registerService(jsonInfo);
+ }
+
+ /**
+ * stop operation by spring <br/>
+ *
+ * @param context
+ * service context
+ * @author
+ * @since GSO 0.5, 2016-8-10
+ */
+ public void stop() {
+ // no operation
+ }
+}
diff --git a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/constant/Constant.java b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/constant/Constant.java
index c5283fac..2e35b5a8 100644
--- a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/constant/Constant.java
+++ b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/constant/Constant.java
@@ -1,139 +1,165 @@
-/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
- *
- * 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.openo.gso.gui.servicegateway.constant;
-
-/**
- * Constant definition.<br/>
- * <p>
- * </p>
- *
- * @author
- * @version GSO 0.5 2016/8/22
- */
-public class Constant {
-
- /**
- * Service instance name.
- */
- public static final String SERVICE_NAME = "name";
-
- /**
- * Service instance description.
- */
- public static final String SERVICE_DESCRIPTION = "description";
-
- /**
- * Service instance ID.
- */
- public static final String SERVICE_INSTANCE_ID = "serviceId";
-
- /**
- * Service package ID.
- */
- public static final String SERVICE_DEF_ID = "serviceDefId";
-
- /**
- * Service template ID.
- */
- public static final String SERVICE_TEMPLATE_ID = "templateId";
-
- /**
- * Service template name.
- */
- public static final String SERVICE_TEMPLATE_NAME = "templateName";
-
- /**
- * service parameters
- */
- public static final String SERVICE_PARAMETERS = "parameters";
-
- /**
- * Create workflow name.
- */
- public static final String WORK_FLOW_PLAN_CREATE = "create";
-
- /**
- * Delete workflow name.
- */
- public static final String WORK_FLOW_PLAN_DELETE = "delete";
-
- /**
- * filed in wso2 body.
- */
- public static final String WSO_PROCESSID = "processId";
-
- /**
- * filed in wso2 body.
- */
- public static final String WSO_PARAMS = "params";
-
- /**
- * Response result;
- */
- public static final String RESPONSE_RESULT = "result";
-
- /**
- * Response status.
- */
- public static final String RESPONSE_STATUS = "status";
-
- /**
- * Response status description.
- */
- public static final String RESPONSE_STATUS_DESCRIPTION = "statusDescription";
-
- /**
- * Error code of response.
- */
- public static final String RESPONSE_ERRORCODE = "errorCode";
-
- /**
- * Operations success.
- */
- public static final String RESPONSE_STATUS_SUCCESS = "success";
-
- /**
- * Operation failed.
- */
- public static final String RESPONSE_STATUS_FAIL = "fail";
-
- /**
- * Identify of csar.
- */
- public static final String CSAR_ID = "csarId";
-
- /**
- * service identify.
- */
- public static final String SERVICE_INDENTIFY = "service";
-
- /**
- * Predefine parameter for service design
- */
- public static final String PREDEFINE_GSO_ID = "predefine_gsoId";
-
- /**
- * Constructor<br/>
- * <p>
- * </p>
- *
- * @since GSO 0.5
- */
- private Constant() {
-
- }
-}
+/*
+ * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ *
+ * 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.openo.gso.gui.servicegateway.constant;
+
+/**
+ * Constant definition.<br/>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version GSO 0.5 2016/8/22
+ */
+public class Constant {
+
+ /**
+ * Service instance ID.
+ */
+ public static final String SERVICE_INDENTIFY = "service";
+
+ /**
+ * Service instance ID.
+ */
+ public static final String SERVICE_INSTANCE_ID = "serviceId";
+
+ /**
+ * Service package ID.
+ */
+ public static final String SERVICE_DEF_ID = "serviceDefId";
+
+ /**
+ * Service gateway URL.
+ */
+ public static final String SERVICE_GATEWAY_URI = "gatewayUri";
+
+
+ /**
+ * Create workflow name.
+ */
+ public static final String WORK_FLOW_PLAN_CREATE = "create";
+
+ /**
+ * Delete workflow name.
+ */
+ public static final String WORK_FLOW_PLAN_DELETE = "delete";
+
+ /**
+ * filed in wso2 body.
+ */
+ public static final String WSO_PROCESSID = "processId";
+
+ /**
+ * filed in wso2 body.
+ */
+ public static final String WSO_PARAMS = "params";
+
+ /**
+ * Response result;
+ */
+ public static final String RESPONSE_RESULT = "result";
+
+ /**
+ * Response status.
+ */
+ public static final String RESPONSE_STATUS = "status";
+
+ /**
+ * Response status description.
+ */
+ public static final String RESPONSE_STATUS_DESCRIPTION = "statusDescription";
+
+ /**
+ * Error code of response.
+ */
+ public static final String RESPONSE_ERRORCODE = "errorCode";
+
+ /**
+ * Operations success.
+ */
+ public static final String RESPONSE_STATUS_SUCCESS = "success";
+
+ /**
+ * Operation failed.
+ */
+ public static final String RESPONSE_STATUS_FAIL = "fail";
+
+ /**
+ * ID of instance.
+ */
+ public static final String NS_INSTANCE_ID = "nsInstanceId";
+
+ /**
+ * service identify.
+ */
+ public static final String SERVICE_ID = "serviceId";
+
+ /**
+ * job Id
+ */
+ public static final String JOB_ID = "jobId";
+
+ /**
+ * service file Path:etc
+ */
+ public static final String FILE_PATH_ETC = "etc";
+
+ /**
+ * service file Path:register
+ */
+ public static final String FILE_PATH_REGISTER = "register";
+
+ /**
+ * service file Path:file name
+ */
+ public static final String FILE_PATH_JSON = "service.json";
+
+ /**
+ * the head type for Restful
+ */
+ public static final String HEAD_ERMAP_TYPE = "Content-Type";
+
+ /**
+ * the head value for Restful
+ */
+ public static final String HEAD_ERMAP_VALUE = "application/json;charset=UTF-8";
+
+ /**
+ * the URL for Register service to the M-service Bus
+ */
+ public static final String M_BUS_REGISTER_URL = "/openoapi/microservices/v1/services";
+
+ /**
+ * the IP key for the service file
+ */
+ public static final String SERVICE_KEY_IP = "getInputIP";
+
+ /**
+ * constant:0
+ */
+ public static final int ZERO = 0;
+
+ /**
+ * Constructor<br/>
+ * <p>
+ * </p>
+ *
+ * @since GSO 0.5
+ */
+ private Constant() {
+
+ }
+}
diff --git a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/exception/ErrorCode.java b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/exception/ErrorCode.java
index 759344e1..d3519a05 100644
--- a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/exception/ErrorCode.java
+++ b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/exception/ErrorCode.java
@@ -1,60 +1,75 @@
-/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
- *
- * 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.openo.gso.gui.servicegateway.exception;
-
-/**
- * Constant Class.<br/>
- * <p>
- * Define constant for recording error.
- * </p>
- *
- * @author
- * @version GSO 0.5 2016/8/4
- */
-public class ErrorCode {
-
- /**
- * Fail to operate database.
- */
- public static final String SVCMGR_OPER_MYSQL_DB_ERROR = "servicemgr.mysql.oper_mysql_db_error";
-
- /**
- * Parameter is wrong.
- */
- public static final String SVCMGR_SERVICEMGR_BAD_PARAM = "servicemgr.bad_param";
-
- /**
- * Operation is failure.
- */
- public static final String SVCMGR_SERVICEMGR_FAIL_OPERATION = "servicemgr.fail.operation";
-
- /**
- * Package is being deleted.
- */
- public static final String SVCMGR_PACKAGE_BEING_DELETED = "servicemgr.package.beingDelete";
-
- /**
- * Constructor<br/>
- * <p>
- * </p>
- *
- * @since GSO 0.5
- */
- private ErrorCode() {
-
- }
-}
+/*
+ * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ *
+ * 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.openo.gso.gui.servicegateway.exception;
+
+/**
+ * Constant Class.<br/>
+ * <p>
+ * Define constant for recording error.
+ * </p>
+ *
+ * @author
+ * @version GSO 0.5 2016/8/4
+ */
+public class ErrorCode {
+
+ /**
+ * Fail to operate database.
+ */
+ public static final String SVCMGR_OPER_MYSQL_DB_ERROR = "servicemgr.mysql.oper_mysql_db_error";
+
+ /**
+ * Parameter is wrong.
+ */
+ public static final String SVCMGR_SERVICEMGR_BAD_PARAM = "servicemgr.bad_param";
+
+ /**
+ * Operation is failure.
+ */
+ public static final String SVCMGR_SERVICEMGR_FAIL_OPERATION = "servicemgr.fail.operation";
+
+ /**
+ * Package is being deleted.
+ */
+ public static final String SVCMGR_PACKAGE_BEING_DELETED = "servicemgr.package.beingDelete";
+
+ /**
+ * operation fail
+ */
+ public static final int FAIL = 3;
+
+ /**
+ * operation partial success
+ */
+ public static final int PARTIAL_SUCCESS = 1;
+
+ /**
+ * operation success
+ */
+ public static final int SUCCESS = 0;
+
+ /**
+ * Constructor<br/>
+ * <p>
+ * </p>
+ *
+ * @since GSO 0.5
+ */
+ private ErrorCode() {
+
+ }
+}
diff --git a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/roa/impl/ServiceGatewayRoaModuleImpl.java b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/roa/impl/ServiceGatewayRoaModuleImpl.java
index 9b7796f9..492d75fe 100644
--- a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/roa/impl/ServiceGatewayRoaModuleImpl.java
+++ b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/roa/impl/ServiceGatewayRoaModuleImpl.java
@@ -1,93 +1,106 @@
-/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
- *
- * 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.openo.gso.gui.servicegateway.roa.impl;
-
-import java.util.Map;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.core.Response;
-
-import org.openo.baseservice.remoteservice.exception.ServiceException;
-import org.openo.gso.gui.servicegateway.roa.inf.IServiceGatewayRoaModule;
-import org.openo.gso.gui.servicegateway.service.inf.IServiceGateway;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Implement class for restful interface.<br/>
- * <p>
- * </p>
- *
- * @author
- * @version GSO 0.5 2016/8/4
- */
-public class ServiceGatewayRoaModuleImpl implements IServiceGatewayRoaModule {
-
- /**
- * Log server.
- */
- private static final Logger LOGGER = LoggerFactory.getLogger(ServiceGatewayRoaModuleImpl.class);
-
- /**
- * Service manager.
- */
- private IServiceGateway serviceManager;
-
- /**
- * @return Returns the serviceManager.
- */
- public IServiceGateway getServiceGateway() {
- return serviceManager;
- }
-
- /**
- * @param serviceManager The serviceManager to set.
- */
- public void setServicemanager(IServiceGateway serviceManager) {
- this.serviceManager = serviceManager;
- }
-
- /**
- * Create service instance.<br/>
- *
- * @param servletReq http request
- * @return response
- * @throws ServiceException when operate database or parameter is wrong.
- * @since GSO 0.5
- */
- @Override
- public Response createService(HttpServletRequest servletReq) {
- Map<String, Object> result = null;
-
- return Response.accepted().entity(result).build();
- }
-
- /**
- * Delete service instance.<br/>
- *
- * @param serviceId service instance id
- * @param servletReq http request
- * @return response
- * @throws ServiceException when operate database or parameter is wrong.
- * @since GSO 0.5
- */
- @Override
- public Response deleteService(String serviceId, HttpServletRequest servletReq) {
-
- return null;
- }
-}
+/*
+ * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ *
+ * 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.openo.gso.gui.servicegateway.roa.impl;
+
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.Response;
+
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.baseservice.util.RestUtils;
+import org.openo.gso.gui.servicegateway.constant.Constant;
+import org.openo.gso.gui.servicegateway.exception.HttpCode;
+import org.openo.gso.gui.servicegateway.roa.inf.IServiceGatewayRoaModule;
+import org.openo.gso.gui.servicegateway.service.impl.ServiceGatewayImpl;
+import org.openo.gso.gui.servicegateway.service.inf.IServiceGateway;
+import org.openo.gso.gui.servicegateway.util.http.ResponseUtils;
+import org.openo.gso.gui.servicegateway.util.validate.ValidateUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Implement class for restful interface.<br/>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version GSO 0.5 2016/8/4
+ */
+public class ServiceGatewayRoaModuleImpl implements IServiceGatewayRoaModule {
+
+ /**
+ * Log server.
+ */
+ private static final Logger LOGGER = LoggerFactory.getLogger(ServiceGatewayRoaModuleImpl.class);
+
+ /**
+ * Service manager.
+ */
+ private IServiceGateway serviceGateway = new ServiceGatewayImpl();
+
+ /**
+ * Create service instance.<br/>
+ *
+ * @param servletReq http request
+ * @return response
+ * @throws ServiceException when operate database or parameter is wrong.
+ * @since GSO 0.5
+ */
+ @Override
+ public Response createService(HttpServletRequest servletReq) {
+ Map<String, Object> operateStatus = null;
+ Map<String, Object> result = null;
+ String serviceId = null;
+ try {
+ // 1. Check validation
+ String reqContent = RestUtils.getRequestBody(servletReq);
+ ValidateUtil.assertStringNotNull(reqContent);
+
+ // 2. Create service
+ serviceId = serviceGateway.createService(reqContent, servletReq);
+ } catch(ServiceException exception) {
+ LOGGER.error("Fail to create service instance.");
+ operateStatus = ResponseUtils.setOperateStatus(Constant.RESPONSE_STATUS_FAIL, exception,
+ String.valueOf(exception.getHttpCode()));
+ result = ResponseUtils.setResult(serviceId, operateStatus);
+
+ return Response.accepted().entity(result).build();
+ }
+
+ operateStatus = ResponseUtils.setOperateStatus(Constant.RESPONSE_STATUS_SUCCESS, null,
+ String.valueOf(HttpCode.RESPOND_OK));
+ result = ResponseUtils.setResult(serviceId, operateStatus);
+
+ return Response.accepted().entity(result).build();
+ }
+
+ /**
+ * Delete service instance.<br/>
+ *
+ * @param serviceId service instance id
+ * @param servletReq http request
+ * @return response
+ * @throws ServiceException when operate database or parameter is wrong.
+ * @since GSO 0.5
+ */
+ @Override
+ public Response deleteService(String serviceId, HttpServletRequest servletReq) {
+
+ return null;
+ }
+}
diff --git a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/service/impl/ServiceGatewayImpl.java b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/service/impl/ServiceGatewayImpl.java
index 3f2a48a7..70162529 100644
--- a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/service/impl/ServiceGatewayImpl.java
+++ b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/service/impl/ServiceGatewayImpl.java
@@ -1,71 +1,133 @@
-/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
- *
- * 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.openo.gso.gui.servicegateway.service.impl;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.openo.baseservice.remoteservice.exception.ServiceException;
-import org.openo.gso.gui.servicegateway.service.inf.IServiceGateway;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * ServiceGateway service class.<br/>
- * <p>
- * </p>
- *
- * @author
- * @version GSO 0.5 2016/8/4
- */
-public class ServiceGatewayImpl implements IServiceGateway {
-
- /**
- * Log service.
- */
- private static final Logger LOGGER = LoggerFactory.getLogger(ServiceGatewayImpl.class);
-
-
- /**
- * Create service instance.<br/>
- *
- * @param reqContent content of request
- * @param httpRequest http request
- * @throws ServiceException when operate DB or parameter is wrong.
- * @since GSO 0.5
- */
- @SuppressWarnings("unchecked")
- @Override
- public Object createService(String reqContent, HttpServletRequest httpRequest) throws ServiceException {
-
-
- return null;
- }
-
- /**
- * Delete service instances.<br/>
- *
- * @param serviceId service instance ID
- * @param httpRequest http request
- * @throws ServiceException operate DB or parameter is wrong.
- * @since GSO 0.5
- */
- @Override
- public void deleteService(String serviceId, HttpServletRequest httpRequest) throws ServiceException {
-
- }
-
-}
+/*
+ * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ *
+ * 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.openo.gso.gui.servicegateway.service.impl;
+
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.commons.lang.StringUtils;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.baseservice.roa.util.restclient.RestfulFactory;
+import org.openo.baseservice.roa.util.restclient.RestfulParametes;
+import org.openo.baseservice.roa.util.restclient.RestfulResponse;
+import org.openo.gso.gui.servicegateway.constant.Constant;
+import org.openo.gso.gui.servicegateway.service.inf.IServiceGateway;
+import org.openo.gso.gui.servicegateway.util.json.JsonUtil;
+import org.openo.gso.gui.servicegateway.util.validate.ValidateUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * ServiceGateway service class.<br/>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version GSO 0.5 2016/8/4
+ */
+public class ServiceGatewayImpl implements IServiceGateway {
+
+ /**
+ * Log service.
+ */
+ private static final Logger LOGGER = LoggerFactory.getLogger(ServiceGatewayImpl.class);
+
+
+ /**
+ * Create service instance.<br/>
+ *
+ * @param reqContent content of request
+ * @param httpRequest http request
+ * @throws ServiceException when operate DB or parameter is wrong.
+ * @since GSO 0.5
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ public String createService(String reqContent, HttpServletRequest httpRequest) throws ServiceException {
+ // check the value
+ if(StringUtils.isEmpty(reqContent))
+ {
+ LOGGER.error("ServiceGatewayImpl createService reqContent is null.");
+ return null;
+ }
+
+ // Parse request
+ Map<String, Object> requestBody = JsonUtil.unMarshal(reqContent, Map.class);
+ Map<String, Object> service = (Map<String, Object>)requestBody.get(Constant.SERVICE_INDENTIFY);
+ if(null == service)
+ {
+ service = requestBody;
+ }
+ ValidateUtil.assertObjectNotNull(requestBody);
+
+ // Validate data
+ String gatewayUri = (String)service.get(Constant.SERVICE_GATEWAY_URI);
+ ValidateUtil.assertStringNotNull(gatewayUri);
+ service.remove(Constant.SERVICE_GATEWAY_URI);
+
+ // call the restful
+ String id = null;
+ try {
+ RestfulResponse restfulRsp = RestfulFactory.getRestInstance("http").post(gatewayUri,
+ getRestfulParameters(JsonUtil.marshal(requestBody)));
+ if (null != restfulRsp) {
+ // Record the result of registration
+ // (201:success;415:Invalid Parameter;500:Internal Server Error)
+ LOGGER.info("restful call result:", restfulRsp.getStatus());
+ id = restfulRsp.getRespHeaderStr(Constant.SERVICE_ID);
+ id = (null == id) ? restfulRsp.getRespHeaderStr(Constant.NS_INSTANCE_ID) : id;
+ id = (null == id) ? restfulRsp.getRespHeaderStr(Constant.JOB_ID) : id;
+ }
+ } catch(ServiceException e) {
+ LOGGER.error("service gateway create restful call result:", e);
+ throw e;
+ }
+
+ return id;
+ }
+
+ /**
+ * get the parameters for restful<br/>
+ *
+ * @author
+ * @param bodyData
+ * Json Body
+ * @return the RestfulParametes Instance
+ * @since GSO 0.5, 2016-8-9
+ */
+ private static RestfulParametes getRestfulParameters(final String bodyData) {
+ RestfulParametes param = new RestfulParametes();
+ param.putHttpContextHeader(Constant.HEAD_ERMAP_TYPE, Constant.HEAD_ERMAP_VALUE);
+ param.setRawData(bodyData);
+ return param;
+ }
+
+ /**
+ * Delete service instances.<br/>
+ *
+ * @param serviceId service instance ID
+ * @param httpRequest http request
+ * @throws ServiceException operate DB or parameter is wrong.
+ * @since GSO 0.5
+ */
+ @Override
+ public void deleteService(String serviceId, HttpServletRequest httpRequest) throws ServiceException {
+
+ }
+
+}
diff --git a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/service/inf/IServiceGateway.java b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/service/inf/IServiceGateway.java
index 77b27bd7..9e18cb13 100644
--- a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/service/inf/IServiceGateway.java
+++ b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/service/inf/IServiceGateway.java
@@ -1,55 +1,55 @@
-/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
- *
- * 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.openo.gso.gui.servicegateway.service.inf;
-
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.openo.baseservice.remoteservice.exception.ServiceException;
-
-/**
- * Interface to operate service.<br/>
- * <p>
- * </p>
- *
- * @author
- * @version GSO 0.5 2016/8/4
- */
-public interface IServiceGateway {
-
- /**
- * Create service instance.<br/>
- *
- * @param reqContent content of request
- * @param httpRequest http request
- * @return service instance
- * @throws ServiceException when operate DB or parameter is wrong.
- * @since GSO 0.5
- */
- Object createService(String reqContent, HttpServletRequest httpRequest) throws ServiceException;
-
- /**
- * Delete service instances.<br/>
- *
- * @param serviceId service instance ID
- * @param httpRequest http request
- * @throws ServiceException operate DB or parameter is wrong.
- * @since GSO 0.5
- */
- void deleteService(String serviceId, HttpServletRequest httpRequest) throws ServiceException;
-
-}
+/*
+ * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ *
+ * 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.openo.gso.gui.servicegateway.service.inf;
+
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+
+/**
+ * Interface to operate service.<br/>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version GSO 0.5 2016/8/4
+ */
+public interface IServiceGateway {
+
+ /**
+ * Create service instance.<br/>
+ *
+ * @param reqContent content of request
+ * @param httpRequest http request
+ * @return service instance
+ * @throws ServiceException when operate DB or parameter is wrong.
+ * @since GSO 0.5
+ */
+ String createService(String reqContent, HttpServletRequest httpRequest) throws ServiceException;
+
+ /**
+ * Delete service instances.<br/>
+ *
+ * @param serviceId service instance ID
+ * @param httpRequest http request
+ * @throws ServiceException operate DB or parameter is wrong.
+ * @since GSO 0.5
+ */
+ void deleteService(String serviceId, HttpServletRequest httpRequest) throws ServiceException;
+
+}
diff --git a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/util/http/ResponseUtils.java b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/util/http/ResponseUtils.java
index d0df0781..05d4f0f9 100644
--- a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/util/http/ResponseUtils.java
+++ b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/util/http/ResponseUtils.java
@@ -1,158 +1,175 @@
-/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
- *
- * 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.openo.gso.gui.servicegateway.util.http;
-
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-import org.codehaus.jackson.type.TypeReference;
-import org.openo.baseservice.remoteservice.exception.ExceptionArgs;
-import org.openo.baseservice.remoteservice.exception.ServiceException;
-import org.openo.baseservice.roa.util.restclient.RestfulResponse;
-import org.openo.gso.gui.servicegateway.constant.Constant;
-import org.openo.gso.gui.servicegateway.exception.ErrorCode;
-import org.openo.gso.gui.servicegateway.exception.HttpCode;
-import org.openo.gso.gui.servicegateway.util.json.JsonUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Interface to deal response result.<br/>
- * <p>
- * </p>
- *
- * @author
- * @version GSO 0.5 2016/9/1
- */
-public class ResponseUtils {
-
- /**
- * Log server
- */
- private static final Logger LOGGER = LoggerFactory.getLogger(ResponseUtils.class);
-
- /**
- * Constructor<br/>
- * <p>
- * </p>
- *
- * @since GSO 0.5
- */
- private ResponseUtils() {
- }
-
- /**
- * Check whether there is exception.<br/>
- * <p>
- * If fail, throw the exception.
- * </p>
- *
- * @param response rest response
- * @param function function name
- * @throws ServiceException when the result of rest request is failure.
- * @since GSO 0.5
- */
- public static void checkResonseAndThrowException(RestfulResponse response, String function)
- throws ServiceException {
- if(!HttpCode.isSucess(response.getStatus())) {
- ServiceException roaExceptionInfo = null;
- try {
- roaExceptionInfo = JsonUtil.unMarshal(response.getResponseContent(), ServiceException.class);
- } catch(ServiceException e) {
- LOGGER.error("transfer the response json string has some error: {}", e);
-
- ExceptionArgs args = new ExceptionArgs();
- args.setDescArgs(new String[] {"Fail to " + function});
-
- throw new ServiceException(ServiceException.DEFAULT_ID, response.getStatus(), args);
- }
-
- throw roaExceptionInfo;
- }
- }
-
- /**
- * Parse data to assigned type model.<br/>
- *
- * @param request restful request
- * @param key key
- * @param type type
- * @return model data
- * @throws ServiceException when transfer failed
- * @since SDNO 0.5
- */
- @SuppressWarnings("unchecked")
- public static <T> List<T> getDataModelFromRsp(String request, String key, Class<T> type) throws ServiceException {
- //ValidateUtil.assertStringNotNull(request);
- Map<String, Object> requestMap = JsonUtil.unMarshal(request, Map.class);
- Object data = requestMap.get(key);
- List<T> dataModelList = new LinkedList<T>();
- if(data instanceof List) {
- for(Object model : (List<T>)data) {
- if(!(model instanceof Map)) {
- LOGGER.error("The format of response content is wrong! Not Map.");
- throw new ServiceException(ErrorCode.SVCMGR_SERVICEMGR_BAD_PARAM,
- "The format of response content is wrong.");
- }
-
- dataModelList.add(JsonUtil.unMarshal(JsonUtil.marshal(model), type));
- }
- }
-
- return dataModelList;
- }
-
- /**
- * Parse data to assigned type model.<br/>
- *
- * @param request restful request
- * @param type type
- * @return model data
- * @throws ServiceException when transfer failed
- * @since SDNO 0.5
- */
- public static <T> T getDataModelFromRspList(String request, TypeReference<T> type) throws ServiceException {
- //ValidateUtil.assertStringNotNull(request);
- return JsonUtil.unMarshal(request, type);
- }
-
- /**
- * Set operation result.<br/>
- *
- * @param status status fail or success
- * @param exception operation exception information
- * @param errorCode error code
- * @return result in form of map
- * @since GSO 0.5
- */
- public static Map<String, Object> setOperateStatus(String status, ServiceException exception, String errorCode) {
- Map<String, Object> result = new HashMap<String, Object>();
- result.put(Constant.RESPONSE_STATUS, status);
- if(null == exception) {
- result.put(Constant.RESPONSE_STATUS_DESCRIPTION, status);
- } else {
- if((null != exception.getExceptionArgs()) && (null != exception.getExceptionArgs().getDescArgs())) {
- result.put(Constant.RESPONSE_STATUS_DESCRIPTION, exception.getExceptionArgs().getDescArgs().toString());
- }
- }
- result.put(Constant.RESPONSE_ERRORCODE, errorCode);
-
- return result;
- }
-}
+/*
+ * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ *
+ * 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.openo.gso.gui.servicegateway.util.http;
+
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.codehaus.jackson.type.TypeReference;
+import org.openo.baseservice.remoteservice.exception.ExceptionArgs;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.baseservice.roa.util.restclient.RestfulResponse;
+import org.openo.gso.gui.servicegateway.constant.Constant;
+import org.openo.gso.gui.servicegateway.exception.ErrorCode;
+import org.openo.gso.gui.servicegateway.exception.HttpCode;
+import org.openo.gso.gui.servicegateway.util.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Interface to deal response result.<br/>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version GSO 0.5 2016/9/1
+ */
+public class ResponseUtils {
+
+ /**
+ * Log server
+ */
+ private static final Logger LOGGER = LoggerFactory.getLogger(ResponseUtils.class);
+
+ /**
+ * Constructor<br/>
+ * <p>
+ * </p>
+ *
+ * @since GSO 0.5
+ */
+ private ResponseUtils() {
+ }
+
+ /**
+ * Check whether there is exception.<br/>
+ * <p>
+ * If fail, throw the exception.
+ * </p>
+ *
+ * @param response rest response
+ * @param function function name
+ * @throws ServiceException when the result of rest request is failure.
+ * @since GSO 0.5
+ */
+ public static void checkResonseAndThrowException(RestfulResponse response, String function)
+ throws ServiceException {
+ if(!HttpCode.isSucess(response.getStatus())) {
+ ServiceException roaExceptionInfo = null;
+ try {
+ roaExceptionInfo = JsonUtil.unMarshal(response.getResponseContent(), ServiceException.class);
+ } catch(ServiceException e) {
+ LOGGER.error("transfer the response json string has some error: {}", e);
+
+ ExceptionArgs args = new ExceptionArgs();
+ args.setDescArgs(new String[] {"Fail to " + function});
+
+ throw new ServiceException(ServiceException.DEFAULT_ID, response.getStatus(), args);
+ }
+
+ throw roaExceptionInfo;
+ }
+ }
+
+ /**
+ * Parse data to assigned type model.<br/>
+ *
+ * @param request restful request
+ * @param key key
+ * @param type type
+ * @return model data
+ * @throws ServiceException when transfer failed
+ * @since SDNO 0.5
+ */
+ @SuppressWarnings("unchecked")
+ public static <T> List<T> getDataModelFromRsp(String request, String key, Class<T> type) throws ServiceException {
+ //ValidateUtil.assertStringNotNull(request);
+ Map<String, Object> requestMap = JsonUtil.unMarshal(request, Map.class);
+ Object data = requestMap.get(key);
+ List<T> dataModelList = new LinkedList<T>();
+ if(data instanceof List) {
+ for(Object model : (List<T>)data) {
+ if(!(model instanceof Map)) {
+ LOGGER.error("The format of response content is wrong! Not Map.");
+ throw new ServiceException(ErrorCode.SVCMGR_SERVICEMGR_BAD_PARAM,
+ "The format of response content is wrong.");
+ }
+
+ dataModelList.add(JsonUtil.unMarshal(JsonUtil.marshal(model), type));
+ }
+ }
+
+ return dataModelList;
+ }
+
+ /**
+ * Parse data to assigned type model.<br/>
+ *
+ * @param request restful request
+ * @param type type
+ * @return model data
+ * @throws ServiceException when transfer failed
+ * @since SDNO 0.5
+ */
+ public static <T> T getDataModelFromRspList(String request, TypeReference<T> type) throws ServiceException {
+ //ValidateUtil.assertStringNotNull(request);
+ return JsonUtil.unMarshal(request, type);
+ }
+
+ /**
+ * Set operation result.<br/>
+ *
+ * @param status status fail or success
+ * @param exception operation exception information
+ * @param errorCode error code
+ * @return result in form of map
+ * @since GSO 0.5
+ */
+ public static Map<String, Object> setOperateStatus(String status, ServiceException exception, String errorCode) {
+ Map<String, Object> result = new HashMap<String, Object>();
+ result.put(Constant.RESPONSE_STATUS, status);
+ if(null == exception) {
+ result.put(Constant.RESPONSE_STATUS_DESCRIPTION, status);
+ } else {
+ if((null != exception.getExceptionArgs()) && (null != exception.getExceptionArgs().getDescArgs())) {
+ result.put(Constant.RESPONSE_STATUS_DESCRIPTION, exception.getExceptionArgs().getDescArgs().toString());
+ }
+ }
+ result.put(Constant.RESPONSE_ERRORCODE, errorCode);
+
+ return result;
+ }
+
+ /**
+ * Assemble operation result.<br/>
+ *
+ * @param objectId instance ID
+ * @param operateCode operation result
+ * @return Response result
+ * @since GSO 0.5
+ */
+ public static Map<String, Object> setResult(String objectId, Object operateCode) {
+ Map<String, Object> result = new HashMap<String, Object>();
+ result.put(Constant.RESPONSE_RESULT, operateCode);
+ String serviceId = (null != objectId) ? objectId : null;
+ result.put(Constant.SERVICE_INSTANCE_ID, serviceId);
+
+ return result;
+ }
+}
diff --git a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/util/register/RegisterUtil.java b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/util/register/RegisterUtil.java
new file mode 100644
index 00000000..4e8b6bd3
--- /dev/null
+++ b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/util/register/RegisterUtil.java
@@ -0,0 +1,161 @@
+/*
+ * Copyright 2016 Huawei Technologies Co., Ltd.
+ *
+ * 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.openo.gso.gui.servicegateway.util.register;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+import org.apache.commons.lang.StringUtils;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.baseservice.roa.util.restclient.RestfulFactory;
+import org.openo.baseservice.roa.util.restclient.RestfulParametes;
+import org.openo.baseservice.roa.util.restclient.RestfulResponse;
+import org.openo.gso.commsvc.common.constant.Constant;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Register Tool <br/>
+ *
+ * @author
+ * @since GSO 0.5, 2016-8-9
+ */
+public class RegisterUtil {
+
+ /**
+ * Logger
+ */
+ private static final Logger LOGGER = LoggerFactory.getLogger(RegisterUtil.class);
+
+ private RegisterUtil() {
+ }
+
+ /**
+ * register the service to M-Bus by the parameter<br/>
+ *
+ * @author
+ * @param jsonInfo
+ * register body Data
+ * @since GSO 0.5, 2016-8-9
+ */
+ public static void registerService(final String jsonInfo) {
+ // check the parameter
+ if (StringUtils.isEmpty(jsonInfo)) {
+ LOGGER.error("RegisterUtil registerService jsonInfo is null");
+ return;
+ }
+
+ // replace the remote IP Address by the jsonInfo
+ String bodyData = jsonInfo;
+ boolean isIPExist = bodyData.indexOf(Constant.SERVICE_KEY_IP) > Constant.ZERO;
+ try {
+ // get the local IP address
+ String localIP = InetAddress.getLocalHost().getHostAddress();
+
+ // if the jsonInfo have the getInputIP string,start to replace the
+ // local IP
+ if (isIPExist) {
+ if (!StringUtils.isEmpty(localIP)) {
+ bodyData = bodyData.replace(Constant.SERVICE_KEY_IP, localIP);
+ } else {
+ LOGGER.error("RegisterUtil registerService localIP is null");
+ return;
+ }
+ }
+ } catch (UnknownHostException e) {
+ LOGGER.error("RegisterUtil registerService getHostAddress fail:", e);
+ if (isIPExist) {
+ // if get local IP failed In the isIPExist is true ,operation is
+ // stopped.
+ return;
+ }
+ }
+
+ // register the service to M-bus by the restful Interface
+ try {
+ RestfulResponse restfulRsp = RestfulFactory.getRestInstance("http").post(Constant.M_BUS_REGISTER_URL,
+ getRestfulParameters(bodyData));
+ if (null != restfulRsp) {
+ // Record the result of registration
+ // (201:success;415:Invalid Parameter;500:Internal Server Error)
+ LOGGER.info("RegisterUtil registerService register result:", restfulRsp.getStatus());
+ }
+ } catch (ServiceException e) {
+ LOGGER.error("RegisterUtil registerService post fail:", e);
+ }
+ }
+
+ /**
+ * get the parameters for restful<br/>
+ *
+ * @author
+ * @param bodyData
+ * Json Body
+ * @return the RestfulParametes Instance
+ * @since GSO 0.5, 2016-8-9
+ */
+ private static RestfulParametes getRestfulParameters(final String bodyData) {
+ RestfulParametes param = new RestfulParametes();
+ param.putHttpContextHeader(Constant.HEAD_ERMAP_TYPE, Constant.HEAD_ERMAP_VALUE);
+ param.setRawData(bodyData);
+ return param;
+ }
+
+ /**
+ * read the service file<br/>
+ *
+ * @param path
+ * the service File Path
+ * @return jsonString
+ * @since GSO 0.5, 2016-8-9
+ */
+ public static String readFile(String path) {
+ // check parameter
+ if (StringUtils.isEmpty(path)) {
+ return null;
+ }
+
+ File file = new File(path);
+ BufferedReader reader = null;
+ String laststr = "";
+ try {
+ reader = new BufferedReader(new FileReader(file));
+ String tempString = null;
+ // Read one line at a time until the end of the null file.
+ while ((tempString = reader.readLine()) != null) {
+ // add the line
+ laststr = laststr + tempString;
+ }
+ reader.close();
+ } catch (IOException e) {
+ LOGGER.error("GSO ReadFile fail.", e);
+ } finally {
+ if (reader != null) {
+ try {
+ reader.close();
+ } catch (IOException e1) {
+ LOGGER.error("GSO ReadFile reader close fail.", e1);
+ }
+ }
+ }
+ return laststr;
+ }
+}
diff --git a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/util/validate/ValidateUtil.java b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/util/validate/ValidateUtil.java
new file mode 100644
index 00000000..461163ea
--- /dev/null
+++ b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/util/validate/ValidateUtil.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2016 Huawei Technologies Co., Ltd.
+ *
+ * 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.openo.gso.gui.servicegateway.util.validate;
+
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.gso.gui.servicegateway.exception.ErrorCode;
+import org.openo.gso.gui.servicegateway.exception.HttpCode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.util.StringUtils;
+
+/**
+ * Validate Util <br/>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version GSO 0.5 2016/8/19
+ */
+public class ValidateUtil {
+
+ /**
+ * Log server.
+ */
+ private static final Logger LOGGER = LoggerFactory.getLogger(ValidateUtil.class);
+
+ /**
+ * Constructor<br/>
+ * <p>
+ * </p>
+ *
+ * @since GSO 0.5
+ */
+ private ValidateUtil() {
+
+ }
+
+ /**
+ * Assert String parameter.<br/>
+ *
+ * @param param parameter data
+ * @throws ServiceException when parameter is null or empty.
+ * @since GSO 0.5
+ */
+ public static void assertStringNotNull(String param) throws ServiceException {
+ if(StringUtils.hasLength(param)) {
+ return;
+ }
+
+ LOGGER.error("Parameter is null or empty.");
+ throw new ServiceException(ErrorCode.SVCMGR_SERVICEMGR_BAD_PARAM, HttpCode.BAD_REQUEST);
+ }
+
+ /**
+ * Assert object is null.<br/>
+ *
+ * @param object data object
+ * @throws ServiceException when object is null.
+ * @since GSO 0.5
+ */
+ public static void assertObjectNotNull(Object object) throws ServiceException {
+ if(null == object) {
+ LOGGER.error("Object is null.");
+ throw new ServiceException(ErrorCode.SVCMGR_SERVICEMGR_BAD_PARAM, "Object is null.");
+ }
+
+ }
+
+}
diff --git a/servicegateway/service/src/test/java/org/openo/gso/gui/servicegateway/roa/impl/ServiceGatewayRoaModuleImplTest.java b/servicegateway/service/src/test/java/org/openo/gso/gui/servicegateway/roa/impl/ServiceGatewayRoaModuleImplTest.java
index 8b5c6c67..adbcd757 100644
--- a/servicegateway/service/src/test/java/org/openo/gso/gui/servicegateway/roa/impl/ServiceGatewayRoaModuleImplTest.java
+++ b/servicegateway/service/src/test/java/org/openo/gso/gui/servicegateway/roa/impl/ServiceGatewayRoaModuleImplTest.java
@@ -1,109 +1,183 @@
-/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
- *
- * 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.openo.gso.gui.servicegateway.roa.impl;
-
-import static org.junit.Assert.assertNotNull;
-
-import java.io.IOException;
-import java.io.Reader;
-import java.sql.Connection;
-import java.sql.SQLException;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.apache.ibatis.io.Resources;
-import org.apache.ibatis.jdbc.ScriptRunner;
-import org.apache.ibatis.session.SqlSession;
-import org.apache.ibatis.session.SqlSessionFactory;
-import org.apache.ibatis.session.SqlSessionFactoryBuilder;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.openo.baseservice.remoteservice.exception.ServiceException;
-import org.openo.gso.gui.servicegateway.service.impl.ServiceGatewayImpl;
-
-/**
- * Test ServicemgrRoaModuleImpl class.<br/>
- * <p>
- * </p>
- *
- * @author
- * @version GSO 0.5 2016/8/3
- */
-public class ServiceGatewayRoaModuleImplTest {
-
- /**
- * Service ROA.
- */
- ServiceGatewayRoaModuleImpl serviceRoa = new ServiceGatewayRoaModuleImpl();
-
- /**
- * Service manager.
- */
- ServiceGatewayImpl serviceManager = new ServiceGatewayImpl();
-
-
- /**
- * Http request.
- */
- HttpServletRequest httpRequest;
-
- /**
- * Before executing UT, start sql.<br/>
- *
- * @since GSO 0.5
- */
- @Before
- public void start() throws IOException, SQLException {
-
- }
-
-
-
- /**
- * After executing UT, close session<br/>
- *
- * @since GSO 0.5
- */
- @After
- public void stop() {
-
- }
-
- /**
- * Test create service.<br/>
- *
- * @throws ServiceException when fail to operate database or parameter is wrong.
- * @since GSO 0.5
- */
- @Test
- public void testCreateService() throws ServiceException {
-
- }
-
- /**
- * Test delete service.<br/>
- *
- * @throws ServiceException when fail to operate database or parameter is wrong.
- * @since GSO 0.5
- */
- @Test
- public void testTeleteService() throws ServiceException {
- serviceRoa.deleteService("1", httpRequest);
- }
-
-}
+/*
+ * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ *
+ * 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.openo.gso.gui.servicegateway.roa.impl;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.sql.SQLException;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.StringUtils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.baseservice.roa.util.restclient.RestfulResponse;
+import org.openo.baseservice.util.RestUtils;
+import org.openo.gso.gui.servicegateway.exception.HttpCode;
+import org.openo.gso.gui.servicegateway.service.impl.ServiceGatewayImpl;
+import org.openo.gso.gui.servicegateway.util.http.HttpUtil;
+
+import mockit.Mock;
+import mockit.MockUp;
+
+/**
+ * Test ServicemgrRoaModuleImpl class.<br/>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version GSO 0.5 2016/8/3
+ */
+public class ServiceGatewayRoaModuleImplTest {
+
+ /**
+ * File path
+ */
+ private static final String FILE_PATH = "src/test/resources/json/";
+
+ /**
+ * Service ROA.
+ */
+ ServiceGatewayRoaModuleImpl serviceRoa = new ServiceGatewayRoaModuleImpl();
+
+ /**
+ * Service manager.
+ */
+ ServiceGatewayImpl serviceManager = new ServiceGatewayImpl();
+
+
+ /**
+ * Http request.
+ */
+ HttpServletRequest httpRequest;
+
+ /**
+ * Rest response.
+ */
+ RestfulResponse responseSuccess;
+
+ /**
+ * Before executing UT, start sql.<br/>
+ *
+ * @since GSO 0.5
+ */
+ @Before
+ public void start() throws IOException, SQLException {
+ responseSuccess = new RestfulResponse();
+ responseSuccess.setStatus(HttpCode.RESPOND_OK);
+ }
+
+
+
+ /**
+ * After executing UT, close session<br/>
+ *
+ * @since GSO 0.5
+ */
+ @After
+ public void stop() {
+
+ }
+
+ /**
+ * Test create service.<br/>
+ *
+ * @throws ServiceException when fail to operate database or parameter is wrong.
+ * @since GSO 0.5
+ */
+ @Test
+ public void testCreateService() throws ServiceException {
+ // mock request body
+ mockGetRequestBody(FILE_PATH + "createServiceInstance.json");
+
+ mockPost(responseSuccess);
+
+ serviceRoa.createService(httpRequest);
+ }
+
+ /**
+ * Test delete service.<br/>
+ *
+ * @throws ServiceException when fail to operate database or parameter is wrong.
+ * @since GSO 0.5
+ */
+ @Test
+ public void testDeleteService() throws ServiceException {
+ serviceRoa.deleteService("1", httpRequest);
+ }
+
+ /**
+ * Mock to get request body.<br/>
+ *
+ * @param file json file path.
+ * @since GSO 0.5
+ */
+ private void mockGetRequestBody(final String file) {
+ new MockUp<RestUtils>() {
+
+ @Mock
+ public String getRequestBody(HttpServletRequest request) {
+ return getJsonString(file);
+ }
+ };
+ }
+
+ /**
+ * Mock rest request for post.<br/>
+ *
+ * @param response rest response
+ * @since GSO 0.5
+ */
+ private void mockPost(final RestfulResponse response) {
+ new MockUp<HttpUtil>() {
+
+ @Mock
+ public RestfulResponse post(final String url, Object sendObj, HttpServletRequest httpRequest) {
+ return response;
+ }
+ };
+ }
+
+ /**
+ * Get json string from file.<br/>
+ *
+ * @param file the path of file
+ * @return json string
+ * @throws IOException when fail to read
+ * @since GSO 0.5
+ */
+ private String getJsonString(final String file) {
+ if(StringUtils.isEmpty(file)) {
+ return "";
+ }
+
+ String json = null;
+ try {
+ FileInputStream fileStream = new FileInputStream(new File(file));
+ json = IOUtils.toString(fileStream);
+ } catch(Exception e) {
+ Assert.fail(e.getMessage());
+ }
+
+ return json;
+ }
+}
diff --git a/servicegateway/service/src/test/java/org/openo/gso/gui/servicegateway/service/impl/ServiceGatewayImplTest.java b/servicegateway/service/src/test/java/org/openo/gso/gui/servicegateway/service/impl/ServiceGatewayImplTest.java
index 734add90..fddebe00 100644
--- a/servicegateway/service/src/test/java/org/openo/gso/gui/servicegateway/service/impl/ServiceGatewayImplTest.java
+++ b/servicegateway/service/src/test/java/org/openo/gso/gui/servicegateway/service/impl/ServiceGatewayImplTest.java
@@ -1,73 +1,72 @@
-/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
- *
- * 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.openo.gso.gui.servicegateway.service.impl;
-
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.openo.baseservice.remoteservice.exception.ServiceException;
-
-/**
- * Test ServiceGatewayImpl Class.<br/>
- * <p>
- * </p>
- *
- * @author
- * @version GSO 0.5 2016/8/3
- */
-public class ServiceGatewayImplTest {
-
- /**
- * Service manager.
- */
- ServiceGatewayImpl serviceManager = new ServiceGatewayImpl();
-
-
- /**
- * Http request.
- */
- HttpServletRequest httpRequest;
-
- @Before
- public void start() {
- }
-
- /**
- * Invalid parameter.<br/>
- *
- * @throws ServiceException when parameter is wrong.
- * @since GSO 0.5
- */
- @Test(expected = ServiceException.class)
- public void testCreateServiceFail() throws ServiceException {
- serviceManager.createService(null, httpRequest);
- }
-
- /**
- * Invalid parameter.<br/>
- *
- * @throws ServiceException when parameter is wrong.
- * @since GSO 0.5
- */
- @Test(expected = ServiceException.class)
- public void testDeleteServiceFail() throws ServiceException {
- serviceManager.deleteService(null, httpRequest);
- }
-
-}
+/*
+ * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ *
+ * 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.openo.gso.gui.servicegateway.service.impl;
+
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+
+/**
+ * Test ServiceGatewayImpl Class.<br/>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version GSO 0.5 2016/8/3
+ */
+public class ServiceGatewayImplTest {
+
+ /**
+ * Service manager.
+ */
+ ServiceGatewayImpl serviceManager = new ServiceGatewayImpl();
+
+ /**
+ * Http request.
+ */
+ HttpServletRequest httpRequest;
+
+ @Before
+ public void start() {
+ }
+
+ /**
+ * Invalid parameter.<br/>
+ *
+ * @throws ServiceException when parameter is wrong.
+ * @since GSO 0.5
+ */
+ @Test(expected = ServiceException.class)
+ public void testCreateServiceFail() throws ServiceException {
+ serviceManager.createService(null, httpRequest);
+ }
+
+ /**
+ * Invalid parameter.<br/>
+ *
+ * @throws ServiceException when parameter is wrong.
+ * @since GSO 0.5
+ */
+ @Test(expected = ServiceException.class)
+ public void testDeleteServiceFail() throws ServiceException {
+ serviceManager.deleteService(null, httpRequest);
+ }
+
+}
diff --git a/servicegateway/service/src/test/resources/json/createServiceInstance.json b/servicegateway/service/src/test/resources/json/createServiceInstance.json
new file mode 100644
index 00000000..d8ba2fea
--- /dev/null
+++ b/servicegateway/service/src/test/resources/json/createServiceInstance.json
@@ -0,0 +1,12 @@
+{
+ "name": "gso_service",
+ "description": "siteToDc",
+ "serviceDefId": "78ede6f3-66cc-46ab-b748-38a6c010d272",
+ "templateId": "38a6c01-66cc-46ab-b748-38a6c010d272",
+ "templateName": "GsoTemplate",
+ "gatewayUri":"/openoapi/lifecyclymgr/v1/services",
+ "parameters": {
+ "POP.vFW-moc": "xxx",
+ "POP.vCPE-moc": "xxx"
+ }
+} \ No newline at end of file