Commit 9b975e4f authored by afreyssin's avatar afreyssin
Browse files

Fit to new behavior and interface of the JoramHelper.

parent 772f4804
......@@ -21,28 +21,19 @@
*/
package org.objectweb.joram.mom.util;
import java.io.IOException;
import java.util.Properties;
import javax.naming.InitialContext;
import javax.naming.Reference;
import org.objectweb.joram.client.jms.Destination;
import org.objectweb.joram.client.jms.admin.ObjectFactory;
import org.objectweb.joram.mom.dest.AdminTopic;
import org.objectweb.joram.mom.dest.AdminTopic.DestinationDesc;
import org.objectweb.joram.shared.DestinationConstants;
import org.objectweb.joram.shared.admin.CreateUserRequest;
import org.objectweb.joram.shared.admin.SetReader;
import org.objectweb.joram.shared.admin.SetWriter;
import org.objectweb.joram.shared.excepts.RequestException;
import org.objectweb.joram.shared.security.SimpleIdentity;
import org.objectweb.util.monolog.api.BasicLevel;
import org.objectweb.util.monolog.api.Logger;
import fr.dyade.aaa.agent.AgentId;
import fr.dyade.aaa.agent.AgentServer;
import fr.dyade.aaa.agent.UnknownServerException;
import fr.dyade.aaa.common.Debug;
/**
......@@ -72,29 +63,14 @@ public class JoramHelper {
*/
public final static void createUser(String userName, String userPass) {
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG,
"createUser(" + userName + ')');
logger.log(BasicLevel.DEBUG, "JoramHelper.createUser(" + userName + ')');
try {
SimpleIdentity identity = new SimpleIdentity();
identity.setIdentity(userName, userPass);
AdminTopic.CreateUserAndSave(new CreateUserRequest(identity, AgentServer.getServerId(), null), null, "-1");
}
catch (UnknownServerException e) {
if (logger.isLoggable(BasicLevel.ERROR))
logger.log(BasicLevel.ERROR,
"Exception:: createUser", e);
} catch (RequestException e) {
if (logger.isLoggable(BasicLevel.ERROR))
logger.log(BasicLevel.ERROR,
"Exception:: createUser", e);
} catch (IOException e) {
if (logger.isLoggable(BasicLevel.ERROR))
logger.log(BasicLevel.ERROR,
"Exception:: createUser", e);
} catch (Exception e) {
} catch (Exception exc) {
if (logger.isLoggable(BasicLevel.ERROR))
logger.log(BasicLevel.ERROR,
"Exception:: createUser", e);
logger.log(BasicLevel.ERROR, "Exception:: JoramHelper.createUser", exc);
}
}
......@@ -118,155 +94,40 @@ public class JoramHelper {
String destClassName,
byte type,
Properties properties,
String fromClassName,
boolean jndiLookup,
boolean jndiRebind,
boolean freerw) throws Exception {
AgentId destId = null;
Destination dest = null;
StringBuffer buff = new StringBuffer();
StringBuffer strbuf = new StringBuffer();
DestinationDesc destDesc = null;
// remove jndi reference if rebind is required
if (jndiRebind) {
try {
Properties props = new Properties();
props.setProperty(JoramHelper.JNDI_INITIAL, AgentServer.getProperty(JoramHelper.JNDI_INITIAL));
props.setProperty(JoramHelper.JNDI_HOST, AgentServer.getProperty(JoramHelper.JNDI_HOST));
props.setProperty(JoramHelper.JNDI_PORT, AgentServer.getProperty(JoramHelper.JNDI_PORT));
//InitialContext ctx = JndiHelper.newInitialContext(props);
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, "JoramHelper.createDestination ::props = " + props);
InitialContext jndiCtx = new InitialContext(props);
jndiCtx.unbind(destName);
} catch (Exception e) {
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, "JoramHelper.createDestination :: Exception ",e);
}
}
Exception typeExc = null;
try {
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG,
"createDestination(" + destName +')');
if (AdminTopic.isDestinationTableContain(destName)) {
destDesc =
AdminTopic.createDestinationAndSave(destName, adminId, properties, type, destClassName, fromClassName, buff);
destId = destDesc.getId();
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG,
"createDestination info = " + buff.toString());
buff.setLength(0);
} else if (jndiLookup) {
Properties props = new Properties();
props.setProperty(JNDI_INITIAL, AgentServer.getProperty(JNDI_INITIAL));
props.setProperty(JNDI_HOST, AgentServer.getProperty(JNDI_HOST));
props.setProperty(JNDI_PORT, AgentServer.getProperty(JNDI_PORT));
//InitialContext ctx = JndiHelper.newInitialContext(props);
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, "props = " + props);
InitialContext ctx = new InitialContext(props);
Object obj = ctx.lookup(destName);
if (obj instanceof Reference) {
ObjectFactory objFactory = new ObjectFactory();
dest = (Destination) objFactory.getObjectInstance(obj, null, null, null);
} else if (obj instanceof Destination) {
dest = (Destination) obj;
}
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG,
"createDestination: dest = " + dest);
if (dest != null) {
destId = AgentId.fromString(dest.getName());
// check the destination type
if (!DestinationConstants.compatible(dest.getType(), type)) {
typeExc = new Exception("JoramHelper, retrieve wrong destination type: " + destName);
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, typeExc);
}
}
}
} catch (Exception e) {
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, "createDestination(" + destName +')', e);
destDesc = AdminTopic.createDestinationAndSave(destName, adminId, properties,
type, destClassName,
"JoramHelper", strbuf);
} catch (Exception exc) {
logger.log(BasicLevel.ERROR, "JoramHelper.createDestination, Cannot create destination " + destName, exc);
throw exc;
}
if (typeExc != null) throw typeExc;
if (destId == null) {
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, "createDestination id = null");
try {
destDesc =
AdminTopic.createDestinationAndSave(destName, adminId, properties, type, destClassName, fromClassName, buff);
destId = destDesc.getId();
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, "createDestination info = " + buff.toString());
buff.setLength(0);
} catch (Exception exc) {
if (logger.isLoggable(BasicLevel.ERROR))
logger.log(BasicLevel.ERROR, "createDestination :: Exception " + buff.toString(), exc);
buff.setLength(0);
throw exc;
}
}
destId = destDesc.getId();
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, "JoramHelper.createDestination info = " + strbuf.toString());
strbuf.setLength(0);
if (freerw) {
try {
AdminTopic.setRightAndSave(new SetReader(null, destId.toString()), null, "-1");
} catch (Exception exc) {
if (logger.isLoggable(BasicLevel.ERROR))
logger.log(BasicLevel.ERROR, "Cannot set FreeReader", exc);
logger.log(BasicLevel.ERROR, "JoramHelper.createDestination, Cannot set FreeReader", exc);
}
try {
AdminTopic.setRightAndSave(new SetWriter(null, destId.toString()), null, "-1");
} catch (Exception exc) {
if (logger.isLoggable(BasicLevel.ERROR))
logger.log(BasicLevel.ERROR, "Cannot set FreeWriter", exc);
logger.log(BasicLevel.ERROR, "JoramHelper.createDestination, Cannot set FreeWriter", exc);
}
}
if (jndiRebind && dest == null) {
if (DestinationConstants.compatible(DestinationConstants.QUEUE_TYPE, destDesc.getType()))
dest = new org.objectweb.joram.client.jms.Queue(""+destDesc.getId());
else
dest = new org.objectweb.joram.client.jms.Topic(""+destDesc.getId());
if (dest != null) {
Properties props = new Properties();
props.setProperty(JNDI_INITIAL, AgentServer.getProperty(JNDI_INITIAL));
props.setProperty(JNDI_HOST, AgentServer.getProperty(JNDI_HOST));
props.setProperty(JNDI_PORT, AgentServer.getProperty(JNDI_PORT));
//InitialContext ctx = JndiHelper.newInitialContext(props);
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, "props = " + props);
InitialContext ctx = new InitialContext(props);
ctx.rebind(destName, dest);
}
}
return destId;
}
// /**
// * set free writing and reading.
// * @param destId
// */
// public final static void setFreeRW(String destId) {
// if (logger.isLoggable(BasicLevel.DEBUG))
// logger.log(BasicLevel.DEBUG, "setFreeRW(" + destId + ')');
// try {
// AdminTopic.setRightAndSave(new SetReader(null,destId), null, "-1");
// AdminTopic.setRightAndSave(new SetWriter(null,destId), null, "-1");
// } catch (Exception e) {
// if (logger.isLoggable(BasicLevel.ERROR))
// logger.log(BasicLevel.ERROR, "Exception:: setFreeRW", e);
// }
// }
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment