[Javassist user questions] - Using Javassist on J2ME MIDlets
by zortag
I would like to use Javassist to modify existing JAD/JAR files for J2ME MIDlets. (Yes I will have permission from the vendor to do this - all the legal considerations are taken care of). Basically I want to display some things to the user before the actual MIDlet runs. I plan to add some extra classes to the MIDlet that do this. These extra classes use basic MIDP 1.0 functionality, nothing fancy at all. But to make the existing MIDlet call these classes, I will need to modify the class specified in the JAD file that extends MIDlet. Let me call this the "original MIDlet class". I need to modify the original MIDlet class startApp() method so that the first thing it does when the app gets launched is to call a method in my extra classes to show this code to the user. When the code in the extra class finishes, it will call the original MIDlet startApp() method again, which will know this time just to execute what was originally there, ie to load and launch the game or app in the MIDlet. I left out a few details but I think you get the idea.
Here are my questions.
How exactly do I run Javassist on a JAR file?
The MIDlet JAR file contains preverified classes. Can I use Javassist on preverified classes?
It looks like Javassist writes the modified class back out to disk. I want to get the modified class file, preverfied, back into the JAR file. What must I do to do this? Must I preverify everything again? Or is the new class already preverified?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4115775#4115775
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4115775
18 years, 3 months
[Beginners Corner] - Re: Getting rebooted: migration from Middlegen to Hibernate
by mjhammel
Finally - success.
There were two problems. The first was a brain fart on my part. I wasn't calling the Ant task that checked if the mysql-connector was installed. Once called, the connector was properly installed to server/default/lib, which is the correct location (at least it works for my situation).
The second problem is that the connector must be installed before JBOSS is started. It can't be hot deployed. So after copying in the connector I restarted JBOSS. Then I deployed my ear file. And it worked.
Well, at least there are no errors on deployment.
So, now, all the config stuff is in place. Enough so that I can start looking at writing meaningful server code once again. I still need to write a sample client to make sure I can get to the initial web services interface. That would be the last infrastructure check, I think. After that it's back to server meat and new features, like implementing a cron-like system using the Timer Service.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4115774#4115774
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4115774
18 years, 3 months
[Persistence, JBoss/CMP, Hibernate, Database] - Re: Connection with active local transaction being reused?
by brent.atkinson
Ok, after digging a little deeper it appears that there were really multiple things going on and while they appeared to be connected they weren't. I have been able to reproduce the issue by setting up a similar (but simpler) application that uses a similarly configured datasource. I simulate the disconnected database by setting a breakpoint after the getConnection() call to get the connection and enabling an IPSec policy that blocks all traffic to the target database.
First, the sticky transaction issue was taken care of by converting from the JDBC transaction programming style to using UserTransaction. I believe (please correct me if I am wrong), this succeeds because the UserTransaction rollback when the underlying connection is closed still cleans up. The JDBC style transaction throws an exception when trying to rollback (because the connection is closed) and so whatever hooks that usually cleanup don't complete. This results in an unfinished local JTA transaction being associated with the connection. Once I changed to using JTA transaction handling using the pattern shown in the wiki at http://www.jboss.com/wiki/Wiki.jsp?page=WhatIsTheCorrectPatternForUserTra..., I no longer get the "Unfinished local transaction" messages. This however, did not fix the problem of the closed connection still being handed out as if it was connected, effectively killing all the applications using the connection pool.
I worked around the dead connection in the pool by configuring my datasource like the following:
<datasources>
| <local-tx-datasource>
| <jndi-name>jdbc/AppName</jndi-name>
|
| <connection-url>
| jdbc:oracle:thin:@host:1521:DEV
| </connection-url>
| <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
|
| <!-- This checks the connections are good before handing them out -->
| <valid-connection-checker-class-name>
| org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker
| </valid-connection-checker-class-name>
|
| <exception-sorter-class-name>
| org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter
| </exception-sorter-class-name>
| <metadata>
| <type-mapping>Oracle9i</type-mapping>
| </metadata>
| </local-tx-datasource>
| </datasources>
Once configured this way, I ran my test again and I now see this after the call to getConnection():
12:01:57,656 INFO [SampleJTAServlet] getting connection from datasource
| 12:01:57,656 WARN [TxConnectionManager] Connection error occured: org.jboss.resource.connectionmanager.TxConnectionManager$TxConnectionEventListener@1ecbac8[state=NORMAL mc=org.jboss.resource.adapter.jdbc.local.LocalManagedConnection@6c9b2 handles=0 lastUse=1198774893984 permit=false trackByTx=false mcp=org.jboss.resource.connectionmanager.JBossManagedConnectionPool$OnePool@1a3d58b context=org.jboss.resource.connectionmanager.InternalManagedConnectionPool@118a7e0 xaResource=org.jboss.resource.connectionmanager.TxConnectionManager$LocalXAResource@1b59c1b txSync=null]
| java.sql.SQLException: pingDatabase failed status=-1
| at org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker.isValidConnection(OracleValidConnectionChecker.java:72)
| at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnectionFactory.isValidConnection(BaseWrapperManagedConnectionFactory.java:435)
| at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.checkValid(BaseWrapperManagedConnection.java:231)
| at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.matchManagedConnections(LocalManagedConnectionFactory.java:200)
| at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.getConnection(InternalManagedConnectionPool.java:209)
| at org.jboss.resource.connectionmanager.JBossManagedConnectionPool$BasePool.getConnection(JBossManagedConnectionPool.java:529)
| at org.jboss.resource.connectionmanager.BaseConnectionManager2.getManagedConnection(BaseConnectionManager2.java:341)
| at org.jboss.resource.connectionmanager.TxConnectionManager.getManagedConnection(TxConnectionManager.java:301)
| at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:396)
| at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:842)
| at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:88)
| at pkg.sample.SampleJTAServlet.doGet(SampleJTAServlet.java:70)
| at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
| at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
| at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
| at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
| at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
| at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
| at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
| at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
| at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
| at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
| at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
| at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
| at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
| at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
| at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
| at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
| at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
| at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
| at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
| at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
| at java.lang.Thread.run(Thread.java:595)
| 12:01:57,671 WARN [JBossManagedConnectionPool] Destroying connection that could not be successfully matched: org.jboss.resource.connectionmanager.TxConnectionManager$TxConnectionEventListener@1ecbac8[state=DESTROYED mc=org.jboss.resource.adapter.jdbc.local.LocalManagedConnection@6c9b2 handles=0 lastUse=1198774893984 permit=false trackByTx=false mcp=org.jboss.resource.connectionmanager.JBossManagedConnectionPool$OnePool@1a3d58b context=org.jboss.resource.connectionmanager.InternalManagedConnectionPool@118a7e0 xaResource=org.jboss.resource.connectionmanager.TxConnectionManager$LocalXAResource@1b59c1b txSync=null]
The query then continues as normal and the transaction completes - problem(s) solved. I am still left with the question, why doesn't the connection pool cleanup the managed connection when usage of it results in a connection closed SQLException? The solution I used seems to handle it ok, but it needs to check on every access rather than lazily being handled when the exception occurs. Am I missing something obvious here?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4115770#4115770
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4115770
18 years, 3 months
[Persistence, JBoss/CMP, Hibernate, Database] - Cascade Delete
by javacory
I'm trying to delete a child object in a @OneToMany relationship and the persistence manager is not removing the child from the database.
The @OneToMany side is mapped as such:
@OneToMany(cascade=CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "parent")
The child is mapped as such:
@ManyToOne
@JoinColumn(name = "PARENT_ID")
The code I'm using to do this is (em is the EntityManager):
Query query = em.createQuery( "... " );
Parent parent = (RawDaar) query.getSingleResult();
parent.getChildren().remove(0);
em.persist( parent );
I noticed the child delete SQL is not generated and when I find the parent back ( after an em.flush() & em.clear() ), the child still exists.
If I do a em.remove( child ), that works, but I didn't think I needed that.
Environment:
EJB3
JBoss 4.2.0GA
Thanks much,
Cory.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4115769#4115769
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4115769
18 years, 3 months
[Beginners Corner] - Re: Getting rebooted: migration from Middlegen to Hibernate
by mjhammel
Well, that one was easy, thanks to this post:
https://www.manning-sandbox.com/message.jspa?messageID=56075
I just added the configuration to my persistence.xml file:
<persistence>
| <persistence-unit name="crunch">
| <jta-data-source>java:/CrunchDS</jta-data-source>
| <properties>
| <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
| <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
| <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
| <property name="hibernate.connection.url" value="jdbc:mysql://localhost/crunch"/>
| <property name="hibernate.connection.username" value="blah"/>
| </properties>
| </persistence-unit>
| </persistence>
The EAR is now deployed, albeit with a huge number of exceptions. I think the problem now is that the location of the mysql-connector jar file (mysql-connector-java-5.0.5-bin.jar) needs to be changed. I used to put it in server/default/lib but I get these errors on the deploy:
| 11:38:11,319 INFO [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=CrunchDS' to JNDI name 'java:CrunchDS'
| 11:38:11,339 INFO [EARDeployer] Init J2EE application: file:/home/mjhammel/src/cei/jboss-4.2.2.GA-cei/server/default/deploy/Crunch.ear
| 11:38:11,422 INFO [JmxKernelAbstraction] creating wrapper delegate for: org.jboss.ejb3.entity.PersistenceUnitDeployment
| 11:38:11,423 INFO [JmxKernelAbstraction] installing MBean: persistence.units:ear=Crunch.ear,unitName=crunch with dependencies:
| 11:38:11,423 INFO [JmxKernelAbstraction] jboss.jca:name=CrunchDS,service=DataSourceBinding
| 11:38:11,425 INFO [PersistenceUnitDeployment] Starting persistence unit persistence.units:ear=Crunch.ear,unitName=crunch
| 11:38:11,436 INFO [Configuration] Reading mappings from resource : META-INF/orm.xml
| 11:38:11,437 INFO [Ejb3Configuration] [PersistenceUnit: crunch] no META-INF/orm.xml found
| 11:38:11,443 INFO [ConnectionProviderFactory] Initializing connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
| 11:38:11,444 INFO [InjectedDataSourceConnectionProvider] Using provided datasource
| 11:38:11,447 WARN [JBossManagedConnectionPool] Throwable while attempting to get a new connection: null
| org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (org.jboss.resource.JBossResourceException: Failed to register driver for: com.mysql.jdbc.Driver; - nested throwable: (java.lang.ClassNotFoundException: No ClassLoaders found for: com.mysql.jdbc.Driver))
The HSQL jar files all seem to be in server/default/lib, so my gut feeling is that the mysql-connector jar file is also supposed to go here. If so, then this problem is not about the connector.
More googling....
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4115768#4115768
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4115768
18 years, 3 months
[Beginners Corner] - Re: Getting rebooted: migration from Middlegen to Hibernate
by mjhammel
The DataSourceBinding problem turned out to be another config file location change between 4.0.5GA and 4.2.2GA. In 4.0.5GA the mysql-ds.xml file was copied to server/default/conf. In 4.2.2GA it needs to go into server/default/deploy. Once I made this change, I got further along - now I'm being told I need to specify the Hibernate dialect. I already did this for the build in the db.properties file, but now I need to find out where to specify it in the deploy.
My db.properties:
mjhammel(tty2)$ cat config/hibernate/db.properties
| hibernate.dialect = org.hibernate.dialect.MySQLDialect
| hibernate.connection.driver_class = com.mysql.jdbc.Driver
| hibernate.connection.url = jdbc:mysql://localhost/crunch
| hibernate.connection.username = root
|
I'm guessing I need to specify the dialect in the mysql-ds.xml file, though I'm not sure of that yet and I don't know the syntax for specifying the syntax. Time for more googling....
The latest error messages from the JBOSS console:
| --- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM ---
| ObjectName: persistence.units:ear=Crunch.ear,unitName=crunch
| State: FAILED
| Reason: javax.persistence.PersistenceException: org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
| I Depend On:
| jboss.jca:service=DataSourceBinding,name=CrunchDS
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4115765#4115765
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4115765
18 years, 3 months
[Beginners Corner] - ClassNotFoundException whereas the JAR is here!
by sarbogast
I have a classloading issue with an EAR application. It contains:
| * spring-2.0.7.jar
| * myapp-core.jar
| * myapp-web.war
|
In myapp-web.war, there is a WEB-INF/web.xml file with the following:
| <web-app>
| <!-- ... -->
| <listener>
| <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
| </listener>
|
| <context-param>
| <param-name>contextConfigLocation</param-name>
| <param-value>
| classpath:applicationContext.xml
| </param-value>
| </context-param>
| </web-app>
|
And applicationContext.xml (Spring configuration file) resides in myapp-core.jar, with the following section:
| <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
| <property name="dataSource"><ref bean="dataSource"/></property>
| <property name="mappingLocations"><ref bean="hibernateMappingLocations"/></property>
| <property name="hibernateProperties"><ref bean="hibernateProperties"/></property>
| </bean>
|
And LocalSessionFactoryBean class resides in spring-2.0.7.
Yet, when I start up my application, I get the following exception:
| 19:05:52,534 ERROR [ContextLoader] Context initialization failed
| org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.orm.hibernate3.LocalSessionFactoryBean] for bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.orm.hibernate3.LocalSessionFactoryBean
| Caused by:
| java.lang.ClassNotFoundException: org.springframework.orm.hibernate3.LocalSessionFactoryBean
| at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358)
| ...
|
And I can't figure out why I get this ClassNotFoundException since spring-2.0.7.jar is here, at the root of the EAR.
Can somebody help me out with that, because I don't understand how EAR classpath works?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4115764#4115764
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4115764
18 years, 3 months
[JBoss Tools (users)] - injection in tests ?
by berkay
Hi.
Want to test my action classes with hibernateSession instead of EntityManager and my actions like below..
|
| @In(create=true)
| private Session hibernateSession;
|
| @Out @In(required=false)
| Category category;
|
| public String save(){
| //bla bla
| hibernateSession.saveOrUpdate(category);
| hibernateSession.flush();
| return "success";
| }
|
when i want to test this action with testNG, hibernate session doesnt initialize..
@Test
| public void testAddCategory() throws Exception {
| Category cat = new Category();
| cat.setName("test");
| CategoryAction action = new CategoryAction();
| action.setCategory(cat);
| //
| assert "categoryTree".equals(action.save());//throws nullpointer because of the not initialized hibernate session
| }
|
and according to me seam doesn't works while testing because Logger and In annotation doesnt works either..
All the examples are about EntityManagerFactory & EntityManager..
How can i find a solution for this test case with hibernate session ??
thanx.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4115763#4115763
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4115763
18 years, 3 months