La ricerca JNDI per la JTA UserTransaction non è disponibile per le discussioni MBean in WebSphere Application Server 7

StackOverflow https://stackoverflow.com/questions/8343533

  •  27-10-2019
  •  | 
  •  

Domanda

Sto cercando di richiamare la logica di business tramite JMX (usando MBeans 'standard') in un'applicazione web in WebSphere Application Server 7 con JTA acceso e vorrei sapere perché questa logica di business non può vedere il JTA UserTransaction quando invocato da un MBean (perché può quando viene richiamata tramite l'interfaccia utente del web app).

Quando ibernazione tentativi per cercare l'UserTransaction via 'java: comp / UserTransaction', viene lanciata la seguente eccezione:

org.hibernate.TransactionException: Could not find UserTransaction in JNDI [java:comp/UserTransaction]
    at org.hibernate.transaction.JTATransactionFactory.getUserTransaction(JTATransactionFactory.java:173)
    at org.hibernate.transaction.JTATransactionFactory.createTransaction(JTATransactionFactory.java:149)

    ...

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at java.lang.reflect.Method.invoke(Method.java:600)
    at com.sun.jmx.mbeanserver.StandardMBeanIntrospector.invokeM2(StandardMBeanIntrospector.java:105)
    at com.sun.jmx.mbeanserver.StandardMBeanIntrospector.invokeM2(StandardMBeanIntrospector.java:39)
    at com.sun.jmx.mbeanserver.MBeanIntrospector.invokeM(MBeanIntrospector.java:220)
    at com.sun.jmx.mbeanserver.PerInterface.getAttribute(PerInterface.java:77)
    at com.sun.jmx.mbeanserver.MBeanSupport.getAttribute(MBeanSupport.java:228)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getAttribute(DefaultMBeanServerInterceptor.java:678)
    at com.sun.jmx.mbeanserver.JmxMBeanServer.getAttribute(JmxMBeanServer.java:650)
    at com.ibm.ws.management.AdminServiceImpl.getAttribute(AdminServiceImpl.java:853)
    at com.ibm.ws.management.remote.AdminServiceForwarder.getAttribute(AdminServiceForwarder.java:270)
    at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1415)
    at javax.management.remote.rmi.RMIConnectionImpl.access$200(RMIConnectionImpl.java:84)
    at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1276)
    at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1371)
    at javax.management.remote.rmi.RMIConnectionImpl.getAttribute(RMIConnectionImpl.java:612)
    at javax.management.remote.rmi._RMIConnectionImpl_Tie.getAttribute(_RMIConnectionImpl_Tie.java:578)
    at javax.management.remote.rmi._RMIConnectionImpl_Tie._invoke(_RMIConnectionImpl_Tie.java:98)
    at com.ibm.CORBA.iiop.ServerDelegate.dispatchInvokeHandler(ServerDelegate.java:622)
    at com.ibm.CORBA.iiop.ServerDelegate.dispatch(ServerDelegate.java:475)
    at com.ibm.rmi.iiop.ORB.process(ORB.java:513)
    at com.ibm.CORBA.iiop.ORB.process(ORB.java:1574)
    at com.ibm.rmi.iiop.Connection.respondTo(Connection.java:2841)
    at com.ibm.rmi.iiop.Connection.doWork(Connection.java:2714)
    at com.ibm.rmi.iiop.WorkUnitImpl.doWork(WorkUnitImpl.java:63)
    at com.ibm.ejs.oa.pool.PooledThread.run(ThreadPool.java:118)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1563)
Caused by: javax.naming.ConfigurationException: A JNDI operation on a "java:" name cannot be completed because the server runtime is not able to associate the operation's thread with any J2EE application component.  This condition can occur when the JNDI client using the "java:" name is not executed on the thread of a server application request.  Make sure that a J2EE application does not execute JNDI operations on "java:" names within static code blocks or in threads created by that J2EE application.  Such code does not necessarily run on the thread of a server application request and therefore is not supported by JNDI operations on "java:" names. [Root exception is javax.naming.NameNotFoundException: Name "comp/UserTransaction" not found in context "java:".]
    at com.ibm.ws.naming.java.javaURLContextImpl.throwConfigurationExceptionWithDefaultJavaNS(javaURLContextImpl.java:428)
    at com.ibm.ws.naming.java.javaURLContextImpl.lookup(javaURLContextImpl.java:399)
    at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:214)
    at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:154)
    at javax.naming.InitialContext.lookup(InitialContext.java:455)
    at org.hibernate.transaction.JTATransactionFactory.getUserTransaction(JTATransactionFactory.java:163)
    ... 53 more
Caused by: javax.naming.NameNotFoundException: Name "comp/UserTransaction" not found in context "java:".
    at com.ibm.ws.naming.ipbase.NameSpace.lookupInternal(NameSpace.java:1178)
    at com.ibm.ws.naming.ipbase.NameSpace.lookup(NameSpace.java:1095)
    at com.ibm.ws.naming.urlbase.UrlContextImpl.lookup(UrlContextImpl.java:1233)
    at com.ibm.ws.naming.java.javaURLContextImpl.lookup(javaURLContextImpl.java:395)
    ... 57 more

Questo problema sembra che sia più di un semplice problema di configurazione hibernate - hibernate sta cercando l'UserTransaction a quello che diciamo IBM è la posizione JNDI corretta UserTransaction ( 'java: comp / UserTransaction') - vedi questo documento infocenter .

Inoltre, posso riprodurre il problema in una semplice applicazione web che ha un MBean che fa la ricerca:

public class JTALookup extends NotificationBroadcasterSupport implements JTALookupMBean {
  Log log = LogFactory.getLog(JTALookup.class);

  /**
   * {@inheritDoc}
   * @see JTALookupMBean#lookupUserTransaction()
   */
  @Override
  public void lookupUserTransaction() {
    try {
      log.info("Attempting 'java:comp/UserTransaction' lookup");
      Object usrTxn = new InitialContext().lookup("java:comp/UserTransaction");
      log.info("Successfully looked up 'java:comp/UserTransaction' [" + usrTxn + "]." );
    } catch (NamingException e) {
      log.info("'java:comp/UserTransaction' lookup failed");
      throw new RuntimeException("Failed to lookup JTA user transaction", e);
    }
  }

e un ascoltatore contesto che richiama la ricerca durante l'avvio e poi registra la MBean:

public void contextInitialized(ServletContextEvent sce) {

    log.info("Initialising context");

    JTALookup jtaLookup = new JTALookup();
    jtaLookup.lookupUserTransaction(); // This succeeds
    log.info("Looked up JTA transaction");

    MBeanServer mbServer = AdminServiceFactory.getMBeanFactory().getMBeanServer();
    log.info("Got MBeanServer");

    try {
      mbServer.registerMBean(jtaLookup, new ObjectName("webJTALookupStub:type=JTALookup"));
      log.info("Registered dummy MBean");
    } catch (Exception e) {
      log.info("Failed to register dummy MBean");
      throw new RuntimeException("Failed to register dummy MBean", e);
    }
}

La ricerca su 'java: comp / UserTransaction' riesce durante l'inizializzazione contesto, ma non riesce (con una simile traccia dello stack a quello sopra) quando viene richiamato tramite JMX, in questo modo:

public static void main(String[] args) {

    JMXServiceURL url = new JMXServiceURL(
        "service:jmx:rmi://" + "your.server.name.co.uk" + ":" + "2809" + "/jndi/JMXConnector"
    );

    Hashtable<String, Object> env = new Hashtable<String, Object>();
    env.put(Context.PROVIDER_URL, "corbaloc:iiop:gbbldd66.sys.chp.co.uk:2809/WsnAdminNameService");
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");

    // Establish the JMX connection.
    JMXConnector jmxc = JMXConnectorFactory.connect(url, env);

    // Get the MBean server connection instance.
    MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();

    ObjectName mbeanName = new ObjectName("webJTALookupStub:type=JTALookup");

    JTALookupMBean mBean = JMX.newMBeanProxy(mbsc, mbeanName, JTALookupMBean.class, true);

    mBean.lookupUserTransaction(); // This fails

Il 'l'estensione del sistema di gestione di WebSphere Application Server con MBean personalizzati' documento nel call-centre di IBM suggerisce che MBeans standard, che sono stati testati in applicazioni all'esterno era dovrebbe funzionare.

IBM fare affermano che la ricerca UserTransaction non è disponibile per:

  • fagioli CMT Enterprise `http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=/com.ibm.websphere.base.doc/info/aes/ae /cjta_glotran.html

  • Fagioli Async creati da EJB `http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/topic/com.ibm.websphere.javadoc.doc/web/apidocs/com/ibm/ websphere / asynchbeans / package-summary.html? resultof =% 22% 61% 73% 79% 6e% 63% 68% 62% 65% 61% 6e% 22% 20% 22% 75% 73% 65% 72% 74 % 72% 61% 6e% 73% 61% 63% 74% 69% 6f% 6e% 22% 20% 22% 75% 73% 65% 72% 74% 72% 61% 6e% 73% 61% 63% 74 % 22% 20

Ci scusiamo per i collegamenti non funzionali - io sono un nuovo utente e quindi possono postare solo due collegamenti di lavoro

.

Do vecchi MBeans pianura rientrano in una di queste categorie dal punto di vista di IBM?

È interessante notare che l'UserTransaction sembra essere accessibile ricerca JNDI 'JTA / UserTransaction' e utilizzando tale come opzione di ripiego sembra funzionare - ma:

  • ERA 7 è compatibile con Java EE 5 e, come di J2EE 1.3 'java: comp / UserTransaction' è la posizione JNDI specificato per l'UserTransaction - vedere la J2EE 1.3 spec `http://java.sun.com/ j2ee / j2ee-1_3-fr-spec.pdf

  • Utilizzo di una ricerca da una versione precedente delle specifiche EE sembra una potenziale fonte di altri insetti, e potrebbe essere affrontando solo una parte del mio problema - il fatto che è stato pensa filo di mia MBean non è associato a un'applicazione potrebbe causare altri problemi.

Un altro punto da notare è che l'UserTransaction è anche nascosto per le discussioni per il lavoro presentato dal MBean al responsabile lavoro dell'applicazione (un gestore di lavoro IBM) - che potrebbe essere perché è il trattamento che il lavoro come se fosse un bean asincrona presentata da un EJB?

Le possibili spiegazioni che si sono verificati a me sono:

  • Ci potrebbe problemi con IBM come impostare le discussioni MBean era 7 e associare quindi con le applicazioni che registrano i MBeans.

  • Ci potrebbero essere alcune opzioni di configurazione aggiuntive per la registrazione MBean che avrebbe lasciato era conosciuta che dovrebbe associare il MBean con l'applicazione che ha registrato esso. Ho provato diversi approac alternativahes ma ha visto la stessa eccezione ogni volta:

    • Registrazione dei MBeans con UserCollaborators e XML descrittori

    • li Registrazione con ModelMBeanInfo

    • li Registrati al AdminService piuttosto che il MBeanServer

    • Migliorare l'ObjectName per il MBean con proprietà aggiuntive (Application, J2EEApplication) al momento della registrazione

  • Ci potrebbero essere alcune opzioni di configurazione aggiuntive per la richiesta del client JMX che avrebbe lasciato era conosciuta che dovrebbe associare l'invocazione MBean con l'applicazione appropriata. Questo post forum suggerisce che è possibile configurare un'applicazione client per accedere al contesto iniziale: `http://www.ibm.com/developerworks/forums/thread.jspa?messageID=14021995

  • I potrebbe semplicemente non essere dovuto provare ad usare MBeans questo modo - nonostante le dichiarazioni di IBM che dovrei essere in grado di. E 'stato suggerito che gli EJB sono la soluzione appropriata per questo tipo di esigenza.

Qualsiasi luce che può essere gettata su questo problema sarebbe molto apprezzato.

È stato utile?

Soluzione

MBean eseguito su un thread separato che la vostra applicazione, in modo che non hanno accesso al contesto di applicazione di denominazione in JNDI, e quindi non hanno accesso al vostro UserTransaction.

Credo che la vostra spiegazione potenziale finale è probabilmente più precisa:

I potrebbe semplicemente non essere dovuto provare ad usare MBeans questo modo - nonostante le dichiarazioni di IBM che dovrei essere in grado di. E 'stato suggerito che gli EJB sono la soluzione appropriata per questo tipo di esigenza.

MBeans potrebbe non essere adatto per questo tipo di lavoro. Piuttosto, utilizzando EJB o un servizio web potrebbe essere più appropriato.

Altri suggerimenti

Devi TransactionManagementType.BEAN impostato su transactionManagement in questo modo:

@TransactionManagement(TransactionManagementType.BEAN) 
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top