//
//package com.eactive.eai.adapter.http.client.impl; 
//
//import java.io.StringReader;
//import java.net.ConnectException;
//import java.net.SocketTimeoutException;
//import java.net.URLDecoder;
//import java.net.URLEncoder;
//import java.util.Arrays;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//import java.util.Properties;
//
//import org.apache.commons.httpclient.HttpClient;
//import org.apache.commons.httpclient.HttpMethodBase;
//import org.apache.commons.httpclient.HttpStatus;
//import org.apache.commons.httpclient.HttpVersion;
//import org.apache.commons.httpclient.NameValuePair;
//import org.apache.commons.httpclient.methods.DeleteMethod;
//import org.apache.commons.httpclient.methods.EntityEnclosingMethod;
//import org.apache.commons.httpclient.methods.GetMethod;
//import org.apache.commons.httpclient.methods.PostMethod;
//import org.apache.commons.httpclient.methods.PutMethod;
//import org.apache.commons.httpclient.protocol.Protocol;
//import org.apache.commons.lang.StringUtils;
//import org.apache.commons.lang.time.StopWatch;
//import org.dom4j.Document;
//import org.dom4j.Element;
//import org.dom4j.io.SAXReader;
//import org.json.simple.JSONObject;
//import org.json.simple.JSONValue;
//import org.springframework.web.util.UriComponents;
//import org.springframework.web.util.UriComponentsBuilder;
//
//import com.eactive.eai.adapter.http.HttpMemoryLogger;
//import com.eactive.eai.adapter.http.HttpMethodType;
//import com.eactive.eai.adapter.http.HttpStatusException;
//import com.eactive.eai.adapter.http.client.HttpClientAdapterServiceKey;
//import com.eactive.eai.adapter.http.client.HttpClientAdapterServiceSupport;
//import com.eactive.eai.adapter.http.client.HttpClientAdapterVO;
//import com.eactive.eai.adapter.http.secure.CustomHttpsSocketFactory;
//import com.eactive.eai.adapter.http.secure.EasySSLProtocolSocketFactory;
//import com.eactive.eai.common.exception.ExceptionUtil;
//import com.eactive.eai.common.message.MessageType;
//import com.eactive.eai.common.util.CommonLib;
//import com.openbanking.eai.common.token.AccessTokenManager;
//import com.openbanking.eai.common.token.OAuth2AccessTokenVO;
//
//
///** 
//* 1. 기능 : EAI HTTP OutBound 용 어댑터로 수동 시스템의 HTTP 웹 컴포넌트를 
//*           GET/POST 방식으로 호출할 수 있는 기능을 제공한다.
//* 2. 처리 개요 : 
//* *     - 2009.11.24 retry 로직 제거  : 요청
//* 3. 주의사항 
//*
//* @author  : 
//* @version : v 1.0.0
//* @see : 
//* @since   : 
//
//*/
//public class HttpClientAdapterServiceRestForCODEF extends HttpClientAdapterServiceSupport implements HttpClientAdapterServiceKey { 
//	
//	public static final String TYPE_VARIABLE_URL_REQUEST = "variableUrlRequest";
//	public static final String TYPE_SIMPLE_REQUEST    = "simpleRequest";
//	
//    public static final String HTTP_HEADER            = "HTTP_HEADER";
//    public static final String EAI_HEADER             = "EAI_HEADER";
//    public static final String EAI_BODY               = "EAI_BODY";
//    
//    public static final String REST_OPTION            = "REST_OPTION";
//    public static final String REST_TYPE              = "type";
//    public static final String REST_EXTRA_PATH        = "extraPath";
//    public static final String REST_METHOD            = "method";
//    
//	public static final String HEADER_CONTENT_TYPE    = "Content-Type";
//	public static final String HEADER_ACEPT           = "Acept";
//    
//    public static final List<String> RETRY_RESPONSE_CODE = Arrays.asList("invalid_token");
//	
//    /** 
//    * 1. 기능 :  전문과 같은 Raw Data 통신에 사용
//    * 2. 처리 개요 : 
//    *     - 속성 정보를 설정 하고 수동 시스템 서비스를 호출 한다.
//    * 3. 주의사항 
//    *
//    * @param    prop    Http Adapter 속성 정보
//    * @param    message 송신 전문
//    * @return   반환 된 byte[] Object
//    * @exception    Exception 수동 시스템 간 통신 중 발생
//    **/
//    public Object execute(Properties prop, byte[] data, Properties tempProp) throws Exception {
//    	HttpClientAdapterVO vo = super.setting(prop, tempProp);
//        
//        // 레이아웃 메세지 타입 REST URL 추출 시 활용. Default JSON
//        String messageType          = prop.getProperty("MESSAGE_TYPE", MessageType.JSON);	
//        /* TSEAIHE02.RESTOPTION 정보 -> JSON 형태로 구성
//         * 		type : simpleRequest, variableUrlRequest
//         * 		extraPath : 어댑터 프로퍼티 URL에 추가될 HTTP REST URL
//         * 		method : get, delete, post, put
//         * 
//         * ex) {"type":"simpleRequest", "extraPath":"v2.0/account/balance", "method": "post"}
//         */
////        String restOptionData       = tempProp.getProperty(REST_OPTION);
//        String restOptionData       = prop.getProperty(REST_OPTION);
//        
//        JSONObject restOptionObject = parseJson(restOptionData);
//        if(restOptionObject == null) {
//        	throw new Exception("OptionData parsing result is NULL");
//        }
//        String rmethod              = restOptionObject.containsKey("method") 
//        		? StringUtils.upperCase((String) restOptionObject.get("method")) 
//        				: "POST";
//        
//		String sendData    = new String(data);
//        Object eaiHeader   = null;
//    	Object eaiBody     = null;
//        HttpClient mclient = this.client;
//        		
//        HashMap<String,String> header = new HashMap<String,String>();
////        for(Object obj :  headerObject.keySet()){
////        	String key = (String)obj;
////        	header.put(key, (String)headerObject.get(key));
////        }
//        //interface 에 설정된게 우선한다.
//        String uri = changeUrl(messageType, vo.getUrl(), restOptionData, sendData);
//        
//        HttpMethodBase method = null;
//        switch (HttpMethodType.getValue(rmethod)) {
//        case GET :
//        	method = new GetMethod(uri);
//        	break;
//        case DELETE : 
//        	method = new DeleteMethod(uri);
//        	break;
//        case POST :
//        	method = new PostMethod(uri);
//        	break;
//        case PUT :
//        	method = new PutMethod(uri);
//        	break;
//        default :
//        	// set default method 
//        	method = new GetMethod(uri);
//        	break;
//        }
//
//        //2008.02.15 : Timeout 처리로직 변경 (0 : 무한대 설정가능하게 함)
//        if(vo.getTimeout() > -1) {
//        	method.getParams().setSoTimeout(vo.getTimeout());
//        }
//        
//        if ( vo.getConnectionTimeout() != 0) {
//        	method.getParams().setParameter("http.connection.timeout", vo.getConnectionTimeout());
//        }
//        method.getParams().setParameter("http.protocol.version", HttpVersion.HTTP_1_0);
//      
//        if(uri != null && uri.startsWith("https")){
//        	Protocol.registerProtocol("https", new Protocol("https",
//        			new CustomHttpsSocketFactory(new EasySSLProtocolSocketFactory()), 443));
//        }
//        
//        if (logger.isDebug()&& "N".equals(vo.getTestCallYn())) {
//        	logger.debug("HttpClientAdapterServiceRestForCODEF] SEND ("+vo.getAdapterGroupName() +") URL=["+vo.getUrl()+"] ");
//        	logger.debug("HttpClientAdapterServiceRestForCODEF] SEND ("+vo.getAdapterGroupName() +") PARAMETER_NAME=["+vo.getParameterName()+"] ");
//        	logger.debug("HttpClientAdapterServiceRestForCODEF] SEND ("+vo.getAdapterGroupName() +") ENCODE=["+vo.getEncode()+"] ");
//        	logger.debug("HttpClientAdapterServiceRestForCODEF] SEND ("+vo.getAdapterGroupName() +") RESPONSE_TYPE=["+vo.getResponseType()+"] ");
//        	logger.debug("HttpClientAdapterServiceRestForCODEF] SEND ("+vo.getAdapterGroupName() +") URL_ENCODE_YN=["+vo.getUrlEncodeYn()+"] ");
//        	logger.debug("HttpClientAdapterServiceRestForCODEF] SEND ("+vo.getAdapterGroupName() +") CONNECTION_TIMEOUT=["+vo.getConnectionTimeout()+"] ");
//        	logger.debug("HttpClientAdapterServiceRestForCODEF] SEND ("+vo.getAdapterGroupName() +") REST_OPTION=["+restOptionData+"] ");
//        }
//        
//        if(vo.getEncode() != null && vo.getEncode().length() > 0) {
//            try {
//            	mclient.getParams().setContentCharset(vo.getEncode());
//            	sendData = new String(data, vo.getEncode());                    
//            } catch(Exception e) {
//                if(logger.isError()){
//                    logger.error("HttpClientAdapterServiceRestForCODEF] ENCODE("+vo.getEncode()+") ERROR : "+ e.toString());
//                    logger.error("HttpClientAdapterServiceRestForCODEF] ENCODE("+vo.getEncode()+") SKIP ");
//                }
//            }
//        }
//        
////        if ("Y".equals(urlEncodeYn)) {
////        	sendData = java.net.URLEncoder.encode(sendData);
////        }
//        
//        /* 레이아웃 메시지 타입이 JSON 형태만 처리 구현. REST를 처리하기 위해 아래 구성을 따라야함
//         * REST 레이아웃 구성
//         * 		HTTP_HEADER (X) : HTTP 헤더에 추가 정보가 필요할 경우 정의
//         * 		EAI_HEADER
//         * 		EAI_BODY
//         */
//        if (MessageType.JSON.equals(messageType)) {
//        	JSONObject dataObject = parseJson(sendData);
//        	if(dataObject != null) {
//	        	eaiHeader  = dataObject.containsKey(EAI_HEADER) ? dataObject.get(EAI_HEADER) : null;
//	        	eaiBody    = dataObject.containsKey(EAI_BODY)   ? dataObject.get(EAI_BODY)   : null;
//        	}
//        }
//        
//        switch (HttpMethodType.getValue(rmethod)) {
//        case GET :
//        case DELETE : 
//        	HashMap<String,String> h = getParameters(eaiHeader);
//        	NameValuePair[] params = new NameValuePair[h.size()];
//        	int count =0;
//        	for(String key : h.keySet()){
//        		String value = h.get(key);
//        		params[count] = new NameValuePair(key, URLEncoder.encode(value, vo.getEncode()));
//        		count++;
//        	}
//        	method.setQueryString(params);
//        	break;
//        case PUT :
//        case POST :
//        	// OpenAPI는 json 타입. type이 다른 경우 헤더정보를 별도로 받아야함
//            method.setRequestHeader(HEADER_CONTENT_TYPE, "application/json; charset="+vo.getEncode());
//        	if(eaiBody != null) {
//        		((EntityEnclosingMethod) method).setRequestBody(URLEncoder.encode(eaiBody.toString(), vo.getEncode()));
//        	}
//        	
//        	break;
//        default :
//        	break;
//        }
//        
//        AccessTokenManager tokenManager = AccessTokenManager.getInstance();
//        OAuth2AccessTokenVO accessToken = (OAuth2AccessTokenVO) tokenManager.getAccessTokenVO(vo.getAdapterGroupName());
//
//        // 토큰이 없거나 토큰이 만료 됐으면 재발급
//        if (accessToken == null || accessToken.isExpired()) {
//        	accessToken = (OAuth2AccessTokenVO) tokenManager.retryAccessTokenVO(vo.getAdapterGroupName(), prop);
//        }
//        
//        method.setRequestHeader("Authorization", accessToken.getAuthorization());
//        
//        if (logger.isDebug()&& "N".equals(vo.getTestCallYn())) {
//        	logger.debug("HttpClientAdapterServiceRestForCODEF] SEND ("+vo.getAdapterGroupName() +") TOKEN=["+accessToken+"] ");
//        }
//		
//		// header 셋팅
//        if (header.size() > 0) {
//        	for (String key : header.keySet()) {
//        		method.setRequestHeader(key, header.get(key));
//        	}
//        }
//        
//        int status = -1;
//        
//        try {
//    
//            if (logger.isDebug() && "N".equals(vo.getTestCallYn())) {
//                logger.debug("HttpClientAdapterServiceRestForCODEF] SEND ("+vo.getAdapterGroupName()+") = ["+sendData+"]");
//                logger.debug("HttpClientAdapterServiceRestForCODEF] SEND ("+vo.getAdapterGroupName()+") = "+CommonLib.getDumpMessage(sendData.getBytes()));
//            }            
//    		StopWatch stopWatch = new StopWatch();
//    		stopWatch.start();
//    		
//    		if (vo.getTraceLevel() >= 3) {
//    			HttpMemoryLogger.txlog(vo.getAdapterGroupName()+vo.getAdapterName(), "SEND ["+sendData+"]"+CommonLib.getDumpMessage(sendData.getBytes()));
//    		}    
//			status = mclient.executeMethod(method);
//
//            stopWatch.stop();
//            
//            //status 200(정상) 이외에는 error 처리 
//            if (status !=200){
//            	try{
//            		logger.error("HttpClientAdapterServiceRestForCODEF] receive status["+status+"] data[" + new String(method.getResponseBody()) +"]");
//            	}catch(Exception e){
//            		logger.error(e);
//            	}
//               	throw new HttpStatusException("수신시스템을 확인하세요. HTTP 에러[ " + status + "] adapterName="+vo.getAdapterGroupName()+"."+vo.getAdapterName(),status);
//            }
//            
//            byte[] responseMessage = method.getResponseBody();
//            
//            //----------------------------------------------------------
//            if (logger.isDebug() && "N".equals(vo.getTestCallYn())) {
//            	logger.debug("HttpClientAdapterServiceRestForCODEF] responseType ="+ vo.getResponseType());
//                logger.debug("HttpClientAdapterServiceRestForCODEF] RECV ("+vo.getAdapterGroupName()+") = ["+new String(responseMessage)+"]");
//                logger.debug("HttpClientAdapterServiceRestForCODEF] RECV ("+vo.getAdapterGroupName()+") = "+CommonLib.getDumpMessage(responseMessage));
//            }
//            if ("ASYNC".equals(vo.getResponseType())) {
//            	if (stopWatch.getTime() > vo.getSlowTranTime()) {
//            		if (logger.isInfo()){
//            			logger.info("HttpClientAdapterServiceRestForCODEF] dummy response time = " + stopWatch.toString()+ " responseMessage=" + new String(responseMessage));
//            		}
//            	}
//            	if ( ! java.util.Arrays.equals(ElinkConfig.getAsyncDummyDataForAdapterGroup(adptGrpName).getBytes(), responseMessage)){
//            		if (vo.getTraceLevel() >= 3) {
//            			HttpMemoryLogger.error(vo.getAdapterGroupName()+vo.getAdapterName(),"http return fail value= ["+responseMessage+"]" + CommonLib.getDumpMessage(responseMessage));
//            		}
//            		throw new Exception ("http return fail value= " + new String(responseMessage));
//            	}
//        		if (vo.getTraceLevel() >= 3) {
//        			HttpMemoryLogger.txlog(vo.getAdapterGroupName()+vo.getAdapterName(),"RECV ["+new String(responseMessage)+"]"+CommonLib.getDumpMessage(responseMessage));
//        		}                	
//            	return null;
//            } else {
//            	/* OAuth 토큰 응답 체크
//            	 * 
//            	 * OAuth 응답 코드
//            	 * invalid_token
//            	 */
//	            JSONObject message = parseJson(URLDecoder.decode(new String(responseMessage), vo.getEncode()));
//	            if(message == null) {
//	            	throw new Exception("responseMessage parsing result is NULL");
//	            }
//	            
//	            String rspCode    = (String) message.get("error");
//	            String rspMessage = (String) message.get("message");
//				
//	            // OAuth 토큰 재요청 코드 확인
//	            if (RETRY_RESPONSE_CODE.contains(rspCode)) {
//	            	if (logger.isDebug() && "N".equals(vo.getTestCallYn())) {
//	                    logger.debug("HttpClientAdapterServiceRestForCODEF] retry access token response code= ["+rspCode+"] message= ["+rspMessage+"]");
//	            	}
//	        		
//	            	// 토큰 재발급
//	            	accessToken = (OAuth2AccessTokenVO) tokenManager.retryAccessTokenVO(vo.getAdapterGroupName(), prop);
//                	method.setRequestHeader("Authorization", accessToken.getAuthorization());
//	            	
//                	if (logger.isDebug()&& "N".equals(vo.getTestCallYn())) {
//                    	logger.debug("HttpClientAdapterServiceRestForCODEF] SEND ("+vo.getAdapterGroupName() +") RETRY TOKEN=["+accessToken+"] ");
//                    }
//                	
//	        		try {
//	        			status = mclient.executeMethod(method);
//	        		} catch (java.net.ConnectException e ) {
//	        			throw new Exception ("retry excuteMethod Exceptioin = " + e.toString());
//	        		}
//	        		
//	        		//status 200(정상) 이외에는 error 처리 
//	                if (status !=200) {
//	                	throw new Exception ("retry http receive status fail value= " + status + " adapterName="+vo.getAdapterGroupName()+"."+vo.getAdapterName() + " uri =" +uri +" method=" +rmethod);
//	                }
//	                
//	                responseMessage = method.getResponseBody();
//	                
//	                if (logger.isDebug() && "N".equals(vo.getTestCallYn())) {
//	                	logger.debug("HttpClientAdapterServiceRestForCODEF] responseType ="+ vo.getResponseType());
//	                    logger.debug("HttpClientAdapterServiceRestForCODEF] retry RECV ("+vo.getAdapterGroupName()+") = ["+new String(responseMessage)+"]");
//	                    logger.debug("HttpClientAdapterServiceRestForCODEF] retry RECV ("+vo.getAdapterGroupName()+") = "+CommonLib.getDumpMessage(responseMessage));
//	                }
//	            }
//            }
//            
//    		if (vo.getTraceLevel() >= 3) {
//    			HttpMemoryLogger.txlog(vo.getAdapterGroupName()+vo.getAdapterName(), "RECV ["+new String(responseMessage)+"]"+CommonLib.getDumpMessage(responseMessage));
//    		}
//    		
//    		String decodedMsg = URLDecoder.decode(new String(responseMessage), vo.getEncode());
//            
//            return decodedMsg.getBytes(vo.getEncode());
//        } catch(SocketTimeoutException ste) { // Read Timeout :: HttpClient 3.1일 경우
//    		if (vo.getTraceLevel() >= 3) {
//    			HttpMemoryLogger.error(vo.getAdapterGroupName()+vo.getAdapterName(),"HttpClientAdapterServiceRestForCODEF] SocketTimeoutException ("+vo.getAdapterGroupName()+") : " + ste.toString(),ste);
//    		}
//    		logger.error("HttpClientAdapterServiceRestForCODEF] SocketTimeoutException ("+vo.getAdapterGroupName()+") : " + ste.toString() ,ste);
//            throw ste;
//        } catch(ConnectException ce) {
//    		if (vo.getTraceLevel() >= 3) {
//    			HttpMemoryLogger.error(vo.getAdapterGroupName()+vo.getAdapterName(),"HttpClientAdapterServiceRestForCODEF] Connection Exception ("+vo.getAdapterGroupName()+") : " + ce.toString(),ce);
//    		}
//    		logger.error("HttpClientAdapterServiceRestForCODEF] Connection Exception ("+vo.getAdapterGroupName()+") : " + ce.toString() ,ce);
//            throw ce;
//        } catch(Exception e) {
//    		if (vo.getTraceLevel() >= 3) {
//    			HttpMemoryLogger.error(vo.getAdapterGroupName()+vo.getAdapterName(),e.toString(),e);
//    		}
//    		logger.error("HttpClientAdapterServiceRestForCODEF] Exception ("+vo.getAdapterGroupName()+") : " + e.toString() ,e);
//            throw e;
//        } finally {
//            if(method != null) method.releaseConnection();
//            if(status != HttpStatus.SC_OK) {
//                String[] msgArgs = new String[1];
//                msgArgs[0] = String.valueOf(status);
//                String resMsg = ExceptionUtil.make("RDCEAIAHA013", msgArgs);
//                if(logger.isDebug()){
//                    logger.debug(resMsg);
//                }
//            }
//        }
//   
//    }
//    
//    private HashMap<String, String> getParameters(Object message) throws Exception {
//		
//		HashMap<String,String> result = new HashMap<String,String>();
//		
//		if (message != null) {
//			if (message instanceof JSONObject) {
//				JSONObject jsonObject = (JSONObject) message;
//	        	for (Object key : jsonObject.keySet()) {
//	        		result.put((String) key, (String) jsonObject.get(key));
//	        	}
//			} else {
//				String[] messages = ((String) message).split("&");
//				String[] data = null;
//				
//				for (int i=0; i< messages.length;i++) {
//					data = messages[i].split("=",2);
//					if (data.length == 2 ){
//						result.put(data[0], data[1]);
//					}
//				}
//			}
//		}
//		
//		return result;
//	}
//    
//    private JSONObject parseJson(String message) throws Exception {
//    	if (message == null) return null;
//    			
//		return (JSONObject) JSONValue.parse(message);
//	}
//	
//    private Document convertXmlDocument(String message) throws Exception{
//		SAXReader builder = new SAXReader(); 
//		Document document = builder.read(new StringReader(message));
//		return document;
//    }
//	
////    private Map<String, String> changeUrlWithMessage(String messageType, String url, String extraPath, String sendData){
////		Map<String, String> responseMap = new HashMap<String, String>();
////		
////		try {
////			if (MessageType.JSON.equals(messageType)) {
////				JSONObject jsonObject = parseJson(sendData);
////				url = changeUrl(messageType, url, extraPath, jsonObject);
////				responseMap.put(URL, url);
////			} else if (MessageType.XML.equals(messageType)) {
////				Document doc = convertXmlDocument(sendData);
////				url = changeUrl(messageType, url, extraPath, doc);
////				responseMap.put(URL, url);
////			}
////		} catch (Exception e) {
////			logger.error("Failed to change url",e);
////		}
////		return responseMap;
////    }
//    
//    private String changeUrl(String messageType, String url, String restOption, Object sendData) {
//    	if ((MessageType.JSON.equals(messageType) || MessageType.XML.equals(messageType))) {
//    		try {
//    			if(StringUtils.isBlank(restOption)) {
//    				return url;
//    			}
//    			JSONObject restOptionObject = parseJson(restOption);
//    			if(restOptionObject == null) throw new Exception("restOption is null");
//    			
//    			String type = (String) restOptionObject.get("type");
//    			String extraPath = (String) restOptionObject.get("extraPath") ;
//    			String method = (String) restOptionObject.get("method");
//    			url = getUrl(url, extraPath);
//    			if (TYPE_VARIABLE_URL_REQUEST.equals(type)) {
//    				HashMap<String, String> uriVariables = new HashMap<String, String>();
//    				if (MessageType.JSON.equals(messageType)) {
//    					JSONObject jsonObject = null;
//    					JSONObject dataObject = null;
//    					if (sendData instanceof JSONObject) {
//    						jsonObject = (JSONObject) sendData;
//    					} else {
//    						jsonObject = (JSONObject) JSONValue.parse((String)sendData);
//    					}
//    					
//    					switch (HttpMethodType.getValue(method)) {
//    			        case GET :
//    			        case DELETE : 
//    			        	dataObject = jsonObject.containsKey(EAI_HEADER) ? (JSONObject) jsonObject.get(EAI_HEADER) : null;
//    			        	break;
//    			        case PUT :
//    			        case POST :
//    			        	dataObject = jsonObject.containsKey(EAI_BODY)   ? (JSONObject) jsonObject.get(EAI_BODY)   : null;
//    			        	break;
//    					}
//    					
//    					if(dataObject != null) {
//	    					for (Object key : dataObject.keySet()) {
//	    						if (url.indexOf("{" + (String) key + "}") > 0) {
//	    							uriVariables.put((String) key, (String) dataObject.get(key));
//	    						}
//	    					}
//    					}
//    				} else if(MessageType.XML.equals(messageType)) {
//    					Document doc ;
//    					if (sendData instanceof Document) {
//    						doc = (Document) sendData;
//    					} else {
//    						doc = convertXmlDocument((String)sendData);
//    					}
//    					if(doc !=null) {
//    						for (Object branch : doc.content()) {
//    							Element element = (Element) branch;
//    							
//    							if (url.indexOf("{" + element.getName() + "}") > 0) {
//    								uriVariables.put(element.getName(), element.getText());
//    							}
//    						}
//    						
////	    					for (Object tempObject : uriVariables) {
////	    						String urlVaribleId = (String) tempObject;
////	    						Element element = (Element) doc.selectSingleNode("//"+urlVaribleId);
////	    						urlVariableList.add(element.getText());
////	    						if (doc.getRootElement() == element) {
//////	    							doc = null;
////	    							break;
////	    						} else {
////	    							element.getParent().remove(element);
////	    						}
////	    					}
//    					}
//    				}
//    				
//    				if (uriVariables.size() > 0) {
//    					UriComponents uriComponents = UriComponentsBuilder.fromUriString(url).buildAndExpand(uriVariables);
//    					url = uriComponents.toUriString();
//    					logger.debug("HttpClientAdapterServiceRestForCODEF] after extand url=["+url+"] ");
//    				}
//    			}
//    		} catch(Exception e) {
//    			logger.error("Failed to change url",e);
//    		}
//    	}
//    	return url;
//    }
//    
//    private String getUrl(String baseUrl, String extraPath) {
//		if (StringUtils.isBlank(extraPath)) {
//			return baseUrl;
//		}
//		if (baseUrl != null && baseUrl.endsWith("/") == false) {
//			baseUrl += "/";
//		}
//		String targetUrl = baseUrl + extraPath;
//		logger.debug("HttpClientAdapterServiceRestForCODEF] after concatenate url=["+targetUrl+"] ");
//		return targetUrl;
//	}
//
//} 
