Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 20546 invoked from network); 12 Aug 2007 05:28:13 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 12 Aug 2007 05:28:13 -0000 Received: (qmail 6172 invoked by uid 500); 12 Aug 2007 05:28:11 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 6143 invoked by uid 500); 12 Aug 2007 05:28:11 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 6134 invoked by uid 99); 12 Aug 2007 05:28:11 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 11 Aug 2007 22:28:11 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED,HS_INDEX_PARAM X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 12 Aug 2007 05:28:12 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 2288E1A981D; Sat, 11 Aug 2007 22:27:42 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r565003 [2/17] - in /activemq/trunk: activemq-fileserver/src/main/java/org/apache/activemq/util/ activemq-fileserver/src/test/java/org/apache/activemq/util/ activemq-jaas/src/main/java/org/apache/activemq/jaas/ activemq-jaas/src/test/java/o... Date: Sun, 12 Aug 2007 05:27:34 -0000 To: commits@activemq.apache.org From: chirino@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070812052742.2288E1A981D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: activemq/trunk/activemq-jaas/src/main/java/org/apache/activemq/jaas/TextFileCertificateLoginModule.java URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-jaas/src/main/java/org/apache/activemq/jaas/TextFileCertificateLoginModule.java?view=diff&rev=565003&r1=565002&r2=565003 ============================================================================== --- activemq/trunk/activemq-jaas/src/main/java/org/apache/activemq/jaas/TextFileCertificateLoginModule.java (original) +++ activemq/trunk/activemq-jaas/src/main/java/org/apache/activemq/jaas/TextFileCertificateLoginModule.java Sat Aug 11 22:27:21 2007 @@ -31,104 +31,105 @@ import javax.security.auth.login.LoginException; /** - * A LoginModule allowing for SSL certificate based authentication based on Distinguished Names (DN) stored in text - * files. - * - * The DNs are parsed using a Properties class where each line is =. - * This class also uses a group definition file where each line is =,,etc. - * The user and group files' locations must be specified in the org.apache.activemq.jaas.textfiledn.user and - * org.apache.activemq.jaas.textfiledn.user properties respectively. - * - * NOTE: This class will re-read user and group files for every authentication (i.e it does live updates of allowed - * groups and users). + * A LoginModule allowing for SSL certificate based authentication based on + * Distinguished Names (DN) stored in text files. The DNs are parsed using a + * Properties class where each line is =. This class also + * uses a group definition file where each line is =,,etc. + * The user and group files' locations must be specified in the + * org.apache.activemq.jaas.textfiledn.user and + * org.apache.activemq.jaas.textfiledn.user properties respectively. NOTE: This + * class will re-read user and group files for every authentication (i.e it does + * live updates of allowed groups and users). * * @author sepandm@gmail.com (Sepand) */ public class TextFileCertificateLoginModule extends CertificateLoginModule { - + private static final String USER_FILE = "org.apache.activemq.jaas.textfiledn.user"; private static final String GROUP_FILE = "org.apache.activemq.jaas.textfiledn.group"; - + private File baseDir; private String usersFilePathname; private String groupsFilePathname; - + /** - * Performs initialization of file paths. - * - * A standard JAAS override. + * Performs initialization of file paths. A standard JAAS override. */ public void initialize(Subject subject, CallbackHandler callbackHandler, Map sharedState, Map options) { - super.initialize(subject, callbackHandler, sharedState, options); + super.initialize(subject, callbackHandler, sharedState, options); if (System.getProperty("java.security.auth.login.config") != null) { baseDir = new File(System.getProperty("java.security.auth.login.config")).getParentFile(); } else { baseDir = new File("."); } - - usersFilePathname = (String) options.get(USER_FILE)+""; - groupsFilePathname = (String) options.get(GROUP_FILE)+""; + + usersFilePathname = (String)options.get(USER_FILE) + ""; + groupsFilePathname = (String)options.get(GROUP_FILE) + ""; } - + /** - * Overriding to allow DN authorization based on DNs specified in text files. - * + * Overriding to allow DN authorization based on DNs specified in text + * files. + * * @param certs The certificate the incoming connection provided. - * @return The user's authenticated name or null if unable to authenticate the user. - * @throws LoginException Thrown if unable to find user file or connection certificate. + * @return The user's authenticated name or null if unable to authenticate + * the user. + * @throws LoginException Thrown if unable to find user file or connection + * certificate. */ protected String getUserNameForCertificates(final X509Certificate[] certs) throws LoginException { if (certs == null) { throw new LoginException("Client certificates not found. Cannot authenticate."); } - - File usersFile = new File(baseDir,usersFilePathname); - + + File usersFile = new File(baseDir, usersFilePathname); + Properties users = new Properties(); - + try { - java.io.FileInputStream in = new java.io.FileInputStream(usersFile); + java.io.FileInputStream in = new java.io.FileInputStream(usersFile); users.load(in); in.close(); } catch (IOException ioe) { throw new LoginException("Unable to load user properties file " + usersFile); } - + String dn = getDistinguishedName(certs); - - for(Enumeration vals = users.elements(), keys = users.keys(); vals.hasMoreElements(); ) { - if ( ((String)vals.nextElement()).equals(dn) ) { + + Enumeration keys = users.keys(); + for (Enumeration vals = users.elements(); vals.hasMoreElements();) { + if (((String)vals.nextElement()).equals(dn)) { return (String)keys.nextElement(); } else { keys.nextElement(); } } - + return null; } - + /** * Overriding to allow for group discovery based on text files. * - * @param username The name of the user being examined. This is the same name returned by - * getUserNameForCertificates. + * @param username The name of the user being examined. This is the same + * name returned by getUserNameForCertificates. * @return A Set of name Strings for groups this user belongs to. * @throws LoginException Thrown if unable to find group definition file. */ - protected Set getUserGroups(String username) throws LoginException { + protected Set getUserGroups(String username) throws LoginException { File groupsFile = new File(baseDir, groupsFilePathname); - + Properties groups = new Properties(); try { - java.io.FileInputStream in = new java.io.FileInputStream(groupsFile); + java.io.FileInputStream in = new java.io.FileInputStream(groupsFile); groups.load(in); in.close(); } catch (IOException ioe) { throw new LoginException("Unable to load group properties file " + groupsFile); } - Set userGroups = new HashSet(); + Set userGroups = new HashSet(); for (Enumeration enumeration = groups.keys(); enumeration.hasMoreElements();) { - String groupName = (String) enumeration.nextElement(); + String groupName = (String)enumeration.nextElement(); String[] userList = (groups.getProperty(groupName) + "").split(","); for (int i = 0; i < userList.length; i++) { if (username.equals(userList[i])) { @@ -137,7 +138,7 @@ } } } - + return userGroups; } } Modified: activemq/trunk/activemq-jaas/src/main/java/org/apache/activemq/jaas/UserPrincipal.java URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-jaas/src/main/java/org/apache/activemq/jaas/UserPrincipal.java?view=diff&rev=565003&r1=565002&r2=565003 ============================================================================== --- activemq/trunk/activemq-jaas/src/main/java/org/apache/activemq/jaas/UserPrincipal.java (original) +++ activemq/trunk/activemq-jaas/src/main/java/org/apache/activemq/jaas/UserPrincipal.java Sat Aug 11 22:27:21 2007 @@ -18,7 +18,6 @@ import java.security.Principal; - /** * @version $Rev: $ $Date: $ */ @@ -28,7 +27,9 @@ private transient int hash; public UserPrincipal(String name) { - if (name == null) throw new IllegalArgumentException("name cannot be null"); + if (name == null) { + throw new IllegalArgumentException("name cannot be null"); + } this.name = name; } @@ -37,12 +38,18 @@ } public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - final UserPrincipal that = (UserPrincipal) o; - - if (!name.equals(that.name)) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + final UserPrincipal that = (UserPrincipal)o; + + if (!name.equals(that.name)) { + return false; + } return true; } Modified: activemq/trunk/activemq-jaas/src/test/java/org/apache/activemq/jaas/CertificateLoginModuleTest.java URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-jaas/src/test/java/org/apache/activemq/jaas/CertificateLoginModuleTest.java?view=diff&rev=565003&r1=565002&r2=565003 ============================================================================== --- activemq/trunk/activemq-jaas/src/test/java/org/apache/activemq/jaas/CertificateLoginModuleTest.java (original) +++ activemq/trunk/activemq-jaas/src/test/java/org/apache/activemq/jaas/CertificateLoginModuleTest.java Sat Aug 11 22:27:21 2007 @@ -17,12 +17,8 @@ package org.apache.activemq.jaas; -import junit.framework.TestCase; - import java.io.IOException; -import java.io.InputStream; import java.security.Principal; -import java.security.cert.X509Certificate; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -33,67 +29,71 @@ import javax.security.auth.Subject; import javax.security.auth.login.LoginException; +import junit.framework.TestCase; + public class CertificateLoginModuleTest extends TestCase { - private static final String userName = "testUser"; - private static final List groupNames = new Vector(); + + private static final String USER_NAME = "testUser"; + private static final List GROUP_NAMES = new Vector(); + private StubCertificateLoginModule loginModule; - + private Subject subject; - + public CertificateLoginModuleTest() { - groupNames.add("testGroup1"); - groupNames.add("testGroup2"); - groupNames.add("testGroup3"); - groupNames.add("testGroup4"); + GROUP_NAMES.add("testGroup1"); + GROUP_NAMES.add("testGroup2"); + GROUP_NAMES.add("testGroup3"); + GROUP_NAMES.add("testGroup4"); } - + protected void setUp() throws Exception { subject = new Subject(); } protected void tearDown() throws Exception { } - - private void loginWithCredentials(String userName, Set groupNames) throws LoginException { - loginModule = new StubCertificateLoginModule(userName, new HashSet(groupNames)); - JaasCertificateCallbackHandler callbackHandler = new JaasCertificateCallbackHandler(null); - + + private void loginWithCredentials(String userName, Set groupNames) throws LoginException { + loginModule = new StubCertificateLoginModule(userName, new HashSet(groupNames)); + JaasCertificateCallbackHandler callbackHandler = new JaasCertificateCallbackHandler(null); + loginModule.initialize(subject, callbackHandler, null, new HashMap()); loginModule.login(); loginModule.commit(); } - + private void checkPrincipalsMatch(Subject subject) { boolean nameFound = false; - boolean groupsFound[] = new boolean[groupNames.size()]; + boolean groupsFound[] = new boolean[GROUP_NAMES.size()]; for (int i = 0; i < groupsFound.length; ++i) { groupsFound[i] = false; } - - for (Iterator iter = subject.getPrincipals().iterator(); iter.hasNext(); ) { - Principal currentPrincipal = (Principal) iter.next(); - + + for (Iterator iter = subject.getPrincipals().iterator(); iter.hasNext();) { + Principal currentPrincipal = (Principal)iter.next(); + if (currentPrincipal instanceof UserPrincipal) { - if (((UserPrincipal)currentPrincipal).getName().equals(userName)) { - if (nameFound == false) { + if (((UserPrincipal)currentPrincipal).getName().equals(USER_NAME)) { + if (!nameFound) { nameFound = true; } else { fail("UserPrincipal found twice."); } - + } else { fail("Unknown UserPrincipal found."); } - + } else if (currentPrincipal instanceof GroupPrincipal) { - int principalIdx = groupNames.indexOf(((GroupPrincipal)currentPrincipal).getName()); - + int principalIdx = GROUP_NAMES.indexOf(((GroupPrincipal)currentPrincipal).getName()); + if (principalIdx < 0) { fail("Unknown GroupPrincipal found."); } - - if (groupsFound[principalIdx] == false) { + + if (!groupsFound[principalIdx]) { groupsFound[principalIdx] = true; } else { fail("GroupPrincipal found twice."); @@ -103,41 +103,40 @@ } } } - + public void testLoginSuccess() throws IOException { try { - loginWithCredentials(userName, new HashSet(groupNames)); + loginWithCredentials(USER_NAME, new HashSet(GROUP_NAMES)); } catch (Exception e) { fail("Unable to login: " + e.getMessage()); } - + checkPrincipalsMatch(subject); } - + public void testLoginFailure() throws IOException { boolean loginFailed = false; - + try { - loginWithCredentials(null, new HashSet()); + loginWithCredentials(null, new HashSet()); } catch (LoginException e) { loginFailed = true; } - + if (!loginFailed) { fail("Logged in with unknown certificate."); } } - + public void testLogOut() throws IOException { try { - loginWithCredentials(userName, new HashSet(groupNames)); + loginWithCredentials(USER_NAME, new HashSet(GROUP_NAMES)); } catch (Exception e) { fail("Unable to login: " + e.getMessage()); } - + loginModule.logout(); - + assertEquals("logout should have cleared Subject principals.", 0, subject.getPrincipals().size()); } } - Modified: activemq/trunk/activemq-jaas/src/test/java/org/apache/activemq/jaas/GroupPrincipalTest.java URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-jaas/src/test/java/org/apache/activemq/jaas/GroupPrincipalTest.java?view=diff&rev=565003&r1=565002&r2=565003 ============================================================================== --- activemq/trunk/activemq-jaas/src/test/java/org/apache/activemq/jaas/GroupPrincipalTest.java (original) +++ activemq/trunk/activemq-jaas/src/test/java/org/apache/activemq/jaas/GroupPrincipalTest.java Sat Aug 11 22:27:21 2007 @@ -16,11 +16,8 @@ */ package org.apache.activemq.jaas; -import org.apache.activemq.jaas.GroupPrincipal; - import junit.framework.TestCase; - /** * @version $Rev: $ $Date: $ */ @@ -29,7 +26,7 @@ public void testArguments() { GroupPrincipal principal = new GroupPrincipal("FOO"); - assertEquals("FOO", principal.getName()); + assertEquals("FOO", principal.getName()); try { new GroupPrincipal(null); Modified: activemq/trunk/activemq-jaas/src/test/java/org/apache/activemq/jaas/LDAPLoginModuleTest.java URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-jaas/src/test/java/org/apache/activemq/jaas/LDAPLoginModuleTest.java?view=diff&rev=565003&r1=565002&r2=565003 ============================================================================== --- activemq/trunk/activemq-jaas/src/test/java/org/apache/activemq/jaas/LDAPLoginModuleTest.java (original) +++ activemq/trunk/activemq-jaas/src/test/java/org/apache/activemq/jaas/LDAPLoginModuleTest.java Sat Aug 11 22:27:21 2007 @@ -55,6 +55,7 @@ public void testNothing() { } + @SuppressWarnings("unchecked") public void testRunning() throws Exception { Hashtable env = new Hashtable(); @@ -85,7 +86,7 @@ } - public void XtestLogin() throws LoginException { + public void xtestLogin() throws LoginException { LoginContext context = new LoginContext("LDAPLogin", new CallbackHandler() { public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (int i = 0; i < callbacks.length; i++) { @@ -103,6 +104,7 @@ context.logout(); } + @SuppressWarnings("unchecked") public void setUp() throws Exception { MutableServerStartupConfiguration startup = new MutableServerStartupConfiguration(); // put some mandatory JNDI properties here @@ -124,6 +126,7 @@ new InitialDirContext(env); } + @SuppressWarnings("unchecked") public void tearDown() throws Exception { Properties env = new Properties(); env.putAll(new ShutdownConfiguration().toJndiEnvironment()); Modified: activemq/trunk/activemq-jaas/src/test/java/org/apache/activemq/jaas/StubCertificateLoginModule.java URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-jaas/src/test/java/org/apache/activemq/jaas/StubCertificateLoginModule.java?view=diff&rev=565003&r1=565002&r2=565003 ============================================================================== --- activemq/trunk/activemq-jaas/src/test/java/org/apache/activemq/jaas/StubCertificateLoginModule.java (original) +++ activemq/trunk/activemq-jaas/src/test/java/org/apache/activemq/jaas/StubCertificateLoginModule.java Sat Aug 11 22:27:21 2007 @@ -25,21 +25,20 @@ public class StubCertificateLoginModule extends CertificateLoginModule { final String userName; final Set groupNames; - - String lastUserName = null; - X509Certificate[] lastCertChain = null; - + + String lastUserName; + X509Certificate[] lastCertChain; + public StubCertificateLoginModule(String userName, Set groupNames) { this.userName = userName; this.groupNames = groupNames; } - protected String getUserNameForCertificates(X509Certificate[] certs) - throws LoginException { + protected String getUserNameForCertificates(X509Certificate[] certs) throws LoginException { lastCertChain = certs; return userName; } - + protected Set getUserGroups(String username) throws LoginException { lastUserName = username; return this.groupNames; Modified: activemq/trunk/activemq-jaas/src/test/java/org/apache/activemq/jaas/UserPrincipalTest.java URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-jaas/src/test/java/org/apache/activemq/jaas/UserPrincipalTest.java?view=diff&rev=565003&r1=565002&r2=565003 ============================================================================== --- activemq/trunk/activemq-jaas/src/test/java/org/apache/activemq/jaas/UserPrincipalTest.java (original) +++ activemq/trunk/activemq-jaas/src/test/java/org/apache/activemq/jaas/UserPrincipalTest.java Sat Aug 11 22:27:21 2007 @@ -16,11 +16,8 @@ */ package org.apache.activemq.jaas; -import org.apache.activemq.jaas.UserPrincipal; - import junit.framework.TestCase; - /** * @version $Rev: $ $Date: $ */ @@ -29,7 +26,7 @@ public void testArguments() { UserPrincipal principal = new UserPrincipal("FOO"); - assertEquals("FOO", principal.getName()); + assertEquals("FOO", principal.getName()); try { new UserPrincipal(null); Modified: activemq/trunk/activemq-jaas/src/test/java/org/apache/activemq/jaas/ldap/MutableServerStartupConfiguration.java URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-jaas/src/test/java/org/apache/activemq/jaas/ldap/MutableServerStartupConfiguration.java?view=diff&rev=565003&r1=565002&r2=565003 ============================================================================== --- activemq/trunk/activemq-jaas/src/test/java/org/apache/activemq/jaas/ldap/MutableServerStartupConfiguration.java (original) +++ activemq/trunk/activemq-jaas/src/test/java/org/apache/activemq/jaas/ldap/MutableServerStartupConfiguration.java Sat Aug 11 22:27:21 2007 @@ -25,12 +25,10 @@ /** * A mutable version of {@link ServerStartupConfiguration}. - * + * * @version $Rev: 233391 $ $Date: 2005-08-18 16:38:47 -0600 (Thu, 18 Aug 2005) $ */ -public class MutableServerStartupConfiguration extends - ServerStartupConfiguration -{ +public class MutableServerStartupConfiguration extends ServerStartupConfiguration { private static final long serialVersionUID = 515104910980600099L; public MutableServerStartupConfiguration() { Modified: activemq/trunk/activemq-jaas/src/test/java/org/apache/activemq/jaas/ldap/ServerContextFactory.java URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-jaas/src/test/java/org/apache/activemq/jaas/ldap/ServerContextFactory.java?view=diff&rev=565003&r1=565002&r2=565003 ============================================================================== --- activemq/trunk/activemq-jaas/src/test/java/org/apache/activemq/jaas/ldap/ServerContextFactory.java (original) +++ activemq/trunk/activemq-jaas/src/test/java/org/apache/activemq/jaas/ldap/ServerContextFactory.java Sat Aug 11 22:27:21 2007 @@ -47,16 +47,17 @@ import org.apache.mina.registry.Service; import org.apache.mina.registry.ServiceRegistry; - /** - * Adds additional bootstrapping for server socket listeners when firing - * up the server. - * + * Adds additional bootstrapping for server socket listeners when firing up the + * server. + * * @version $Rev: 233391 $ $Date: 2005-08-18 16:38:47 -0600 (Thu, 18 Aug 2005) $ * @see javax.naming.spi.InitialContextFactory */ public class ServerContextFactory extends CoreContextFactory { - private static final Log log = LogFactory.getLog(ServerContextFactory.class); + + private static final Log LOG = LogFactory.getLog(ServerContextFactory.class); + private static Service ldapService; private static Service kerberosService; private static ServiceRegistry minaRegistry; @@ -69,16 +70,16 @@ if (minaRegistry != null) { if (ldapService != null) { minaRegistry.unbind(ldapService); - if (log.isInfoEnabled()) { - log.info("Unbind of LDAP Service complete: " + ldapService); + if (LOG.isInfoEnabled()) { + LOG.info("Unbind of LDAP Service complete: " + ldapService); } ldapService = null; } if (kerberosService != null) { minaRegistry.unbind(kerberosService); - if (log.isInfoEnabled()) { - log.info("Unbind of KRB5 Service complete: " + kerberosService); + if (LOG.isInfoEnabled()) { + LOG.info("Unbind of KRB5 Service complete: " + kerberosService); } kerberosService = null; } @@ -86,8 +87,7 @@ } public void afterStartup(ContextFactoryService service) throws NamingException { - ServerStartupConfiguration cfg = - (ServerStartupConfiguration) service.getConfiguration().getStartupConfiguration(); + ServerStartupConfiguration cfg = (ServerStartupConfiguration)service.getConfiguration().getStartupConfiguration(); Hashtable env = service.getConfiguration().getEnvironment(); if (cfg.isEnableNetworking()) { @@ -107,74 +107,74 @@ minaRegistry = cfg.getMinaServiceRegistry(); } - /** * Starts the Kerberos protocol provider which is backed by the LDAP store. - * - * @throws NamingException if there are problems starting up the Kerberos provider + * + * @throws NamingException if there are problems starting up the Kerberos + * provider */ private void startKerberosProtocol(Hashtable env) throws NamingException { /* - * Looks like KdcConfiguration takes properties and we use Hashtable for JNDI - * so I'm copying over the String based properties into a new Properties obj. + * Looks like KdcConfiguration takes properties and we use Hashtable for + * JNDI so I'm copying over the String based properties into a new + * Properties obj. */ Properties props = new Properties(); Iterator list = env.keySet().iterator(); while (list.hasNext()) { - String key = (String) list.next(); + String key = (String)list.next(); if (env.get(key) instanceof String) { - props.setProperty(key, (String) env.get(key)); + props.setProperty(key, (String)env.get(key)); } } - // construct the configuration, get the port, create the service, and prepare kdc objects + // construct the configuration, get the port, create the service, and + // prepare kdc objects KdcConfiguration config = new KdcConfiguration(props); int port = PropertiesUtils.get(env, KdcConfiguration.KERBEROS_PORT_KEY, KdcConfiguration.DEFAULT_KERBEROS_PORT); Service service = new Service("kerberos", TransportType.DATAGRAM, new InetSocketAddress(port)); LdapContext ctx = getBaseRealmContext(config, env); PrincipalStore store = new JndiPrincipalStoreImpl(ctx, new LdapName("ou=Users")); - SamSubsystem.getInstance().setUserContext((DirContext) ctx, "ou=Users"); + SamSubsystem.getInstance().setUserContext((DirContext)ctx, "ou=Users"); try { minaRegistry.bind(service, new KerberosProtocolProvider(config, store)); kerberosService = service; - if (log.isInfoEnabled()) { - log.info("Successful bind of KRB5 Service completed: " + kerberosService); + if (LOG.isInfoEnabled()) { + LOG.info("Successful bind of KRB5 Service completed: " + kerberosService); } - } - catch (IOException e) { - log.error("Could not start the kerberos service on port " + - KdcConfiguration.DEFAULT_KERBEROS_PORT, e); + } catch (IOException e) { + LOG.error("Could not start the kerberos service on port " + KdcConfiguration.DEFAULT_KERBEROS_PORT, e); } } - /** - * Maps a Kerberos Realm name to a position within the DIT. The primary realm of - * the KDC will use this area for configuration and for storing user entries. - * + * Maps a Kerberos Realm name to a position within the DIT. The primary + * realm of the KDC will use this area for configuration and for storing + * user entries. + * * @param config the KDC's configuration - * @param env the JNDI environment properties + * @param env the JNDI environment properties * @return the base context for the primary realm of the KDC * @throws NamingException */ + @SuppressWarnings("unchecked") private LdapContext getBaseRealmContext(KdcConfiguration config, Hashtable env) throws NamingException { - Hashtable cloned = (Hashtable) env.clone(); + Hashtable cloned = (Hashtable)env.clone(); String dn = NamespaceTools.inferLdapName(config.getPrimaryRealm()); cloned.put(Context.PROVIDER_URL, dn); - if (log.isInfoEnabled()) { - log.info("Getting initial context for realm base at " + dn + " for " + config.getPrimaryRealm()); + if (LOG.isInfoEnabled()) { + LOG.info("Getting initial context for realm base at " + dn + " for " + config.getPrimaryRealm()); } - return new InitialLdapContext(cloned, new Control[]{}); + return new InitialLdapContext(cloned, new Control[] {}); } - /** * Starts up the LDAP protocol provider to service LDAP requests - * + * * @throws NamingException if there are problems starting the LDAP provider */ private void startLdapProtocol(ServerStartupConfiguration cfg, Hashtable env) throws NamingException { @@ -183,17 +183,16 @@ Service service = new Service("ldap", TransportType.SOCKET, new InetSocketAddress(host, port)); try { - minaRegistry.bind(service, new LdapProtocolProvider((Hashtable) env.clone())); + minaRegistry.bind(service, new LdapProtocolProvider((Hashtable)env.clone())); ldapService = service; - if (log.isInfoEnabled()) { - log.info("Successful bind of LDAP Service completed: " + ldapService); + if (LOG.isInfoEnabled()) { + LOG.info("Successful bind of LDAP Service completed: " + ldapService); } - } - catch (IOException e) { + } catch (IOException e) { String msg = "Failed to bind the LDAP protocol service to the service registry: " + service; LdapConfigurationException lce = new LdapConfigurationException(msg); lce.setRootCause(e); - log.error(msg, e); + LOG.error(msg, e); throw lce; } } Modified: activemq/trunk/activemq-jaas/src/test/java/org/apache/activemq/jaas/ldap/ServerStartupConfiguration.java URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-jaas/src/test/java/org/apache/activemq/jaas/ldap/ServerStartupConfiguration.java?view=diff&rev=565003&r1=565002&r2=565003 ============================================================================== --- activemq/trunk/activemq-jaas/src/test/java/org/apache/activemq/jaas/ldap/ServerStartupConfiguration.java (original) +++ activemq/trunk/activemq-jaas/src/test/java/org/apache/activemq/jaas/ldap/ServerStartupConfiguration.java Sat Aug 11 22:27:21 2007 @@ -35,7 +35,7 @@ private ServiceRegistry minaServiceRegistry = new SimpleServiceRegistry(); private int ldapPort = 389; private int ldapsPort = 636; - private InetAddress host = null; + private InetAddress host; private boolean enableKerberos; protected ServerStartupConfiguration() { Modified: activemq/trunk/activemq-jpa-store/src/main/java/org/apache/activemq/store/jpa/JPAMessageStore.java URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-jpa-store/src/main/java/org/apache/activemq/store/jpa/JPAMessageStore.java?view=diff&rev=565003&r1=565002&r2=565003 ============================================================================== --- activemq/trunk/activemq-jpa-store/src/main/java/org/apache/activemq/store/jpa/JPAMessageStore.java (original) +++ activemq/trunk/activemq-jpa-store/src/main/java/org/apache/activemq/store/jpa/JPAMessageStore.java Sat Aug 11 22:27:21 2007 @@ -38,165 +38,165 @@ public class JPAMessageStore implements MessageStore { - protected final JPAPersistenceAdapter adapter; - protected final WireFormat wireFormat; - protected final ActiveMQDestination destination; - protected final String destinationName; + protected final JPAPersistenceAdapter adapter; + protected final WireFormat wireFormat; + protected final ActiveMQDestination destination; + protected final String destinationName; protected AtomicLong lastMessageId = new AtomicLong(-1); - public JPAMessageStore(JPAPersistenceAdapter adapter, ActiveMQDestination destination) { - this.adapter = adapter; - this.destination = destination; - this.destinationName = destination.getQualifiedName(); - this.wireFormat = this.adapter.getWireFormat(); - } - - public void addMessage(ConnectionContext context, Message message) throws IOException { - - EntityManager manager = adapter.beginEntityManager(context); - try { - - ByteSequence sequence = wireFormat.marshal(message); - sequence.compact(); - - StoredMessage sm = new StoredMessage(); - sm.setDestination(destinationName); - sm.setId(message.getMessageId().getBrokerSequenceId()); - sm.setMessageId(message.getMessageId().toString()); - sm.setExiration(message.getExpiration()); - sm.setData(sequence.data); - - manager.persist(sm); - - } catch (Throwable e) { - adapter.rollbackEntityManager(context,manager); - throw IOExceptionSupport.create(e); - } - adapter.commitEntityManager(context,manager); - } - - public ActiveMQDestination getDestination() { - return destination; - } - - public Message getMessage(MessageId identity) throws IOException { - Message rc; - EntityManager manager = adapter.beginEntityManager(null); - try { - StoredMessage message=null; - if( identity.getBrokerSequenceId()!= 0 ) { - message = manager.find(StoredMessage.class, identity.getBrokerSequenceId()); - } else { - Query query = manager.createQuery("select m from StoredMessage m where m.messageId=?1"); - query.setParameter(1, identity.toString()); - message = (StoredMessage) query.getSingleResult(); - } - - rc = (Message) wireFormat.unmarshal(new ByteSequence(message.getData())); - } catch (Throwable e) { - adapter.rollbackEntityManager(null,manager); - throw IOExceptionSupport.create(e); - } - adapter.commitEntityManager(null,manager); - return rc; - } - - public int getMessageCount() throws IOException { - Long rc; - EntityManager manager = adapter.beginEntityManager(null); - try { - Query query = manager.createQuery("select count(m) from StoredMessage m"); - rc = (Long) query.getSingleResult(); - } catch (Throwable e) { - adapter.rollbackEntityManager(null,manager); - throw IOExceptionSupport.create(e); - } - adapter.commitEntityManager(null,manager); - return rc.intValue(); - } - - @SuppressWarnings("unchecked") - public void recover(MessageRecoveryListener container) throws Exception { - EntityManager manager = adapter.beginEntityManager(null); - try { - Query query = manager.createQuery("select m from StoredMessage m where m.destination=?1 order by m.id asc"); - query.setParameter(1, destinationName); - for (StoredMessage m : (List)query.getResultList()) { - Message message = (Message) wireFormat.unmarshal(new ByteSequence(m.getData())); - container.recoverMessage(message); - } - } catch (Throwable e) { - adapter.rollbackEntityManager(null,manager); - throw IOExceptionSupport.create(e); - } - adapter.commitEntityManager(null,manager); - } - - @SuppressWarnings("unchecked") - public void recoverNextMessages(int maxReturned, MessageRecoveryListener listener) throws Exception { - - EntityManager manager = adapter.beginEntityManager(null); - try { - - Query query = manager.createQuery("select m from StoredMessage m where m.destination=?1 and m.id>?2 order by m.id asc"); - query.setParameter(1, destinationName); - query.setParameter(2, lastMessageId.get()); - query.setMaxResults(maxReturned); - int count = 0; - for (StoredMessage m : (List)query.getResultList()) { - Message message = (Message) wireFormat.unmarshal(new ByteSequence(m.getData())); - listener.recoverMessage(message); - lastMessageId.set(m.getId()); - count++; - if( count >= maxReturned ) { - return; - } - } - - } catch (Throwable e) { - adapter.rollbackEntityManager(null,manager); - throw IOExceptionSupport.create(e); - } - adapter.commitEntityManager(null,manager); - } - - public void removeAllMessages(ConnectionContext context) throws IOException { - EntityManager manager = adapter.beginEntityManager(context); - try { - Query query = manager.createQuery("delete from StoredMessage m where m.destination=?1"); - query.setParameter(1, destinationName); - query.executeUpdate(); - } catch (Throwable e) { - adapter.rollbackEntityManager(context,manager); - throw IOExceptionSupport.create(e); - } - adapter.commitEntityManager(context,manager); - } - - public void removeMessage(ConnectionContext context, MessageAck ack) throws IOException { - EntityManager manager = adapter.beginEntityManager(context); - try { - Query query = manager.createQuery("delete from StoredMessage m where m.id=?1"); - query.setParameter(1, ack.getLastMessageId().getBrokerSequenceId()); - query.executeUpdate(); - } catch (Throwable e) { - adapter.rollbackEntityManager(context,manager); - throw IOExceptionSupport.create(e); - } - adapter.commitEntityManager(context,manager); - } + public JPAMessageStore(JPAPersistenceAdapter adapter, ActiveMQDestination destination) { + this.adapter = adapter; + this.destination = destination; + this.destinationName = destination.getQualifiedName(); + this.wireFormat = this.adapter.getWireFormat(); + } + + public void addMessage(ConnectionContext context, Message message) throws IOException { + + EntityManager manager = adapter.beginEntityManager(context); + try { + + ByteSequence sequence = wireFormat.marshal(message); + sequence.compact(); + + StoredMessage sm = new StoredMessage(); + sm.setDestination(destinationName); + sm.setId(message.getMessageId().getBrokerSequenceId()); + sm.setMessageId(message.getMessageId().toString()); + sm.setExiration(message.getExpiration()); + sm.setData(sequence.data); + + manager.persist(sm); + + } catch (Throwable e) { + adapter.rollbackEntityManager(context, manager); + throw IOExceptionSupport.create(e); + } + adapter.commitEntityManager(context, manager); + } + + public ActiveMQDestination getDestination() { + return destination; + } + + public Message getMessage(MessageId identity) throws IOException { + Message rc; + EntityManager manager = adapter.beginEntityManager(null); + try { + StoredMessage message = null; + if (identity.getBrokerSequenceId() != 0) { + message = manager.find(StoredMessage.class, identity.getBrokerSequenceId()); + } else { + Query query = manager.createQuery("select m from StoredMessage m where m.messageId=?1"); + query.setParameter(1, identity.toString()); + message = (StoredMessage)query.getSingleResult(); + } + + rc = (Message)wireFormat.unmarshal(new ByteSequence(message.getData())); + } catch (Throwable e) { + adapter.rollbackEntityManager(null, manager); + throw IOExceptionSupport.create(e); + } + adapter.commitEntityManager(null, manager); + return rc; + } + + public int getMessageCount() throws IOException { + Long rc; + EntityManager manager = adapter.beginEntityManager(null); + try { + Query query = manager.createQuery("select count(m) from StoredMessage m"); + rc = (Long)query.getSingleResult(); + } catch (Throwable e) { + adapter.rollbackEntityManager(null, manager); + throw IOExceptionSupport.create(e); + } + adapter.commitEntityManager(null, manager); + return rc.intValue(); + } + + @SuppressWarnings("unchecked") + public void recover(MessageRecoveryListener container) throws Exception { + EntityManager manager = adapter.beginEntityManager(null); + try { + Query query = manager.createQuery("select m from StoredMessage m where m.destination=?1 order by m.id asc"); + query.setParameter(1, destinationName); + for (StoredMessage m : (List)query.getResultList()) { + Message message = (Message)wireFormat.unmarshal(new ByteSequence(m.getData())); + container.recoverMessage(message); + } + } catch (Throwable e) { + adapter.rollbackEntityManager(null, manager); + throw IOExceptionSupport.create(e); + } + adapter.commitEntityManager(null, manager); + } + + @SuppressWarnings("unchecked") + public void recoverNextMessages(int maxReturned, MessageRecoveryListener listener) throws Exception { + + EntityManager manager = adapter.beginEntityManager(null); + try { + + Query query = manager.createQuery("select m from StoredMessage m where m.destination=?1 and m.id>?2 order by m.id asc"); + query.setParameter(1, destinationName); + query.setParameter(2, lastMessageId.get()); + query.setMaxResults(maxReturned); + int count = 0; + for (StoredMessage m : (List)query.getResultList()) { + Message message = (Message)wireFormat.unmarshal(new ByteSequence(m.getData())); + listener.recoverMessage(message); + lastMessageId.set(m.getId()); + count++; + if (count >= maxReturned) { + return; + } + } + + } catch (Throwable e) { + adapter.rollbackEntityManager(null, manager); + throw IOExceptionSupport.create(e); + } + adapter.commitEntityManager(null, manager); + } + + public void removeAllMessages(ConnectionContext context) throws IOException { + EntityManager manager = adapter.beginEntityManager(context); + try { + Query query = manager.createQuery("delete from StoredMessage m where m.destination=?1"); + query.setParameter(1, destinationName); + query.executeUpdate(); + } catch (Throwable e) { + adapter.rollbackEntityManager(context, manager); + throw IOExceptionSupport.create(e); + } + adapter.commitEntityManager(context, manager); + } + + public void removeMessage(ConnectionContext context, MessageAck ack) throws IOException { + EntityManager manager = adapter.beginEntityManager(context); + try { + Query query = manager.createQuery("delete from StoredMessage m where m.id=?1"); + query.setParameter(1, ack.getLastMessageId().getBrokerSequenceId()); + query.executeUpdate(); + } catch (Throwable e) { + adapter.rollbackEntityManager(context, manager); + throw IOExceptionSupport.create(e); + } + adapter.commitEntityManager(context, manager); + } - public void resetBatching() { + public void resetBatching() { lastMessageId.set(-1); - } + } - public void setUsageManager(UsageManager usageManager) { - } + public void setUsageManager(UsageManager usageManager) { + } - public void start() throws Exception { - } + public void start() throws Exception { + } - public void stop() throws Exception { - } + public void stop() throws Exception { + } } Modified: activemq/trunk/activemq-jpa-store/src/main/java/org/apache/activemq/store/jpa/JPAPersistenceAdapter.java URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-jpa-store/src/main/java/org/apache/activemq/store/jpa/JPAPersistenceAdapter.java?view=diff&rev=565003&r1=565002&r2=565003 ============================================================================== --- activemq/trunk/activemq-jpa-store/src/main/java/org/apache/activemq/store/jpa/JPAPersistenceAdapter.java (original) +++ activemq/trunk/activemq-jpa-store/src/main/java/org/apache/activemq/store/jpa/JPAPersistenceAdapter.java Sat Aug 11 22:27:21 2007 @@ -45,212 +45,214 @@ import org.apache.commons.logging.LogFactory; /** - * An implementation of {@link PersistenceAdapter} that uses JPA to - * store it's messages. + * An implementation of {@link PersistenceAdapter} that uses JPA to store it's + * messages. * * @org.apache.xbean.XBean element="jpaPersistenceAdapter" - * * @version $Revision: 1.17 $ */ public class JPAPersistenceAdapter implements PersistenceAdapter { - private static final Log log = LogFactory.getLog(JPAPersistenceAdapter.class); String entityManagerName = "activemq"; - Properties entityManagerProperties = System.getProperties(); - EntityManagerFactory entityManagerFactory; - private WireFormat wireFormat; - private MemoryTransactionStore transactionStore; - - public void beginTransaction(ConnectionContext context) throws IOException { - if( context.getLongTermStoreContext()!=null ) - throw new IOException("Transation already started."); - - EntityManager manager = getEntityManagerFactory().createEntityManager(); - manager.getTransaction().begin(); - context.setLongTermStoreContext(manager); - } - - public void commitTransaction(ConnectionContext context) throws IOException { - EntityManager manager = (EntityManager) context.getLongTermStoreContext(); - if( manager==null ) - throw new IOException("Transation not started."); - context.setLongTermStoreContext(null); - manager.getTransaction().commit(); - manager.close(); - } - - public void rollbackTransaction(ConnectionContext context) throws IOException { - EntityManager manager = (EntityManager) context.getLongTermStoreContext(); - if( manager==null ) - throw new IOException("Transation not started."); - context.setLongTermStoreContext(null); - manager.getTransaction().rollback(); - manager.close(); - } - - public EntityManager beginEntityManager(ConnectionContext context) { - if( context==null || context.getLongTermStoreContext()==null ) { - EntityManager manager = getEntityManagerFactory().createEntityManager(); - manager.getTransaction().begin(); - return manager; - } else { - return (EntityManager) context.getLongTermStoreContext(); - } - } - - public void commitEntityManager(ConnectionContext context, EntityManager manager) { - if( context==null || context.getLongTermStoreContext()==null ) { - manager.getTransaction().commit(); - manager.close(); - } - } - - public void rollbackEntityManager(ConnectionContext context, EntityManager manager) { - if( context==null || context.getLongTermStoreContext()==null ) { - manager.getTransaction().rollback(); - manager.close(); - } - } + Properties entityManagerProperties = System.getProperties(); + EntityManagerFactory entityManagerFactory; + private WireFormat wireFormat; + private MemoryTransactionStore transactionStore; + + public void beginTransaction(ConnectionContext context) throws IOException { + if (context.getLongTermStoreContext() != null) { + throw new IOException("Transation already started."); + } + EntityManager manager = getEntityManagerFactory().createEntityManager(); + manager.getTransaction().begin(); + context.setLongTermStoreContext(manager); + } + + public void commitTransaction(ConnectionContext context) throws IOException { + EntityManager manager = (EntityManager)context.getLongTermStoreContext(); + if (manager == null) { + throw new IOException("Transation not started."); + } + context.setLongTermStoreContext(null); + manager.getTransaction().commit(); + manager.close(); + } + + public void rollbackTransaction(ConnectionContext context) throws IOException { + EntityManager manager = (EntityManager)context.getLongTermStoreContext(); + if (manager == null) { + throw new IOException("Transation not started."); + } + context.setLongTermStoreContext(null); + manager.getTransaction().rollback(); + manager.close(); + } + + public EntityManager beginEntityManager(ConnectionContext context) { + if (context == null || context.getLongTermStoreContext() == null) { + EntityManager manager = getEntityManagerFactory().createEntityManager(); + manager.getTransaction().begin(); + return manager; + } else { + return (EntityManager)context.getLongTermStoreContext(); + } + } + + public void commitEntityManager(ConnectionContext context, EntityManager manager) { + if (context == null || context.getLongTermStoreContext() == null) { + manager.getTransaction().commit(); + manager.close(); + } + } + + public void rollbackEntityManager(ConnectionContext context, EntityManager manager) { + if (context == null || context.getLongTermStoreContext() == null) { + manager.getTransaction().rollback(); + manager.close(); + } + } - public MessageStore createQueueMessageStore(ActiveMQQueue destination) throws IOException { - MessageStore rc = new JPAMessageStore(this, destination); + public MessageStore createQueueMessageStore(ActiveMQQueue destination) throws IOException { + MessageStore rc = new JPAMessageStore(this, destination); if (transactionStore != null) { rc = transactionStore.proxy(rc); } return rc; - } + } - public TopicMessageStore createTopicMessageStore(ActiveMQTopic destination) throws IOException { - TopicMessageStore rc = new JPATopicMessageStore(this, destination); + public TopicMessageStore createTopicMessageStore(ActiveMQTopic destination) throws IOException { + TopicMessageStore rc = new JPATopicMessageStore(this, destination); if (transactionStore != null) { rc = transactionStore.proxy(rc); } return rc; - } + } - public TransactionStore createTransactionStore() throws IOException { + public TransactionStore createTransactionStore() throws IOException { if (transactionStore == null) { transactionStore = new MemoryTransactionStore(); } return this.transactionStore; - } + } + + public void deleteAllMessages() throws IOException { + EntityManager manager = beginEntityManager(null); + try { + Query query = manager.createQuery("delete from StoredMessage m"); + query.executeUpdate(); + query = manager.createQuery("delete from StoredSubscription ss"); + query.executeUpdate(); + } catch (Throwable e) { + rollbackEntityManager(null, manager); + throw IOExceptionSupport.create(e); + } + commitEntityManager(null, manager); + } - public void deleteAllMessages() throws IOException { - EntityManager manager = beginEntityManager(null); - try { - Query query = manager.createQuery("delete from StoredMessage m"); - query.executeUpdate(); - query = manager.createQuery("delete from StoredSubscription ss"); - query.executeUpdate(); - } catch (Throwable e) { - rollbackEntityManager(null,manager); - throw IOExceptionSupport.create(e); - } - commitEntityManager(null,manager); - } - - public Set getDestinations() { - HashSet rc = new HashSet(); - - EntityManager manager = beginEntityManager(null); - try { - Query query = manager.createQuery("select distinct m.destination from StoredMessage m"); - for (String dest : (List)query.getResultList()) { - rc.add(ActiveMQDestination.createDestination(dest,ActiveMQDestination.QUEUE_TYPE)); - } - } catch (RuntimeException e) { - rollbackEntityManager(null,manager); - throw e; - } - commitEntityManager(null,manager); - return rc; - } - - public long getLastMessageBrokerSequenceId() throws IOException { - long rc=0; - EntityManager manager = beginEntityManager(null); - try { - Query query = manager.createQuery("select max(m.id) from StoredMessage m"); - Long t = (Long) query.getSingleResult(); - if( t != null ) { - rc = t; - } - } catch (Throwable e) { - rollbackEntityManager(null,manager); - throw IOExceptionSupport.create(e); - } - commitEntityManager(null,manager); - return rc; - } - - public boolean isUseExternalMessageReferences() { - return false; - } - - public void setUsageManager(UsageManager usageManager) { - } - - public void start() throws Exception { - } - - public void stop() throws Exception { - if( entityManagerFactory !=null ) { - entityManagerFactory.close(); - } - } - - public EntityManagerFactory getEntityManagerFactory() { - if( entityManagerFactory == null ) { - entityManagerFactory = createEntityManagerFactory(); - } - return entityManagerFactory; - } - protected EntityManagerFactory createEntityManagerFactory() { - return Persistence.createEntityManagerFactory(getEntityManagerName(), getEntityManagerProperties()); - } - - public void setEntityManagerFactory(EntityManagerFactory entityManagerFactory) { - this.entityManagerFactory = entityManagerFactory; - } - - public Properties getEntityManagerProperties() { - return entityManagerProperties; - } - public void setEntityManagerProperties( - Properties entityManagerProperties) { - this.entityManagerProperties = entityManagerProperties; - } - - public String getEntityManagerName() { - return entityManagerName; - } - public void setEntityManagerName(String entityManager) { - this.entityManagerName = entityManager; - } - - public WireFormat getWireFormat() { - if(wireFormat==null) { - wireFormat = createWireFormat(); - } - return wireFormat; - } - - private WireFormat createWireFormat() { - OpenWireFormatFactory wff = new OpenWireFormatFactory(); - return wff.createWireFormat(); - } - - public void setWireFormat(WireFormat wireFormat) { - this.wireFormat = wireFormat; - } + public Set getDestinations() { + HashSet rc = new HashSet(); + + EntityManager manager = beginEntityManager(null); + try { + Query query = manager.createQuery("select distinct m.destination from StoredMessage m"); + for (String dest : (List)query.getResultList()) { + rc.add(ActiveMQDestination.createDestination(dest, ActiveMQDestination.QUEUE_TYPE)); + } + } catch (RuntimeException e) { + rollbackEntityManager(null, manager); + throw e; + } + commitEntityManager(null, manager); + return rc; + } + + public long getLastMessageBrokerSequenceId() throws IOException { + long rc = 0; + EntityManager manager = beginEntityManager(null); + try { + Query query = manager.createQuery("select max(m.id) from StoredMessage m"); + Long t = (Long)query.getSingleResult(); + if (t != null) { + rc = t; + } + } catch (Throwable e) { + rollbackEntityManager(null, manager); + throw IOExceptionSupport.create(e); + } + commitEntityManager(null, manager); + return rc; + } + + public boolean isUseExternalMessageReferences() { + return false; + } + + public void setUsageManager(UsageManager usageManager) { + } + + public void start() throws Exception { + } + + public void stop() throws Exception { + if (entityManagerFactory != null) { + entityManagerFactory.close(); + } + } + + public EntityManagerFactory getEntityManagerFactory() { + if (entityManagerFactory == null) { + entityManagerFactory = createEntityManagerFactory(); + } + return entityManagerFactory; + } + + protected EntityManagerFactory createEntityManagerFactory() { + return Persistence.createEntityManagerFactory(getEntityManagerName(), getEntityManagerProperties()); + } + + public void setEntityManagerFactory(EntityManagerFactory entityManagerFactory) { + this.entityManagerFactory = entityManagerFactory; + } + + public Properties getEntityManagerProperties() { + return entityManagerProperties; + } + + public void setEntityManagerProperties(Properties entityManagerProperties) { + this.entityManagerProperties = entityManagerProperties; + } + + public String getEntityManagerName() { + return entityManagerName; + } + + public void setEntityManagerName(String entityManager) { + this.entityManagerName = entityManager; + } + + public WireFormat getWireFormat() { + if (wireFormat == null) { + wireFormat = createWireFormat(); + } + return wireFormat; + } + + private WireFormat createWireFormat() { + OpenWireFormatFactory wff = new OpenWireFormatFactory(); + return wff.createWireFormat(); + } + + public void setWireFormat(WireFormat wireFormat) { + this.wireFormat = wireFormat; + } - public void checkpoint(boolean sync) throws IOException{ + public void checkpoint(boolean sync) throws IOException { } - public void setBrokerName(String brokerName){ + public void setBrokerName(String brokerName) { } - public void setDirectory(File dir){ + public void setDirectory(File dir) { } } Modified: activemq/trunk/activemq-jpa-store/src/main/java/org/apache/activemq/store/jpa/JPAReferenceStore.java URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-jpa-store/src/main/java/org/apache/activemq/store/jpa/JPAReferenceStore.java?view=diff&rev=565003&r1=565002&r2=565003 ============================================================================== --- activemq/trunk/activemq-jpa-store/src/main/java/org/apache/activemq/store/jpa/JPAReferenceStore.java (original) +++ activemq/trunk/activemq-jpa-store/src/main/java/org/apache/activemq/store/jpa/JPAReferenceStore.java Sat Aug 11 22:27:21 2007 @@ -36,181 +36,181 @@ import org.apache.activemq.wireformat.WireFormat; public class JPAReferenceStore implements ReferenceStore { - - protected final JPAPersistenceAdapter adapter; - protected final WireFormat wireFormat; - protected final ActiveMQDestination destination; - protected final String destinationName; + + protected final JPAPersistenceAdapter adapter; + protected final WireFormat wireFormat; + protected final ActiveMQDestination destination; + protected final String destinationName; protected AtomicLong lastMessageId = new AtomicLong(-1); - - public JPAReferenceStore(JPAPersistenceAdapter adapter, ActiveMQDestination destination) { - this.adapter = adapter; - this.destination = destination; - this.destinationName = destination.getQualifiedName(); - this.wireFormat = this.adapter.getWireFormat(); - } - - public ActiveMQDestination getDestination() { - return destination; - } - - public void addMessage(ConnectionContext context, Message message) throws IOException { - throw new RuntimeException("Use addMessageReference instead"); - } - - public Message getMessage(MessageId identity) throws IOException { - throw new RuntimeException("Use addMessageReference instead"); - } - - public void addMessageReference(ConnectionContext context, MessageId messageId, ReferenceData data) throws IOException { - EntityManager manager = adapter.beginEntityManager(context); - try { - - StoredMessageReference sm = new StoredMessageReference(); - sm.setDestination(destinationName); - sm.setId(messageId.getBrokerSequenceId()); - sm.setMessageId(messageId.toString()); - sm.setExiration(data.getExpiration()); - sm.setFileId(data.getFileId()); - sm.setOffset(data.getOffset()); - - manager.persist(sm); - - } catch (Throwable e) { - adapter.rollbackEntityManager(context,manager); - throw IOExceptionSupport.create(e); - } - adapter.commitEntityManager(context,manager); - } - - public ReferenceData getMessageReference(MessageId identity) throws IOException { - ReferenceData rc=null; - EntityManager manager = adapter.beginEntityManager(null); - try { - StoredMessageReference message=null; - if( identity.getBrokerSequenceId()!= 0 ) { - message = manager.find(StoredMessageReference.class, identity.getBrokerSequenceId()); - } else { - Query query = manager.createQuery("select m from StoredMessageReference m where m.messageId=?1"); - query.setParameter(1, identity.toString()); - message = (StoredMessageReference) query.getSingleResult(); - } - if( message !=null ) { - rc = new ReferenceData(); - rc.setExpiration(message.getExiration()); - rc.setFileId(message.getFileId()); - rc.setOffset(message.getOffset()); - } - } catch (Throwable e) { - adapter.rollbackEntityManager(null,manager); - throw IOExceptionSupport.create(e); - } - adapter.commitEntityManager(null,manager); - return rc; - } - - public int getMessageCount() throws IOException { - Long rc; - EntityManager manager = adapter.beginEntityManager(null); - try { - Query query = manager.createQuery("select count(m) from StoredMessageReference m"); - rc = (Long) query.getSingleResult(); - } catch (Throwable e) { - adapter.rollbackEntityManager(null,manager); - throw IOExceptionSupport.create(e); - } - adapter.commitEntityManager(null,manager); - return rc.intValue(); - } - - public void recover(MessageRecoveryListener container) throws Exception { - EntityManager manager = adapter.beginEntityManager(null); - try { - Query query = manager.createQuery("select m from StoredMessageReference m where m.destination=?1 order by m.id asc"); - query.setParameter(1, destinationName); - for (StoredMessageReference m : (List)query.getResultList()) { - MessageId id = new MessageId(m.getMessageId()); - id.setBrokerSequenceId(m.getId()); - container.recoverMessageReference(id); - } - } catch (Throwable e) { - adapter.rollbackEntityManager(null,manager); - throw IOExceptionSupport.create(e); - } - adapter.commitEntityManager(null,manager); - } - - public void recoverNextMessages(int maxReturned, MessageRecoveryListener listener) throws Exception { - - EntityManager manager = adapter.beginEntityManager(null); - try { - - Query query = manager.createQuery("select m from StoredMessageReference m where m.destination=?1 and m.id>?2 order by m.id asc"); - query.setParameter(1, destinationName); - query.setParameter(2, lastMessageId.get()); - query.setMaxResults(maxReturned); - int count = 0; - for (StoredMessageReference m : (List)query.getResultList()) { - MessageId id = new MessageId(m.getMessageId()); - id.setBrokerSequenceId(m.getId()); - listener.recoverMessageReference(id); - lastMessageId.set(m.getId()); - count++; - if( count >= maxReturned ) { - return; - } - } - - } catch (Throwable e) { - adapter.rollbackEntityManager(null,manager); - throw IOExceptionSupport.create(e); - } - adapter.commitEntityManager(null,manager); - } - - public void removeAllMessages(ConnectionContext context) throws IOException { - EntityManager manager = adapter.beginEntityManager(context); - try { - Query query = manager.createQuery("delete from StoredMessageReference m where m.destination=?1"); - query.setParameter(1, destinationName); - query.executeUpdate(); - } catch (Throwable e) { - adapter.rollbackEntityManager(context,manager); - throw IOExceptionSupport.create(e); - } - adapter.commitEntityManager(context,manager); - } - - public void removeMessage(ConnectionContext context, MessageAck ack) throws IOException { - EntityManager manager = adapter.beginEntityManager(context); - try { - Query query = manager.createQuery("delete from StoredMessageReference m where m.id=?1"); - query.setParameter(1, ack.getLastMessageId().getBrokerSequenceId()); - query.executeUpdate(); - } catch (Throwable e) { - adapter.rollbackEntityManager(context,manager); - throw IOExceptionSupport.create(e); - } - adapter.commitEntityManager(context,manager); - } - public void resetBatching() { + public JPAReferenceStore(JPAPersistenceAdapter adapter, ActiveMQDestination destination) { + this.adapter = adapter; + this.destination = destination; + this.destinationName = destination.getQualifiedName(); + this.wireFormat = this.adapter.getWireFormat(); + } + + public ActiveMQDestination getDestination() { + return destination; + } + + public void addMessage(ConnectionContext context, Message message) throws IOException { + throw new RuntimeException("Use addMessageReference instead"); + } + + public Message getMessage(MessageId identity) throws IOException { + throw new RuntimeException("Use addMessageReference instead"); + } + + public void addMessageReference(ConnectionContext context, MessageId messageId, ReferenceData data) throws IOException { + EntityManager manager = adapter.beginEntityManager(context); + try { + + StoredMessageReference sm = new StoredMessageReference(); + sm.setDestination(destinationName); + sm.setId(messageId.getBrokerSequenceId()); + sm.setMessageId(messageId.toString()); + sm.setExiration(data.getExpiration()); + sm.setFileId(data.getFileId()); + sm.setOffset(data.getOffset()); + + manager.persist(sm); + + } catch (Throwable e) { + adapter.rollbackEntityManager(context, manager); + throw IOExceptionSupport.create(e); + } + adapter.commitEntityManager(context, manager); + } + + public ReferenceData getMessageReference(MessageId identity) throws IOException { + ReferenceData rc = null; + EntityManager manager = adapter.beginEntityManager(null); + try { + StoredMessageReference message = null; + if (identity.getBrokerSequenceId() != 0) { + message = manager.find(StoredMessageReference.class, identity.getBrokerSequenceId()); + } else { + Query query = manager.createQuery("select m from StoredMessageReference m where m.messageId=?1"); + query.setParameter(1, identity.toString()); + message = (StoredMessageReference)query.getSingleResult(); + } + if (message != null) { + rc = new ReferenceData(); + rc.setExpiration(message.getExiration()); + rc.setFileId(message.getFileId()); + rc.setOffset(message.getOffset()); + } + } catch (Throwable e) { + adapter.rollbackEntityManager(null, manager); + throw IOExceptionSupport.create(e); + } + adapter.commitEntityManager(null, manager); + return rc; + } + + public int getMessageCount() throws IOException { + Long rc; + EntityManager manager = adapter.beginEntityManager(null); + try { + Query query = manager.createQuery("select count(m) from StoredMessageReference m"); + rc = (Long)query.getSingleResult(); + } catch (Throwable e) { + adapter.rollbackEntityManager(null, manager); + throw IOExceptionSupport.create(e); + } + adapter.commitEntityManager(null, manager); + return rc.intValue(); + } + + public void recover(MessageRecoveryListener container) throws Exception { + EntityManager manager = adapter.beginEntityManager(null); + try { + Query query = manager.createQuery("select m from StoredMessageReference m where m.destination=?1 order by m.id asc"); + query.setParameter(1, destinationName); + for (StoredMessageReference m : (List)query.getResultList()) { + MessageId id = new MessageId(m.getMessageId()); + id.setBrokerSequenceId(m.getId()); + container.recoverMessageReference(id); + } + } catch (Throwable e) { + adapter.rollbackEntityManager(null, manager); + throw IOExceptionSupport.create(e); + } + adapter.commitEntityManager(null, manager); + } + + public void recoverNextMessages(int maxReturned, MessageRecoveryListener listener) throws Exception { + + EntityManager manager = adapter.beginEntityManager(null); + try { + + Query query = manager.createQuery("select m from StoredMessageReference m where m.destination=?1 and m.id>?2 order by m.id asc"); + query.setParameter(1, destinationName); + query.setParameter(2, lastMessageId.get()); + query.setMaxResults(maxReturned); + int count = 0; + for (StoredMessageReference m : (List)query.getResultList()) { + MessageId id = new MessageId(m.getMessageId()); + id.setBrokerSequenceId(m.getId()); + listener.recoverMessageReference(id); + lastMessageId.set(m.getId()); + count++; + if (count >= maxReturned) { + return; + } + } + + } catch (Throwable e) { + adapter.rollbackEntityManager(null, manager); + throw IOExceptionSupport.create(e); + } + adapter.commitEntityManager(null, manager); + } + + public void removeAllMessages(ConnectionContext context) throws IOException { + EntityManager manager = adapter.beginEntityManager(context); + try { + Query query = manager.createQuery("delete from StoredMessageReference m where m.destination=?1"); + query.setParameter(1, destinationName); + query.executeUpdate(); + } catch (Throwable e) { + adapter.rollbackEntityManager(context, manager); + throw IOExceptionSupport.create(e); + } + adapter.commitEntityManager(context, manager); + } + + public void removeMessage(ConnectionContext context, MessageAck ack) throws IOException { + EntityManager manager = adapter.beginEntityManager(context); + try { + Query query = manager.createQuery("delete from StoredMessageReference m where m.id=?1"); + query.setParameter(1, ack.getLastMessageId().getBrokerSequenceId()); + query.executeUpdate(); + } catch (Throwable e) { + adapter.rollbackEntityManager(context, manager); + throw IOExceptionSupport.create(e); + } + adapter.commitEntityManager(context, manager); + } + + public void resetBatching() { lastMessageId.set(-1); - } + } - public void setUsageManager(UsageManager usageManager) { - } + public void setUsageManager(UsageManager usageManager) { + } - public void start() throws Exception { - } + public void start() throws Exception { + } - public void stop() throws Exception { - } + public void stop() throws Exception { + } - public void setBatch(MessageId startAfter){ + public void setBatch(MessageId startAfter) { } - public boolean supportsExternalBatchControl(){ + public boolean supportsExternalBatchControl() { return false; } } Modified: activemq/trunk/activemq-jpa-store/src/main/java/org/apache/activemq/store/jpa/JPAReferenceStoreAdapter.java URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-jpa-store/src/main/java/org/apache/activemq/store/jpa/JPAReferenceStoreAdapter.java?view=diff&rev=565003&r1=565002&r2=565003 ============================================================================== --- activemq/trunk/activemq-jpa-store/src/main/java/org/apache/activemq/store/jpa/JPAReferenceStoreAdapter.java (original) +++ activemq/trunk/activemq-jpa-store/src/main/java/org/apache/activemq/store/jpa/JPAReferenceStoreAdapter.java Sat Aug 11 22:27:21 2007 @@ -38,123 +38,121 @@ import org.apache.activemq.util.IOExceptionSupport; /** - * An implementation of {@link ReferenceStoreAdapter} that uses JPA to - * store it's message references. + * An implementation of {@link ReferenceStoreAdapter} that uses JPA to store + * it's message references. * * @org.apache.xbean.XBean element="jpaReferenceStoreAdapter" - * * @version $Revision: 1.17 $ */ public class JPAReferenceStoreAdapter extends JPAPersistenceAdapter implements ReferenceStoreAdapter { - @Override - public MessageStore createQueueMessageStore(ActiveMQQueue destination) throws IOException { - throw new RuntimeException("Use createQueueReferenceStore instead."); - } - - @Override - public TopicMessageStore createTopicMessageStore(ActiveMQTopic destination) throws IOException { - throw new RuntimeException("Use createTopicReferenceStore instead."); - } - - public ReferenceStore createQueueReferenceStore(ActiveMQQueue destination) throws IOException { - JPAReferenceStore rc = new JPAReferenceStore(this, destination); + @Override + public MessageStore createQueueMessageStore(ActiveMQQueue destination) throws IOException { + throw new RuntimeException("Use createQueueReferenceStore instead."); + } + + @Override + public TopicMessageStore createTopicMessageStore(ActiveMQTopic destination) throws IOException { + throw new RuntimeException("Use createTopicReferenceStore instead."); + } + + public ReferenceStore createQueueReferenceStore(ActiveMQQueue destination) throws IOException { + JPAReferenceStore rc = new JPAReferenceStore(this, destination); + return rc; + } + + public TopicReferenceStore createTopicReferenceStore(ActiveMQTopic destination) throws IOException { + JPATopicReferenceStore rc = new JPATopicReferenceStore(this, destination); + return rc; + } + + public void deleteAllMessages() throws IOException { + EntityManager manager = beginEntityManager(null); + try { + Query query = manager.createQuery("delete from StoredMessageReference m"); + query.executeUpdate(); + query = manager.createQuery("delete from StoredSubscription ss"); + query.executeUpdate(); + } catch (Throwable e) { + rollbackEntityManager(null, manager); + throw IOExceptionSupport.create(e); + } + commitEntityManager(null, manager); + } + + public Set getDestinations() { + HashSet rc = new HashSet(); + + EntityManager manager = beginEntityManager(null); + try { + Query query = manager.createQuery("select distinct m.destination from StoredMessageReference m"); + for (String dest : (List)query.getResultList()) { + rc.add(ActiveMQDestination.createDestination(dest, ActiveMQDestination.QUEUE_TYPE)); + } + } catch (RuntimeException e) { + rollbackEntityManager(null, manager); + throw e; + } + commitEntityManager(null, manager); return rc; - } + } - public TopicReferenceStore createTopicReferenceStore(ActiveMQTopic destination) throws IOException { - JPATopicReferenceStore rc = new JPATopicReferenceStore(this, destination); + public long getLastMessageBrokerSequenceId() throws IOException { + long rc = 0; + EntityManager manager = beginEntityManager(null); + try { + Query query = manager.createQuery("select max(m.id) from StoredMessageReference m"); + Long t = (Long)query.getSingleResult(); + if (t != null) { + rc = t; + } + } catch (Throwable e) { + rollbackEntityManager(null, manager); + throw IOExceptionSupport.create(e); + } + commitEntityManager(null, manager); return rc; - } - + } - public void deleteAllMessages() throws IOException { - EntityManager manager = beginEntityManager(null); - try { - Query query = manager.createQuery("delete from StoredMessageReference m"); - query.executeUpdate(); - query = manager.createQuery("delete from StoredSubscription ss"); - query.executeUpdate(); - } catch (Throwable e) { - rollbackEntityManager(null,manager); - throw IOExceptionSupport.create(e); - } - commitEntityManager(null,manager); - } - - public Set getDestinations() { - HashSet rc = new HashSet(); - - EntityManager manager = beginEntityManager(null); - try { - Query query = manager.createQuery("select distinct m.destination from StoredMessageReference m"); - for (String dest : (List)query.getResultList()) { - rc.add(ActiveMQDestination.createDestination(dest,ActiveMQDestination.QUEUE_TYPE)); - } - } catch (RuntimeException e) { - rollbackEntityManager(null,manager); - throw e; - } - commitEntityManager(null,manager); - return rc; - } - - public long getLastMessageBrokerSequenceId() throws IOException { - long rc=0; - EntityManager manager = beginEntityManager(null); - try { - Query query = manager.createQuery("select max(m.id) from StoredMessageReference m"); - Long t = (Long) query.getSingleResult(); - if( t != null ) { - rc = t; - } - } catch (Throwable e) { - rollbackEntityManager(null,manager); - throw IOExceptionSupport.create(e); - } - commitEntityManager(null,manager); - return rc; - } - - public Set getReferenceFileIdsInUse() throws IOException { - HashSet rc=null; - EntityManager manager = beginEntityManager(null); - try { - Query query = manager.createQuery("select distinct m.fileId from StoredMessageReference m"); - rc=new HashSet((List)query.getResultList()); - } catch (Throwable e) { - rollbackEntityManager(null,manager); - throw IOExceptionSupport.create(e); - } - commitEntityManager(null,manager); - return rc; - } + public Set getReferenceFileIdsInUse() throws IOException { + HashSet rc = null; + EntityManager manager = beginEntityManager(null); + try { + Query query = manager.createQuery("select distinct m.fileId from StoredMessageReference m"); + rc = new HashSet((List)query.getResultList()); + } catch (Throwable e) { + rollbackEntityManager(null, manager); + throw IOExceptionSupport.create(e); + } + commitEntityManager(null, manager); + return rc; + } /** * @return * @see org.apache.activemq.store.ReferenceStoreAdapter#isStoreValid() */ - public boolean isStoreValid(){ + public boolean isStoreValid() { return false; } /** * @see org.apache.activemq.store.ReferenceStoreAdapter#clearMessages() */ - public void clearMessages(){ + public void clearMessages() { } /** * @see org.apache.activemq.store.ReferenceStoreAdapter#recoverState() */ - public void recoverState(){ + public void recoverState() { } - public Map retrievePreparedState() throws IOException{ + public Map retrievePreparedState() throws IOException { return null; } - public void savePreparedState(Map map) throws IOException{ + public void savePreparedState(Map map) throws IOException { } }