summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorj00302280 <j00101220@huawei.com>2016-10-31 11:04:38 +0800
committerj00302280 <j00101220@huawei.com>2016-10-31 11:04:38 +0800
commitfb502a095b9d6dfa57dc9ee01d06d45edff46ae2 (patch)
tree813c378c67597b22e162f3cd1dab5e70aad565d3
parente3ad21f93f114361f147371c8e512600ab1c8803 (diff)
Issue ID:GSO-83
Change-Id: I0bc49849255bc2c2c702cc261f2f86b1a967fb12 Signed-off-by: j00302280 <j00101220@huawei.com>
-rw-r--r--servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/exception/HttpCode.java2
-rw-r--r--servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/service/impl/ServiceGatewayImpl.java24
2 files changed, 20 insertions, 6 deletions
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
index 2577903f..473de721 100644
--- 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
@@ -56,6 +56,8 @@ public class HttpCode {
* Http response is ok.
*/
public static final int RESPOND_OK = 200;
+
+ public static final int CREATED_OK = 201;
/**
* Conflict
diff --git a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/service/impl/ServiceGatewayImpl.java b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/service/impl/ServiceGatewayImpl.java
index 5f23ad4e..ae9e6c43 100644
--- a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/service/impl/ServiceGatewayImpl.java
+++ b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/service/impl/ServiceGatewayImpl.java
@@ -22,12 +22,14 @@ 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;
@@ -90,14 +92,24 @@ public class ServiceGatewayImpl implements IServiceGateway {
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) {
+ if (null != restfulRsp)
+ {
// Record the result of registration
// (201:success;415:Invalid Parameter;500:Internal Server Error)
- LOGGER.info("restful call result:"+ restfulRsp.getStatus());
- 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;
+ 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);