Commits

Sun Ning  committed a0426e5

remove jms session

  • Participants
  • Parent commits 5de0663

Comments (0)

Files changed (2)

             <version>1.2</version>
         </dependency>
 		
-		<dependency>
-			<groupId>javax.jms</groupId>
-			<artifactId>jms</artifactId>
-			<version>1.1</version>
-			<scope>compile</scope>
-		</dependency>
 
 		<!--dependency>
 			<groupId>org.apache.activemq</groupId>

File src/main/java/com/classicning/yan/session/jms/JMSCaptchaSession.java

-/**
- * 
- */
-package com.classicning.yan.session.jms;
-
-import java.util.Properties;
-import java.util.logging.Logger;
-
-import javax.jms.JMSException;
-import javax.jms.QueueConnection;
-import javax.jms.QueueConnectionFactory;
-import javax.jms.ObjectMessage;
-import javax.jms.QueueSession;
-import javax.jms.QueueSender;
-import javax.jms.QueueReceiver;
-import javax.jms.Queue;
-import javax.jms.Session;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-
-import org.apache.commons.lang.NotImplementedException;
-
-import com.classicning.yan.GlobalConfiguration;
-import com.classicning.yan.model.CaptchaData;
-import com.classicning.yan.session.CaptchaSession;
-
-/**
- * @author Sun Ning/SNDA
- *
- */
-@Deprecated
-public class JMSCaptchaSession implements CaptchaSession {
-	
-	private static final String CONNECTION_FACTORY_NAMES = 
-			"captcha_server_jms_queue_factory";
-	
-	private static final String QUEUE_NAME = "captcha_server_jms_queue";
-	
-	private static final Long RECEIVE_TIMEOUT = 15*1000L;
-	
-	private QueueConnection connection = null;
-	private QueueSession session = null;
-	private Queue reposQueue = null;
-	
-	public JMSCaptchaSession(){
-		try {
-			this.init();
-		} catch (NamingException e) {
-			Logger.getLogger(this.getClass().getName()).severe(e.getMessage());
-		} catch (JMSException e) {
-			Logger.getLogger(this.getClass().getName()).severe(e.getMessage());
-		}
-	}
-
-    /**
-     * Initialize base configuration.
-     * @throws NamingException
-     * @throws JMSException
-     */
-	private void init() throws NamingException, JMSException{
-		Properties env = this.loadProperties();
-		InitialContext ctx = new InitialContext(env);
-		
-		QueueConnectionFactory connectionFactory = (QueueConnectionFactory)
-				ctx.lookup(CONNECTION_FACTORY_NAMES);
-		connection = connectionFactory.createQueueConnection();
-		session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
-		
-		reposQueue = (Queue)ctx.lookup(QUEUE_NAME);
-		
-		connection.start();
-	}
-	
-	private Properties loadProperties(){
-		Properties env = new Properties();
-		
-		env.put(Context.SECURITY_PRINCIPAL, GlobalConfiguration.get(
-				"yan.jms.securityprincipal"));
-		env.put(Context.SECURITY_CREDENTIALS, GlobalConfiguration.get(
-				"yan.jms.securitycredentials"));
-		env.put(Context.INITIAL_CONTEXT_FACTORY, GlobalConfiguration.get(
-				"yan.jms.initialcontextfactory"));
-		env.put(Context.PROVIDER_URL, GlobalConfiguration.get(
-				"yan.jms.providerurl"));
-		
-		env.put("connectionFactoryNames", CONNECTION_FACTORY_NAMES);
-		env.put("queue."+QUEUE_NAME, "jms."+QUEUE_NAME);
-		
-		return env;
-	}
-
-	/* (non-Javadoc)
-	 * @see com.sdo.captchaserver.repos.KeyCodeRepository#get(java.lang.String)
-	 */
-	@Override
-	public CaptchaData get(String key) {
-		try {
-			String filter = "Key = '"+key+"'";
-			QueueReceiver receiver =  session.createReceiver(reposQueue, filter);
-			ObjectMessage msg = (ObjectMessage)receiver.receive(RECEIVE_TIMEOUT);
-			if(msg != null){
-				CaptchaData kcm = (CaptchaData)msg.getObject();
-			
-				return kcm;
-			}else{
-				return null;
-			}
-		} catch (JMSException e) {
-			Logger.getLogger(this.getClass().getName()).severe(e.getMessage());
-			return null;
-		}
-	}
-
-	/* (non-Javadoc)
-	 * @see com.sdo.captchaserver.repos.KeyCodeRepository#put(java.lang.String, com.sdo.captchaserver.repos.KeyCodeModel)
-	 */
-	@Override
-	public void put(String key, CaptchaData kcm) {
-		try {
-			QueueSender sender = session.createSender(reposQueue);
-			
-			ObjectMessage msg = session.createObjectMessage();
-			msg.setStringProperty("Key", key);
-			msg.setObject(kcm);
-			msg.setJMSExpiration(System.currentTimeMillis() + 
-					GlobalConfiguration.getInt(
-							"yan.expireminutes") * 60 * 1000);
-			
-			sender.send(msg);
-			
-		} catch (JMSException e) {
-			Logger.getLogger(this.getClass().getName()).severe(e.getMessage());
-		}
-
-	}
-
-	@Override
-	public CaptchaData get(String key, boolean removeOnGet) {
-		throw new NotImplementedException();
-	}
-
-}