Pages

Thursday, December 13, 2012

Migration from Jetty to Glassfish is finished successfully!

It was quite a long journey. More than a month. The road-map looks approximately as such:
need to improve unit testability -> need for injection framework -> Guice arkwardness -> CDI arkwardness -> fall back to Guice -> Guice restrictions -> fall back to CDI -> Jetty+CDI arkwardess (which I've still made working) -> Glassfish. There were somewhere in the middle investigations of Scala cake pattern, but it turned not so comprehensive as injection frameworks.
See previous post for some details.

Some several years old log of my attempts to choose dependency injection framework, if I remember correctly. *Nostalgic

Guice + JSF problems:
1. Bean fields resolving
2. Mess up with order of initialization of Eager servlets, Eager beans, Context creation listeners.
3. Field injection doen't works with scala default constructors if injected fields are used immediately.
4. It should be used in conjuction with guice servlet module.
5. Note: Every servlet (or filter) is required to be a @Singleton. If you cannot annotate the class directly, you must bind it using bind(..).in(Singleton.class), separate to the filter() or servlet() rules. //http://code.google.com/p/google-guice/wiki/ServletModule
6. Guice servlet doesn't tolerate filters (at least) in web.xml. They should be moved to configServlets.
7. Guice configureServlets doesn't provide a whole replacement for web.xml
8. serve(...).with(classOf[javax.faces.webapp.FacesServlet]) - won't, because it requires HttpServlet.
9. There is no mention of JSF on Guice referense site. Guice development looks abandoned.
10. The implementation of EL variable resolver (GuiceResolver) is incomplete. It doesn't provide setters etc.


6,7,8 looks like a design flow, i.e. following this design we will have a lot of mess.

CDI troubles.
1. Seems bounded to WebSphere, IBM and proprietary marketing.
2. Problems with eager singletons. There is no alternative to JSF's @ManagedBean(eager=true)
3. To solve 2 I decided to use CODI cause here http://stackoverflow.com/questions/7828987/jsf-named-bean-eager-application-scoped-aka-managedbeaneager-true/7903857#7903857 some guy promises it will help.
4. Got error while initializing of CODI.
"no org.apache.myfaces.extensions.cdi.core.api.provider.BeanManagerProvider in place! Please ensure that you configured the CDI implementation of your choice properly. If your setup is correct, please clear all caches and compiled artifacts. If there is still a problem, try one of the controlled bootstrapping add-ons for the CDI implementation you are using."
==========================================
After poking for half an hour around found this
https://cwiki.apache.org/EXTCDI/workarounds-for-containers.html
without any links of bootstrap addons. Another 15 minutes:
http://code.google.com/a/apache-extras.org/p/myfaces-codi-addons/
Copypasted one class.
Got some progress but with many exceptions. Seems maven failed to resolve dependencies:
=====================================================
java.lang.ClassNotFoundException: org.eclipse.jetty.servlet.ServletContextHandler$Decorator

It looks tha this class is missing starting from Jetty 7.2. See similar problems http://s237.codeinspot.com/q/2679795
The previous suggestion is wrong the true reason is:
Jetty-server 8.0.1... package resolved dependency to jetty-servlet 3.0.... instead of 8.0...
Jetty-server pom.xml doesn't specify version of jetty-servlet.
I've made maven exclusion. Although m2e seems failing maintain up to date project config. I mean pom.xml doesn't always correspond to runned instance.
=======================================================
java.lang.ClassNotFoundException: javax.validation.Validator
java.lang.ClassNotFoundException: javax.validation.MessageInterpolator

Added validation-api : 1.0.0.GA
========================================================
Got:
java.lang.ClassNotFoundException: javax.persistence.EntityManager

Added javax.persistence from eclipse
=======================================================
Got exceptions that passivating beans must be serializable. Added 'implements Serializable' without analizyng if someone needs cusome serialization.

Got 10 validation exceptions about unsatisfyed injection dependensies.
Fixing...
1. WELD-001408 Unsatisfied dependencies for type ...
Fix: add @Produces methods to some beans.

2. WELD-001435 Normal scoped bean class alehro.{mysite}.background.BackgroundTasksSupervisor is not proxyable because it has no no-args constructor
Fix: add no-args constructors for the sake of internal features of Weld: http://stackoverflow.com/a/7584762/585819.
==========================================================
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Trying Glassfish
Got error while trying to deploy {mySite}:
[#|2012-11-23T01:32:25.422+0300|FINE|glassfish3.1.2|javax.enterprise.resource.webcontainer.jsf.config|_ThreadID=20;_ThreadName=Thread-2;ClassName=com.sun.faces.config.WebConfiguration;MethodName=processJndiEntries;|javax.naming.NamingException: Lookup failed for 'java:comp/env/ClientStateSavingPassword' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: No object bound to name java:comp/env/ClientStateSavingPassword]|#]

Probably it's because I'm new to JNDI. Solution:
Recreate all from scratch Create project
http://www.tech-juice.org/2012/05/13/hello-world-with-jsf-2-0-glassfish-3-maven-svn-and-eclipse/

================================================================
Another big trouble while starting with Glassfish 3.1.2.
Averybody says that beans.xml can be empty. But it shouldn't. guessnumber oracle's example won't deploy with errors. But my code taken from tutorial
http://www.tech-juice.org/2012/05/13/hello-world-with-jsf-2-0-glassfish-3-maven-svn-and-eclipse/
just silently doesn't work. #{helloWord.greetings} doesn't get calculated.
I made a mistake: beans.xml instead of bean.xml. IT WAS STUPID, STUPID - error killed another half a day. guessnumber helped.

The reeason of failed deploy: <listener-class>org.apacheExtras.myfaces.codi.addon.weld.startup.WeldAwareConfigurationListener</listener-class>
in web.xml
======================================================================
Cannot use arquillian with glassfish. Have exception durin deployment of tests:

[#|2012-11-28T23:23:37.468+0400|SEVERE|glassfish3.1.2|javax.enterprise.system.tools.admin.org.glassfish.deployment.admin|_ThreadID=103;_ThreadName=Thread-2;|Exception while loading the app : javax.ejb.CreateException: Initialization failed for Singleton StartUpSettings
javax.ejb.CreateException: Initialization failed for Singleton StartUpSettings
at com.sun.ejb.containers.AbstractSingletonContainer.createSingletonEJB(AbstractSingletonContainer.java:547)
...
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.NullPointerException
at java.util.concurrent.ConcurrentHashMap.hash(ConcurrentHashMap.java:332)
...
|#]

Friday, July 15, 2011

Moving my little home page to Google sites

Here is it alehro00.com. Registering at Google sites forced me to do it with new Google account. Juggling of Google accounts really sucks.

Saturday, July 9, 2011

How do I handle multipart form data? or How do I handle file uploads to my app?

Google App Engine for Java Questions - Google App Engine - Google Code
How do I handle multipart form data? or How do I handle file uploads to my app?

You can obtain the uploaded file data from a multipart form post using classes from the Apache Commons FileUpload package. Specifically you may want to use FileItemStream, FileItermIterator and ServletFileUpload as illustrated below.

If you see a java.lang.NoClassDefFoundError after starting your application, make sure that the Apache Commons FileUpload JAR file has been copied to your war/WEB-INF/lib directory and added to your build path.

import org.apache.commons.fileupload.FileItemStream;

Friday, July 1, 2011

Finished native build of vorbis library for android.

http://code.google.com/p/vorbis-android/

Encodes fast like a hell. At least ten times faster than java encoder.

Monday, June 27, 2011

Voice recording and playing on Android.

I need free voice recorder app for Android. Unfortunately there isn't such app on the market powerful enough. All applications I've tried missed record pause/continue functionality. So, I decided to take ready solution (http://code.google.com/p/diktofon/) and add some features. Because it uses AudioRecord adding the pause/continue recording functionality wasn't a problem. So, it's done.
But saving audio to wav files, i.e. without compression takes a lot of space (1 MByte per minute). And I decided to compress the audio. I've tried two solutions JSpeex and oggDroid.
It turned that they are both two slow.
So, I've added two commands to context menu of files list in the Diktofon. They are "Continue recording" and "Compress record".
"Continue recording" allows to continue recording of any wav file with the same settings as current settings. This command works well.
"Compress record" allows to convert wav file to ogg file (ogg is open source audio codec supported in the Android). But currently this command works very slow. E.g. it converts 1 minute speech for about 10 minutes. Although at the current release converting freezes app's GUI completely.
Here is my release: http://alehro.com/distr/advvoicerecorder/Diktofon.apk

Thursday, December 17, 2009

Radiation, particles transport.

http://www.fluka.org/fluka.php

http://www-rsicc.ornl.gov/rsiccnew/CodesAvailableElsewhere.htm

http://www.nea.fr/html/dbprog/peneloperef.html //not available for using