aboutsummaryrefslogtreecommitdiffstats
path: root/servicegateway
diff options
context:
space:
mode:
authorjin xin <j00101220@huawei.com>2016-12-20 01:25:02 +0000
committerGerrit Code Review <gerrit@open-o.org>2016-12-20 01:25:02 +0000
commit10524fbb1df4d120a1f404f917066bfbde239c7c (patch)
treee413953e67b3f36782ab77560219192836c1e5a3 /servicegateway
parent31b545d8d7f7277706afb1298fa5eda85c78fe0f (diff)
parent32581b6364e1389276e476d8dc7912aab3f6224d (diff)
Merge "fix issue : GSO-124"
Diffstat (limited to 'servicegateway')
-rw-r--r--servicegateway/deployment/src/main/release/etc/conf/restclient.json2
-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/roa/impl/ServiceGatewayRoaModuleImpl.java2
-rw-r--r--servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/service/impl/ServiceGatewayImpl.java30
-rw-r--r--servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/util/http/ResponseUtils.java4
5 files changed, 28 insertions, 12 deletions
diff --git a/servicegateway/deployment/src/main/release/etc/conf/restclient.json b/servicegateway/deployment/src/main/release/etc/conf/restclient.json
index b30e05c0..c7e61a56 100644
--- a/servicegateway/deployment/src/main/release/etc/conf/restclient.json
+++ b/servicegateway/deployment/src/main/release/etc/conf/restclient.json
@@ -7,5 +7,5 @@
"ConnectTimeout":"1000",
"thread":"10",
"idletimeout":"500000",
- "timeout":"10000"
+ "timeout":"600000"
} \ No newline at end of file
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/roa/impl/ServiceGatewayRoaModuleImpl.java b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/roa/impl/ServiceGatewayRoaModuleImpl.java
index bd91ff2c..059e6fdc 100644
--- a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/roa/impl/ServiceGatewayRoaModuleImpl.java
+++ b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/roa/impl/ServiceGatewayRoaModuleImpl.java
@@ -124,6 +124,6 @@ public class ServiceGatewayRoaModuleImpl implements IServiceGatewayRoaModule {
public void setServiceGateway(IServiceGateway serviceGateway)
{
this.serviceGateway = serviceGateway;
- }
+ }
}
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 4f592f5b..aea5ee98 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,13 +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());
- id = restfulRsp.getRespHeaderStr(Constant.SERVICE_ID);
- id = (null == id) ? restfulRsp.getRespHeaderStr(Constant.NS_INSTANCE_ID) : id;
- id = (null == id) ? restfulRsp.getRespHeaderStr(Constant.JOB_ID) : id;
+ 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);
@@ -164,13 +177,14 @@ public class ServiceGatewayImpl implements IServiceGateway {
restfulRsp = RestfulFactory.getRestInstance("http").post(gatewayUri,
getRestfulParameters(JsonUtil.marshal(requestBody)));
if (null != restfulRsp) {
- String jobId = restfulRsp.getRespHeaderStr(Constant.JOB_ID);
+ 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());
+ LOGGER.info("restful call result: {}", restfulRsp.getStatus());
+ LOGGER.info("restful call content:{}", restfulRsp.getResponseContent());
}
return result;
} catch(ServiceException e) {
diff --git a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/util/http/ResponseUtils.java b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/util/http/ResponseUtils.java
index 05d4f0f9..eb753aa8 100644
--- a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/util/http/ResponseUtils.java
+++ b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/util/http/ResponseUtils.java
@@ -16,6 +16,7 @@
package org.openo.gso.gui.servicegateway.util.http;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
@@ -148,11 +149,10 @@ public class ResponseUtils {
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_STATUS_DESCRIPTION, Arrays.asList(exception.getExceptionArgs().getDescArgs()).toString());
}
}
result.put(Constant.RESPONSE_ERRORCODE, errorCode);
-
return result;
}