diff options
Diffstat (limited to 'servicegateway/service/src/main')
18 files changed, 0 insertions, 1726 deletions
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 deleted file mode 100644 index 0055931d..00000000 --- a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/activator/Activator.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2016, Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.openo.gso.gui.servicegateway.activator; - -import java.io.File; - -import org.apache.commons.lang3.StringUtils; -import org.openo.baseservice.util.impl.SystemEnvVariablesFactory; -import org.openo.gso.gui.servicegateway.constant.Constant; -import org.openo.gso.gui.servicegateway.util.register.RegisterUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Service Start <br/> - * - * @author - * @since GSO 0.5, 2016-8-10 - */ -public class Activator { - - private static final Logger LOGGER = LoggerFactory.getLogger(Activator.class); - - - /** - * start operation by spring <br/> - * - * @param context - * service context - * @author - * @since GSO 0.5, 2016-8-10 - */ - public void start() { - // register restful to M-Bus when starting service - registerService(); - } - - /** - * register the service to M-Bus<br/> - * - * @author - * @since GSO 0.5, 2016-8-10 - */ - private void registerService() { - // get the jsonString form the service file - String root = SystemEnvVariablesFactory.getInstance().getAppRoot(); - String serviceFilePath = root + File.separator + Constant.FILE_PATH_ETC + File.separator - + Constant.FILE_PATH_REGISTER + File.separator + Constant.FILE_PATH_JSON; - String jsonInfo = RegisterUtil.readFile(serviceFilePath); - - // check the jsonInfo - if(StringUtils.isEmpty(jsonInfo)) { - LOGGER.error("ServiceGateway ReadFile fail: jsonInfo is null. the serviceFilePath=" + serviceFilePath); - return; - } - - // register service by the jsonInfo - RegisterUtil.registerService(jsonInfo); - } - - /** - * stop operation by spring <br/> - * - * @param context - * service context - * @author - * @since GSO 0.5, 2016-8-10 - */ - public void stop() { - // no operation - } -} diff --git a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/constant/Constant.java b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/constant/Constant.java deleted file mode 100644 index 3a26a606..00000000 --- a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/constant/Constant.java +++ /dev/null @@ -1,174 +0,0 @@ -/* - * 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"; - - /** - * Service operation. - */ - public static final String SERVICE_OPERATION = "operation"; - - /** - * Service delete operation. - */ - public static final String SERVICE_DELETE_OPERATION = "delete"; - - /** - * Create workflow name. - */ - public static final String WORK_FLOW_PLAN_CREATE = "create"; - - /** - * Delete workflow name. - */ - public static final String WORK_FLOW_PLAN_DELETE = "delete"; - - /** - * filed in wso2 body. - */ - public static final String WSO_PROCESSID = "processId"; - - /** - * filed in wso2 body. - */ - public static final String WSO_PARAMS = "params"; - - /** - * Response result; - */ - public static final String RESPONSE_RESULT = "result"; - - /** - * Response status. - */ - public static final String RESPONSE_STATUS = "status"; - - /** - * Response status description. - */ - public static final String RESPONSE_STATUS_DESCRIPTION = "statusDescription"; - - /** - * Error code of response. - */ - public static final String RESPONSE_ERRORCODE = "errorCode"; - - /** - * Operations success. - */ - public static final String RESPONSE_STATUS_SUCCESS = "success"; - - /** - * Operation failed. - */ - public static final String RESPONSE_STATUS_FAIL = "fail"; - - /** - * ID of instance. - */ - public static final String NS_INSTANCE_ID = "nsInstanceId"; - - /** - * service identify. - */ - public static final String SERVICE_ID = "serviceId"; - - /** - * job Id - */ - public static final String JOB_ID = "jobId"; - - /** - * service file Path:etc - */ - public static final String FILE_PATH_ETC = "etc"; - - /** - * service file Path:register - */ - public static final String FILE_PATH_REGISTER = "register"; - - /** - * service file Path:file name - */ - public static final String FILE_PATH_JSON = "service.json"; - - /** - * the head type for Restful - */ - public static final String HEAD_ERMAP_TYPE = "Content-Type"; - - /** - * the head value for Restful - */ - public static final String HEAD_ERMAP_VALUE = "application/json;charset=UTF-8"; - - /** - * the URL for Register service to the M-service Bus - */ - public static final String M_BUS_REGISTER_URL = "/openoapi/microservices/v1/services"; - - /** - * the IP key for the service file - */ - public static final String SERVICE_KEY_IP = "getInputIP"; - - /** - * constant:0 - */ - public static final int ZERO = 0; - - /** - * Constructor<br/> - * <p> - * </p> - * - * @since GSO 0.5 - */ - private Constant() { - - } -} diff --git a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/exception/ErrorCode.java b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/exception/ErrorCode.java deleted file mode 100644 index d3519a05..00000000 --- a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/exception/ErrorCode.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2016, Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.openo.gso.gui.servicegateway.exception; - -/** - * Constant Class.<br/> - * <p> - * Define constant for recording error. - * </p> - * - * @author - * @version GSO 0.5 2016/8/4 - */ -public class ErrorCode { - - /** - * Fail to operate database. - */ - public static final String SVCMGR_OPER_MYSQL_DB_ERROR = "servicemgr.mysql.oper_mysql_db_error"; - - /** - * Parameter is wrong. - */ - public static final String SVCMGR_SERVICEMGR_BAD_PARAM = "servicemgr.bad_param"; - - /** - * Operation is failure. - */ - public static final String SVCMGR_SERVICEMGR_FAIL_OPERATION = "servicemgr.fail.operation"; - - /** - * Package is being deleted. - */ - public static final String SVCMGR_PACKAGE_BEING_DELETED = "servicemgr.package.beingDelete"; - - /** - * operation fail - */ - public static final int FAIL = 3; - - /** - * operation partial success - */ - public static final int PARTIAL_SUCCESS = 1; - - /** - * operation success - */ - public static final int SUCCESS = 0; - - /** - * Constructor<br/> - * <p> - * </p> - * - * @since GSO 0.5 - */ - private ErrorCode() { - - } -} diff --git a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/exception/HttpCode.java b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/exception/HttpCode.java deleted file mode 100644 index 473de721..00000000 --- a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/exception/HttpCode.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * 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; - - public static final int CREATED_OK = 201; - - /** - * 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 deleted file mode 100644 index 059e6fdc..00000000 --- a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/roa/impl/ServiceGatewayRoaModuleImpl.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * 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); - LOGGER.info("Received a request form the NBI the reqContent is :"+ 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) { - Map<String, Object> result = null; - try { - // 1. Check validation - String reqContent = RestUtils.getRequestBody(servletReq); - ValidateUtil.assertStringNotNull(reqContent); - - // 2. Delete service - result = serviceGateway.deleteService(serviceId, reqContent, servletReq); - } catch(ServiceException exception) { - LOGGER.error("Fail to delete service instance."); - return Response.serverError().build(); - } - return Response.accepted().entity(result).build(); - } - - public IServiceGateway getServiceGateway() - { - return serviceGateway; - } - - public void setServiceGateway(IServiceGateway serviceGateway) - { - this.serviceGateway = serviceGateway; - } - -} 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 deleted file mode 100644 index 0e8b03ce..00000000 --- a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/roa/inf/IServiceGatewayRoaModule.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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.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 - */ - @POST - @Produces({"application/json"}) - @Consumes({"application/json"}) - @Path("/{serviceId}/terminate") - 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 deleted file mode 100644 index aea5ee98..00000000 --- a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/service/impl/ServiceGatewayImpl.java +++ /dev/null @@ -1,196 +0,0 @@ -/* - * 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.HashMap; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; - -import org.apache.commons.lang.StringUtils; -import org.openo.baseservice.remoteservice.exception.ExceptionArgs; -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.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.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."); - throw new ServiceException("ServiceGatewayImpl createService reqContent is 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 { - LOGGER.info("Send the cretation RESTful request to orchestrator.The Body is"+ requestBody.toString()); - RestfulResponse restfulRsp = RestfulFactory.getRestInstance("http").post(gatewayUri, - getRestfulParameters(JsonUtil.marshal(requestBody))); - LOGGER.info("Receive the cretation RESTful response from orchestrator.The status is:"+restfulRsp.getStatus()+" the content is:"+ - restfulRsp.getResponseContent()); - if (null != restfulRsp) - { - // Record the result of registration - // (201:success;415:Invalid Parameter;500:Internal Server Error) - LOGGER.info("restful call result:"+ restfulRsp.getStatus()); - if(restfulRsp.getStatus() == HttpCode.RESPOND_ACCEPTED || restfulRsp.getStatus() == HttpCode.RESPOND_OK || restfulRsp.getStatus() == HttpCode.CREATED_OK) - { - Map<String,Object> rspBody = JsonUtil.unMarshal(restfulRsp.getResponseContent(),Map.class); - id = (String)rspBody.get(Constant.SERVICE_ID); - id = (null == id) ? (String)rspBody.get(Constant.NS_INSTANCE_ID) : id; - id = (null == id) ? (String)rspBody.get(Constant.JOB_ID) : id; - } - else - { - ExceptionArgs args = new ExceptionArgs(); - args.setDescArgs(new String[] {"Fail to create service:" + restfulRsp.getResponseContent()}); - throw new ServiceException(ServiceException.DEFAULT_ID, restfulRsp.getStatus(), args); - } - } - } 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 Map<String, Object> deleteService(String serviceId, String reqContent, HttpServletRequest httpRequest) throws ServiceException { - if(httpRequest == null) - { - LOGGER.error("ServiceGatewayImpl.deleteService httpRequest is null"); - throw new ServiceException("ServiceGatewayImpl.deleteService httpRequest is null"); - } - // Parse request - Map<String, Object> requestBody = JsonUtil.unMarshal(reqContent, Map.class); - ValidateUtil.assertObjectNotNull(requestBody); - - // Validate data - String gatewayUri = (String)requestBody.get(Constant.SERVICE_GATEWAY_URI); - ValidateUtil.assertStringNotNull(gatewayUri); - requestBody.remove(Constant.SERVICE_GATEWAY_URI); - - String operation = (String) requestBody.get(Constant.SERVICE_OPERATION); - ValidateUtil.assertStringNotNull(operation); - requestBody.remove(Constant.SERVICE_OPERATION); - - // call the restful - try { - RestfulResponse restfulRsp = null; - Map<String, Object> result = new HashMap<String, Object>(); - if(Constant.SERVICE_DELETE_OPERATION.equalsIgnoreCase(operation)) { - restfulRsp = RestfulFactory.getRestInstance("http").delete(gatewayUri, - getRestfulParameters(JsonUtil.marshal(requestBody))); - result.put(Constant.RESPONSE_STATUS, "success"); - result.put(Constant.RESPONSE_STATUS_DESCRIPTION, "It is deleting."); - result.put(Constant.RESPONSE_ERRORCODE, "202"); - } else { - restfulRsp = RestfulFactory.getRestInstance("http").post(gatewayUri, - getRestfulParameters(JsonUtil.marshal(requestBody))); - if (null != restfulRsp) { - Map<String,Object> rspBody = JsonUtil.unMarshal(restfulRsp.getResponseContent(),Map.class); - String jobId = (String)rspBody.get(Constant.JOB_ID); - result.put(Constant.JOB_ID, jobId); - } - } - if (null != restfulRsp) { - LOGGER.info("restful call result: {}", restfulRsp.getStatus()); - LOGGER.info("restful call content:{}", restfulRsp.getResponseContent()); - } - return result; - } catch(ServiceException e) { - LOGGER.error("service gateway delete restful call result:", e); - throw e; - } - } - -} 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 deleted file mode 100644 index a5f6b6fa..00000000 --- a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/service/inf/IServiceGateway.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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; - -import java.util.Map; - -/** - * 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 - */ - Map<String, Object> deleteService(String serviceId, String reqContent, 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 deleted file mode 100644 index d255f31a..00000000 --- a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/util/http/HttpUtil.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * 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 deleted file mode 100644 index eb753aa8..00000000 --- a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/util/http/ResponseUtils.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * 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.Arrays; -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, Arrays.asList(exception.getExceptionArgs().getDescArgs()).toString()); - } - } - result.put(Constant.RESPONSE_ERRORCODE, errorCode); - return result; - } - - /** - * Assemble operation result.<br/> - * - * @param objectId instance ID - * @param operateCode operation result - * @return Response result - * @since GSO 0.5 - */ - public static Map<String, Object> setResult(String objectId, Object operateCode) { - Map<String, Object> result = new HashMap<String, Object>(); - result.put(Constant.RESPONSE_RESULT, operateCode); - String serviceId = (null != objectId) ? objectId : null; - result.put(Constant.SERVICE_INSTANCE_ID, serviceId); - - return result; - } -} diff --git a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/util/json/JsonUtil.java b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/util/json/JsonUtil.java deleted file mode 100644 index 683f5d9b..00000000 --- a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/util/json/JsonUtil.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * 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/java/org/openo/gso/gui/servicegateway/util/register/RegisterUtil.java b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/util/register/RegisterUtil.java deleted file mode 100644 index 4e8b6bd3..00000000 --- a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/util/register/RegisterUtil.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.openo.gso.gui.servicegateway.util.register; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.net.InetAddress; -import java.net.UnknownHostException; - -import org.apache.commons.lang.StringUtils; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.openo.baseservice.roa.util.restclient.RestfulFactory; -import org.openo.baseservice.roa.util.restclient.RestfulParametes; -import org.openo.baseservice.roa.util.restclient.RestfulResponse; -import org.openo.gso.commsvc.common.constant.Constant; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Register Tool <br/> - * - * @author - * @since GSO 0.5, 2016-8-9 - */ -public class RegisterUtil { - - /** - * Logger - */ - private static final Logger LOGGER = LoggerFactory.getLogger(RegisterUtil.class); - - private RegisterUtil() { - } - - /** - * register the service to M-Bus by the parameter<br/> - * - * @author - * @param jsonInfo - * register body Data - * @since GSO 0.5, 2016-8-9 - */ - public static void registerService(final String jsonInfo) { - // check the parameter - if (StringUtils.isEmpty(jsonInfo)) { - LOGGER.error("RegisterUtil registerService jsonInfo is null"); - return; - } - - // replace the remote IP Address by the jsonInfo - String bodyData = jsonInfo; - boolean isIPExist = bodyData.indexOf(Constant.SERVICE_KEY_IP) > Constant.ZERO; - try { - // get the local IP address - String localIP = InetAddress.getLocalHost().getHostAddress(); - - // if the jsonInfo have the getInputIP string,start to replace the - // local IP - if (isIPExist) { - if (!StringUtils.isEmpty(localIP)) { - bodyData = bodyData.replace(Constant.SERVICE_KEY_IP, localIP); - } else { - LOGGER.error("RegisterUtil registerService localIP is null"); - return; - } - } - } catch (UnknownHostException e) { - LOGGER.error("RegisterUtil registerService getHostAddress fail:", e); - if (isIPExist) { - // if get local IP failed In the isIPExist is true ,operation is - // stopped. - return; - } - } - - // register the service to M-bus by the restful Interface - try { - RestfulResponse restfulRsp = RestfulFactory.getRestInstance("http").post(Constant.M_BUS_REGISTER_URL, - getRestfulParameters(bodyData)); - if (null != restfulRsp) { - // Record the result of registration - // (201:success;415:Invalid Parameter;500:Internal Server Error) - LOGGER.info("RegisterUtil registerService register result:", restfulRsp.getStatus()); - } - } catch (ServiceException e) { - LOGGER.error("RegisterUtil registerService post fail:", e); - } - } - - /** - * get the parameters for restful<br/> - * - * @author - * @param bodyData - * Json Body - * @return the RestfulParametes Instance - * @since GSO 0.5, 2016-8-9 - */ - private static RestfulParametes getRestfulParameters(final String bodyData) { - RestfulParametes param = new RestfulParametes(); - param.putHttpContextHeader(Constant.HEAD_ERMAP_TYPE, Constant.HEAD_ERMAP_VALUE); - param.setRawData(bodyData); - return param; - } - - /** - * read the service file<br/> - * - * @param path - * the service File Path - * @return jsonString - * @since GSO 0.5, 2016-8-9 - */ - public static String readFile(String path) { - // check parameter - if (StringUtils.isEmpty(path)) { - return null; - } - - File file = new File(path); - BufferedReader reader = null; - String laststr = ""; - try { - reader = new BufferedReader(new FileReader(file)); - String tempString = null; - // Read one line at a time until the end of the null file. - while ((tempString = reader.readLine()) != null) { - // add the line - laststr = laststr + tempString; - } - reader.close(); - } catch (IOException e) { - LOGGER.error("GSO ReadFile fail.", e); - } finally { - if (reader != null) { - try { - reader.close(); - } catch (IOException e1) { - LOGGER.error("GSO ReadFile reader close fail.", e1); - } - } - } - return laststr; - } -} diff --git a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/util/validate/ValidateUtil.java b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/util/validate/ValidateUtil.java deleted file mode 100644 index 461163ea..00000000 --- a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/util/validate/ValidateUtil.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.openo.gso.gui.servicegateway.util.validate; - -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.openo.gso.gui.servicegateway.exception.ErrorCode; -import org.openo.gso.gui.servicegateway.exception.HttpCode; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.util.StringUtils; - -/** - * Validate Util <br/> - * <p> - * </p> - * - * @author - * @version GSO 0.5 2016/8/19 - */ -public class ValidateUtil { - - /** - * Log server. - */ - private static final Logger LOGGER = LoggerFactory.getLogger(ValidateUtil.class); - - /** - * Constructor<br/> - * <p> - * </p> - * - * @since GSO 0.5 - */ - private ValidateUtil() { - - } - - /** - * Assert String parameter.<br/> - * - * @param param parameter data - * @throws ServiceException when parameter is null or empty. - * @since GSO 0.5 - */ - public static void assertStringNotNull(String param) throws ServiceException { - if(StringUtils.hasLength(param)) { - return; - } - - LOGGER.error("Parameter is null or empty."); - throw new ServiceException(ErrorCode.SVCMGR_SERVICEMGR_BAD_PARAM, HttpCode.BAD_REQUEST); - } - - /** - * Assert object is null.<br/> - * - * @param object data object - * @throws ServiceException when object is null. - * @since GSO 0.5 - */ - public static void assertObjectNotNull(Object object) throws ServiceException { - if(null == object) { - LOGGER.error("Object is null."); - throw new ServiceException(ErrorCode.SVCMGR_SERVICEMGR_BAD_PARAM, "Object is null."); - } - - } - -} diff --git a/servicegateway/service/src/main/resources/META-INF/auth.properties b/servicegateway/service/src/main/resources/META-INF/auth.properties deleted file mode 100644 index 121f2944..00000000 --- a/servicegateway/service/src/main/resources/META-INF/auth.properties +++ /dev/null @@ -1,18 +0,0 @@ -############################################################################### -# /* -# * 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/log4j.properties b/servicegateway/service/src/main/resources/log4j.properties deleted file mode 100644 index ee3b9462..00000000 --- a/servicegateway/service/src/main/resources/log4j.properties +++ /dev/null @@ -1,21 +0,0 @@ -# Copyright 2016 Huawei Technologies Co., Ltd. - -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at - -# http://www.apache.org/licenses/LICENSE-2.0 - -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -log4j.rootLogger=INFO,root -log4j.appender.root.Append=true -log4j.appender.root.File=${catalina.base}/logs/servicegateway.log -log4j.appender.root.layout.ConversionPattern=%d %-5p [%t][%X{moduleID}][%C %L] %m%n -log4j.appender.root.layout=org.apache.log4j.PatternLayout -log4j.appender.root.MaxBackupIndex=50 -log4j.appender.root.MaxFileSize=20MB -log4j.appender.root=org.apache.log4j.RollingFileAppender
\ No newline at end of file diff --git a/servicegateway/service/src/main/resources/service-configure.properties b/servicegateway/service/src/main/resources/service-configure.properties deleted file mode 100644 index 45c2564b..00000000 --- a/servicegateway/service/src/main/resources/service-configure.properties +++ /dev/null @@ -1,17 +0,0 @@ -###############################################################################
-# /*
-# * 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 deleted file mode 100644 index 7ebfc4f8..00000000 --- a/servicegateway/service/src/main/resources/spring/service.xml +++ /dev/null @@ -1,56 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - Copyright 2016 Huawei Technologies Co., Ltd. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---> -<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="serviceGatewayRoaModuleImpl"></ref> - </jaxrs:serviceBeans> - <!-- registering providers --> - <jaxrs:providers> - <bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider" /> - </jaxrs:providers> - </jaxrs:server> - - <bean class="org.openo.gso.gui.servicegateway.activator.Activator"></bean> - - <bean id="Activator" class="org.openo.gso.gui.servicegateway.activator.Activator" init-method="start" destroy-method="stop"> - </bean> - - <bean id="serviceGatewayRoaModuleImpl" class="org.openo.gso.gui.servicegateway.roa.impl.ServiceGatewayRoaModuleImpl"> - <property name="serviceGateway" ref="serviceGateway"></property> - </bean> - - <bean id="serviceGateway" class="org.openo.gso.gui.servicegateway.service.impl.ServiceGatewayImpl"> - </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 deleted file mode 100644 index 174ba383..00000000 --- a/servicegateway/service/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,47 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - Copyright 2016 Huawei Technologies Co., Ltd. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---> - -<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> - <init-param> - <param-name>hide-service-list-page</param-name> - <param-value>true</param-value> - </init-param> - </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> |