modify common module
author“shentao” <shentao@chinamobile.com>
Sun, 18 Sep 2016 11:17:29 +0000 (19:17 +0800)
committer“shentao” <shentao@chinamobile.com>
Sun, 18 Sep 2016 11:17:29 +0000 (19:17 +0800)
Change-Id: Id2553bbffe2a3aea2e944c0a8fcec771b5ccf277
Signed-off-by: “shentao” <shentao@chinamobile.com>
12 files changed:
openo-portal/pom.xml
openo-portal/portal-common/pom.xml
openo-portal/portal-common/src/main/webapp/WEB-INF/web.xml [new file with mode: 0644]
servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/activator/Activator.java
servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/constant/Constant.java
servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/exception/ErrorCode.java
servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/roa/impl/ServiceGatewayRoaModuleImpl.java
servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/service/impl/ServiceGatewayImpl.java
servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/service/inf/IServiceGateway.java
servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/util/http/ResponseUtils.java
servicegateway/service/src/test/java/org/openo/gso/gui/servicegateway/roa/impl/ServiceGatewayRoaModuleImplTest.java
servicegateway/service/src/test/java/org/openo/gso/gui/servicegateway/service/impl/ServiceGatewayImplTest.java

index 20585b1..e6dbf7b 100644 (file)
@@ -27,4 +27,9 @@
     <artifactId>openo-portal</artifactId>
     <packaging>pom</packaging>
     <name>portal</name>
+
+    <modules>
+      <module>portal-package</module>
+      <module>portal-common</module>
+    </modules>
 </project>
index 8109207..ba32aaa 100644 (file)
 
 -->
 <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>
+  <parent>
+    <groupId>org.openo.gso.gui</groupId>
+    <artifactId>openo-portal</artifactId>
+    <version>1.0.0-SNAPSHOT</version>
+    <relativePath></relativePath>
+  </parent>
 
-    <artifactId>common</artifactId>
-       <version>1.0.0-SNAPSHOT</version>
-    <packaging>pom</packaging>
+  <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 (file)
index 0000000..7c09959
--- /dev/null
@@ -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>
index 2f539e7..0055931 100644 (file)
@@ -1,86 +1,86 @@
-/*\r
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.gso.gui.servicegateway.activator;\r
-\r
-import java.io.File;\r
-\r
-import org.apache.commons.lang3.StringUtils;\r
-import org.openo.baseservice.util.impl.SystemEnvVariablesFactory;\r
-import org.openo.gso.gui.servicegateway.constant.Constant;\r
-import org.openo.gso.gui.servicegateway.util.register.RegisterUtil;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-/**\r
- * Service Start <br/>\r
- * \r
- * @author\r
- * @since GSO 0.5, 2016-8-10\r
- */\r
-public class Activator {\r
-\r
-    private static final Logger LOGGER = LoggerFactory.getLogger(Activator.class);\r
-\r
-\r
-    /**\r
-     * start operation by spring <br/>\r
-     * \r
-     * @param context\r
-     *            service context\r
-     * @author\r
-     * @since GSO 0.5, 2016-8-10\r
-     */\r
-    public void start() {\r
-        // register restful to M-Bus when starting service\r
-        registerService();\r
-    }\r
-\r
-    /**\r
-     * register the service to M-Bus<br/>\r
-     * \r
-     * @author\r
-     * @since GSO 0.5, 2016-8-10\r
-     */\r
-    private void registerService() {\r
-        // get the jsonString form the service file\r
-        String root = SystemEnvVariablesFactory.getInstance().getAppRoot();\r
-        String serviceFilePath = root + File.separator + Constant.FILE_PATH_ETC + File.separator\r
-                + Constant.FILE_PATH_REGISTER + File.separator + Constant.FILE_PATH_JSON;\r
-        String jsonInfo = RegisterUtil.readFile(serviceFilePath);\r
-\r
-        // check the jsonInfo\r
-        if(StringUtils.isEmpty(jsonInfo)) {\r
-            LOGGER.error("ServiceGateway ReadFile  fail: jsonInfo is null. the serviceFilePath=" + serviceFilePath);\r
-            return;\r
-        }\r
-\r
-        // register service by the jsonInfo\r
-        RegisterUtil.registerService(jsonInfo);\r
-    }\r
-\r
-    /**\r
-     * stop operation by spring <br/>\r
-     * \r
-     * @param context\r
-     *            service context\r
-     * @author\r
-     * @since GSO 0.5, 2016-8-10\r
-     */\r
-    public void stop() {\r
-        // no operation\r
-    }\r
-}\r
+/*
+ * 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
+    }
+}
index 58b0b22..2e35b5a 100644 (file)
-/*\r
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.gso.gui.servicegateway.constant;\r
-\r
-/**\r
- * Constant definition.<br/>\r
- * <p>\r
- * </p>\r
- * \r
- * @author\r
- * @version GSO 0.5 2016/8/22\r
- */\r
-public class Constant {\r
-\r
-        /**\r
-     * Service instance ID.\r
-     */\r
-    public static final String SERVICE_INDENTIFY = "service";\r
-    \r
-    /**\r
-     * Service instance ID.\r
-     */\r
-    public static final String SERVICE_INSTANCE_ID = "serviceId";\r
-\r
-    /**\r
-     * Service package ID.\r
-     */\r
-    public static final String SERVICE_DEF_ID = "serviceDefId";\r
-\r
-    /**\r
-     * Service gateway URL.\r
-     */\r
-    public static final String SERVICE_GATEWAY_URI = "gatewayUri";\r
-\r
-\r
-    /**\r
-     * Create workflow name.\r
-     */\r
-    public static final String WORK_FLOW_PLAN_CREATE = "create";\r
-\r
-    /**\r
-     * Delete workflow name.\r
-     */\r
-    public static final String WORK_FLOW_PLAN_DELETE = "delete";\r
-\r
-    /**\r
-     * filed in wso2 body.\r
-     */\r
-    public static final String WSO_PROCESSID = "processId";\r
-\r
-    /**\r
-     * filed in wso2 body.\r
-     */\r
-    public static final String WSO_PARAMS = "params";\r
-\r
-    /**\r
-     * Response result;\r
-     */\r
-    public static final String RESPONSE_RESULT = "result";\r
-\r
-    /**\r
-     * Response status.\r
-     */\r
-    public static final String RESPONSE_STATUS = "status";\r
-\r
-    /**\r
-     * Response status description.\r
-     */\r
-    public static final String RESPONSE_STATUS_DESCRIPTION = "statusDescription";\r
-\r
-    /**\r
-     * Error code of response.\r
-     */\r
-    public static final String RESPONSE_ERRORCODE = "errorCode";\r
-\r
-    /**\r
-     * Operations success.\r
-     */\r
-    public static final String RESPONSE_STATUS_SUCCESS = "success";\r
-\r
-    /**\r
-     * Operation failed.\r
-     */\r
-    public static final String RESPONSE_STATUS_FAIL = "fail";\r
-\r
-    /**\r
-     * ID of instance.\r
-     */\r
-    public static final String NS_INSTANCE_ID = "nsInstanceId";\r
-\r
-    /**\r
-     * service identify.\r
-     */\r
-    public static final String SERVICE_ID = "serviceId";\r
-\r
-    /**\r
-     * job Id\r
-     */\r
-    public static final String JOB_ID = "jobId";\r
-    \r
-    /**\r
-     * service file Path:etc\r
-     */\r
-    public static final String FILE_PATH_ETC = "etc";\r
-\r
-    /**\r
-     * service file Path:register\r
-     */\r
-    public static final String FILE_PATH_REGISTER = "register";\r
-\r
-    /**\r
-     * service file Path:file name\r
-     */\r
-    public static final String FILE_PATH_JSON = "service.json";\r
-    \r
-    /**\r
-     * the head type for Restful\r
-     */\r
-    public static final String HEAD_ERMAP_TYPE = "Content-Type";\r
-\r
-    /**\r
-     * the head value for Restful\r
-     */\r
-    public static final String HEAD_ERMAP_VALUE = "application/json;charset=UTF-8";\r
-    \r
-    /**\r
-     * the URL for Register service to the M-service Bus\r
-     */\r
-    public static final String M_BUS_REGISTER_URL = "/openoapi/microservices/v1/services";\r
-\r
-    /**\r
-     * the IP key for the service file\r
-     */\r
-    public static final String SERVICE_KEY_IP = "getInputIP";\r
-\r
-    /**\r
-     * constant:0\r
-     */\r
-    public static final int ZERO = 0;\r
-\r
-    /**\r
-     * Constructor<br/>\r
-     * <p>\r
-     * </p>\r
-     * \r
-     * @since GSO 0.5\r
-     */\r
-    private Constant() {\r
-\r
-    }\r
-}\r
+/*
+ * 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() {
+
+    }
+}
index 1a94e70..d3519a0 100644 (file)
@@ -1,75 +1,75 @@
-/*\r
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.gso.gui.servicegateway.exception;\r
-\r
-/**\r
- * Constant Class.<br/>\r
- * <p>\r
- * Define constant for recording error.\r
- * </p>\r
- * \r
- * @author\r
- * @version GSO 0.5 2016/8/4\r
- */\r
-public class ErrorCode {\r
-\r
-    /**\r
-     * Fail to operate database.\r
-     */\r
-    public static final String SVCMGR_OPER_MYSQL_DB_ERROR = "servicemgr.mysql.oper_mysql_db_error";\r
-\r
-    /**\r
-     * Parameter is wrong.\r
-     */\r
-    public static final String SVCMGR_SERVICEMGR_BAD_PARAM = "servicemgr.bad_param";\r
-\r
-    /**\r
-     * Operation is failure.\r
-     */\r
-    public static final String SVCMGR_SERVICEMGR_FAIL_OPERATION = "servicemgr.fail.operation";\r
-\r
-    /**\r
-     * Package is being deleted.\r
-     */\r
-    public static final String SVCMGR_PACKAGE_BEING_DELETED = "servicemgr.package.beingDelete";\r
-    \r
-    /**\r
-     * operation fail\r
-     */\r
-    public static final int FAIL = 3;\r
-\r
-    /**\r
-     * operation partial success\r
-     */\r
-    public static final int PARTIAL_SUCCESS = 1;\r
-    \r
-    /**\r
-     * operation success\r
-     */\r
-    public static final int SUCCESS = 0;\r
-\r
-    /**\r
-     * Constructor<br/>\r
-     * <p>\r
-     * </p>\r
-     * \r
-     * @since GSO 0.5\r
-     */\r
-    private ErrorCode() {\r
-\r
-    }\r
-}\r
+/*
+ * 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() {
+
+    }
+}
index 7480bdc..492d75f 100644 (file)
-/*\r
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.gso.gui.servicegateway.roa.impl;\r
-\r
-import java.util.Map;\r
-\r
-import javax.servlet.http.HttpServletRequest;\r
-import javax.ws.rs.core.Response;\r
-\r
-import org.openo.baseservice.remoteservice.exception.ServiceException;\r
-import org.openo.baseservice.util.RestUtils;\r
-import org.openo.gso.gui.servicegateway.constant.Constant;\r
-import org.openo.gso.gui.servicegateway.exception.HttpCode;\r
-import org.openo.gso.gui.servicegateway.roa.inf.IServiceGatewayRoaModule;\r
-import org.openo.gso.gui.servicegateway.service.impl.ServiceGatewayImpl;\r
-import org.openo.gso.gui.servicegateway.service.inf.IServiceGateway;\r
-import org.openo.gso.gui.servicegateway.util.http.ResponseUtils;\r
-import org.openo.gso.gui.servicegateway.util.validate.ValidateUtil;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-/**\r
- * Implement class for restful interface.<br/>\r
- * <p>\r
- * </p>\r
- * \r
- * @author\r
- * @version GSO 0.5 2016/8/4\r
- */\r
-public class ServiceGatewayRoaModuleImpl implements IServiceGatewayRoaModule {\r
-\r
-    /**\r
-     * Log server.\r
-     */\r
-    private static final Logger LOGGER = LoggerFactory.getLogger(ServiceGatewayRoaModuleImpl.class);\r
-\r
-    /**\r
-     * Service manager.\r
-     */\r
-    private IServiceGateway serviceGateway = new ServiceGatewayImpl();\r
-\r
-    /**\r
-     * Create service instance.<br/>\r
-     * \r
-     * @param servletReq http request\r
-     * @return response\r
-     * @throws ServiceException when operate database or parameter is wrong.\r
-     * @since GSO 0.5\r
-     */\r
-    @Override\r
-    public Response createService(HttpServletRequest servletReq) {\r
-       Map<String, Object> operateStatus = null;\r
-        Map<String, Object> result = null;\r
-        String serviceId = null;\r
-        try {\r
-            // 1. Check validation\r
-            String reqContent = RestUtils.getRequestBody(servletReq);\r
-            ValidateUtil.assertStringNotNull(reqContent);\r
-\r
-            // 2. Create service\r
-            serviceId = serviceGateway.createService(reqContent, servletReq);\r
-        } catch(ServiceException exception) {\r
-            LOGGER.error("Fail to create service instance.");\r
-            operateStatus = ResponseUtils.setOperateStatus(Constant.RESPONSE_STATUS_FAIL, exception,\r
-                    String.valueOf(exception.getHttpCode()));            \r
-            result = ResponseUtils.setResult(serviceId, operateStatus);\r
-\r
-            return Response.accepted().entity(result).build();\r
-        }\r
-\r
-        operateStatus = ResponseUtils.setOperateStatus(Constant.RESPONSE_STATUS_SUCCESS, null,\r
-                String.valueOf(HttpCode.RESPOND_OK));\r
-        result = ResponseUtils.setResult(serviceId, operateStatus);\r
-\r
-        return Response.accepted().entity(result).build();\r
-    }\r
-\r
-    /**\r
-     * Delete service instance.<br/>\r
-     * \r
-     * @param serviceId service instance id\r
-     * @param servletReq http request\r
-     * @return response\r
-     * @throws ServiceException when operate database or parameter is wrong.\r
-     * @since GSO 0.5\r
-     */\r
-    @Override\r
-    public Response deleteService(String serviceId, HttpServletRequest servletReq) {\r
-\r
-        return null;\r
-    }\r
-}\r
+/*
+ * 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;
+    }
+}
index e2200d4..7016252 100644 (file)
-/*\r
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.gso.gui.servicegateway.service.impl;\r
-\r
-import java.util.Map;\r
-\r
-import javax.servlet.http.HttpServletRequest;\r
-\r
-import org.apache.commons.lang.StringUtils;\r
-import org.openo.baseservice.remoteservice.exception.ServiceException;\r
-import org.openo.baseservice.roa.util.restclient.RestfulFactory;\r
-import org.openo.baseservice.roa.util.restclient.RestfulParametes;\r
-import org.openo.baseservice.roa.util.restclient.RestfulResponse;\r
-import org.openo.gso.gui.servicegateway.constant.Constant;\r
-import org.openo.gso.gui.servicegateway.service.inf.IServiceGateway;\r
-import org.openo.gso.gui.servicegateway.util.json.JsonUtil;\r
-import org.openo.gso.gui.servicegateway.util.validate.ValidateUtil;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-/**\r
- * ServiceGateway service class.<br/>\r
- * <p>\r
- * </p>\r
- * \r
- * @author\r
- * @version GSO 0.5 2016/8/4\r
- */\r
-public class ServiceGatewayImpl implements IServiceGateway {\r
-\r
-    /**\r
-     * Log service.\r
-     */\r
-    private static final Logger LOGGER = LoggerFactory.getLogger(ServiceGatewayImpl.class);\r
-\r
-\r
-    /**\r
-     * Create service instance.<br/>\r
-     * \r
-     * @param reqContent content of request\r
-     * @param httpRequest http request\r
-     * @throws ServiceException when operate DB or parameter is wrong.\r
-     * @since GSO 0.5\r
-     */\r
-    @SuppressWarnings("unchecked")\r
-    @Override\r
-    public String createService(String reqContent, HttpServletRequest httpRequest) throws ServiceException {\r
-       // check the value\r
-       if(StringUtils.isEmpty(reqContent))\r
-       {\r
-               LOGGER.error("ServiceGatewayImpl createService reqContent is null.");\r
-               return null;\r
-       }\r
-       \r
-       // Parse request\r
-        Map<String, Object> requestBody = JsonUtil.unMarshal(reqContent, Map.class);\r
-        Map<String, Object> service = (Map<String, Object>)requestBody.get(Constant.SERVICE_INDENTIFY);\r
-        if(null == service)\r
-        {\r
-               service = requestBody;\r
-        }\r
-        ValidateUtil.assertObjectNotNull(requestBody);\r
-\r
-        // Validate data\r
-        String gatewayUri = (String)service.get(Constant.SERVICE_GATEWAY_URI);\r
-        ValidateUtil.assertStringNotNull(gatewayUri);\r
-        service.remove(Constant.SERVICE_GATEWAY_URI);\r
-\r
-        // call the restful \r
-        String id = null;\r
-        try {\r
-               RestfulResponse restfulRsp = RestfulFactory.getRestInstance("http").post(gatewayUri,\r
-                    getRestfulParameters(JsonUtil.marshal(requestBody)));\r
-            if (null != restfulRsp) {\r
-                // Record the result of registration\r
-                // (201:success;415:Invalid Parameter;500:Internal Server Error)\r
-                LOGGER.info("restful call result:", restfulRsp.getStatus());\r
-                id = restfulRsp.getRespHeaderStr(Constant.SERVICE_ID);\r
-                id = (null == id) ? restfulRsp.getRespHeaderStr(Constant.NS_INSTANCE_ID) : id;\r
-                id = (null == id) ? restfulRsp.getRespHeaderStr(Constant.JOB_ID) : id;\r
-            }\r
-        } catch(ServiceException e) {\r
-               LOGGER.error("service gateway create restful call result:", e);\r
-            throw e;\r
-        }\r
-\r
-        return id;\r
-    }\r
-    \r
-    /**\r
-     * get the parameters for restful<br/>\r
-     * \r
-     * @author\r
-     * @param bodyData\r
-     *            Json Body\r
-     * @return the RestfulParametes Instance\r
-     * @since GSO 0.5, 2016-8-9\r
-     */\r
-    private static RestfulParametes getRestfulParameters(final String bodyData) {\r
-        RestfulParametes param = new RestfulParametes();\r
-        param.putHttpContextHeader(Constant.HEAD_ERMAP_TYPE, Constant.HEAD_ERMAP_VALUE);\r
-        param.setRawData(bodyData);\r
-        return param;\r
-    }\r
-\r
-    /**\r
-     * Delete service instances.<br/>\r
-     * \r
-     * @param serviceId service instance ID\r
-     * @param httpRequest http request\r
-     * @throws ServiceException operate DB or parameter is wrong.\r
-     * @since GSO 0.5\r
-     */\r
-    @Override\r
-    public void deleteService(String serviceId, HttpServletRequest httpRequest) throws ServiceException {\r
-\r
-    }\r
-\r
-}\r
+/*
+ * 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 {
+
+    }
+
+}
index f9ecb74..9e18cb1 100644 (file)
@@ -1,55 +1,55 @@
-/*\r
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.gso.gui.servicegateway.service.inf;\r
-\r
-\r
-import javax.servlet.http.HttpServletRequest;\r
-\r
-import org.openo.baseservice.remoteservice.exception.ServiceException;\r
-\r
-/**\r
- * Interface to operate service.<br/>\r
- * <p>\r
- * </p>\r
- * \r
- * @author\r
- * @version GSO 0.5 2016/8/4\r
- */\r
-public interface IServiceGateway {\r
-\r
-    /**\r
-     * Create service instance.<br/>\r
-     * \r
-     * @param reqContent content of request\r
-     * @param httpRequest http request\r
-     * @return service instance\r
-     * @throws ServiceException when operate DB or parameter is wrong.\r
-     * @since GSO 0.5\r
-     */\r
-       String createService(String reqContent, HttpServletRequest httpRequest) throws ServiceException;\r
-\r
-    /**\r
-     * Delete service instances.<br/>\r
-     * \r
-     * @param serviceId service instance ID\r
-     * @param httpRequest http request\r
-     * @throws ServiceException operate DB or parameter is wrong.\r
-     * @since GSO 0.5\r
-     */\r
-    void deleteService(String serviceId, HttpServletRequest httpRequest) throws ServiceException;\r
-\r
-}\r
+/*
+ * 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;
+
+}
index 7780e6e..05d4f0f 100644 (file)
-/*\r
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.gso.gui.servicegateway.util.http;\r
-\r
-import java.util.HashMap;\r
-import java.util.LinkedList;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import org.codehaus.jackson.type.TypeReference;\r
-import org.openo.baseservice.remoteservice.exception.ExceptionArgs;\r
-import org.openo.baseservice.remoteservice.exception.ServiceException;\r
-import org.openo.baseservice.roa.util.restclient.RestfulResponse;\r
-import org.openo.gso.gui.servicegateway.constant.Constant;\r
-import org.openo.gso.gui.servicegateway.exception.ErrorCode;\r
-import org.openo.gso.gui.servicegateway.exception.HttpCode;\r
-import org.openo.gso.gui.servicegateway.util.json.JsonUtil;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-/**\r
- * Interface to deal response result.<br/>\r
- * <p>\r
- * </p>\r
- * \r
- * @author\r
- * @version GSO 0.5 2016/9/1\r
- */\r
-public class ResponseUtils {\r
-\r
-    /**\r
-     * Log server\r
-     */\r
-    private static final Logger LOGGER = LoggerFactory.getLogger(ResponseUtils.class);\r
-\r
-    /**\r
-     * Constructor<br/>\r
-     * <p>\r
-     * </p>\r
-     * \r
-     * @since GSO 0.5\r
-     */\r
-    private ResponseUtils() {\r
-    }\r
-\r
-    /**\r
-     * Check whether there is exception.<br/>\r
-     * <p>\r
-     * If fail, throw the exception.\r
-     * </p>\r
-     * \r
-     * @param response rest response\r
-     * @param function function name\r
-     * @throws ServiceException when the result of rest request is failure.\r
-     * @since GSO 0.5\r
-     */\r
-    public static void checkResonseAndThrowException(RestfulResponse response, String function)\r
-            throws ServiceException {\r
-        if(!HttpCode.isSucess(response.getStatus())) {\r
-            ServiceException roaExceptionInfo = null;\r
-            try {\r
-                roaExceptionInfo = JsonUtil.unMarshal(response.getResponseContent(), ServiceException.class);\r
-            } catch(ServiceException e) {\r
-                LOGGER.error("transfer the response json string has some error: {}", e);\r
-\r
-                ExceptionArgs args = new ExceptionArgs();\r
-                args.setDescArgs(new String[] {"Fail to " + function});\r
-\r
-                throw new ServiceException(ServiceException.DEFAULT_ID, response.getStatus(), args);\r
-            }\r
-\r
-            throw roaExceptionInfo;\r
-        }\r
-    }\r
-\r
-    /**\r
-     * Parse data to assigned type model.<br/>\r
-     * \r
-     * @param request restful request\r
-     * @param key key\r
-     * @param type type\r
-     * @return model data\r
-     * @throws ServiceException when transfer failed\r
-     * @since SDNO 0.5\r
-     */\r
-    @SuppressWarnings("unchecked")\r
-    public static <T> List<T> getDataModelFromRsp(String request, String key, Class<T> type) throws ServiceException {\r
-        //ValidateUtil.assertStringNotNull(request);\r
-        Map<String, Object> requestMap = JsonUtil.unMarshal(request, Map.class);\r
-        Object data = requestMap.get(key);\r
-        List<T> dataModelList = new LinkedList<T>();\r
-        if(data instanceof List) {\r
-            for(Object model : (List<T>)data) {\r
-                if(!(model instanceof Map)) {\r
-                    LOGGER.error("The format of response content is wrong! Not Map.");\r
-                    throw new ServiceException(ErrorCode.SVCMGR_SERVICEMGR_BAD_PARAM,\r
-                            "The format of response content is wrong.");\r
-                }\r
-\r
-                dataModelList.add(JsonUtil.unMarshal(JsonUtil.marshal(model), type));\r
-            }\r
-        }\r
-\r
-        return dataModelList;\r
-    }\r
-\r
-    /**\r
-     * Parse data to assigned type model.<br/>\r
-     * \r
-     * @param request restful request\r
-     * @param type type\r
-     * @return model data\r
-     * @throws ServiceException when transfer failed\r
-     * @since SDNO 0.5\r
-     */\r
-    public static <T> T getDataModelFromRspList(String request, TypeReference<T> type) throws ServiceException {\r
-        //ValidateUtil.assertStringNotNull(request);\r
-        return JsonUtil.unMarshal(request, type);\r
-    }\r
-\r
-    /**\r
-     * Set operation result.<br/>\r
-     * \r
-     * @param status status fail or success\r
-     * @param exception operation exception information\r
-     * @param errorCode error code\r
-     * @return result in form of map\r
-     * @since GSO 0.5\r
-     */\r
-    public static Map<String, Object> setOperateStatus(String status, ServiceException exception, String errorCode) {\r
-        Map<String, Object> result = new HashMap<String, Object>();\r
-        result.put(Constant.RESPONSE_STATUS, status);\r
-        if(null == exception) {\r
-            result.put(Constant.RESPONSE_STATUS_DESCRIPTION, status);\r
-        } else {\r
-            if((null != exception.getExceptionArgs()) && (null != exception.getExceptionArgs().getDescArgs())) {\r
-                result.put(Constant.RESPONSE_STATUS_DESCRIPTION, exception.getExceptionArgs().getDescArgs().toString());\r
-            }\r
-        }\r
-        result.put(Constant.RESPONSE_ERRORCODE, errorCode);\r
-\r
-        return result;\r
-    }\r
-    \r
-    /**\r
-     * Assemble operation result.<br/>\r
-     * \r
-     * @param objectId instance ID\r
-     * @param operateCode operation result\r
-     * @return Response result\r
-     * @since GSO 0.5\r
-     */\r
-    public static Map<String, Object> setResult(String objectId, Object operateCode) {\r
-        Map<String, Object> result = new HashMap<String, Object>();\r
-        result.put(Constant.RESPONSE_RESULT, operateCode);\r
-        String serviceId = (null != objectId) ? objectId : null;\r
-        result.put(Constant.SERVICE_INSTANCE_ID, serviceId);\r
-\r
-        return result;\r
-    }\r
-}\r
+/*
+ * 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;
+    }
+}
index fabe83d..adbcd75 100644 (file)
-/*\r
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.gso.gui.servicegateway.roa.impl;\r
-\r
-import java.io.File;\r
-import java.io.FileInputStream;\r
-import java.io.IOException;\r
-import java.sql.SQLException;\r
-\r
-import javax.servlet.http.HttpServletRequest;\r
-\r
-import org.apache.commons.io.IOUtils;\r
-import org.apache.commons.lang.StringUtils;\r
-import org.junit.After;\r
-import org.junit.Assert;\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import org.openo.baseservice.remoteservice.exception.ServiceException;\r
-import org.openo.baseservice.roa.util.restclient.RestfulResponse;\r
-import org.openo.baseservice.util.RestUtils;\r
-import org.openo.gso.gui.servicegateway.exception.HttpCode;\r
-import org.openo.gso.gui.servicegateway.service.impl.ServiceGatewayImpl;\r
-import org.openo.gso.gui.servicegateway.util.http.HttpUtil;\r
-\r
-import mockit.Mock;\r
-import mockit.MockUp;\r
-\r
-/**\r
- * Test ServicemgrRoaModuleImpl class.<br/>\r
- * <p>\r
- * </p>\r
- * \r
- * @author\r
- * @version GSO 0.5 2016/8/3\r
- */\r
-public class ServiceGatewayRoaModuleImplTest {\r
-\r
-       /**\r
-     * File path\r
-     */\r
-    private static final String FILE_PATH = "src/test/resources/json/";\r
-       \r
-    /**\r
-     * Service ROA.\r
-     */\r
-       ServiceGatewayRoaModuleImpl serviceRoa = new ServiceGatewayRoaModuleImpl();\r
-\r
-    /**\r
-     * Service manager.\r
-     */\r
-       ServiceGatewayImpl serviceManager = new ServiceGatewayImpl();\r
-\r
-\r
-    /**\r
-     * Http request.\r
-     */\r
-    HttpServletRequest httpRequest;\r
-    \r
-    /**\r
-     * Rest response.\r
-     */\r
-    RestfulResponse responseSuccess;\r
-\r
-    /**\r
-     * Before executing UT, start sql.<br/>\r
-     * \r
-     * @since GSO 0.5\r
-     */\r
-    @Before\r
-    public void start() throws IOException, SQLException {\r
-       responseSuccess = new RestfulResponse();\r
-       responseSuccess.setStatus(HttpCode.RESPOND_OK);\r
-    }\r
-\r
-\r
-\r
-    /**\r
-     * After executing UT, close session<br/>\r
-     * \r
-     * @since GSO 0.5\r
-     */\r
-    @After\r
-    public void stop() {\r
-\r
-    }\r
-\r
-    /**\r
-     * Test create service.<br/>\r
-     * \r
-     * @throws ServiceException when fail to operate database or parameter is wrong.\r
-     * @since GSO 0.5\r
-     */\r
-    @Test\r
-    public void testCreateService() throws ServiceException {\r
-       // mock request body\r
-        mockGetRequestBody(FILE_PATH + "createServiceInstance.json");\r
-        \r
-        mockPost(responseSuccess);\r
-\r
-        serviceRoa.createService(httpRequest);\r
-    }\r
-\r
-    /**\r
-     * Test delete service.<br/>\r
-     * \r
-     * @throws ServiceException when fail to operate database or parameter is wrong.\r
-     * @since GSO 0.5\r
-     */\r
-    @Test\r
-    public void testDeleteService() throws ServiceException {\r
-        serviceRoa.deleteService("1", httpRequest);\r
-    }\r
-\r
-    /**\r
-     * Mock to get request body.<br/>\r
-     * \r
-     * @param file json file path.\r
-     * @since GSO 0.5\r
-     */\r
-    private void mockGetRequestBody(final String file) {\r
-        new MockUp<RestUtils>() {\r
-\r
-            @Mock\r
-            public String getRequestBody(HttpServletRequest request) {\r
-                return getJsonString(file);\r
-            }\r
-        };\r
-    }\r
-    \r
-    /**\r
-     * Mock rest request for post.<br/>\r
-     * \r
-     * @param response rest response\r
-     * @since GSO 0.5\r
-     */\r
-    private void mockPost(final RestfulResponse response) {\r
-        new MockUp<HttpUtil>() {\r
-\r
-            @Mock\r
-            public RestfulResponse post(final String url, Object sendObj, HttpServletRequest httpRequest) {\r
-                return response;\r
-            }\r
-        };\r
-    }\r
-    \r
-    /**\r
-     * Get json string from file.<br/>\r
-     * \r
-     * @param file the path of file\r
-     * @return json string\r
-     * @throws IOException when fail to read\r
-     * @since GSO 0.5\r
-     */\r
-    private String getJsonString(final String file) {\r
-        if(StringUtils.isEmpty(file)) {\r
-            return "";\r
-        }\r
-\r
-        String json = null;\r
-        try {\r
-            FileInputStream fileStream = new FileInputStream(new File(file));\r
-            json = IOUtils.toString(fileStream);\r
-        } catch(Exception e) {\r
-            Assert.fail(e.getMessage());\r
-        }\r
-\r
-        return json;\r
-    }\r
-}\r
+/*
+ * 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;
+    }
+}
index bf2efa0..fddebe0 100644 (file)
@@ -1,72 +1,72 @@
-/*\r
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.gso.gui.servicegateway.service.impl;\r
-\r
-\r
-import javax.servlet.http.HttpServletRequest;\r
-\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import org.openo.baseservice.remoteservice.exception.ServiceException;\r
-\r
-/**\r
- * Test ServiceGatewayImpl Class.<br/>\r
- * <p>\r
- * </p>\r
- * \r
- * @author\r
- * @version GSO 0.5 2016/8/3\r
- */\r
-public class ServiceGatewayImplTest {\r
-\r
-    /**\r
-     * Service manager.\r
-     */\r
-    ServiceGatewayImpl serviceManager = new ServiceGatewayImpl();\r
-\r
-    /**\r
-     * Http request.\r
-     */\r
-    HttpServletRequest httpRequest;\r
-\r
-    @Before\r
-    public void start() {\r
-    }\r
-\r
-    /**\r
-     * Invalid parameter.<br/>\r
-     * \r
-     * @throws ServiceException when parameter is wrong.\r
-     * @since GSO 0.5\r
-     */\r
-    @Test(expected = ServiceException.class)\r
-    public void testCreateServiceFail() throws ServiceException {\r
-        serviceManager.createService(null, httpRequest);\r
-    }\r
-\r
-    /**\r
-     * Invalid parameter.<br/>\r
-     * \r
-     * @throws ServiceException when parameter is wrong.\r
-     * @since GSO 0.5\r
-     */\r
-    @Test(expected = ServiceException.class)\r
-    public void testDeleteServiceFail() throws ServiceException {\r
-        serviceManager.deleteService(null, httpRequest);\r
-    }\r
-\r
-}\r
+/*
+ * 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);
+    }
+
+}