You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Yann BLAZART <ya...@externe.bnpparibas.com> on 2015/09/22 18:52:33 UTC

tomcat MBeans in tomee embedded

Hello everybody.

In my projects I need to know dynamically the remote port of the launched tomee-embedded (http/https).

For that I user the following code :
private Integer[] detectPort() {
        Integer [] ports = new Integer[]{-1,-1};
        try {
            MBeanServer mBeanServer = MBeanServerFactory.findMBeanServer(null).get(0);
            ObjectName name = new ObjectName("Catalina", "type", "Server");
            Server server = (Server) mBeanServer.getAttribute(name, "managedResource");

            Service[] services = server.findServices();
            for (Service service : services) {
                for (Connector connector : service.findConnectors()) {
                    ProtocolHandler protocolHandler = connector.getProtocolHandler();
                    if (protocolHandler instanceof Http11Protocol
                            || protocolHandler instanceof Http11AprProtocol
                            || protocolHandler instanceof Http11NioProtocol) {
                        if ( connector.getSecure() ) {
                            ports[1] = connector.getPort();
                        } else {
                            ports[0]=connector.getPort();
                        }
                    }
                }
            }
        } catch (MalformedObjectNameException | MBeanException | AttributeNotFoundException | InstanceNotFoundException | ReflectionException ex) {
            throw new EJBException(ex);
        }
        return ports;
    }


But this doesn't work with the tome-embedded plugin,.

I readed that for tomcat I need to add <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
In server.xml

How can I do with tome embedded ?


This message and any attachments (the "message") is
intended solely for the intended addressees and is confidential. 
If you receive this message in error,or are not the intended recipient(s), 
please delete it and any copies from your systems and immediately notify
the sender. Any unauthorized view, use that does not comply with its purpose, 
dissemination or disclosure, either whole or partial, is prohibited. Since the internet 
cannot guarantee the integrity of this message which may not be reliable, BNP PARIBAS 
(and its subsidiaries) shall not be liable for the message if modified, changed or falsified. 
Do not print this message unless it is necessary,consider the environment.

----------------------------------------------------------------------------------------------------------------------------------

Ce message et toutes les pieces jointes (ci-apres le "message") 
sont etablis a l'intention exclusive de ses destinataires et sont confidentiels.
Si vous recevez ce message par erreur ou s'il ne vous est pas destine,
merci de le detruire ainsi que toute copie de votre systeme et d'en avertir
immediatement l'expediteur. Toute lecture non autorisee, toute utilisation de 
ce message qui n'est pas conforme a sa destination, toute diffusion ou toute 
publication, totale ou partielle, est interdite. L'Internet ne permettant pas d'assurer
l'integrite de ce message electronique susceptible d'alteration, BNP Paribas 
(et ses filiales) decline(nt) toute responsabilite au titre de ce message dans l'hypothese
ou il aurait ete modifie, deforme ou falsifie. 
N'imprimez ce message que si necessaire, pensez a l'environnement.

RE: tomcat MBeans in tomee embedded

Posted by Yann BLAZART <ya...@externe.bnpparibas.com>.
Wonderfull !

Amazing !!
 It works !

You've saved my evening, thanks !

-----Original Message-----
From: Romain Manni-Bucau [mailto:rmannibucau@gmail.com] 
Sent: mardi 22 septembre 2015 18:54
To: users@tomee.apache.org
Subject: Re: tomcat MBeans in tomee embedded

tomee embedded uses by default "Tomcat" instead of "Catalina". Alternative is to use TomcatHelper.getServer() as entry point.


Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog <http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> | LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber <http://www.tomitribe.com>

2015-09-22 9:52 GMT-07:00 Yann BLAZART <ya...@externe.bnpparibas.com>
:

> Hello everybody.
>
> In my projects I need to know dynamically the remote port of the 
> launched tomee-embedded (http/https).
>
> For that I user the following code :
> private Integer[] detectPort() {
>         Integer [] ports = new Integer[]{-1,-1};
>         try {
>             MBeanServer mBeanServer =
> MBeanServerFactory.findMBeanServer(null).get(0);
>             ObjectName name = new ObjectName("Catalina", "type", "Server");
>             Server server = (Server) mBeanServer.getAttribute(name, 
> "managedResource");
>
>             Service[] services = server.findServices();
>             for (Service service : services) {
>                 for (Connector connector : service.findConnectors()) {
>                     ProtocolHandler protocolHandler = 
> connector.getProtocolHandler();
>                     if (protocolHandler instanceof Http11Protocol
>                             || protocolHandler instanceof Http11AprProtocol
>                             || protocolHandler instanceof
> Http11NioProtocol) {
>                         if ( connector.getSecure() ) {
>                             ports[1] = connector.getPort();
>                         } else {
>                             ports[0]=connector.getPort();
>                         }
>                     }
>                 }
>             }
>         } catch (MalformedObjectNameException | MBeanException | 
> AttributeNotFoundException | InstanceNotFoundException | 
> ReflectionException ex) {
>             throw new EJBException(ex);
>         }
>         return ports;
>     }
>
>
> But this doesn't work with the tome-embedded plugin,.
>
> I readed that for tomcat I need to add <Listener 
> className="org.apache.catalina.mbeans.ServerLifecycleListener" /> In 
> server.xml
>
> How can I do with tome embedded ?
>
>
> This message and any attachments (the "message") is intended solely 
> for the intended addressees and is confidential.
> If you receive this message in error,or are not the intended 
> recipient(s), please delete it and any copies from your systems and 
> immediately notify the sender. Any unauthorized view, use that does 
> not comply with its purpose, dissemination or disclosure, either whole 
> or partial, is prohibited. Since the internet cannot guarantee the 
> integrity of this message which may not be reliable, BNP PARIBAS (and 
> its subsidiaries) shall not be liable for the message if modified, 
> changed or falsified.
> Do not print this message unless it is necessary,consider the environment.
>
>
> ----------------------------------------------------------------------
> ------------------------------------------------------------
>
> Ce message et toutes les pieces jointes (ci-apres le "message") sont 
> etablis a l'intention exclusive de ses destinataires et sont 
> confidentiels.
> Si vous recevez ce message par erreur ou s'il ne vous est pas destine, 
> merci de le detruire ainsi que toute copie de votre systeme et d'en 
> avertir immediatement l'expediteur. Toute lecture non autorisee, toute 
> utilisation de ce message qui n'est pas conforme a sa destination, 
> toute diffusion ou toute publication, totale ou partielle, est 
> interdite. L'Internet ne permettant pas d'assurer l'integrite de ce 
> message electronique susceptible d'alteration, BNP Paribas (et ses 
> filiales) decline(nt) toute responsabilite au titre de ce message dans 
> l'hypothese ou il aurait ete modifie, deforme ou falsifie.
> N'imprimez ce message que si necessaire, pensez a l'environnement.
>

Re: tomcat MBeans in tomee embedded

Posted by Romain Manni-Bucau <rm...@gmail.com>.
tomee embedded uses by default "Tomcat" instead of "Catalina". Alternative
is to use TomcatHelper.getServer() as entry point.


Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com>

2015-09-22 9:52 GMT-07:00 Yann BLAZART <ya...@externe.bnpparibas.com>
:

> Hello everybody.
>
> In my projects I need to know dynamically the remote port of the launched
> tomee-embedded (http/https).
>
> For that I user the following code :
> private Integer[] detectPort() {
>         Integer [] ports = new Integer[]{-1,-1};
>         try {
>             MBeanServer mBeanServer =
> MBeanServerFactory.findMBeanServer(null).get(0);
>             ObjectName name = new ObjectName("Catalina", "type", "Server");
>             Server server = (Server) mBeanServer.getAttribute(name,
> "managedResource");
>
>             Service[] services = server.findServices();
>             for (Service service : services) {
>                 for (Connector connector : service.findConnectors()) {
>                     ProtocolHandler protocolHandler =
> connector.getProtocolHandler();
>                     if (protocolHandler instanceof Http11Protocol
>                             || protocolHandler instanceof Http11AprProtocol
>                             || protocolHandler instanceof
> Http11NioProtocol) {
>                         if ( connector.getSecure() ) {
>                             ports[1] = connector.getPort();
>                         } else {
>                             ports[0]=connector.getPort();
>                         }
>                     }
>                 }
>             }
>         } catch (MalformedObjectNameException | MBeanException |
> AttributeNotFoundException | InstanceNotFoundException |
> ReflectionException ex) {
>             throw new EJBException(ex);
>         }
>         return ports;
>     }
>
>
> But this doesn't work with the tome-embedded plugin,.
>
> I readed that for tomcat I need to add <Listener
> className="org.apache.catalina.mbeans.ServerLifecycleListener" />
> In server.xml
>
> How can I do with tome embedded ?
>
>
> This message and any attachments (the "message") is
> intended solely for the intended addressees and is confidential.
> If you receive this message in error,or are not the intended recipient(s),
> please delete it and any copies from your systems and immediately notify
> the sender. Any unauthorized view, use that does not comply with its
> purpose,
> dissemination or disclosure, either whole or partial, is prohibited. Since
> the internet
> cannot guarantee the integrity of this message which may not be reliable,
> BNP PARIBAS
> (and its subsidiaries) shall not be liable for the message if modified,
> changed or falsified.
> Do not print this message unless it is necessary,consider the environment.
>
>
> ----------------------------------------------------------------------------------------------------------------------------------
>
> Ce message et toutes les pieces jointes (ci-apres le "message")
> sont etablis a l'intention exclusive de ses destinataires et sont
> confidentiels.
> Si vous recevez ce message par erreur ou s'il ne vous est pas destine,
> merci de le detruire ainsi que toute copie de votre systeme et d'en avertir
> immediatement l'expediteur. Toute lecture non autorisee, toute utilisation
> de
> ce message qui n'est pas conforme a sa destination, toute diffusion ou
> toute
> publication, totale ou partielle, est interdite. L'Internet ne permettant
> pas d'assurer
> l'integrite de ce message electronique susceptible d'alteration, BNP
> Paribas
> (et ses filiales) decline(nt) toute responsabilite au titre de ce message
> dans l'hypothese
> ou il aurait ete modifie, deforme ou falsifie.
> N'imprimez ce message que si necessaire, pensez a l'environnement.
>