users@glassfish.java.net

Configuration of GlassFish from within a web app

From: <glassfish_at_javadesktop.org>
Date: Wed, 07 Jul 2010 10:19:13 PDT

Hi,

we would like to configure GlassFishv3 from within a Web Application (servlet) which serves as set up wizard for our application (i.e. ask the user a few questions and then set up everything that's needed to work with the app). One of the things we need to set up is a JDBC connection pool.

We searched a while for information about how to use the GlassFish config API, but unfortunately, we found only documentation about how to implement a new asadmin command. We found nothing about how to use existing commands besides the 'asadmin' command line program.

After digging into the source codes of 'asadmin', we tried it the following way:

**************************************************************************************************
Bundle bundle = FrameworkUtil.getBundle(javax.mail.Address.class);
bundle.start();
BundleContext bc = bundle.getBundleContext();
ServiceReference ref = bc.getServiceReference(Habitat.class.getName());
Habitat habitat = (Habitat) bc.getService(ref);

CLICommand cmd = CLICommand.getCommand(habitat, "create-jdbc-connection-pool");
int resultCode = cmd.execute(
"--datasourceclassname", "org.postgresql.xa.PGXADataSource",
"--restype", "javax.sql.XADataSource",
"--property", "password=password:user=user:databaseName=somedatabase",
"pool-name"
);
**************************************************************************************************

However, we get the following error message:

WARNING: StandardWrapperValve[OverviewServlet]: PWC1406: Servlet.service() for servlet OverviewServlet threw exception
java.lang.RuntimeException: java.lang.NullPointerException
        at org.nightlabs.glassfish.autoconfig.servlet.BaseServlet.doPost(BaseServlet.java:43)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:751)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:844)
        at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1518)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:277)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:171)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:651)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:591)
        at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
        at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:87)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:158)
        at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:321)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:222)
        at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
        at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:803)
        at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:706)
        at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:987)
        at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:178)
        at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
        at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
        at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
        at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
        at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:526)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:507)
        at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NullPointerException
        at com.sun.enterprise.admin.cli.CLICommand.initializeLogger(CLICommand.java:526)
        at com.sun.enterprise.admin.cli.CLICommand.<init>(CLICommand.java:213)
        at com.sun.enterprise.admin.cli.remote.RemoteCommand.<init>(RemoteCommand.java:233)
        at com.sun.enterprise.admin.cli.CLICommand.getCommand(CLICommand.java:178)
        at org.nightlabs.glassfish.autoconfig.servlet.OverviewServlet.handleRequest(OverviewServlet.java:79)
        at org.nightlabs.glassfish.autoconfig.servlet.BaseServlet.doPost(BaseServlet.java:40)
        ... 27 more

Maybe we're barking up the wrong tree... Any hints would be highly appreciated!

Best regards,

Frederik Löser
[Message sent by forum member 'nlfred']

http://forums.java.net/jive/thread.jspa?messageID=477024