English 中文(简体)
Glassfish - describing the environment which a web application is running
原标题:

I would like a web application to learn things about its environment so that it can describe various details when an exception occurs.

How would I get the ip address(es) that glassfish is running on within the web application?

I would like to also take a snapshot of the configuration, JDBC connections, JMS, JNDI, etc. Is this possible?

I guess this would be more related to the API of glassfish and injecting a bean or mbean.

Walter

最佳回答

I do the following:

  1. find all network interfaces on the machine
  2. record JVM information

This gives me enough information to determine where a problem came from.

Walter

问题回答

How would I get the ip address(es) that glassfish is running on within the web application?

You can get such information in ServletRequest, e.g. the port.

I would like to also take a snapshot of the configuration, JDBC connections, JMS, JNDI, etc. Is this possible?

You will need to rely on the metadata of the connection or the connection factory. If fear this is not entirely portable, but you should be able to get some information, e.g. the JDBC metadata.

You can also connect the JMX beans of Glassfish. I did that once from a web app to monitor the connection that were allocated over time. If you know the name of the JMX beans to look up (e.g. if you know the name of the data source) you can get a wagon on information there. Basically everything that the native Glassfish console display is there.

You could maybe gather all the information at startup-up withing a ServletContextListener and then store them somewhere to spit them out in case of an exception.

Note that you can disclose potential sensitive information to the end-user, which is not a recommended practice.

How would I get the ip address(es) that glassfish is running on within the web application?

Use ServletRequest#getLocalPort() for that (not ServletRequest#getServerPort() which actually returns the port number to which the request was sent, most often 80, and might be different from the port the container is listening to due to routing/load balancing).

I would like to also take a snapshot of the configuration, JDBC connections, JMS, JNDI, etc. Is this possible?

Well, you can maybe browse the JNDI tree to see what is in there but your application is not supposed to be aware of all the details (understand: I don t think you ll be able to access all metadata, at least not this way).

Another option would be to connect to GlassFish s exposed administrative MBeans via JMX. But this will require the admin credentials (and might thus not be possible).

Maybe you should clarify your needs and constraints to get more precise answers.





相关问题
Recommended way to develop using Jetty and Eclipse

I am currently developing a J2EE application and I would like to use Jetty. I would like to have iot integrated with Eclipse, so I could debug the appliaction. I ve tried out couple of plugins (...

Call function periodically in Java

we need run one function periodically in Java web application . How to call function of some class periodically ? Is there any way that call function when some event occured like high load in server ...

Why make an EJB rather than a Web Service?

I would have thought that there is a lot of information out there on this, but I haven t found anything that really answers my question. What are the advantages of making an EJB rather than a web ...

Where should I put this configuration setting?

I m designing a fairly small web application which will run on a Sun application server (v9.1). It only has a few pages, no database of its own, and will retrieve/update data via web services. There s ...

JNDI Names -- Is Prefix "jdbc/" needed?

What s up with JNDI names? I m trying to get a javax.sql.DataSource using the new annotations feature of Java 5. It s not working for me, so I want to ask... I have a in my web.xml, inside of it is ...

hibernate interceptors : afterTransactionCompletion

I wrote a Hibernate interceptor : public class MyInterceptor extends EmptyInterceptor { private boolean isCanal=false; public boolean onSave(Object entity, Serializable arg1, Object[] arg2, String[]...

热门标签