inbound에 json 전문일 때, 최상위에 Array('[]')타입이 바로 올때, 변환처리를 위해,
KJB_ROOTLESS_ARRAY 라는 키의 Object를 warraped 처리
This commit is contained in:
+27
-4
@@ -949,11 +949,23 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
|
||||
if (eaiBody == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (eaiBody instanceof JSONObject) {
|
||||
JSONObject jsonObject = (JSONObject) eaiBody;
|
||||
if( jsonObject.containsKey("KJB_ROOTLESS_ARRAY") ) {
|
||||
ContentType contentTypeObj = ContentType.create(contentType, charset);
|
||||
JSONArray array = (JSONArray) jsonObject.get("KJB_ROOTLESS_ARRAY");
|
||||
StringEntity entity = new StringEntity(array.toJSONString(), contentTypeObj);
|
||||
method.setEntity(entity);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (StringUtils.contains(contentType, "application/x-www-form-urlencoded")) {
|
||||
if (eaiBody instanceof JSONObject) {
|
||||
List<NameValuePair> params = new ArrayList<>();
|
||||
JSONObject jsonObject = (JSONObject) eaiBody;
|
||||
|
||||
for (Object key : jsonObject.keySet()) {
|
||||
//String encryptedValue = encrypt((String) jsonObject.get(key)); // encrypt by jwhong
|
||||
//params.add(new BasicNameValuePair((String) key, encryptedValue ));
|
||||
@@ -1456,11 +1468,22 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private JSONObject parseJson(String message) throws Exception {
|
||||
if (message == null) {
|
||||
return null;
|
||||
}
|
||||
if (message == null || message.trim().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (JSONObject) JSONValue.parse(message);
|
||||
Object obj = JSONValue.parse(message);
|
||||
|
||||
if (obj instanceof JSONObject) {
|
||||
return (JSONObject) obj;
|
||||
} else if (obj instanceof JSONArray) {
|
||||
// 배열일 경우 새로운 객체로 감싸서 반환
|
||||
JSONObject wrapper = new JSONObject();
|
||||
wrapper.put("KJB_ROOTLESS_ARRAY", obj);
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
return null; // 혹은 상황에 맞는 예외 처리
|
||||
}
|
||||
|
||||
private Document convertXmlDocument(String message) throws Exception {
|
||||
|
||||
+30
-1
@@ -19,6 +19,9 @@ import com.eactive.eai.inbound.processor.Processor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.time.StopWatch;
|
||||
import org.apache.mina.common.ByteBuffer;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletInputStream;
|
||||
@@ -180,6 +183,21 @@ public class HttpAdapterServiceStandard extends HttpAdapterServiceSupport
|
||||
prop.put(PROPERTIES_NAME_HTTP_REQUEST_METHOD, request.getMethod());
|
||||
prop.put(ALLOW_IP, httpProp.getProperty(ALLOW_IP, ""));
|
||||
|
||||
String body = new String ( requestBytes,encode);
|
||||
|
||||
try {
|
||||
Object root = JSONValue.parse(body);
|
||||
if( root instanceof JSONArray ) {
|
||||
JSONObject wrappedObject = new JSONObject();
|
||||
wrappedObject.put("KJB_ROOTLESS_ARRAY", root);
|
||||
requestBytes = wrappedObject.toJSONString().getBytes(encode);
|
||||
}
|
||||
|
||||
}catch (Exception e) {
|
||||
// ignore json이 아니기에 해줄것이 없음.
|
||||
}
|
||||
|
||||
|
||||
// 로컬 서비스 호출
|
||||
Object result = null;
|
||||
if (MessageUtil.isBytesMessage(messageType)) {
|
||||
@@ -208,7 +226,7 @@ public class HttpAdapterServiceStandard extends HttpAdapterServiceSupport
|
||||
responseData = ElinkConfig.getAsyncDummyDataForAdapterGroup(adptGrpName, adptName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
response.setCharacterEncoding(encode);
|
||||
response.getWriter().print(responseData);
|
||||
if (traceLevel >= 3){
|
||||
@@ -230,6 +248,17 @@ public class HttpAdapterServiceStandard extends HttpAdapterServiceSupport
|
||||
responseData = addData + responseData;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
Object root = JSONValue.parse(responseData);
|
||||
if( root instanceof JSONObject ) {
|
||||
JSONObject wrappedObject = (JSONObject) root;
|
||||
responseData = wrappedObject.get("KJB_ROOTLESS_ARRAY").toString();
|
||||
}
|
||||
|
||||
}catch (Exception e) {
|
||||
// ignore json이 아니기에 해줄것이 없음.
|
||||
}
|
||||
// 300응답에서 받은 Header정보 사용하기 위해 읽어옴.
|
||||
Map<String, Object> responsePropertyMap = new HashMap<String, Object>();
|
||||
responsePropertyMap = (Map<String, Object>) prop.get(OUTBOUND_PROPERTY_MAP);
|
||||
|
||||
Reference in New Issue
Block a user