본문 바로가기
JAVA/comet

DWR reverse Ajax / Spring MVC -2

by 아이티.파머 2011. 9. 1.
반응형
이번엔 Class
1. Hello.class

/*
 * $Id: Hello.java ,v 1.1 2011. 8. 31. 오전 8:56:24 dongbuFarm Exp $
 * created by    : An Sang Kil
 * creation-date : 2011. 8. 31.
 * =========================================================
 * Copyright (c) 2011 ManInSoft, Inc. All rights reserved.
 */
package com.dongbu.farm.system.dwr;



public class Hello {

public String say(String msg){
System.out.println("mssage :: [" + msg +  "]");
return "hello" + msg;
}   

}

2. CharDWR class

/*
 * $Id: Chat.java ,v 1.1 2011. 9. 1. 오후 1:58:08 dongbuFarm Exp $
 * created by    : An Sang Kil
 * creation-date : 2011. 9. 1.
 * =========================================================
 * Copyright (c) 2011 ManInSoft, Inc. All rights reserved.
 */
package com.dongbu.farm.system.dwr;

import java.util.Collection;

import javax.servlet.ServletContext;

import org.apache.log4j.Logger;
import org.directwebremoting.ScriptSession;   
import org.directwebremoting.ServerContext;
import org.directwebremoting.ServerContextFactory;
import org.directwebremoting.WebContext;
import org.directwebremoting.WebContextFactory;
import org.directwebremoting.proxy.ScriptProxy;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.web.context.WebApplicationContext;

public class ChatDWR implements ApplicationContextAware{
private Logger logger = Logger.getLogger(this.getClass());
//private WebContext webContext;
private ServletContext  servletContext;
//private ServerContext serverContext;
@Override
public void setApplicationContext(ApplicationContext applicationContext) {
this.servletContext = ((WebApplicationContext)applicationContext).getServletContext();
public ChatDWR(){
//this.webContext = WebContextFactory.get();
//this.servletContext = webContext.getServletContext();
//this.serverContext = ServerContextFactory.get(servletContext);
}
public void notify(String msg){
String [] arr = msg.split(":");
ChatVO vo = new ChatVO();
vo.setUserName(arr[0]);
vo.setMsg(arr[1]);
logger.info("msg :: [" + msg +  "]");
//String contextPath = servletContext.getContextPath();
//Collection<ScriptSession> sessions = serverContext.getScriptSessionsByPage("/index.jsp");
WebContext wctx = WebContextFactory.get();
String currentPage = wctx.getCurrentPage();
Collection<ScriptSession> sessions = wctx.getScriptSessionsByPage(currentPage);
ScriptProxy proxy = new ScriptProxy(sessions);
proxy.addFunctionCall("notifyMsg", vo);
logger.info("call finish :: 호출완료");
/*
//Spring Freamworks 전용
WebContext wctx = WebContextFactory.get();
String currentPage = wctx.getCurrentPage();
Collection sessions = wctx.getScriptSessionsByPage(currentPage);
Util utilAll = new Util(sessions);
utilAll.addOptions("chatlog", messages, "text");
ScriptBuffer script = new ScriptBuffer();
script.appendScript("receiveMessages(").appendData(messages).appendScript(");");*/

}
}
 

반응형

'JAVA > comet' 카테고리의 다른 글

DWR reverse Ajax / Spring MVC -3  (0) 2011.09.01
DWR reverse Ajax / Spring MVC -1  (0) 2011.09.01
dwr Spting 환경설정  (0) 2011.08.31
Ajax real time (Reverse AJAX)  (0) 2011.08.30
수정요망 원하는 시간에 리로드  (0) 2011.06.17