aboutsummaryrefslogtreecommitdiffstats
path: root/servicegateway/service
diff options
context:
space:
mode:
Diffstat (limited to 'servicegateway/service')
-rw-r--r--servicegateway/service/pom.xml162
-rw-r--r--servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/activator/Activator.java83
-rw-r--r--servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/constant/Constant.java139
-rw-r--r--servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/exception/ErrorCode.java60
-rw-r--r--servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/exception/HttpCode.java86
-rw-r--r--servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/roa/impl/ServiceGatewayRoaModuleImpl.java93
-rw-r--r--servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/roa/inf/IServiceGatewayRoaModule.java73
-rw-r--r--servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/service/impl/ServiceGatewayImpl.java71
-rw-r--r--servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/service/inf/IServiceGateway.java55
-rw-r--r--servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/util/http/HttpUtil.java138
-rw-r--r--servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/util/http/ResponseUtils.java158
-rw-r--r--servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/util/json/JsonUtil.java133
-rw-r--r--servicegateway/service/src/main/resources/META-INF/auth.properties18
-rw-r--r--servicegateway/service/src/main/resources/service-configure.properties17
-rw-r--r--servicegateway/service/src/main/resources/spring/service.xml96
-rw-r--r--servicegateway/service/src/main/webapp/WEB-INF/web.xml33
-rw-r--r--servicegateway/service/src/test/java/org/openo/gso/gui/servicegateway/exception/ErrorCodeTest.java39
-rw-r--r--servicegateway/service/src/test/java/org/openo/gso/gui/servicegateway/exception/HttpCodeTest.java47
-rw-r--r--servicegateway/service/src/test/java/org/openo/gso/gui/servicegateway/roa/impl/ServiceGatewayRoaModuleImplTest.java109
-rw-r--r--servicegateway/service/src/test/java/org/openo/gso/gui/servicegateway/service/impl/ServiceGatewayImplTest.java73
20 files changed, 1683 insertions, 0 deletions
diff --git a/servicegateway/service/pom.xml b/servicegateway/service/pom.xml
new file mode 100644
index 00000000..ccf02ee2
--- /dev/null
+++ b/servicegateway/service/pom.xml
@@ -0,0 +1,162 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- /* * 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. */ -->
+
+<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>servicegateway</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>service</artifactId>
+ <name>service</name>
+ <packaging>war</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.openo.common-services.common-utilities</groupId>
+ <artifactId>commonlib-cbb</artifactId>
+ <version>1.0.1-SNAPSHOT</version>
+ </dependency>
+ <!-- roa -->
+ <dependency>
+ <groupId>org.openo.common-services.common-utilities</groupId>
+ <artifactId>commonlib-restclient</artifactId>
+ <version>1.0.1-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-frontend-jaxrs</artifactId>
+ <version>3.1.6</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-httpclient</groupId>
+ <artifactId>commons-httpclient</artifactId>
+ <version>3.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.openo.gso.commsvc</groupId>
+ <artifactId>org.openo.gso.commsvc.common</artifactId>
+ <version>2.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-beans</artifactId>
+ <version>3.1.0.RELEASE</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ <version>3.1.0.RELEASE</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-jdbc</artifactId>
+ <version>3.1.0.RELEASE</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ <version>3.1.0.RELEASE</version>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>4.1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.mybatis</groupId>
+ <artifactId>mybatis</artifactId>
+ <version>3.2.7</version>
+ </dependency>
+ <dependency>
+ <groupId>org.mybatis</groupId>
+ <artifactId>mybatis-spring</artifactId>
+ <version>1.2.0</version>
+ <type>jar</type>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.mchange</groupId>
+ <artifactId>c3p0</artifactId>
+ <version>0.9.2.1</version>
+ <type>jar</type>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.jackson</groupId>
+ <artifactId>jackson-jaxrs</artifactId>
+ <version>1.9.2</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>3.1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>com.googlecode.jmockit</groupId>
+ <artifactId>jmockit</artifactId>
+ <version>1.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.12</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jmockit</groupId>
+ <artifactId>jmockit-coverage</artifactId>
+ <version>1.18</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ <version>1.4.190</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <argLine>-XX:-UseSplitVerifier</argLine>
+ <skipTests>true</skipTests>
+ <testFailureIgnore>true</testFailureIgnore>
+ <excludes>
+ <exclude>${excludesFile}</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>cobertura-maven-plugin</artifactId>
+ <version>2.7</version>
+ <configuration>
+ <formats>
+ <format>html</format>
+ <format>xml</format>
+ </formats>
+ <instrumentation>
+ <excludes>
+ <exclude>org/**/*Test.class</exclude>
+ </excludes>
+ </instrumentation>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</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
new file mode 100644
index 00000000..befe9328
--- /dev/null
+++ b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/activator/Activator.java
@@ -0,0 +1,83 @@
+/*
+ * 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
+ }
+}
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
new file mode 100644
index 00000000..c5283fac
--- /dev/null
+++ b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/constant/Constant.java
@@ -0,0 +1,139 @@
+/*
+ * 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() {
+
+ }
+}
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
new file mode 100644
index 00000000..759344e1
--- /dev/null
+++ b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/exception/ErrorCode.java
@@ -0,0 +1,60 @@
+/*
+ * 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() {
+
+ }
+}
diff --git a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/exception/HttpCode.java b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/exception/HttpCode.java
new file mode 100644
index 00000000..05f5220f
--- /dev/null
+++ b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/exception/HttpCode.java
@@ -0,0 +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.exception;
+
+/**
+ * Constant Class.<br/>
+ * <p>
+ * Define constant for http operation.
+ * </p>
+ *
+ * @author
+ * @version GSO 0.5 2016/8/4
+ */
+public class HttpCode {
+
+ /**
+ * Fail to request.
+ */
+ public static final int BAD_REQUEST = 400;
+
+ /**
+ * Inner error
+ */
+ public static final int INTERNAL_SERVER_ERROR = 500;
+
+ /**
+ * Not accept request.
+ */
+ public static final int NOT_ACCEPTABLE = 406;
+
+ /**
+ * Not found service.
+ */
+ public static final int NOT_FOUND = 404;
+
+ /**
+ * Accept request.
+ */
+ public static final int RESPOND_ACCEPTED = 202;
+
+ /**
+ * Http response is ok.
+ */
+ public static final int RESPOND_OK = 200;
+
+ /**
+ * Conflict
+ */
+ public static final int RESPOND_CONFLICT = 409;
+
+ /**
+ * Constructor<br/>
+ * <p>
+ * </p>
+ *
+ * @since GSO 0.5
+ */
+ private HttpCode() {
+
+ }
+
+ /**
+ * Whether request is successful.<br/>
+ *
+ * @param httpCode response code
+ * @return true or false
+ * @since GSO 0.5
+ */
+ public static boolean isSucess(int httpCode) {
+ return httpCode / 100 == 2;
+ }
+}
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
new file mode 100644
index 00000000..9b7796f9
--- /dev/null
+++ b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/roa/impl/ServiceGatewayRoaModuleImpl.java
@@ -0,0 +1,93 @@
+/*
+ * 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;
+ }
+}
diff --git a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/roa/inf/IServiceGatewayRoaModule.java b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/roa/inf/IServiceGatewayRoaModule.java
new file mode 100644
index 00000000..929af508
--- /dev/null
+++ b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/roa/inf/IServiceGatewayRoaModule.java
@@ -0,0 +1,73 @@
+/*
+ * 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.inf;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+
+/**
+ * API for restful interface.<br/>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version GSO 0.5 2016/8/4
+ */
+@Path("/servicegateway/v1/services")
+@Consumes({"application/json"})
+@Produces({"application/json"})
+public interface IServiceGatewayRoaModule {
+
+ /**
+ * Create service instance.<br/>
+ *
+ * @param servletReq http request
+ * @return response
+ * @throws ServiceException when operate database or parameter is wrong.
+ * @since GSO 0.5
+ */
+ @POST
+ @Produces({"application/json"})
+ @Consumes({"application/json"})
+ Response createService(@Context HttpServletRequest servletReq) throws ServiceException;
+
+ /**
+ * 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
+ */
+ @DELETE
+ @Produces({"application/json"})
+ @Consumes({"application/json"})
+ @Path("/{serviceId}")
+ Response deleteService(@PathParam("serviceId") String serviceId, @Context HttpServletRequest servletReq)
+ throws ServiceException;
+
+}
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
new file mode 100644
index 00000000..3f2a48a7
--- /dev/null
+++ b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/service/impl/ServiceGatewayImpl.java
@@ -0,0 +1,71 @@
+/*
+ * 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 {
+
+ }
+
+}
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
new file mode 100644
index 00000000..77b27bd7
--- /dev/null
+++ b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/service/inf/IServiceGateway.java
@@ -0,0 +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;
+
+}
diff --git a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/util/http/HttpUtil.java b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/util/http/HttpUtil.java
new file mode 100644
index 00000000..81546493
--- /dev/null
+++ b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/util/http/HttpUtil.java
@@ -0,0 +1,138 @@
+/*
+ * 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.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+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.util.json.JsonUtil;
+
+/**
+ * Method class that provides interface to do http request.<br/>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version GSO 0.5 2016/9/1
+ */
+public class HttpUtil {
+
+ /**
+ * Constructor<br/>
+ * <p>
+ * </p>
+ *
+ * @since GSO 0.5
+ */
+ private HttpUtil() {
+
+ }
+
+ /**
+ * Get operation.<br/>
+ *
+ * @param url request location
+ * @param httpHeaders request headers
+ * @param httpRequest http request
+ * @return response
+ * @throws ServiceException when request is failure.
+ * @since GSO 0.5
+ */
+ public static RestfulResponse get(final String url, final Map<String, String> httpHeaders,
+ HttpServletRequest httpRequest) throws ServiceException {
+ final RestfulParametes restfulParametes = getRestfulParametes(httpRequest);
+ for(Map.Entry<String, String> entry : httpHeaders.entrySet()) {
+ restfulParametes.putHttpContextHeader(entry.getKey(), entry.getValue());
+ }
+
+ return RestfulFactory.getRestInstance(RestfulFactory.PROTO_HTTP).get(url, restfulParametes);
+ }
+
+ /**
+ * Post operation.<br/>
+ *
+ * @param url request location
+ * @param sendObj request body
+ * @param httpRequest http request
+ * @return response
+ * @throws ServiceException when request is failure.
+ * @since GSO 0.5
+ */
+ public static RestfulResponse post(final String url, Object sendObj, HttpServletRequest httpRequest)
+ throws ServiceException {
+
+ final RestfulParametes restfulParametes = getRestfulParametes(httpRequest);
+ if(sendObj != null) {
+ String strJsonReq = JsonUtil.marshal(sendObj);
+ restfulParametes.setRawData(strJsonReq);
+ }
+
+ return RestfulFactory.getRestInstance(RestfulFactory.PROTO_HTTP).post(url, restfulParametes);
+ }
+
+ /**
+ * Delete operation.<br/>
+ *
+ * @param url request location
+ * @param httpRequest http request
+ * @return response
+ * @throws ServiceException when request is failure.
+ * @since GSO 0.5
+ */
+ public static RestfulResponse delete(final String url, HttpServletRequest httpRequest) throws ServiceException {
+ final RestfulParametes restfulParametes = getRestfulParametes(httpRequest);
+ return RestfulFactory.getRestInstance(RestfulFactory.PROTO_HTTP).delete(url, restfulParametes);
+ }
+
+ /**
+ * Put operation.<br/>
+ *
+ * @param url request location
+ * @param httpHeaders request headers
+ * @param httpRequest http request
+ * @return response
+ * @throws ServiceException when request is failure.
+ * @since GSO 0.5
+ */
+ public static RestfulResponse put(final String url, final Map<String, String> httpHeaders,
+ HttpServletRequest httpRequest) throws ServiceException {
+ final RestfulParametes restfulParametes = getRestfulParametes(httpRequest);
+ for(Map.Entry<String, String> entry : httpHeaders.entrySet()) {
+ restfulParametes.putHttpContextHeader(entry.getKey(), entry.getValue());
+ }
+
+ return RestfulFactory.getRestInstance(RestfulFactory.PROTO_HTTP).put(url, restfulParametes);
+ }
+
+ /**
+ * Fill in request parameters.<br/>
+ *
+ * @param httpRequest http request
+ * @return rest parameters
+ * @since GSO 0.5
+ */
+ public static RestfulParametes getRestfulParametes(HttpServletRequest httpRequest) {
+ final RestfulParametes restfulParametes = new RestfulParametes();
+ restfulParametes.putHttpContextHeader("Content-Type", "application/json;charset=UTF-8");
+ return restfulParametes;
+ }
+}
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
new file mode 100644
index 00000000..d0df0781
--- /dev/null
+++ b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/util/http/ResponseUtils.java
@@ -0,0 +1,158 @@
+/*
+ * 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;
+ }
+}
diff --git a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/util/json/JsonUtil.java b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/util/json/JsonUtil.java
new file mode 100644
index 00000000..afb3c238
--- /dev/null
+++ b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/util/json/JsonUtil.java
@@ -0,0 +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.util.json;
+
+import java.io.IOException;
+
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
+import org.codehaus.jackson.type.TypeReference;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.gso.gui.servicegateway.exception.ErrorCode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import net.sf.json.JSON;
+
+/**
+ * Interface for json analyzing.<br/>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version GSO 0.5 2016/9/1
+ */
+public class JsonUtil {
+
+ /**
+ * Log service
+ */
+ private static final Logger LOGGER = LoggerFactory.getLogger(JsonUtil.class);
+
+ /**
+ * Mapper.
+ */
+ private static final ObjectMapper MAPPER = new ObjectMapper();
+
+ static {
+ MAPPER.setDeserializationConfig(MAPPER.getDeserializationConfig()
+ .without(org.codehaus.jackson.map.DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES));
+ MAPPER.setSerializationInclusion(Inclusion.NON_NULL);
+ }
+
+ /**
+ * Constructor<br/>
+ * <p>
+ * </p>
+ *
+ * @since GSO 0.5
+ */
+ private JsonUtil() {
+
+ }
+
+ /**
+ * Parse the string in form of json.<br/>
+ *
+ * @param jsonstr json string.
+ * @param type that convert json string to
+ * @return
+ * @throws ServiceException
+ * @since GSO 0.5
+ */
+ public static <T> T unMarshal(String jsonstr, Class<T> type) throws ServiceException {
+ try {
+ return MAPPER.readValue(jsonstr, type);
+ } catch(IOException e) {
+ LOGGER.error("jsonstr unMarshal failed!", e);
+ throw new ServiceException(ErrorCode.SVCMGR_SERVICEMGR_BAD_PARAM, "jsonstr unMarshal failed!");
+ }
+ }
+
+ /**
+ * Parse the string in form of json.<br/>
+ *
+ * @param jsonstr json string.
+ * @param type that convert json string to
+ * @return
+ * @throws ServiceException
+ * @since GSO 0.5
+ */
+ public static <T> T unMarshal(String jsonstr, TypeReference<T> type) throws ServiceException {
+ try {
+ return MAPPER.readValue(jsonstr, type);
+ } catch(IOException e) {
+ LOGGER.error("jsonstr unMarshal failed!", e);
+ throw new ServiceException(ErrorCode.SVCMGR_SERVICEMGR_BAD_PARAM, "jsonstr unMarshal failed!");
+ }
+ }
+
+ /**
+ * Convert object to json string.<br/>
+ *
+ * @param srcObj data object
+ * @return json string
+ * @throws ServiceException when fail to convert.
+ * @since GSO 0.5
+ */
+ public static String marshal(Object srcObj) throws ServiceException {
+ if(srcObj instanceof JSON) {
+ return srcObj.toString();
+ }
+ try {
+ return MAPPER.writeValueAsString(srcObj);
+ } catch(IOException e) {
+ LOGGER.error("srcObj marshal failed!", e);
+ throw new ServiceException(ErrorCode.SVCMGR_SERVICEMGR_BAD_PARAM, "srcObj marshal failed!");
+ }
+ }
+
+ /**
+ * Get mapper.<br/>
+ *
+ * @return mapper
+ * @since GSO 0.5
+ */
+ public static ObjectMapper getMapper() {
+ return MAPPER;
+ }
+}
diff --git a/servicegateway/service/src/main/resources/META-INF/auth.properties b/servicegateway/service/src/main/resources/META-INF/auth.properties
new file mode 100644
index 00000000..121f2944
--- /dev/null
+++ b/servicegateway/service/src/main/resources/META-INF/auth.properties
@@ -0,0 +1,18 @@
+###############################################################################
+# /*
+# * 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.
+# */
+###############################################################################
+auth=disable
diff --git a/servicegateway/service/src/main/resources/service-configure.properties b/servicegateway/service/src/main/resources/service-configure.properties
new file mode 100644
index 00000000..45c2564b
--- /dev/null
+++ b/servicegateway/service/src/main/resources/service-configure.properties
@@ -0,0 +1,17 @@
+###############################################################################
+# /*
+# * 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.
+# */
+###############################################################################
diff --git a/servicegateway/service/src/main/resources/spring/service.xml b/servicegateway/service/src/main/resources/spring/service.xml
new file mode 100644
index 00000000..c91ed1ca
--- /dev/null
+++ b/servicegateway/service/src/main/resources/spring/service.xml
@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- /* * 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. */ -->
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:ctx="http://www.springframework.org/schema/context" xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:oms="http://www.huawei.com/schema/oms"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/context
+ http://www.springframework.org/schema/context/spring-context.xsd
+ http://www.huawei.com/schema/oms
+ http://www.huawei.com/schema/oms/oms.xsd
+ http://cxf.apache.org/jaxrs
+ http://cxf.apache.org/schemas/jaxrs.xsd">
+
+ <!-- these are included in the dependency jar -->
+ <import resource="classpath:META-INF/cxf/cxf.xml" />
+ <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
+
+ <!-- jar rest server registration -->
+ <jaxrs:server id="sampleServer" address="/">
+ <!-- registering beans -->
+ <jaxrs:serviceBeans>
+ <ref bean="ServicemgrRoaModuleImpl"></ref>
+ <ref bean="ServicePackageModuleImpl"></ref>
+ </jaxrs:serviceBeans>
+ <!-- registering providers -->
+ <jaxrs:providers>
+ <bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider" />
+ </jaxrs:providers>
+ </jaxrs:server>
+
+ <bean id="datasource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
+ <property name="driverClass" value="com.mysql.jdbc.Driver" />
+ <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/mybatistest" />
+ <property name="user" value="root" />
+ <property name="password" value="Test_12345" />
+ </bean>
+
+ <bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
+ <property name="dataSource" ref="datasource" />
+ <property name="mapperLocations" value="classpath*:mybatis/mappers/*.xml" />
+ </bean>
+
+ <bean id="session" class="org.mybatis.spring.SqlSessionTemplate">
+ <constructor-arg index="0" ref="sessionFactory" />
+ </bean>
+
+ <bean class="org.openo.gso.servicemgr.activator.Activator"></bean>
+
+ <bean id="Activator" class="org.openo.gso.servicemgr.activator.Activator" init-method="start" destroy-method="stop">
+ </bean>
+
+ <bean id="ServicemgrRoaModuleImpl" class="org.openo.gso.servicemgr.roa.impl.ServicemgrRoaModuleImpl">
+ <property name="ServiceGateway" ref="ServiceGateway"></property>
+ </bean>
+
+ <bean id="ServiceGateway" class="org.openo.gso.servicemgr.service.impl.ServiceGatewayImpl">
+ <property name="serviceModelDao" ref="serviceModelDao"></property>
+ <property name="subServiceDao" ref="subServiceDao"></property>
+ <property name="servicePackageDao" ref="servicePackageDao"></property>
+ <property name="catalogProxy" ref="catalogProxy"></property>
+ <property name="wsoProxy" ref="wsoProxy"></property>
+ </bean>
+
+ <bean id="ServicePackageModuleImpl" class="org.openo.gso.servicemgr.roa.impl.ServicePackageModuleImpl">
+ <property name="packageMgr" ref="packageMgr"></property>
+ </bean>
+
+ <bean id="packageMgr" class="org.openo.gso.servicemgr.service.impl.PackageManagerImpl">
+ <property name="servicePackageDao" ref="servicePackageDao"></property>
+ <property name="catalogProxy" ref="catalogProxy"></property>
+ </bean>
+
+ <bean id="serviceModelDao" class="org.openo.gso.servicemgr.dao.impl.ServiceModelDaoImpl">
+ <property name="session" ref="session" />
+ </bean>
+
+ <bean id="servicePackageDao" class="org.openo.gso.servicemgr.dao.impl.ServicePackageDaoImpl">
+ <property name="session" ref="session" />
+ </bean>
+
+ <bean id="subServiceDao" class="org.openo.gso.servicemgr.dao.impl.SubServiceDaoImpl">
+ <property name="session" ref="session" />
+ </bean>
+
+ <bean id="catalogProxy" class="org.openo.gso.servicemgr.restproxy.impl.CatalogProxyImpl">
+ </bean>
+
+ <bean id="wsoProxy" class="org.openo.gso.servicemgr.restproxy.impl.WsoProxyImpl">
+ </bean>
+</beans> \ No newline at end of file
diff --git a/servicegateway/service/src/main/webapp/WEB-INF/web.xml b/servicegateway/service/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 00000000..6f06aed3
--- /dev/null
+++ b/servicegateway/service/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- /* * 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. */ -->
+
+<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
+ http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
+
+ <servlet>
+ <servlet-name>CXFServlet</servlet-name>
+ <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>CXFServlet</servlet-name>
+ <url-pattern>/openoapi/*</url-pattern>
+ </servlet-mapping>
+
+ <listener>
+ <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
+ </listener>
+ <context-param>
+ <param-name>contextConfigLocation</param-name>
+ <param-value>WEB-INF/classes/spring/*.xml,classpath*:spring/applicationContext.xml,classpath*:spring/service.xml</param-value>
+ </context-param>
+
+ <session-config>
+ <session-timeout>10000000</session-timeout>
+ </session-config>
+</web-app>
diff --git a/servicegateway/service/src/test/java/org/openo/gso/gui/servicegateway/exception/ErrorCodeTest.java b/servicegateway/service/src/test/java/org/openo/gso/gui/servicegateway/exception/ErrorCodeTest.java
new file mode 100644
index 00000000..422c5e41
--- /dev/null
+++ b/servicegateway/service/src/test/java/org/openo/gso/gui/servicegateway/exception/ErrorCodeTest.java
@@ -0,0 +1,39 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+/**
+ * Test Constant class.<br/>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version GSO 0.5 2016/8/4
+ */
+public class ErrorCodeTest {
+
+ @Test
+ public void test() {
+ assertEquals("servicemgr.mysql.oper_mysql_db_error", ErrorCode.SVCMGR_OPER_MYSQL_DB_ERROR);
+ assertEquals("servicemgr.bad_param", ErrorCode.SVCMGR_SERVICEMGR_BAD_PARAM);
+ }
+
+}
diff --git a/servicegateway/service/src/test/java/org/openo/gso/gui/servicegateway/exception/HttpCodeTest.java b/servicegateway/service/src/test/java/org/openo/gso/gui/servicegateway/exception/HttpCodeTest.java
new file mode 100644
index 00000000..cefdb50b
--- /dev/null
+++ b/servicegateway/service/src/test/java/org/openo/gso/gui/servicegateway/exception/HttpCodeTest.java
@@ -0,0 +1,47 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+/**
+ * Test Constant class.<br/>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version GSO 0.5 2016/8/4
+ */
+public class HttpCodeTest {
+
+ @Test
+ public void test() {
+ assertEquals(400, HttpCode.BAD_REQUEST);
+ assertEquals(500, HttpCode.INTERNAL_SERVER_ERROR);
+ assertEquals(406, HttpCode.NOT_ACCEPTABLE);
+ assertEquals(404, HttpCode.NOT_FOUND);
+ assertEquals(202, HttpCode.RESPOND_ACCEPTED);
+ assertEquals(200, HttpCode.RESPOND_OK);
+ assertTrue(HttpCode.isSucess(200));
+ assertFalse(HttpCode.isSucess(400));
+ }
+
+}
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
new file mode 100644
index 00000000..8b5c6c67
--- /dev/null
+++ b/servicegateway/service/src/test/java/org/openo/gso/gui/servicegateway/roa/impl/ServiceGatewayRoaModuleImplTest.java
@@ -0,0 +1,109 @@
+/*
+ * 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);
+ }
+
+}
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
new file mode 100644
index 00000000..734add90
--- /dev/null
+++ b/servicegateway/service/src/test/java/org/openo/gso/gui/servicegateway/service/impl/ServiceGatewayImplTest.java
@@ -0,0 +1,73 @@
+/*
+ * 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);
+ }
+
+}