[jboss-user] [JCA/JBoss] - Re: How to change datasource properties using java client co
chetanchatwani
do-not-reply at jboss.com
Fri May 8 05:22:27 EDT 2009
Hi Vicky,
Thanks for you help, however I am getting following excprion :
javax.management.InstanceNotFoundException: jboss.jca:service=ManagedConnectionF
actory,name=BizLogicDB
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getMBean(Unknow
n Source)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(Unknown
Source)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(Unknown Source)
at TestJBoss.main(TestJBoss.java:61)
*************************************Source code*********
import javax.management.MBeanServer;
import javax.management.MBeanServerInvocationHandler;
import javax.management.ObjectName;
import javax.management.MBeanServerFactory;
import org.jboss.mx.util.MBeanServerLocator;
import java.util.Properties;
import javax.management.AttributeList;
import javax.management.Attribute;
import javax.naming.InitialContext;
import javax.naming.Context;
public class TestJBoss {
public static void main(String args[]) {
final String jndiURL = "jdbc/BizLogicDB";
final String serverUrl="jnp://sys181.tdiinc.com:18026";
final StringBuilder properties = new StringBuilder(512);
javax.naming.InitialContext ic = null;
try{
ic = getInitialContext(serverUrl);
if(null!=ic){
System.out.println("Got InitialContext object");
} else {
System.out.println("Failed to get InitialContext object");
}
MBeanServer server = MBeanServerFactory.createMBeanServer("ejbServer");
if(null!=server){
System.out.println("Got server object");
ObjectName mcfName = new ObjectName("jboss.jca:service=ManagedConnectionFactory,name=" + "BizLogicDB");
ObjectName mcpName = new ObjectName("jboss.jca:service=ManagedConnectionPool,name=" + jndiURL);
ObjectName dsName = new ObjectName("jboss.jca:service=DataSourceBinding,name=" + jndiURL);
Object dsBean = server.createMBean("org.jboss.resource.adapter.jdbc.remote.WrapperDataSourceService", dsName);
if(null!=mcfName){
System.out.println("Got mcfName object");
} else {
System.out.println("Failed to get mcfName object");
}
if(null!=dsName){
System.out.println("Got dsName object");
AttributeList al = new AttributeList();
al.add(new Attribute("UseJavaContext", Boolean.TRUE));
server.setAttributes(dsName, al);
properties.append("\nUser=");
properties.append("chetan1");
properties.append("\nPassword=");
properties.append("chetan1");
properties.append('\n');
server.invoke(mcfName, "setManagedConnectionFactoryAttribute", new Object[] { "XADataSourceProperties",
java.lang.String.class, properties.toString() }, new String[] { "java.lang.String", "java.lang.Class",
"java.lang.Object" });
} else {
System.out.println("Failed to get dsName object");
}
} else {
System.out.println("Failed to get server object");
}
}catch(Throwable th){
th.printStackTrace();
}
}
public static InitialContext getInitialContext(String serverUrl) throws Exception{
Properties props = new Properties();
props.put(Context.PROVIDER_URL, serverUrl);
props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
props.setProperty(Context.SECURITY_PRINCIPAL, "guest");
props.setProperty(Context.SECURITY_CREDENTIALS, "guest");
return new InitialContext(props);
}
}
************************************************************
Any help for same
Thanks and Regards,
Chetan
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4229660#4229660
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4229660
More information about the jboss-user
mailing list