Rhapsody of Zephyr

2015년 8월 31일 월요일

This parser does not support specification "null" version "null" 에러발생시 처리방법

Struts2 showcase를 실행해보려고 했는데 에러가 발생하였다.

This parser does not support specification "null" version "null" 구글링 검색결과 톰캣7버전을 사용할 경우, 그리고 classpath에 2개이상의 parser가 있을경우 잘못된 버전을 사용하기 때문이라고 한다. 톰캣 옵션에 다음과 같은 옵션을 추가하면 에러없이 구동이 된다.

















[원문]
If you start Tomcat 7 and got the error: java.lang.UnsupportedOperationException: This parser does not support specification "null" version "null"

Just put the parameter below and restart Tomcat:
-Djavax.xml.parsers.SAXParserFactory=com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl


This happens because you have two parsers in your classpath, and the Tomcat is getting a error loading the wrong version.
*This happened to me when I use Paypal SDK in Tomcat 7 and MyFaces.

출처 : http://softwareisart.blogspot.kr/2012/09/this-parser-does-not-support.html

2014년 1월 10일 금요일

[전자정부] XmlView 사용설정하기

1. Maven - pom.xml 설정

 org.springframework
 spring-oxm
 3.0.5.RELEASE


 com.thoughtworks.xstream
 xstream
 1.4.4

2. egov-com-servlet.xml 설정








    
     
      
          
      
     
        
        
    


3. XmlVO 생성
Annotation설정만으로 XML태그명을 설정할 수 있다.@XStreamImplicit(itemFieldName="item")로 선언된 ArrayList의 변수들은 하위의 childNode로 <변수명>값</변수명>으로 자동변환된다.
package kr.kca.olap.bp.service;

import java.util.ArrayList;
import java.util.List;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamImplicit;

@XStreamAlias("items")  //XML의 Root Node명
public class TplanDemdChartVO {
 
 @XStreamImplicit(itemFieldName="item")
 List chartVOList = new ArrayList();

 public List getChartVOList() {
  return chartVOList;
 }

 public void setChartVOList(List chartVOList) {
  this.chartVOList = chartVOList;
 }
 
}
4. Controller에서 사용하기
@RequestMapping(value="/olap/bp/getXmlTplanDemdSurvSttsList.do")
public ModelAndView getXmlTplanDemdSurvSttsList(@ModelAttribute("searchVO") TplanDemdSurvSttsDefaultVO searchVO, 
  ModelMap model) throws Exception {
 
 ModelAndView modelAndView = new ModelAndView("xmlView");  //xmlView로 선언된 ModelAndView를 생성한다.
 
 TplanDemdChartVO chartVO = new TplanDemdChartVO();
 chartVO.setChartVOList(tplanDemdSurvSttsService.selectTplanChartList(searchVO));
 
    modelAndView.addObject("xmlData", chartVO);
    
    return modelAndView;
}
5. XmlView 결과

 
  Jan
  900
 
 
  Feb
  1400
 
 
  Mar
  1500
 
 
  Apr
  1900
 
 
  May
  1400
 

이와같이 간단한 설정으로 XmlView를 사용할 수 있다.

[전자정부] Spring i18n 국제화 Locale Resolver

Spring 국제화 Locale 설정 시 유의사항



    



 


 
 
  1
 
 
    
        
       


2014년 1월 3일 금요일

[전자정부] 동시접속 제한을 위한 SessionListener #2

#properties 파일은 /WEB-INF/classes/session.properties.

#Max 동접자수
maxSessionValidCount=1000


WEB.xml에 Listener 등록 /WEB-INF/web.xml에 #1 의 SessionListener 등록


   
   SessionRetrieveListener
   kr.kca.pm.main.SessionListener


Java 단에서 예외사항 처리
//로그인 세션정보 Listener에 전달
HttpSession session = request.getSession();
sessionListener.setLoginSession(session);

//로그아웃 세션정보 Listener에 전달
HttpSession session = request.getSession();
sessionListener.setLogoutSession(session);

/** 동시접속자 접속(대기)를 위한 Listener 생성 */
SessionListener sessionListener = new SessionListener();

//로그인 세션 갯수를 호출하는 메소드로 동시접속자를 제한하자!
if(sessionListener.isMaxLoginSessions()) {
   
   /* 로그인 시 maxLoginSession 갯수보다 많을경우 예외사항 처리 */
   ctx.makeErrorResult("현재 동시접속자수가 많습니다. 잠시후에 이용하기시 바랍니다.");
   return;
}

[전자정부] 동시접속 제한을 위한 SessionListener #1

package kr.kca.pm.main;

import java.io.InputStream;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Properties;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

/**
 * 동시 접속자 세션관리 HttpListener
 * /WEB-INF/classes/session.properties 설정파일을 참조
 * 동시접속자 허용수를 setting 할 수 있도록 함. (제한접속자 수를 늘려야 할 경우 클래스 Compile없이 사용하도록)
 * Site 접속시점 세션생성 
 * Site 로그인시점 세션생성을 분리하여 접속자 수 Counting!
 * 
 * @author bcchung
 * @since 2013.07.15
 * @version 1.0
 * @see
 * 
 * 개정이력(Modification Information) >>
 *   
 *   수정일         수정자           수정내용
 *  -------       --------    ---------------------------
 *  2013.07.15    정백철          최초 생성
 * 
 */
public class SessionListener implements HttpSessionListener {
 public static SessionListener sessionManager = null;
 public static Hashtable sessionMonitor;
 public static Hashtable loginSessionMonitor;
 public static int maxSessionValidCount;

 public SessionListener() {
  if (sessionMonitor == null) sessionMonitor = new Hashtable();
  if (loginSessionMonitor == null) loginSessionMonitor = new Hashtable();
  sessionManager = this;
  
  Properties prop = new Properties();
  try {
   InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("session.properties");
   prop.load(inputStream);
  } catch (Exception e) {
   maxSessionValidCount = 300;
   e.printStackTrace();
  }
  
  maxSessionValidCount = Integer.parseInt((String) prop.get("maxSessionValidCount"));
//  System.out.println(" ########################### maxSessionValidCount : " + maxSessionValidCount);
 }

 public static synchronized SessionListener getInstance() {
  if (sessionManager == null)
   sessionManager = new SessionListener();
  return sessionManager;
 }

 /** 현재 활성화 된 session의 수를 반환한다. */
 public int getActiveSessionCount() {
  return sessionMonitor.size();
 }

 /** 현재 등록된 session의 id목록을 반환한다. */
 public Enumeration getIds() {
  return sessionMonitor.keys();
 }
 
 /** 전체 세션갯수를 측정하여 로그인(대기)상태 메세지 창 호출 */
 public boolean isMaxLoginSessions() {
  boolean retVal = false;
  
  if(maxSessionValidCount <= getActiveLoginSessionCount()) {
   retVal = true;
  }
  
  return retVal;
 }
 
 /** 현재 활성화 된 session의 수를 반환한다. */
 public int getActiveLoginSessionCount() {
  return loginSessionMonitor.size();
 }
 
 /** 로그인한 Session Put */
 public void setLoginSession(HttpSession session) {
  synchronized (loginSessionMonitor) {
   loginSessionMonitor.put(session.getId(), session);
   
   System.out.println(" ############################################################################### ");
   System.out.println(" # 접속자 (로그인 허용인원수) : " + maxSessionValidCount + " 명#");
   System.out.println(" # 접속자 (사이트 접속자수) : " + getActiveSessionCount() + " 명#");
   System.out.println(" # 접속자 (로그인 사용자수) : " + getActiveLoginSessionCount() + " 명#");
   System.out.println(" ############################################################################### ");
  }
 }
 
 /** 로그아웃한 Session Remove */
 public void setLogoutSession(HttpSession session) {
  synchronized (loginSessionMonitor) {
   loginSessionMonitor.remove(session.getId());
  }
 }

 /**
  * 현재 등록된 session중 현재 접속된 사용자 정보와 중복 여부 확인 후 중복 접속 이면 이전의 세션을 소멸 시킨다.
  */
 /*public boolean checkDuplicationLogin(String sessionId, String userEeno) {
  boolean ret = false;
  Enumeration eNum = sessionMonitor.elements();
  System.out.println("session count : " + getActiveSessionCount());
  while (eNum.hasMoreElements()) {
   HttpSession sh_session = null;
   try {
    sh_session = (HttpSession) eNum.nextElement();
   } catch (Exception e) {
    continue;
   }
   UserModel baseModel = sh_session.getAttribute("UserInfo");
   if (baseModel != null) {
    if (userEeno.equals(baseModel.getUserId_())
      && !sessionId.equals(sh_session.getId())) {
     // 전달 받은 사번과(userEeno) 기존 세션값 중 사번이 중복 되면
     // 기존 세션을 소멸 시킨다.
     // 사용자 로그아웃 이력(중복접속)을 저장한다.
     try {
      HashMap param = new HashMap();
      param.put("usrId", baseModel.getUserId_());
      param.put("ipAddr", baseModel.getRemoteIp_());
      param.put("logKind", "LOGOUT");
      param.put("logRsn", "DUPLICATE");
      // DB 처리
      xxxxxxxx.insertLoginLog(param);

     } catch (Exception e) {
      e.printStackTrace();
     }
     // 해당 세션 무효화
     sh_session.invalidate();
     ret = true;
     break;
    }
   }
  }
  return ret;
 }*/

 /** 세션 생성시 이벤트 처리 **/
 public void sessionCreated(HttpSessionEvent event) {
  HttpSession session = event.getSession();
  synchronized (sessionMonitor) {
   sessionMonitor.put(session.getId(), session);
   
   System.out.println(" ############################################################################### ");
   System.out.println(" # 접속자 (로그인 허용인원수) : " + maxSessionValidCount + " 명#");
   System.out.println(" # 접속자 (사이트 접속자수) : " + getActiveSessionCount() + " 명#");
   System.out.println(" # 접속자 (로그인 사용자수) : " + getActiveLoginSessionCount() + " 명#");
   System.out.println(" ############################################################################### ");
  }
 }

 /** 세션 소멸(종료)시 이벤트 처리 **/
 public void sessionDestroyed(HttpSessionEvent event) {
  HttpSession session = event.getSession();
  synchronized (sessionMonitor) {
   sessionMonitor.remove(session.getId());
   loginSessionMonitor.remove(session.getId());
   
   System.out.println(" ############################################################################### ");
   System.out.println(" # 접속자 (로그인 허용인원수) : " + maxSessionValidCount + " 명#");
   System.out.println(" # 접속자 (사이트 접속자수) : " + getActiveSessionCount() + " 명#");
   System.out.println(" # 접속자 (로그인 사용자수) : " + getActiveLoginSessionCount() + " 명#");
   System.out.println(" ############################################################################### ");
  }
 }
}